memory leak in napi_get_frags (2)

Status: moderation: reported syz repro on 2026/12/02 00:54
Subsystems: nfc
Labels: prio:low
[Documentation on labels]
Reported-by: syzbot+ed04e0ee3d751c897ff2@syzkaller.appspotmail.com
First crash: 1h48m, last: 1h48m
✨ AI-generated root cause summary:

In drivers/nfc/nfcmrvl/usb.c, nfcmrvl_usb_nci_send() relies on the URB completion callback nfcmrvl_tx_complete() to free the transmitted sk_buff via kfree_skb(skb), but fails to free skb when URB allocation or submission fails. When triggered via NFC_CMD_DEV_UP on a USB device whose bulk OUT endpoint has wMaxPacketSize == 0, usb_submit_urb() rejects the URB with -EMSGSIZE, so nfcmrvl_tx_complete() never runs and the sk_buff allocated by nci_send_cmd() (along with its kmalloc_reserve() head buffer) is leaked. The callers (nfcmrvl_nci_send(), nci_send_frame(), and nci_cmd_work()) hand skb ownership to ndev->ops->send() and do not free it on error.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 19cc08c1a6a6:

Root Cause Analysis

The memory leak is caused by missing sk_buff cleanup on error paths in nfcmrvl_usb_nci_send() (drivers/nfc/nfcmrvl/usb.c).

Object Lifecycle and Broken Invariant

In the NCI core, nci_send_frame() (net/nfc/nci/core.c:1369-1386) transfers ownership of the struct sk_buff to ndev->ops->send(ndev, skb). Callers such as nci_cmd_work() (net/nfc/nci/core.c:1633) and nci_tx_work() (net/nfc/nci/core.c:1549) ignore the return value of nci_send_frame(), and nfcmrvl_nci_send() (drivers/nfc/nfcmrvl/main.c:48-68) sets skb->dev = (void *)ndev and delegates directly to priv->if_ops->nci_send(priv, skb). Consequently, the transport driver's nci_send implementation is responsible for freeing skb on both success and failure (as done in nfcmrvl_i2c_nci_send() in drivers/nfc/nfcmrvl/i2c.c:139-145 and other NCI drivers such as fdp_nci_send() and nxp_nci_send()).

In drivers/nfc/nfcmrvl/usb.c, nfcmrvl_usb_nci_send() (lines 219–264) normally relies on the URB completion callback nfcmrvl_tx_complete() (lines 146–163) to free skb via kfree_skb(skb) (with urb->context = skb). However, nfcmrvl_usb_nci_send() fails to free skb whenever nfcmrvl_tx_complete() is not reached:

  1. If !drv_data->bulk_tx_ep (lines 227–228) or usb_alloc_urb() fails (lines 230–232), it returns -ENODEV / -ENOMEM without calling kfree_skb(skb).
  2. When usb_submit_urb(urb, GFP_ATOMIC) fails (lines 250–257), nfcmrvl_tx_complete() is never invoked. The error handler only calls kfree(urb->setup_packet), usb_unanchor_urb(urb), and usb_free_urb(urb), leaving skb unfreed (and drv_data->tx_in_flight incremented by nfcmrvl_inc_tx() at line 240 without a matching decrement).
  3. Similarly, if an URB is anchored on &drv_data->deferred while NFCMRVL_USB_SUSPENDING is set (lines 240–246) and later discarded in nfcmrvl_play_deferred() (lines 372–397) or unanchored via usb_scuttle_anchored_urbs(&drv_data->deferred) in nfcmrvl_usb_nci_close() (line 215) / nfcmrvl_resume() (line 430), urb->context (skb) is never freed.

