memory leak in build_skb

Status: upstream: reported syz repro on 2026/10/30 03:34
Subsystems: net
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+a3f21220cbbb6e14ee2e@syzkaller.appspotmail.com
First crash: 2d05h, last: 2d05h
✨ AI-generated root cause summary:
In IPsec IP-TFS (XFRM_MODE_IPTFS) processing, when inner packets (including the reused outer skb) are parsed and added to a temporary local 'sublist' during __input_process_payload(), any error encountering invalid header data or truncated payload jumps to 'done:'. At 'done:', packets on 'sublist' are neither delivered nor freed, and the reused outer skb is neither placed in 'defer' nor freed by kfree_skb(), permanently leaking the sk_buff and its attached sec_path extension.
▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 65ba8f34ec88:
### Root Cause Analysis #### 1. Overview of the Bug The reported bug is a permanent kernel memory leak of an `sk_buff` (size 240) and its attached `sec_path` extension `skb_ext` (size 192). The leak occurs in the IP-TFS (IP Traffic Flow Security, `XFRM_MODE_IPTFS`) encapsulation logic in `net/xfrm/xfrm_iptfs.c`. #### 2. Detailed Technical Walkthrough 1. **Packet Ingestion and Tunnel / ESP Processing**: An ESP packet received via a TUN interface is passed up through `tun_get_user()` -> `netif_receive_skb()` -> `ip_rcv()` -> `ip_protocol_deliver_rcu()` -> `xfrm4_esp_rcv()`. The VTI ESP protocol handler (`vti_rcv_proto()` / `vti_input()`) looks up the tunnel and invokes `xfrm_input(skb, nexthdr, spi, encap_type)`. 2. **XFRM Processing & IPTFS Handoff**: In `net/xfrm/xfrm_input.c:xfrm_input()`, a security path extension is allocated and attached to the skb via `secpath_set(skb)` at line 571 (the second leaked object, size 192). After ESP payload decryption (`esp_input()`), `xfrm_input()` calls `xfrm_inner_mode_input(x, skb)`. Because the SA mode is configured as `XFRM_MODE_IPTFS` (mode 5), it executes `iptfs_input()` (`net/xfrm/xfrm_iptfs.c:1724`). `iptfs_input()` takes ownership of the skb and returns `-EINPROGRESS`, which causes `xfrm_input()` to return `0` without freeing or dropping the skb. 3. **Packet Reassembly and Payload Processing**: `iptfs_input()` orders the incoming packet and calls `iptfs_input_ordered(x, skb)` (`net/xfrm/xfrm_iptfs.c:1225`). `iptfs_input_ordered()` initializes a local list on its stack frame (`struct list_head sublist; INIT_LIST_HEAD(&sublist);`) and calls `__input_process_payload(x, data, &skbseq, &sublist)`. 4. **The Root Cause Defect in `__input_process_payload()`**: Inside `__input_process_payload()` (`net/xfrm/xfrm_iptfs.c:950`): - In the while loop (`while (data < tail)`), the received linear `skb` is reused for the first inner packet (lines 1066–1094): `first_skb = skb;` `defer = NULL;` - The packet is prepared and added to the list of packets to be forwarded: `iptfs_complete_inner_skb(x, skb);` `list_add_tail(&skb->list, sublist);` (line 1178) - When the loop continues to evaluate the subsequent data block (such as trailing payload bytes, malformed padding, or subsequent inner packet headers), if an error occurs (such as `skb_copy_seq_read()` failure, invalid inner IP version `iph->version` not in {0, 4, 6}, or invalid header/packet length `iplen < iphlen`): ```c } else { XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR); goto done; } ``` Execution immediately jumps to `done:` (line 1201), skipping the packet transmission loop at line 1196 (`list_for_each_entry_safe(skb, next, sublist, list)`). - At label `done:`, cleanup logic only handles `defer` or `!first_skb`: ```c done: skb = skbseq->root_skb; skb_abort_seq_read(skbseq); if (defer) { consume_skb(defer); } else if (!first_skb) { kfree_skb(skb); } return true; ``` Because `first_skb` was set to `skb` and `defer` is `NULL`, neither branch is taken! Furthermore, `sublist` is never walked or drained. Any packets queued onto `sublist` (including `first_skb` and any reassembled packets added earlier by `iptfs_reassem_cont()`) remain linked in `sublist`. - `__input_process_payload()` returns `true`. In `iptfs_input_ordered()`, `consumed` is `true`, so `if (!consumed)` at line 1297 is not taken. - `iptfs_input_ordered()` returns, destroying the stack frame holding `sublist`. The hex dump in the leak report confirms this: `skb->next` and `skb->prev` contain `0xffffc900021f3890`, which is the exact address of `sublist` on the kernel thread stack. ### Classification and Impact - **RootCauseFiles**: `net/xfrm/xfrm_iptfs.c` contains the missing cleanup in `__input_process_payload()`. - **MemoryCorruption**: `false`. The unreferenced `sk_buff` and `sec_path` objects are orphaned on the heap without any surviving dangling pointers reachable by subsequent kernel operations; no invalid write, invalid free, or use-after-free occurs. - **InfoLeak**: `none`. The defect only leaks memory allocation slots, disclosing no kernel data to user space. - **RawDenialOfService**: `true`. Each malformed or unaligned IP-TFS packet causes permanent kernel heap exhaustion of `sk_buff` and `skb_ext` slab caches, eventually causing an out-of-memory denial of service. - **IsNetCandidate**: `true`. The bug is located in the XFRM IPsec networking subsystem and IP-TFS protocol processing. - **IsKVMCandidate**: `false`. The issue is unrelated to KVM or virtualization.
▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
39b6667f assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ✅ NetworkTrigger: ✅ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ✅ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ memory leak in build_skb 2026/10/28 09:56 2026/10/28 09:56 2026/10/28 11:04 96923c60
▶ ▼ Discussions (2)
Title Replies (including bot) Last reply
[syzbot] [net?] memory leak in build_skb 1 (3) 2026/10/30 08:49
[PATCH net] xfrm: iptfs: fix skb leak on error in __input_process_payload() 1 (1) 2026/10/30 08:33
▶ ▼ Last patch testing requests (1)
Created Duration User Patch Repo Result
2026/10/30 08:26 2m edumazet@kernel.org patch upstream error job log

