* [PATCH] net: skb: guard kmalloc_reserve() against oversized allocations
@ 2025-09-20 11:37 Kriish Sharma
2025-09-20 15:38 ` Andrew Lunn
0 siblings, 1 reply; 2+ messages in thread
From: Kriish Sharma @ 2025-09-20 11:37 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni, horms, willemb, kerneljasonxing,
martin.lau, mhal, almasrymina, ebiggers, aleksander.lobakin
Cc: netdev, linux-kernel, skhan, Kriish Sharma, syzbot+5a2250fd91b28106c37b
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
Signed-off-by: Kriish Sharma <kriish.sharma2006@gmail.com>
---
net/core/skbuff.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index ee0274417948..98efa95ea038 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -591,6 +591,8 @@ 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))
+ return NULL;
*size = (unsigned int)obj_size;
/*
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] net: skb: guard kmalloc_reserve() against oversized allocations
2025-09-20 11:37 [PATCH] net: skb: guard kmalloc_reserve() against oversized allocations Kriish Sharma
@ 2025-09-20 15:38 ` Andrew Lunn
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Lunn @ 2025-09-20 15:38 UTC (permalink / raw)
To: Kriish Sharma
Cc: davem, edumazet, kuba, pabeni, horms, willemb, kerneljasonxing,
martin.lau, mhal, almasrymina, ebiggers, aleksander.lobakin,
netdev, linux-kernel, skhan, syzbot+5a2250fd91b28106c37b
On Sat, Sep 20, 2025 at 11:37:23AM +0000, Kriish Sharma wrote:
> 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.
What is the value of KMALLOC_MAX_SIZE? Do we actually want a
warn_once() here because it indicates a driver bug, or missing
validation of user space parameters?
Andrew
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-20 15:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-20 11:37 [PATCH] net: skb: guard kmalloc_reserve() against oversized allocations Kriish Sharma
2025-09-20 15:38 ` Andrew Lunn
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®