How the Reproducer Triggers the Leak

  1. syz_usb_connect attaches a virtual USB device matching nfcmrvl_table (0x1286:0x2046, interface class 0xff, subclass 4, protocol 1 in drivers/nfc/nfcmrvl/usb.c:15-18). Its bulk OUT endpoint (0x01) has wMaxPacketSize == 0. nfcmrvl_probe() (drivers/nfc/nfcmrvl/usb.c:285-330) only checks that bulk RX/TX endpoints exist via usb_find_common_endpoints(), so registration succeeds.
  2. Sending NFC_CMD_DEV_UP invokes nfc_genl_dev_up() -> nfc_dev_up() -> nci_dev_up() -> nci_open_device() (net/nfc/nci/core.c:474-552), which opens the driver and calls __nci_request(ndev, nci_reset_req, ...).
  3. nci_reset_req() calls nci_send_cmd() (net/nfc/nci/core.c:1390-1418), which allocates a struct sk_buff via nci_skb_alloc() -> alloc_skb() -> __alloc_skb() (net/core/skbuff.c:675-746) and writes the 4-byte NCI_OP_CORE_RESET_CMD (20 00 01 01 seen in the second kmemleak hex dump) into skb->head (allocated via kmalloc_reserve(), size 704).
    • Note on the two kmemleak records: the first record (0xffff88810de57c00, size 240, allocated via napi_skb_cache_get() during an earlier wg_peer_create() -> napi_get_frags_check()) is the struct sk_buff itself, which was placed into the per-CPU napi_alloc_cache and later popped by __alloc_skb() (napi_skb_cache_get(false) at net/core/skbuff.c:699). Its hex dump shows skb->dev at offset 16 (0xffff888126b92000, set to ndev in nfcmrvl_nci_send() at drivers/nfc/nfcmrvl/main.c:54) and skb->sk = NULL at offset 24 (skb_orphan() in nci_send_frame()). Because this sk_buff itself became unreferenced after ndev was freed on USB disconnect, kmemleak reported both the unreferenced struct sk_buff (with its original bulk-cache allocation stack) and its skb->head buffer (0xffff888106699b80).
  4. nci_cmd_work() dequeues skb and calls nci_send_frame() -> nfcmrvl_nci_send() -> nfcmrvl_usb_nci_send().
  5. usb_submit_urb() (drivers/usb/core/urb.c:444-452) sees usb_endpoint_maxp(&ep->desc) == 0 on bulk_tx_ep and immediately returns -EMSGSIZE. nfcmrvl_usb_nci_send() unanchors and frees urb without calling kfree_skb(skb), leaking both skb and skb->head.
▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
8a1d109f assessment-security DenialOfService: ✅ Exploitable: ❌ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ memory leak in napi_get_frags (2) 2026/12/02 00:02 2026/12/02 00:02 2026/12/02 00:49 35891725
▶ ▼ Similar bugs (1)
Kernel Title Rank 🛈 Repro Cause bisect Fix bisect Count Last Reported Patched Status
upstream memory leak in napi_get_frags net 3 syz, C 11 2125d 2146d 22/30 fixed on 2023/02/24 13:50

