Netdev List
 help / color / mirror / Atom feed
* [PATCH net] keys, dns: Limit the payload dump in dns_resolver_preparse()
@ 2026-12-02 12:31 Yingjie Wang
  2026-12-02 21:44 ` Jarkko Sakkinen
  0 siblings, 1 reply; 2+ messages in thread
From: Yingjie Wang @ 2026-12-02 12:31 UTC (permalink / raw)
  To: David Howells, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Simon Horman, Jarkko Sakkinen, keyrings@vger.kernel.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org

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@outlook.com>
---
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


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

end of thread, other threads:[~2026-12-02 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 12:31 [PATCH net] keys, dns: Limit the payload dump in dns_resolver_preparse() Yingjie Wang
2026-12-02 21:44 ` Jarkko Sakkinen

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