Re: [RFC PATCH] lib/asn1_decoder: add KUnit test suite

From: Jarkko Sakkinen

Date: Mon Nov 16 2026 - 22:10:02 EST


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