The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [RFC PATCH] lib/asn1_decoder: add KUnit test suite
@ 2026-11-17  0:17 William Chuang
  2026-11-17  1:32 ` Jarkko Sakkinen
  0 siblings, 1 reply; 5+ messages in thread
From: William Chuang @ 2026-11-17  0:17 UTC (permalink / raw)
  To: Andrew Morton
  Cc: David Howells, keyrings, kunit-dev, linux-kernel, William Chuang

Add a KUnit test suite for the ASN.1 BER/DER decoder in
lib/asn1_decoder.c.  A tiny two-field grammar (SEQUENCE { INTEGER,
OCTET STRING }) drives asn1_ber_decoder() with well-formed and
malformed byte strings and checks that valid input is parsed and each
class of malformed input is rejected with the documented error code
rather than over-read.

The suite has 13 cases: one well-formed decode; eight malformed-input
rejections (truncation, length overrun, long tag, wrong tag, oversize,
short header, missing and malformed end-of-contents); three
success-path cases (indefinite length with end-of-contents, long-form
length, zero-length string); and one bounded deterministic
random-stress case whose callbacks assert that every slice handed back
lies within the input buffer (KASAN additionally catches any
over-read).

Tested with KUnit on UML:

  $ ./tools/testing/kunit/kunit.py run asn1_decoder
  ================ asn1_decoder (13 subtests) ================
  [PASSED] asn1_test_decode_valid
  ...
  ================== [PASSED] asn1_decoder ===================
  Testing complete. Ran 13 tests: passed: 13

This suite was developed with the assistance of an AI coding assistant
(Claude Opus 4.8): the test vectors and C were drafted with the
assistant and reviewed by hand, and this changelog was written with its
help.  Beyond the KUnit run above, the decoder was checked against the
suite with an independent verification kit -- exhaustive enumeration and
randomized, grammar-biased and coverage-guided (libFuzzer) fuzzing under
a guard page and KASAN/UBSan, CBMC bounded model checking of the real
decoder, and Coq and Lean models of the no-over-read invariant; no
over-read was found.  That kit is maintained separately and is not part
of this patch.  I understand the code and take responsibility for it.

Signed-off-by: William Chuang <founder@logarcheon.com>
---
 lib/Kconfig.debug              |  17 ++
 lib/tests/Makefile             |   4 +
 lib/tests/asn1_decoder_kunit.c | 360 +++++++++++++++++++++++++++++++++
 lib/tests/asn1_test.asn1       |  11 +
 4 files changed, 392 insertions(+)
 create mode 100644 lib/tests/asn1_decoder_kunit.c
 create mode 100644 lib/tests/asn1_test.asn1

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 2d22638ec13a6..f69025ae3cb9d 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -2998,6 +2998,23 @@ config BASE64_KUNIT
 
 	  If unsure, say N.
 
+config ASN1_DECODER_KUNIT_TEST
+	tristate "KUnit tests for the ASN.1 BER/DER decoder" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	select ASN1
+	help
+	  This builds the KUnit tests for the ASN.1 BER/DER decoder in
+	  lib/asn1_decoder.c.  A tiny grammar drives asn1_ber_decoder() with
+	  well-formed and malformed input and checks that valid input is
+	  parsed and each class of malformed input is rejected rather than
+	  over-read.
+
+	  For more information on KUnit and unit tests in general please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 config BITS_TEST
 	tristate "KUnit test for bit functions and macros" if !KUNIT_ALL_TESTS
 	depends on KUNIT
diff --git a/lib/tests/Makefile b/lib/tests/Makefile
index df0537e1b91fa..4e5b6016c4e4c 100644
--- a/lib/tests/Makefile
+++ b/lib/tests/Makefile
@@ -60,3 +60,7 @@ obj-$(CONFIG_RATELIMIT_KUNIT_TEST) += test_ratelimit.o
 obj-$(CONFIG_UUID_KUNIT_TEST) += uuid_kunit.o
 
 obj-$(CONFIG_TEST_RUNTIME_MODULE)		+= module/
+
+obj-$(CONFIG_ASN1_DECODER_KUNIT_TEST) += asn1_decoder_kunit_test.o
+asn1_decoder_kunit_test-y := asn1_decoder_kunit.o asn1_test.asn1.o
+$(obj)/asn1_decoder_kunit.o: $(obj)/asn1_test.asn1.h
diff --git a/lib/tests/asn1_decoder_kunit.c b/lib/tests/asn1_decoder_kunit.c
new file mode 100644
index 0000000000000..5196df7b281a3
--- /dev/null
+++ b/lib/tests/asn1_decoder_kunit.c
@@ -0,0 +1,360 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * KUnit tests for the ASN.1 BER/DER decoder in lib/asn1_decoder.c.
+ *
+ * A tiny grammar (asn1_test.asn1: SEQUENCE { INTEGER, OCTET STRING }) drives
+ * the decoder.  The cases feed well-formed and malformed DER byte strings to
+ * asn1_ber_decoder() and check that valid input is parsed and the action
+ * callbacks fire with the expected values, while each class of malformed input
+ * is rejected (rather than over-read) with the documented error code.
+ *
+ * Copyright (C) 2026 Logarcheon Inc.
+ */
+#include <kunit/test.h>
+#include <linux/asn1_decoder.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/string.h>
+
+#include "asn1_test.asn1.h"
+
+struct asn1_test_ctx {
+	unsigned int	int_calls;
+	unsigned int	str_calls;
+	u8		int_first;
+	size_t		str_len;
+	u8		str_buf[8];
+	/*
+	 * Optional slice oracle.  When @buf is set, every callback checks that
+	 * the (value, vlen) slice it is handed lies inside [buf, buf + buflen);
+	 * the stress case uses this to catch a bad slice directly, without
+	 * waiting for KASAN.  Tests that leave @buf NULL skip the check.
+	 */
+	const u8	*buf;
+	size_t		buflen;
+	bool		slice_oob;
+};
+
+static void asn1_test_check_slice(struct asn1_test_ctx *ctx,
+				  const void *value, size_t vlen)
+{
+	const u8 *v = value;
+
+	if (!ctx->buf || vlen == 0)
+		return;
+	if (v < ctx->buf || v + vlen > ctx->buf + ctx->buflen)
+		ctx->slice_oob = true;
+}
+
+/*
+ * Action callbacks referenced by asn1_test.asn1.  They must be non-static and
+ * match the names used in the grammar; asn1_test.asn1.h declares them.
+ */
+int asn1_test_note_int(void *context, size_t hdrlen, unsigned char tag,
+		       const void *value, size_t vlen)
+{
+	struct asn1_test_ctx *ctx = context;
+
+	ctx->int_calls++;
+	asn1_test_check_slice(ctx, value, vlen);
+	if (vlen >= 1)
+		ctx->int_first = ((const u8 *)value)[0];
+	return 0;
+}
+
+int asn1_test_note_str(void *context, size_t hdrlen, unsigned char tag,
+		       const void *value, size_t vlen)
+{
+	struct asn1_test_ctx *ctx = context;
+
+	ctx->str_calls++;
+	asn1_test_check_slice(ctx, value, vlen);
+	ctx->str_len = vlen;
+	if (vlen <= sizeof(ctx->str_buf))
+		memcpy(ctx->str_buf, value, vlen);
+	return 0;
+}
+
+/* SEQUENCE { INTEGER 0x2a, OCTET STRING "hi" } */
+static const u8 asn1_test_der_valid[] = {
+	0x30, 0x07,
+		0x02, 0x01, 0x2a,
+		0x04, 0x02, 0x68, 0x69,
+};
+
+/* A well-formed message is decoded and both actions fire with the right data. */
+static void asn1_test_decode_valid(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	int ret;
+
+	ret = asn1_ber_decoder(&asn1_test_decoder, &ctx,
+			       asn1_test_der_valid,
+			       sizeof(asn1_test_der_valid));
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, ctx.int_calls, 1u);
+	KUNIT_EXPECT_EQ(test, ctx.int_first, (u8)0x2a);
+	KUNIT_EXPECT_EQ(test, ctx.str_calls, 1u);
+	KUNIT_EXPECT_EQ(test, ctx.str_len, (size_t)2);
+	KUNIT_EXPECT_MEMEQ(test, ctx.str_buf, "hi", 2);
+}
+
+/* The SEQUENCE header claims 7 content octets but only 6 are present. */
+static void asn1_test_truncated_content(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x07,
+			0x02, 0x01, 0x2a,
+			0x04, 0x02, 0x68,	/* final octet missing */
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/* The INTEGER length (0x7f) runs past the end of the containing SEQUENCE. */
+static void asn1_test_length_overrun(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x03,
+			0x02, 0x7f, 0x00,
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/* A high-tag-number (long) tag form is not supported and must be rejected. */
+static void asn1_test_long_tag(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x03,
+			0x1f, 0x01, 0x00,	/* tag low 5 bits == 0x1f */
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/* A top-level tag that is not the expected SEQUENCE is rejected. */
+static void asn1_test_wrong_tag(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x31, 0x07,			/* SET instead of SEQUENCE */
+			0x02, 0x01, 0x2a,
+			0x04, 0x02, 0x68, 0x69,
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/* datalen above the decoder's 65535-octet ceiling returns -EMSGSIZE. */
+static void asn1_test_too_large(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	size_t len = 0x10000;		/* 65536 > 65535 */
+	u8 *buf;
+
+	buf = kzalloc(len, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, buf);
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx, buf, len),
+			-EMSGSIZE);
+	kfree(buf);
+}
+
+/* A buffer too short to hold even one tag+length header is rejected. */
+static void asn1_test_short_header(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = { 0x30 };
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/* Indefinite-length constructed form with no terminating EOC is rejected. */
+static void asn1_test_missing_eoc(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x80,			/* indefinite length */
+			0x02, 0x01, 0x2a,
+			0x04, 0x02, 0x68, 0x69,
+						/* no 0x00 0x00 EOC */
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/* An EOC marker with a non-zero length octet is rejected. */
+static void asn1_test_invalid_eoc(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x80,			/* indefinite length */
+			0x02, 0x01, 0x2a,
+			0x04, 0x02, 0x68, 0x69,
+			0x00, 0x01,		/* EOC with bad length */
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			-EBADMSG);
+}
+
+/*
+ * Indefinite-length constructed form terminated by a proper end-of-contents
+ * marker is accepted, and both actions fire.  This exercises the success path
+ * of the indefinite-length branch (the failure paths are covered above).
+ */
+static void asn1_test_indefinite_ok(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x80,			/* SEQUENCE, indefinite length */
+			0x02, 0x01, 0x2a,
+			0x04, 0x02, 0x68, 0x69,
+			0x00, 0x00,		/* end-of-contents */
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			0);
+	KUNIT_EXPECT_EQ(test, ctx.int_calls, 1u);
+	KUNIT_EXPECT_EQ(test, ctx.str_calls, 1u);
+	KUNIT_EXPECT_EQ(test, ctx.str_len, (size_t)2);
+}
+
+/* A two-octet (0x81) long-form length is parsed the same as the short form. */
+static void asn1_test_long_form_length(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x81, 0x07,		/* long-form length: 1 octet, 0x07 */
+			0x02, 0x01, 0x2a,
+			0x04, 0x02, 0x68, 0x69,
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			0);
+	KUNIT_EXPECT_EQ(test, ctx.int_first, (u8)0x2a);
+	KUNIT_EXPECT_EQ(test, ctx.str_len, (size_t)2);
+}
+
+/* A zero-length OCTET STRING is valid; the action fires with vlen == 0. */
+static void asn1_test_zero_length_string(struct kunit *test)
+{
+	struct asn1_test_ctx ctx = {};
+	static const u8 der[] = {
+		0x30, 0x05,
+			0x02, 0x01, 0x2a,
+			0x04, 0x00,		/* OCTET STRING of length 0 */
+	};
+
+	KUNIT_EXPECT_EQ(test,
+			asn1_ber_decoder(&asn1_test_decoder, &ctx,
+					 der, sizeof(der)),
+			0);
+	KUNIT_EXPECT_EQ(test, ctx.str_calls, 1u);
+	KUNIT_EXPECT_EQ(test, ctx.str_len, (size_t)0);
+}
+
+/*
+ * Bounded deterministic stress.  A fixed-seed xorshift PRNG drives a few
+ * thousand pseudo-random byte strings (lengths 0..255) through the decoder.
+ * The decoder must never crash, and whenever it reports success the slice
+ * oracle in the callbacks must not have seen an out-of-range (value, vlen).
+ * On a KASAN build any over-read is caught in addition to the oracle.  The
+ * seed and iteration count are fixed so the case is reproducible and runs in
+ * bounded time.
+ */
+static void asn1_test_random_stress(struct kunit *test)
+{
+	static const unsigned int iterations = 4096;
+	u32 state = 0x1a2b3c4du;		/* fixed seed: reproducible */
+	u8 *buf;
+	unsigned int i;
+
+	buf = kmalloc(256, GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, buf);
+
+	for (i = 0; i < iterations; i++) {
+		struct asn1_test_ctx ctx = {};
+		size_t len, j;
+		int ret;
+
+		state ^= state << 13;
+		state ^= state >> 17;
+		state ^= state << 5;
+		len = state % 256;
+
+		for (j = 0; j < len; j++) {
+			state ^= state << 13;
+			state ^= state >> 17;
+			state ^= state << 5;
+			buf[j] = state & 0xff;
+		}
+
+		ctx.buf = buf;
+		ctx.buflen = len;
+		ret = asn1_ber_decoder(&asn1_test_decoder, &ctx, buf, len);
+
+		/* Any return is acceptable; a bad slice on success is not. */
+		if (ret == 0)
+			KUNIT_EXPECT_FALSE(test, ctx.slice_oob);
+		else
+			KUNIT_EXPECT_LT(test, ret, 0);
+	}
+
+	kfree(buf);
+}
+
+static struct kunit_case asn1_decoder_test_cases[] = {
+	KUNIT_CASE(asn1_test_decode_valid),
+	KUNIT_CASE(asn1_test_truncated_content),
+	KUNIT_CASE(asn1_test_length_overrun),
+	KUNIT_CASE(asn1_test_long_tag),
+	KUNIT_CASE(asn1_test_wrong_tag),
+	KUNIT_CASE(asn1_test_too_large),
+	KUNIT_CASE(asn1_test_short_header),
+	KUNIT_CASE(asn1_test_missing_eoc),
+	KUNIT_CASE(asn1_test_invalid_eoc),
+	KUNIT_CASE(asn1_test_indefinite_ok),
+	KUNIT_CASE(asn1_test_long_form_length),
+	KUNIT_CASE(asn1_test_zero_length_string),
+	KUNIT_CASE(asn1_test_random_stress),
+	{}
+};
+
+static struct kunit_suite asn1_decoder_test_suite = {
+	.name = "asn1_decoder",
+	.test_cases = asn1_decoder_test_cases,
+};
+
+kunit_test_suite(asn1_decoder_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for the ASN.1 BER/DER decoder");
+MODULE_LICENSE("GPL");
diff --git a/lib/tests/asn1_test.asn1 b/lib/tests/asn1_test.asn1
new file mode 100644
index 0000000000000..b3da8041a5b2a
--- /dev/null
+++ b/lib/tests/asn1_test.asn1
@@ -0,0 +1,11 @@
+-- SPDX-License-Identifier: GPL-2.0-or-later
+--
+-- Minimal grammar used only by the ASN.1 decoder KUnit tests
+-- (lib/tests/asn1_decoder_kunit.c).  It exercises a constructed type, a
+-- primitive INTEGER and a primitive OCTET STRING, each with an action, which
+-- is enough to drive the decoder's tag/length handling and action dispatch.
+
+TestData ::= SEQUENCE {
+	num	INTEGER ({ asn1_test_note_int }),
+	str	OCTET STRING ({ asn1_test_note_str })
+	}

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] lib/asn1_decoder: add KUnit test suite
  2026-11-17  0:17 [RFC PATCH] lib/asn1_decoder: add KUnit test suite William Chuang
@ 2026-11-17  1:32 ` Jarkko Sakkinen
  2026-11-17  2:39   ` William Chuang, Founder – Logarcheon
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17  1:32 UTC (permalink / raw)
  To: William Chuang
  Cc: Andrew Morton, David Howells, keyrings, kunit-dev, linux-kernel

On Tue, Nov 17, 2026 at 12:17:17AM +0000, William Chuang wrote:
> Add a KUnit test suite for the ASN.1 BER/DER decoder in
> lib/asn1_decoder.c.  A tiny two-field grammar (SEQUENCE { INTEGER,
> OCTET STRING }) drives asn1_ber_decoder() with well-formed and
> malformed byte strings and checks that valid input is parsed and each
> class of malformed input is rejected with the documented error code
> rather than over-read.

1. I'm not convinced. Why overall?
2. Why KUnit?
3. Why host the test in kernel?

Br, Jarkko

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] lib/asn1_decoder: add KUnit test suite
  2026-11-17  1:32 ` Jarkko Sakkinen
