* [PATCH] lib/asn1_encoder: fix encoding of zero OID components
@ 2026-11-20 13:00 zzz
2026-11-24 6:03 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: zzz @ 2026-11-20 13:00 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, James.Bottomley
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.
OpenAI Codex was used to inspect the encoder, implement the fix, and
prepare the reproducer, regression tests and change description.
Fixes: b07067627cd5 ("lib: Add ASN.1 encoder")
Signed-off-by: zzz <abc0eichs@qq.com>
---
Prompt summary: inspect current mainline for a reproducible bug and
prepare a kernel-source fix following the Linux submission rules.
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.
- GCC with ASan/UBSan: 45 checks of the actual source passed, covering
zero components, base-128 boundaries and output-buffer capacities.
- OpenSSL rejected the original 1.2.0 and 1.2.0.1 encodings and decoded
the corrected encodings successfully.
- x86_64 allnoconfig object build with W=1: no warnings.
- checkpatch --strict: clean, including the Signed-off-by tag.
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.
lib/asn1_encoder.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/asn1_encoder.c b/lib/asn1_encoder.c
index 92f35aae1..0cff56769 100644
--- 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;
}
base-commit: 65e4fd942f72a9dba0e4e257290c4fa1aa756854
--
2.42.0.windows.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lib/asn1_encoder: fix encoding of zero OID components
2026-11-20 13:00 [PATCH] lib/asn1_encoder: fix encoding of zero OID components zzz
@ 2026-11-24 6:03 ` Andrew Morton
2026-11-24 9:21 ` Jarkko Sakkinen
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2026-11-24 6:03 UTC (permalink / raw)
To: zzz
Cc: linux-kernel, James.Bottomley, Jarkko Sakkinen, David Howells,
keyrings, linux-integrity
On Fri, 20 Nov 2026 21:00:55 +0800 zzz <abc0eichs@qq.com> 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!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lib/asn1_encoder: fix encoding of zero OID components
2026-11-24 6:03 ` Andrew Morton
@ 2026-11-24 9:21 ` Jarkko Sakkinen
0 siblings, 0 replies; 3+ messages in thread
From: Jarkko Sakkinen @ 2026-11-24 9:21 UTC (permalink / raw)
To: Andrew Morton
Cc: zzz, linux-kernel, James.Bottomley, David Howells, keyrings,
linux-integrity
On Mon, Nov 23, 2026 at 10:03:11PM -0800, Andrew Morton wrote:
> > 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.
It's a good catch :-)
But yeah, we need a person, this is not anonymous/pseudonym project but
the change itself is apppreciated.
Br, Jarkko
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-24 9:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 13:00 [PATCH] lib/asn1_encoder: fix encoding of zero OID components zzz
2026-11-24 6:03 ` Andrew Morton
2026-11-24 9:21 ` Jarkko Sakkinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox