Re: [PATCH] lib/asn1_encoder: fix encoding of zero OID components

From: Andrew Morton

Date: Tue Nov 24 2026 - 01:03:18 EST


On Fri, 20 Nov 2026 21:00:55 +0800 zzz <abc0eichs@xxxxxx> wrote:
>

Sorry, "zzz" isn't usable. See
Documentation/process/submitting-patches.rst under "Sign your
work":"using a known identity (sorry, no anonymous contributions.)".

So for now I'll rewrite this as From:me and Reported-by:zzz. Please
send a

Signed-off-by: Your Real Name <email@address>

as a reply-to-all to this message and I shall alter the attributions
appropriately.

> asn1_encode_oid_digit() encodes a zero component as 0x80, setting the
> continuation bit on its only octet. A trailing zero therefore produces
> an unterminated subidentifier, while an interior zero produces an
> overlong encoding of the following component.
>
> For example, 1.2.0 is encoded as 06 02 2a 80 instead of 06 02 2a 00.
> Emit zero without the continuation bit, as required for the final
> octet of a base-128 subidentifier.

Super-slim bug and it appears that nothing in the current tree uses
this code path. But a bug is a bug.

> Validation:
> - A local UML KUnit suite called the actual encoder with six OID
> vectors and short buffers. The original failed the zero-component
> vectors; the fixed kernel passed both subtests.

Feel free to send along a patch which adds a KUint test for the
asn1_decoder code.

> The sole current in-tree caller uses a fixed, nonzero TPM OID whose
> encoding is unchanged. This fixes the exported encoder's handling of
> valid zero components; it does not claim an observed TPM failure.

yup.

> --- a/lib/asn1_encoder.c
> +++ b/lib/asn1_encoder.c
> @@ -97,7 +97,7 @@ static int asn1_encode_oid_digit(unsigned char **_data, int *data_len, u32 oid)
>
> /* quick case */
> if (oid == 0) {
> - *data++ = 0x80;
> + *data++ = 0;
> (*data_len)--;
> goto out;
> }

Thanks, Added to the pile!