@ 2026-11-17  2:39   ` William Chuang, Founder – Logarcheon
  2026-11-17  3:09     ` Jarkko Sakkinen
  0 siblings, 1 reply; 5+ messages in thread
From: William Chuang, Founder – Logarcheon @ 2026-11-17  2:39 UTC (permalink / raw)
  To: Jarkko Sakkinen
  Cc: Andrew Morton, David Howells, keyrings, kunit-dev, linux-kernel

Fair questions.

Why at all: asn1_ber_decoder() parses untrusted ASN.1 BER/DER input. X.509 certificates (keyrings) and PKCS#7 signatures (module signing) both go through it, and it has had a length-validation bug of this kind before — CVE-2016-0758, in asn1_find_indefinite_length(). 
Scope: the suite checks that malformed and truncated input is rejected rather than over-read, in the cases it exercises. It does not reproduce that CVE or prove the decoder memory-safe. That it isn’t vacuous: I weakened one bounds check in asn1_decoder.c to allow a short over-read. asn1_test_truncated_content then fails its return-value check — the decoder accepts a truncated SEQUENCE (returns 0 instead of -EBADMSG). The other 12 cases pass; reverting restores 13/13.

Why KUnit: it exercises the in-kernel decoder directly, with no
userspace harness, and the cases can also run under KASAN/UBSAN
(verified in my config). It is deterministic and is not built into production kernels.

