Netdev List
 help / color / mirror / Atom feed
From: Yingjie Wang <x-professor@outlook.com>
To: David Howells <dhowells@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	Jarkko Sakkinen <jarkko@kernel.org>,
	"keyrings@vger.kernel.org" <keyrings@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH net] keys, dns: Limit the payload dump in dns_resolver_preparse()
Date: Wed, 2 Dec 2026 12:31:59 +0000	[thread overview]
Message-ID: <20261202123156.764901-1-x-professor@outlook.com> (raw)

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


             reply	other threads:[~2026-12-02 12:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 12:31 Yingjie Wang [this message]
2026-12-02 21:44 ` [PATCH net] keys, dns: Limit the payload dump in dns_resolver_preparse() Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202123156.764901-1-x-professor@outlook.com \
    --to=x-professor@outlook.com \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jarkko@kernel.org \
    --cc=keyrings@vger.kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox