[PATCH net] tun: reject oversized skb head allocations
From: Zhao Gongyi
Date: Sat Nov 28 2026 - 21:05:54 EST
tun_alloc_skb() moves payload beyond the page-fragment capacity into
the linear head without checking the resulting allocation size.
If the head exceeds KMALLOC_MAX_SIZE, kmalloc_reserve() retries
without __GFP_NOWARN for tasks eligible for pfmemalloc reserves. This
can trigger a warning and panic when panic_on_warn is enabled:
WARNING: mm/slub.c:5459 at ___kmalloc_large_node+0x111/0x140
Call Trace:
kmalloc_reserve
__alloc_skb
alloc_skb_with_frags
sock_alloc_send_pskb
tun_get_user
tun_chr_write_iter
Reject requests whose aligned head, including headroom and
skb_shared_info, exceeds KMALLOC_MAX_SIZE with -EMSGSIZE before
allocation.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Link: https://lore.kernel.org/netdev/20261108180953.67715-1-yanhaishuang@xxxxxxxxxxxxxxxxxxxx/
Cc: stable@xxxxxxxxxxxxxxx
Cc: Haishuang Yan <yanhaishuang@xxxxxxxxxxxxxxxxxxxx>
Cc: Narcisa Vasile <narcisav.kernel@xxxxxxxxx>
Signed-off-by: Zhao Gongyi <zhaogongyi@xxxxxxxxxxxxx>
---
Full W=1 builds on net (x86-64, GCC 12.2.0) passed under
allyesconfig and allmodconfig with CONFIG_WERROR=n. With WERROR=y,
baseline and patched builds failed on the same existing warnings.
No new diagnostics were observed after applying the patch.
TUN/TAP selftests had identical A/B results: TUN 7 pass / 84 fail /
12 xfail; TAP 0 pass / 3 fail. Geneve and interface setup failures
limit regression coverage.
drivers/net/tun.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ae05b1e58..771c8bba8 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1570,6 +1570,9 @@ static struct sk_buff *tun_alloc_skb(struct tun_file *tfile,
if (len - linear > MAX_SKB_FRAGS * (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
linear = len - MAX_SKB_FRAGS * (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER);
+ if (unlikely(SKB_HEAD_ALIGN(prepad + linear) > KMALLOC_MAX_SIZE))
+ return ERR_PTR(-EMSGSIZE);
+
skb = sock_alloc_send_pskb(sk, prepad + linear, len - linear, noblock,
&err, PAGE_ALLOC_COSTLY_ORDER);
if (!skb)
base-commit: 28a371228d4eb4857cc31eeb1a0d7d01e9c3ea2f