mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/asn1_encoder: fix encoding of zero OID components
@ 2026-11-20 13:00 zzz
  0 siblings, 0 replies; only message 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	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-20 13:02 UTC | newest]

Thread overview: (only message) (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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®