Sample crash report:
2026/10/28 09:56:01 executed programs: 5
BUG: memory leak
unreferenced object 0xffff888104c73c00 (size 240):
  comm "syz.0.17", pid 5970, jiffies 4294947974
  hex dump (first 32 bytes):
    90 38 1f 02 00 c9 ff ff 90 38 1f 02 00 c9 ff ff  .8.......8......
    00 00 6a 24 81 88 ff ff 00 00 00 00 00 00 00 00  ..j$............
  backtrace (crc 84fdfeb5):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    slab_alloc_node mm/slub.c:5033 [inline]
    kmem_cache_alloc_noprof+0x35b/0x3e0 mm/slub.c:5047
    __build_skb net/core/skbuff.c:495 [inline]
    build_skb+0x25/0x120 net/core/skbuff.c:511
    __tun_build_skb drivers/net/tun.c:1631 [inline]
    tun_build_skb+0x489/0x770 drivers/net/tun.c:1726
    tun_get_user+0xd2e/0x2040 drivers/net/tun.c:1860
    tun_chr_write_iter+0x71/0x120 drivers/net/tun.c:2100
    new_sync_write fs/read_write.c:595 [inline]
    vfs_write+0x3ae/0x720 fs/read_write.c:687
    ksys_write+0xa5/0x170 fs/read_write.c:739
    do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
    do_syscall_64+0xe9/0x530 arch/x86/entry/syscall_64.c:84
    entry_SYSCALL_64_after_hwframe+0x77/0x7f

BUG: memory leak
unreferenced object 0xffff888104d139c0 (size 192):
  comm "syz.0.17", pid 5970, jiffies 4294947974
  hex dump (first 32 bytes):
    01 00 00 00 00 02 00 00 00 00 0b 00 00 00 00 00  ................
    80 9f 7b 24 81 88 ff ff 00 00 00 00 00 00 00 00  ..{$............
  backtrace (crc 420634a7):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    slab_alloc_node mm/slub.c:5033 [inline]
    kmem_cache_alloc_noprof+0x35b/0x3e0 mm/slub.c:5047
    __skb_ext_alloc+0x1a/0x50 net/core/skbuff.c:7246
    skb_ext_add+0x1a6/0x280 net/core/skbuff.c:7350
    secpath_set+0x7c/0xc0 net/xfrm/xfrm_input.c:127
    xfrm_input+0x381/0x28a0 net/xfrm/xfrm_input.c:571
    vti_input+0xf4/0x160 net/ipv4/ip_vti.c:69
    xfrm4_esp_rcv+0x46/0xb0 net/ipv4/xfrm4_protocol.c:104
    ip_protocol_deliver_rcu+0x259/0x260 net/ipv4/ip_input.c:207
    ip_local_deliver_finish+0x115/0x1e0 net/ipv4/ip_input.c:241
    NF_HOOK include/linux/netfilter.h:325 [inline]
    NF_HOOK include/linux/netfilter.h:319 [inline]
    ip_local_deliver+0x97/0x140 net/ipv4/ip_input.c:262
    dst_input include/net/dst.h:481 [inline]
    ip_rcv_finish net/ipv4/ip_input.c:492 [inline]
    NF_HOOK include/linux/netfilter.h:325 [inline]
    NF_HOOK include/linux/netfilter.h:319 [inline]
    ip_rcv+0x212/0x230 net/ipv4/ip_input.c:612
    __netif_receive_skb_one_core+0xce/0x100 net/core/dev.c:6405
    __netif_receive_skb+0x1d/0x80 net/core/dev.c:6518
    netif_receive_skb_internal net/core/dev.c:6604 [inline]
    netif_receive_skb+0x49/0x200 net/core/dev.c:6663
    tun_rx_batched drivers/net/tun.c:1575 [inline]
    tun_get_user+0x1ccc/0x2040 drivers/net/tun.c:2053
    tun_chr_write_iter+0x71/0x120 drivers/net/tun.c:2100

connection error: failed to recv *flatrpc.ExecutorMessageRawT: EOF

Crashes (1):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/10/28 09:56 upstream 65ba8f34ec88 96923c60 .config console log report syz / log [disk image] [vmlinux] [kernel image] ci-upstream-gce-leak memory leak in build_skb
* Struck through repros no longer work on HEAD.