Re: [PATCH net] keys, dns: Limit the payload dump in dns_resolver_preparse()
From: Jarkko Sakkinen
Date: Wed Dec 02 2026 - 16:44:48 EST
On Wed, Dec 02, 2026 at 12:31:59PM +0000, Yingjie Wang wrote:
> With the dns_resolver "debug" module parameter set,
> dns_resolver_preparse() prints the whole key payload, using datalen as
> the "%*.*s" precision. add_key() accepts payloads of up to 1MiB - 1
> bytes, but vsnprintf() limits the precision to 32767, so a larger
> payload hits:
>
> precision 32768 too large
> WARNING: lib/vsprintf.c:2659 at vsnprintf+0x1019/0x12a0, CPU#0: repro/284
>
> With panic_on_warn, this panics the kernel. Once debugging is enabled,
> any user who can call add_key() can trigger it, because the payload is
> preparsed before the key quota is checked.
>
> Commit 9c438d7a3a52 ("KEYS: DNS: limit the length of option strings")
> fixed the same warning for option strings, but the entry trace still
> dumps the full payload.
>
> A printk record is limited to 1024 bytes anyway, so print at most the
> first 128 bytes of the payload. Its length is still printed, so the
> truncation remains visible. The field width only padded the output
> with spaces, so drop it.
>
> This bug was found by a fuzzer.
>
> Fixes: d46d494214ca ("KEYS: DNS: Use key preparsing")
> Signed-off-by: Yingjie Wang <x-professor@xxxxxxxxxxx>
> ---
> Tested on top of 4dce97c6c265 (x86_64, KASAN) with debug=1 and add_key()
> payloads from 128 bytes to 1MiB - 1 from an unprivileged user. Without
> this patch, a 32768-byte payload triggers the warning, and panics the
> kernel with panic_on_warn=1. With it, there is no warning at any size,
> the trace shows at most 128 bytes followed by the length, and add_key()
> returns the same results as before.
>
> Jarkko's "KEYS: Drop key_type_dead" series (v7) moves the key type into
> its own module but does not touch this line; this patch applies on top
> of it as well.
>
> net/dns_resolver/dns_key.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/dns_resolver/dns_key.c b/net/dns_resolver/dns_key.c
> index 451247864a63..c12bf47d6363 100644
> --- a/net/dns_resolver/dns_key.c
> +++ b/net/dns_resolver/dns_key.c
> @@ -121,7 +121,7 @@ dns_resolver_preparse(struct key_preparsed_payload *prep)
> goto store_result;
> }
>
> - kenter("'%*.*s',%u", datalen, datalen, data, datalen);
> + kenter("'%.*s',%u", min(datalen, 128), data, datalen);
>
> if (!data || data[datalen - 1] != '\0')
> return -EINVAL;
>
> base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
> --
> 2.43.0
>
Good catch. And these type of changes contribute to e.g., key_type_dead
removal a lot because they also "transmutate" patches on a healthy
vector. Messy but working code is also quality code IMHO. So no need to
disregard value of these changes at all.
If e.g., bug fix for instance gets deleted by some bigger change it
makes sure that "cuts are better" i.e., they accelarate quality.
I don't see anything upimportant in that; or I should stop
doing this if I ever think otherwise.
Reviewed-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
Br, Jarkko