Re: [PATCH] net: skb: guard kmalloc_reserve() against oversized allocations

From: Andrew Lunn

Date: Sat Sep 20 2025 - 11:38:51 EST


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