Re: [RFC PATCH] lib/asn1_decoder: add KUnit test suite
From: William Chuang, Founder – Logarcheon
Date: Mon Nov 16 2026 - 21:39:46 EST
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@xxxxxxxxxx> 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
>