From: zzz <abc0eichs@qq.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, James.Bottomley@HansenPartnership.com
Subject: [PATCH] lib/asn1_encoder: fix encoding of zero OID components
Date: Fri, 20 Nov 2026 21:00:55 +0800 [thread overview]
Message-ID: <tencent_AFE15D698FFD4F18E16A6EF7CDA002D69806@qq.com> (raw)
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
reply other threads:[~2026-11-20 13:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_AFE15D698FFD4F18E16A6EF7CDA002D69806@qq.com \
--to=abc0eichs@qq.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®