* [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations
@ 2025-09-20 20:11 Kriish Sharma
2025-09-20 20:19 ` Eric Dumazet
2025-09-21 6:38 ` [syzbot ci] " syzbot ci
0 siblings, 2 replies; 3+ messages in thread
From: Kriish Sharma @ 2025-09-20 20:11 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
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations
2025-09-20 20:11 [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations Kriish Sharma
@ 2025-09-20 20:19 ` Eric Dumazet
2025-09-21 6:38 ` [syzbot ci] " syzbot ci
1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2025-09-20 20:19 UTC (permalink / raw)
To: Kriish Sharma
Cc: davem, kuba, pabeni, horms, willemb, kerneljasonxing, martin.lau,
mhal, almasrymina, ebiggers, aleksander.lobakin, netdev,
linux-kernel, skhan, syzbot+5a2250fd91b28106c37b
On Sat, Sep 20, 2025 at 1:12 PM Kriish Sharma
<kriish.sharma2006@gmail.com> 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.
>
> 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;
> + }
> +
You are essentially duplicating a warning, which already exists.
You can be sure syzbot will hit hit this warning.
Instead, please fix usbnet.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [syzbot ci] Re: [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations
2025-09-20 20:11 [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations Kriish Sharma
2025-09-20 20:19 ` Eric Dumazet
@ 2025-09-21 6:38 ` syzbot ci
1 sibling, 0 replies; 3+ messages in thread
From: syzbot ci @ 2025-09-21 6:38 UTC (permalink / raw)
To: aleksander.lobakin, almasrymina, davem, ebiggers, edumazet, horms,
kerneljasonxing, kriish.sharma2006, kuba, linux-kernel,
martin.lau, mhal, netdev, pabeni, skhan, syzbot, willemb
Cc: syzbot, syzkaller-bugs
syzbot ci has tested the following series
[v1] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations
https://lore.kernel.org/all/20250920201138.402247-1-kriish.sharma2006@gmail.com
* [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations
and found the following issues:
* WARNING in __alloc_skb
* WARNING in pskb_expand_head
Full report is available here:
https://ci.syzbot.org/series/3048e542-7fa8-46b3-8e97-499b35ec361d
***
WARNING in __alloc_skb
tree: net-next
URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netdev/net-next.git
base: 315f423be0d1ebe720d8fd4fa6bed68586b13d34
arch: amd64
compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
config: https://ci.syzbot.org/builds/3d048fda-1178-4af7-acb5-2eb1a391f26b/config
C repro: https://ci.syzbot.org/findings/64757740-d6bb-483c-8261-a190a051189b/c_repro
syz repro: https://ci.syzbot.org/findings/64757740-d6bb-483c-8261-a190a051189b/syz_repro
------------[ cut here ]------------
kmalloc_reserve: request size 2147480000 exceeds KMALLOC_MAX_SIZE (4194304)
WARNING: CPU: 0 PID: 5990 at net/core/skbuff.c:598 kmalloc_reserve+0x2df/0x2f0 net/core/skbuff.c:596
Modules linked in:
CPU: 0 UID: 0 PID: 5990 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
RIP: 0010:kmalloc_reserve+0x2df/0x2f0 net/core/skbuff.c:596
Code: ff e8 d5 4a 64 f8 c6 05 67 27 32 06 01 90 b9 00 00 40 00 48 c7 c7 a0 0b 94 8c 48 c7 c6 49 5a 96 8d 4c 89 ea e8 82 e7 27 f8 90 <0f> 0b 90 90 45 31 e4 e9 37 ff ff ff 0f 1f 44 00 00 90 90 90 90 90
RSP: 0018:ffffc90002c3f798 EFLAGS: 00010246
RAX: 6aef4e9a5451c800 RBX: dffffc0000000001 RCX: ffff8881079a5640
RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000002
RBP: ffffc90002c3f7e4 R08: ffff88804b024253 R09: 1ffff1100960484a
R10: dffffc0000000000 R11: ffffed100960484b R12: 000000007ffff080
R13: 000000007ffff1c0 R14: 0000000000000cc0 R15: 1ffff92000587efc
FS: 00005555874d6500(0000) GS:ffff8880b8613000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000200000006038 CR3: 000000010b696000 CR4: 00000000000006f0
Call Trace:
<TASK>
__alloc_skb+0x142/0x2d0 net/core/skbuff.c:677
alloc_skb include/linux/skbuff.h:1377 [inline]
sock_wmalloc+0xb2/0x130 net/core/sock.c:2798
pppol2tp_sendmsg+0x183/0x5f0 net/l2tp/l2tp_ppp.c:275
sock_sendmsg_nosec net/socket.c:714 [inline]
__sock_sendmsg+0x21c/0x270 net/socket.c:729
____sys_sendmsg+0x52d/0x830 net/socket.c:2614
___sys_sendmsg+0x21f/0x2a0 net/socket.c:2668
__sys_sendmmsg+0x227/0x430 net/socket.c:2757
__do_sys_sendmmsg net/socket.c:2784 [inline]
__se_sys_sendmmsg net/socket.c:2781 [inline]
__x64_sys_sendmmsg+0xa0/0xc0 net/socket.c:2781
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f45f258eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffda5a883d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000133
RAX: ffffffffffffffda RBX: 00007f45f27d5fa0 RCX: 00007f45f258eba9
RDX: 04000000000001ce RSI: 0000200000005f80 RDI: 0000000000000004
RBP: 00007f45f2611e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000008040 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f45f27d5fa0 R14: 00007f45f27d5fa0 R15: 0000000000000004
</TASK>
***
WARNING in pskb_expand_head
tree: net-next
URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/netdev/net-next.git
base: 315f423be0d1ebe720d8fd4fa6bed68586b13d34
arch: amd64
compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8
config: https://ci.syzbot.org/builds/3d048fda-1178-4af7-acb5-2eb1a391f26b/config
C repro: https://ci.syzbot.org/findings/951f3d6d-b4db-4f6e-b7e5-df8d3799b0ab/c_repro
syz repro: https://ci.syzbot.org/findings/951f3d6d-b4db-4f6e-b7e5-df8d3799b0ab/syz_repro
------------[ cut here ]------------
kmalloc_reserve: request size 4194368 exceeds KMALLOC_MAX_SIZE (4194304)
WARNING: CPU: 1 PID: 5991 at net/core/skbuff.c:598 kmalloc_reserve+0x2df/0x2f0 net/core/skbuff.c:596
Modules linked in:
CPU: 1 UID: 0 PID: 5991 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
RIP: 0010:kmalloc_reserve+0x2df/0x2f0 net/core/skbuff.c:596
Code: ff e8 d5 4a 64 f8 c6 05 67 27 32 06 01 90 b9 00 00 40 00 48 c7 c7 a0 0b 94 8c 48 c7 c6 49 5a 96 8d 4c 89 ea e8 82 e7 27 f8 90 <0f> 0b 90 90 45 31 e4 e9 37 ff ff ff 0f 1f 44 00 00 90 90 90 90 90
RSP: 0018:ffffc90003b9f6d8 EFLAGS: 00010246
RAX: a130a6a821c6fc00 RBX: dffffc0000000001 RCX: ffff88802051b980
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000002
RBP: ffffc90003b9f794 R08: ffff888136624253 R09: 1ffff11026cc484a
R10: dffffc0000000000 R11: ffffed1026cc484b R12: 00000000003fff00
R13: 0000000000400040 R14: 0000000000000820 R15: 1ffff92000773ef2
FS: 00005555572cd500(0000) GS:ffff8881a3c13000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000001b30b63fff CR3: 0000000027cee000 CR4: 00000000000006f0
Call Trace:
<TASK>
pskb_expand_head+0x18e/0x1150 net/core/skbuff.c:2248
__skb_cow include/linux/skbuff.h:3847 [inline]
skb_cow_head include/linux/skbuff.h:3881 [inline]
__vlan_insert_inner_tag include/linux/if_vlan.h:360 [inline]
__vlan_insert_tag include/linux/if_vlan.h:406 [inline]
skb_vlan_push+0x30a/0x8d0 net/core/skbuff.c:6390
____bpf_skb_vlan_push net/core/filter.c:3209 [inline]
bpf_skb_vlan_push+0x217/0x900 net/core/filter.c:3199
bpf_prog_db72096d6b827dfb+0x4c/0x55
bpf_dispatcher_nop_func include/linux/bpf.h:1335 [inline]
__bpf_prog_run include/linux/filter.h:718 [inline]
bpf_prog_run include/linux/filter.h:725 [inline]
bpf_test_run+0x318/0x7b0 net/bpf/test_run.c:434
bpf_prog_test_run_skb+0xb30/0x1560 net/bpf/test_run.c:1099
bpf_prog_test_run+0x2c7/0x340 kernel/bpf/syscall.c:4590
__sys_bpf+0x581/0x870 kernel/bpf/syscall.c:6047
__do_sys_bpf kernel/bpf/syscall.c:6139 [inline]
__se_sys_bpf kernel/bpf/syscall.c:6137 [inline]
__x64_sys_bpf+0x7c/0x90 kernel/bpf/syscall.c:6137
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0xfa/0x3b0 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7efd6458eba9
Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffe070e5238 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 00007efd647d5fa0 RCX: 00007efd6458eba9
RDX: 0000000000000050 RSI: 0000200000000180 RDI: 000000000000000a
RBP: 00007efd64611e19 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007efd647d5fa0 R14: 00007efd647d5fa0 R15: 0000000000000003
</TASK>
***
If these findings have caused you to resend the series or submit a
separate fix, please add the following tag to your commit message:
Tested-by: syzbot@syzkaller.appspotmail.com
---
This report is generated by a bot. It may contain errors.
syzbot ci engineers can be reached at syzkaller@googlegroups.com.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-21 6:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-20 20:11 [PATCH] [PATCH v2] net: skb: guard kmalloc_reserve() against oversized allocations Kriish Sharma
2025-09-20 20:19 ` Eric Dumazet
2025-09-21 6:38 ` [syzbot ci] " syzbot ci
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).