mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kriish Sharma <kriish.sharma2006@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, willemb@google.com,
	kerneljasonxing@gmail.com, martin.lau@kernel.org, mhal@rbox.co,
	almasrymina@google.com, ebiggers@google.com,
	aleksander.lobakin@intel.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	skhan@linuxfoundation.org,
	Kriish Sharma <kriish.sharma2006@gmail.com>,
	syzbot+5a2250fd91b28106c37b@syzkaller.appspotmail.com
Subject: [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations
Date: Sat, 20 Sep 2025 20:11:38 +0000	[thread overview]
Message-ID: <20250920201138.402247-1-kriish.sharma2006@gmail.com> (raw)

Add an explicit size check in kmalloc_reserve() to reject requests
larger than KMALLOC_MAX_SIZE before they reach the allocator.

syzbot reported warnings triggered by attempts to allocate buffers
with an object size exceeding KMALLOC_MAX_SIZE. While the existing
code relies on kmalloc() failure and a comment states that truncation
is "harmless", in practice this causes high-order allocation warnings
and noisy kernel logs that interfere with testing.

This patch introduces an early guard in kmalloc_reserve() that returns
NULL if obj_size exceeds KMALLOC_MAX_SIZE. This ensures impossible
requests fail fast and silently, avoiding allocator warnings while
keeping the intended semantics unchanged.

Fixes: 7fa4d8dc380f ("Add linux-next specific files for 20250821")
Reported-by: syzbot+5a2250fd91b28106c37b@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=5a2250fd91b28106c37b

---
v2:
 - Add WARN_ONCE() to make oversized allocations visible

Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
---
 net/core/skbuff.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ee0274417948..70588f98c07e 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -591,6 +591,13 @@ static void *kmalloc_reserve(unsigned int *size, gfp_t flags, int node,
 	/* The following cast might truncate high-order bits of obj_size, this
 	 * is harmless because kmalloc(obj_size >= 2^32) will fail anyway.
 	 */
+	if (unlikely(obj_size > KMALLOC_MAX_SIZE)) {
+		WARN_ONCE(1,
+			  "%s: request size %zu exceeds KMALLOC_MAX_SIZE (%lu)\n",
+			  __func__, obj_size, KMALLOC_MAX_SIZE);
+		return NULL;
+	}
+
 	*size = (unsigned int)obj_size;
 
 	/*
-- 
2.34.1


             reply	other threads:[~2025-09-20 20:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-20 20:11 Kriish Sharma [this message]
2025-09-20 20:19 ` Eric Dumazet
2025-09-21  6:38 ` [syzbot ci] " syzbot ci

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=20250920201138.402247-1-kriish.sharma2006@gmail.com \
    --to=kriish.sharma2006@gmail.com \
    --cc=aleksander.lobakin@intel.com \
    --cc=almasrymina@google.com \
    --cc=davem@davemloft.net \
    --cc=ebiggers@google.com \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kerneljasonxing@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@kernel.org \
    --cc=mhal@rbox.co \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=skhan@linuxfoundation.org \
    --cc=syzbot+5a2250fd91b28106c37b@syzkaller.appspotmail.com \
    --cc=willemb@google.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

all inboxes | Powered by JetHome®