Why in-kernel: the coverage travels with the code. An out-of-tree test does not run when someone changes lib/asn1_decoder.c.

I agree the maintenance has to be justified by the coverage. If the current cases are too thin to carry, I’m happy to strengthen or narrow them on your feedback.

Thanks,
William



On Monday, November 16th, 2026 at 6:32 PM, Jarkko Sakkinen <jarkko@kernel.org> wrote:

> On Tue, Nov 17, 2026 at 12:17:17AM +0000, William Chuang wrote:
> > Add a KUnit test suite for the ASN.1 BER/DER decoder in
> > lib/asn1_decoder.c.  A tiny two-field grammar (SEQUENCE { INTEGER,
> > OCTET STRING }) drives asn1_ber_decoder() with well-formed and
> > malformed byte strings and checks that valid input is parsed and each
> > class of malformed input is rejected with the documented error code
> > rather than over-read.
>
> 1. I'm not convinced. Why overall?
> 2. Why KUnit?
> 3. Why host the test in kernel?
>
> Br, Jarkko
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] lib/asn1_decoder: add KUnit test suite
  2026-11-17  2:39   ` William Chuang, Founder – Logarcheon
@ 2026-11-17  3:09     ` Jarkko Sakkinen
  2026-11-17  3:24       ` Jarkko Sakkinen
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17  3:09 UTC (permalink / raw)
  To: William Chuang, Founder – Logarcheon
  Cc: Andrew Morton, David Howells, keyrings, kunit-dev, linux-kernel

On Tue, Nov 17, 2026 at 02:39:37AM +0000, William Chuang, Founder – Logarcheon wrote:
> Fair questions.
> 
> Why at all: asn1_ber_decoder() parses untrusted ASN.1 BER/DER input. X.509 certificates (keyrings) and PKCS#7 signatures (module signing) both go through it, and it has had a length-validation bug of this kind before — CVE-2016-0758, in asn1_find_indefinite_length(). 
> Scope: the suite checks that malformed and truncated input is rejected rather than over-read, in the cases it exercises. It does not reproduce that CVE or prove the decoder memory-safe. That it isn’t vacuous: I weakened one bounds check in asn1_decoder.c to allow a short over-read. asn1_test_truncated_content then fails its return-value check — the decoder accepts a truncated SEQUENCE (returns 0 instead of -EBADMSG). The other 12 cases pass; reverting restores 13/13.
> 
> Why KUnit: it exercises the in-kernel decoder directly, with no
> userspace harness, and the cases can also run under KASAN/UBSAN
> (verified in my config). It is deterministic and is not built into production kernels.
> 
> Why in-kernel: the coverage travels with the code. An out-of-tree test does not run when someone changes lib/asn1_decoder.c.
> 
> I agree the maintenance has to be justified by the coverage. If the current cases are too thin to carry, I’m happy to strengthen or narrow them on your feedback.
> 
> Thanks,
> William

I'd start by learning to use the email client properly at first:

https://docs.kernel.org/process/email-clients.html

Br, Jarkko

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RFC PATCH] lib/asn1_decoder: add KUnit test suite
  2026-11-17  3:09     ` Jarkko Sakkinen
@ 2026-11-17  3:24       ` Jarkko Sakkinen
  0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2026-11-17  3:24 UTC (permalink / raw)
  To: William Chuang, Founder – Logarcheon
  Cc: Andrew Morton, David Howells, keyrings, kunit-dev, linux-kernel

On Tue, Nov 17, 2026 at 05:09:57AM +0200, Jarkko Sakkinen wrote:
> On Tue, Nov 17, 2026 at 02:39:37AM +0000, William Chuang, Founder – Logarcheon wrote:
> > Fair questions.
> > 
> > Why at all: asn1_ber_decoder() parses untrusted ASN.1 BER/DER input. X.509 certificates (keyrings) and PKCS#7 signatures (module signing) both go through it, and it has had a length-validation bug of this kind before — CVE-2016-0758, in asn1_find_indefinite_length(). 
> > Scope: the suite checks that malformed and truncated input is rejected rather than over-read, in the cases it exercises. It does not reproduce that CVE or prove the decoder memory-safe. That it isn’t vacuous: I weakened one bounds check in asn1_decoder.c to allow a short over-read. asn1_test_truncated_content then fails its return-value check — the decoder accepts a truncated SEQUENCE (returns 0 instead of -EBADMSG). The other 12 cases pass; reverting restores 13/13.
> > 
> > Why KUnit: it exercises the in-kernel decoder directly, with no
> > userspace harness, and the cases can also run under KASAN/UBSAN
> > (verified in my config). It is deterministic and is not built into production kernels.
> > 
> > Why in-kernel: the coverage travels with the code. An out-of-tree test does not run when someone changes lib/asn1_decoder.c.
> > 
> > I agree the maintenance has to be justified by the coverage. If the current cases are too thin to carry, I’m happy to strengthen or narrow them on your feedback.
> > 
> > Thanks,
> > William
> 
> I'd start by learning to use the email client properly at first:
> 
> https://docs.kernel.org/process/email-clients.html

Within past 17 years the total number of commits is 22. This includes
all the possible. Of these total six carry a Fixes tag.

That makes about 0.35 bug fixes annually. How do you explain this?

For me this looks whole a lot like LLM lottery i.e., sending random
and useless patches in the hopes that something might happen to get
in.

Your previous kunit supports this point of view given that it is
a possible "LLM remix" of a patch (kunit for assoc_array) that I
sent a month ago but we discarded the idea in favor of a better
solution.

Stop doing this.

Br, Jarkko

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-17  3:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17  0:17 [RFC PATCH] lib/asn1_decoder: add KUnit test suite William Chuang
2026-11-17  1:32 ` Jarkko Sakkinen
2026-11-17  2:39   ` William Chuang, Founder – Logarcheon
2026-11-17  3:09     ` Jarkko Sakkinen
2026-11-17  3:24       ` Jarkko Sakkinen

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