Sample crash report:
BUG: memory leak
unreferenced object 0xffff88810de57c00 (size 240):
  comm "syz-executor", pid 5815, jiffies 4294943783
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
    00 20 b9 26 81 88 ff ff 00 00 00 00 00 00 00 00  . .&............
  backtrace (crc 9941ea3a):
    kmemleak_alloc_recursive include/linux/kmemleak.h:44 [inline]
    slab_post_alloc_hook mm/slub.c:4733 [inline]
    kmem_cache_alloc_bulk_noprof+0x258/0x3d0 mm/slub.c:7671
    napi_skb_cache_get net/core/skbuff.c:292 [inline]
    __alloc_skb+0x3de/0x4e0 net/core/skbuff.c:694
    napi_alloc_skb+0x1ed/0x2f0 net/core/skbuff.c:856
    napi_get_frags net/core/gro.c:721 [inline]
    napi_get_frags+0x3c/0x80 net/core/gro.c:716
    napi_get_frags_check net/core/dev.c:7819 [inline]
    netif_napi_add_weight_locked+0x232/0x3c0 net/core/dev.c:7860
    netif_napi_add_weight include/linux/netdevice.h:2918 [inline]
    netif_napi_add include/linux/netdevice.h:2935 [inline]
    wg_peer_create+0x204/0x2b0 drivers/net/wireguard/peer.c:57
    set_peer+0x680/0x9f0 drivers/net/wireguard/netlink.c:392
    wg_set_device_doit+0x459/0x740 drivers/net/wireguard/netlink.c:569
    genl_family_rcv_msg_doit+0x12e/0x1a0 net/netlink/genetlink.c:1114
    genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
    genl_rcv_msg+0x302/0x440 net/netlink/genetlink.c:1209
    netlink_rcv_skb+0x89/0x1c0 net/netlink/af_netlink.c:2585
    genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
    netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
    netlink_unicast+0x3e0/0x530 net/netlink/af_netlink.c:1362
    netlink_sendmsg+0x36f/0x710 net/netlink/af_netlink.c:1921
    sock_sendmsg_nosec net/socket.c:800 [inline]
    __sock_sendmsg net/socket.c:818 [inline]
    __sys_sendto+0x2d2/0x2e0 net/socket.c:2283
    __do_sys_sendto net/socket.c:2290 [inline]
    __se_sys_sendto net/socket.c:2286 [inline]
    __x64_sys_sendto+0x28/0x30 net/socket.c:2286

BUG: memory leak
unreferenced object 0xffff888106699b80 (size 704):
  comm "syz.5.22", pid 5987, jiffies 4294943783
  hex dump (first 32 bytes):
    20 00 01 01 00 00 00 00 00 00 00 00 00 00 00 00   ...............
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace (crc 40ddf9):
    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_node_noprof+0x368/0x400 mm/slub.c:5105
    kmalloc_reserve+0xd2/0x1b0 net/core/skbuff.c:616
    __alloc_skb+0x15d/0x4e0 net/core/skbuff.c:716
    alloc_skb include/linux/skbuff.h:1391 [inline]
    nci_skb_alloc include/net/nfc/nci_core.h:330 [inline]
    nci_send_cmd+0x46/0x110 net/nfc/nci/core.c:1397
    nci_reset_req net/nfc/nci/core.c:167 [inline]
    __nci_request net/nfc/nci/core.c:108 [inline]
    nci_open_device net/nfc/nci/core.c:503 [inline]
    nci_dev_up+0x1b6/0x690 net/nfc/nci/core.c:643
    nfc_dev_up+0xca/0x160 net/nfc/core.c:118
    nfc_genl_dev_up+0x3d/0x70 net/nfc/netlink.c:775
    genl_family_rcv_msg_doit+0x12e/0x1a0 net/netlink/genetlink.c:1114
    genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
    genl_rcv_msg+0x302/0x440 net/netlink/genetlink.c:1209
    netlink_rcv_skb+0x89/0x1c0 net/netlink/af_netlink.c:2585
    genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
    netlink_unicast_kernel net/netlink/af_netlink.c:1336 [inline]
    netlink_unicast+0x3e0/0x530 net/netlink/af_netlink.c:1362
    netlink_sendmsg+0x36f/0x710 net/netlink/af_netlink.c:1921
    sock_sendmsg_nosec net/socket.c:800 [inline]
    __sock_sendmsg net/socket.c:818 [inline]
    ____sys_sendmsg+0x54a/0x580 net/socket.c:2713
    ___sys_sendmsg+0x12c/0x160 net/socket.c:2770
    __sys_sendmsg+0xcd/0x140 net/socket.c:2802

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/12/02 00:02 upstream 19cc08c1a6a6 90414683 .config console log report syz / log [disk image] [vmlinux] [kernel image] ci-upstream-gce-leak memory leak in napi_get_frags
* Struck through repros no longer work on HEAD.