| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/11/05 11:13 | flow | patch-triage |
17mArgs:null Results: {
"EnableConfigs": [
"TUN",
"INET",
"VHOST_NET"
],
"FocusSymbols": [
"tun_get_user",
"tun_napi_receive",
"tun_napi_poll",
"tun_xdp_one",
"tun_queue_purge"
],
"KMSANReasoning": "The patch bounds the NAPI skb backlog in drivers/net/tun.c to prevent unbounded memory usage when packets are queued faster than NAPI poll consumes them. It introduces a queue length check against net_hotdata.max_backlog, drops excess packets (handling zerocopy completion when applicable), and moves the temporary splice queue from the stack in tun_napi_receive() into a persistent member in struct tun_file (tfile-\u003enapi_process_queue).\n\nKMSAN vs KASAN Applicability:\n- No uninitialized memory usage: The new queue structure `napi_process_queue` in `struct tun_file` is explicitly initialized with `__skb_queue_head_init()` during `tun_chr_open()`. All conditional logic depends strictly on initialized state (queue lengths, net_hotdata.max_backlog, tfile-\u003enapi_enabled, msg_control).\n- No kernel-to-user info-leak: The patch touches packet queuing and drop paths within the network driver; no uninitialized kernel structures, padding, or buffers are copied to user space.\n- Any bugs introduced by this patch would pertain to synchronization/concurrency, queue starvation, skb lifecycle management (leaks or use-after-free), or socket control flow. These failure modes are covered by standard bug detectors, KASAN, and LOCKDEP rather than KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies the TUN/TAP driver (drivers/net/tun.c) to bound the IFF_NAPI receive queue using net_hotdata.max_backlog. It alters queue management by moving the NAPI processing queue to struct tun_file (napi_process_queue) so leftover skbs are not pushed back onto sk_write_queue, implements packet drop and NAPI scheduling logic when queues are full in tun_get_user() and tun_xdp_one(), and updates queue purging in tun_queue_purge(). TUN/TAP devices and vhost-net are software-emulated virtual network drivers readily reachable in standard virtualized environments. Fuzzing is warranted to detect potential concurrency regressions, memory leaks, double frees, or locking issues during packet queuing, NAPI processing, and driver teardown.",
"WorthFuzzing": true
} |
| 1/1 | 2026/11/05 11:13 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 476baedcb9b3a5e1c53d957010b106174895cec8\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Thu Nov 5 11:13:41 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/tun.c b/drivers/net/tun.c\nindex 770b8fe085c323..ea99ee0aee2bb5 100644\n--- a/drivers/net/tun.c\n+++ b/drivers/net/tun.c\n@@ -58,6 +58,7 @@\n #include \u003clinux/nsproxy.h\u003e\n #include \u003clinux/virtio_net.h\u003e\n #include \u003clinux/rcupdate.h\u003e\n+#include \u003cnet/hotdata.h\u003e\n #include \u003cnet/net_namespace.h\u003e\n #include \u003cnet/netns/generic.h\u003e\n #include \u003cnet/rtnetlink.h\u003e\n@@ -140,6 +141,8 @@ struct tun_file {\n \t\tunsigned int ifindex;\n \t};\n \tstruct napi_struct napi;\n+\t/* NAPI poll only: skbs taken off sk_write_queue, not yet received */\n+\tstruct sk_buff_head napi_process_queue;\n \tbool napi_enabled;\n \tbool napi_frags_enabled;\n \tstruct mutex napi_mutex;\t/* Protects access to the above napi */\n@@ -227,31 +230,40 @@ struct veth {\n static void tun_flow_init(struct tun_struct *tun);\n static void tun_flow_uninit(struct tun_struct *tun);\n \n+/* In IFF_NAPI mode written packets wait in the tfile's sk_write_queue for the\n+ * NAPI poll, which may run later in a kthread or ksoftirqd. Bound that queue\n+ * like the per-CPU backlog of netif_rx().\n+ */\n+static bool tun_napi_queue_full(const struct sk_buff_head *queue)\n+{\n+\treturn skb_queue_len_lockless(queue) \u003e\n+\t READ_ONCE(net_hotdata.max_backlog);\n+}\n+\n static int tun_napi_receive(struct napi_struct *napi, int budget)\n {\n \tstruct tun_file *tfile = container_of(napi, struct tun_file, napi);\n+\tstruct sk_buff_head *process_queue = \u0026tfile-\u003enapi_process_queue;\n \tstruct sk_buff_head *queue = \u0026tfile-\u003esk.sk_write_queue;\n-\tstruct sk_buff_head process_queue;\n \tstruct sk_buff *skb;\n \tint received = 0;\n \n-\t__skb_queue_head_init(\u0026process_queue);\n-\n-\tspin_lock(\u0026queue-\u003elock);\n-\tskb_queue_splice_tail_init(queue, \u0026process_queue);\n-\tspin_unlock(\u0026queue-\u003elock);\n-\n-\twhile (received \u003c budget \u0026\u0026 (skb = __skb_dequeue(\u0026process_queue))) {\n+\twhile (received \u003c budget) {\n+\t\t/* Refill only when empty: leftovers are not put back on the\n+\t\t * queue writers check, so neither queue exceeds the limit.\n+\t\t */\n+\t\tif (skb_queue_empty(process_queue)) {\n+\t\t\tspin_lock(\u0026queue-\u003elock);\n+\t\t\tskb_queue_splice_tail_init(queue, process_queue);\n+\t\t\tspin_unlock(\u0026queue-\u003elock);\n+\t\t\tif (skb_queue_empty(process_queue))\n+\t\t\t\tbreak;\n+\t\t}\n+\t\tskb = __skb_dequeue(process_queue);\n \t\tnapi_gro_receive(napi, skb);\n \t\t++received;\n \t}\n \n-\tif (!skb_queue_empty(\u0026process_queue)) {\n-\t\tspin_lock(\u0026queue-\u003elock);\n-\t\tskb_queue_splice(\u0026process_queue, queue);\n-\t\tspin_unlock(\u0026queue-\u003elock);\n-\t}\n-\n \treturn received;\n }\n \n@@ -572,6 +584,8 @@ static void tun_queue_purge(struct tun_file *tfile)\n \t\ttun_ptr_free(ptr);\n \n \tskb_queue_purge(\u0026tfile-\u003esk.sk_write_queue);\n+\t/* NAPI is disabled by now */\n+\t__skb_queue_purge(\u0026tfile-\u003enapi_process_queue);\n \tskb_queue_purge(\u0026tfile-\u003esk.sk_error_queue);\n }\n \n@@ -1856,6 +1870,23 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t\t\tzerocopy = true;\n \t}\n \n+\t/* NAPI queue full: drop before allocating, and schedule NAPI, which a\n+\t * MSG_MORE sender may not have done yet. Rechecked under the lock.\n+\t */\n+\tif (tfile-\u003enapi_enabled \u0026\u0026\n+\t unlikely(tun_napi_queue_full(\u0026tfile-\u003esk.sk_write_queue))) {\n+\t\tlocal_bh_disable();\n+\t\tnapi_schedule(\u0026tfile-\u003enapi);\n+\t\tlocal_bh_enable();\n+\t\tif (msg_control) {\n+\t\t\tstruct ubuf_info *uarg = msg_control;\n+\n+\t\t\tuarg-\u003eops-\u003ecomplete(NULL, uarg, false);\n+\t\t}\n+\t\tdev_core_stats_rx_dropped_inc(tun-\u003edev);\n+\t\treturn total_len;\n+\t}\n+\n \tif (!frags \u0026\u0026 tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) {\n \t\t/* For the packet that is not easy to be processed\n \t\t * (e.g gso or jumbo packet), we will do it at after\n@@ -2045,6 +2076,17 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t\t\tgoto free_skb;\n \t\t}\n \n+\t\t/* NAPI queue full: drop, as above */\n+\t\tif (unlikely(tun_napi_queue_full(queue))) {\n+\t\t\tspin_unlock(\u0026queue-\u003elock);\n+\t\t\tnapi_schedule(\u0026tfile-\u003enapi);\n+\t\t\tlocal_bh_enable();\n+\t\t\trcu_read_unlock();\n+\t\t\tdev_core_stats_rx_dropped_inc(tun-\u003edev);\n+\t\t\tdrop_reason = SKB_DROP_REASON_FULL_RING;\n+\t\t\tgoto free_skb;\n+\t\t}\n+\n \t\t__skb_queue_tail(queue, skb);\n \t\tqueue_len = skb_queue_len(queue);\n \t\tspin_unlock(\u0026queue-\u003elock);\n@@ -2649,6 +2691,17 @@ static int tun_xdp_one(struct tun_struct *tun,\n \t\t\treturn -EBUSY;\n \t\t}\n \n+\t\t/* NAPI queue full: drop, and schedule NAPI so that it drains\n+\t\t * even if nothing in this batch gets queued\n+\t\t */\n+\t\tif (unlikely(tun_napi_queue_full(queue))) {\n+\t\t\tspin_unlock(\u0026queue-\u003elock);\n+\t\t\tnapi_schedule(\u0026tfile-\u003enapi);\n+\t\t\tkfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING);\n+\t\t\tdev_core_stats_rx_dropped_inc(tun-\u003edev);\n+\t\t\treturn 0;\n+\t\t}\n+\n \t\t__skb_queue_tail(queue, skb);\n \t\tspin_unlock(\u0026queue-\u003elock);\n \t\tret = 1;\n@@ -3571,6 +3624,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)\n \t}\n \n \tmutex_init(\u0026tfile-\u003enapi_mutex);\n+\t__skb_queue_head_init(\u0026tfile-\u003enapi_process_queue);\n \tRCU_INIT_POINTER(tfile-\u003etun, NULL);\n \ttfile-\u003eflags = 0;\n \ttfile-\u003eifindex = 0;\ndiff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile\nindex df215e1a62621b..de4cdaac99a037 100644\n--- a/tools/testing/selftests/net/Makefile\n+++ b/tools/testing/selftests/net/Makefile\n@@ -203,6 +203,7 @@ TEST_GEN_PROGS := \\\n \ttap \\\n \ttcp_port_share \\\n \ttls \\\n+\ttun_vhost \\\n \tudp_splice_checksum \\\n # end of TEST_GEN_PROGS\n \ndiff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config\nindex cb8cb4696df793..1dce372caf4316 100644\n--- a/tools/testing/selftests/net/config\n+++ b/tools/testing/selftests/net/config\n@@ -136,6 +136,7 @@ CONFIG_TRACEPOINTS=y\n CONFIG_TUN=y\n CONFIG_USER_NS=y\n CONFIG_VETH=y\n+CONFIG_VHOST_NET=m\n CONFIG_VLAN_8021Q=y\n CONFIG_VXLAN=m\n CONFIG_XFRM_INTERFACE=m\ndiff --git a/tools/testing/selftests/net/tun_vhost.c b/tools/testing/selftests/net/tun_vhost.c\nnew file mode 100644\nindex 00000000000000..dbf76d324a7e20\n--- /dev/null\n+++ b/tools/testing/selftests/net/tun_vhost.c\n@@ -0,0 +1,361 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * Send packets from vhost-net into a tap device with IFF_NAPI and check\n+ * that the NAPI queue is bounded by netdev_max_backlog: excess packets\n+ * are dropped and counted, and every buffer is returned to the driver,\n+ * zerocopy ones included.\n+ *\n+ * vhost-net passes packets to tun in three ways:\n+ * - batch: batches of XDP buffers (tun_xdp_one()), the default when the\n+ * socket send buffer is unlimited and zerocopy is disabled\n+ * - copy: one packet per sendmsg(), when the send buffer is limited\n+ * - zerocopy: one packet per sendmsg() with a ubuf_info to complete,\n+ * only with vhost_net experimental_zcopytx=1 (else skipped)\n+ *\n+ * Tun schedules NAPI only after a batch, or after the last of a series of\n+ * MSG_MORE packets, so with a small netdev_max_backlog the queue always\n+ * overflows. It must keep draining while the sender keeps sending.\n+ *\n+ * Author: Antonio Quartulli \u003cantonio@mandelbit.com\u003e\n+ */\n+\n+#define _GNU_SOURCE\n+#include \u003cerrno.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003cpoll.h\u003e\n+#include \u003csched.h\u003e\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003clinux/if.h\u003e\n+#include \u003clinux/if_arp.h\u003e\n+#include \u003clinux/if_ether.h\u003e\n+#include \u003clinux/if_tun.h\u003e\n+#include \u003clinux/vhost.h\u003e\n+#include \u003clinux/virtio_config.h\u003e\n+#include \u003clinux/virtio_net.h\u003e\n+#include \u003clinux/virtio_ring.h\u003e\n+#include \u003csys/eventfd.h\u003e\n+#include \u003csys/ioctl.h\u003e\n+#include \u003csys/socket.h\u003e\n+\n+#include \"kselftest_harness.h\"\n+\n+#define TV_IFNAME\t\"tvh0\"\n+#define TV_RING_NUM\t256\n+#define TV_BUF_SIZE\t2048\n+#define TV_HDR_LEN\tsizeof(struct virtio_net_hdr_v1)\n+#define TV_PKTS\t\t(64 * TV_RING_NUM)\n+#define TV_BACKLOG\t\"8\"\n+#define TV_TX_VQ\t1\n+\n+static const unsigned char tv_mac_tap[ETH_ALEN] = { 2, 0, 0, 0, 0, 1 };\n+static const unsigned char tv_mac_dst[ETH_ALEN] = { 2, 0, 0, 0, 0, 2 };\n+static const unsigned char tv_mac_src[ETH_ALEN] = { 2, 0, 0, 0, 0, 3 };\n+\n+struct tv_stats {\n+\tunsigned long long rx_packets;\n+\tunsigned long long rx_dropped;\n+};\n+\n+static int tv_read_stats(const char *ifname, struct tv_stats *st)\n+{\n+\tchar line[512], *p;\n+\tFILE *f;\n+\tint ret = -1;\n+\n+\tf = fopen(\"/proc/net/dev\", \"r\");\n+\tif (!f)\n+\t\treturn -1;\n+\twhile (fgets(line, sizeof(line), f)) {\n+\t\tp = strchr(line, ':');\n+\t\tif (!p)\n+\t\t\tcontinue;\n+\t\t*p = '\\0';\n+\t\tif (strcmp(line + strspn(line, \" \"), ifname))\n+\t\t\tcontinue;\n+\t\tif (sscanf(p + 1, \"%*u %llu %*u %llu\", \u0026st-\u003erx_packets,\n+\t\t\t \u0026st-\u003erx_dropped) == 2)\n+\t\t\tret = 0;\n+\t\tbreak;\n+\t}\n+\tfclose(f);\n+\treturn ret;\n+}\n+\n+FIXTURE(tun_vhost)\n+{\n+\tint backlog_fd;\n+\tchar backlog[32];\n+\tint tap;\n+\tint vhost;\n+\tint kick;\n+\tint call;\n+\tvoid *ring;\n+\tstruct vring vr;\n+\tchar *bufs;\n+\tunsigned short avail_idx;\n+\tunsigned short used_idx;\n+};\n+\n+FIXTURE_VARIANT(tun_vhost)\n+{\n+\tbool batch;\n+\tbool limit_sndbuf;\n+\tbool zerocopy;\n+\tint pktlen;\n+};\n+\n+FIXTURE_VARIANT_ADD(tun_vhost, batch)\n+{\n+\t.batch = true,\n+\t.pktlen = 64,\n+};\n+\n+FIXTURE_VARIANT_ADD(tun_vhost, copy)\n+{\n+\t.limit_sndbuf = true,\n+\t.pktlen = 64,\n+};\n+\n+FIXTURE_VARIANT_ADD(tun_vhost, zerocopy)\n+{\n+\t.limit_sndbuf = true,\n+\t.zerocopy = true,\n+\t.pktlen = 1000,\n+};\n+\n+static bool tv_zerocopy_enabled(void)\n+{\n+\tchar c = '0';\n+\tint fd;\n+\n+\tfd = open(\"/sys/module/vhost_net/parameters/experimental_zcopytx\",\n+\t\t O_RDONLY);\n+\tif (fd \u003c 0)\n+\t\treturn false;\n+\tif (read(fd, \u0026c, 1) != 1)\n+\t\tc = '0';\n+\tclose(fd);\n+\treturn c == '1';\n+}\n+\n+static void tv_vhost_setup(struct __test_metadata *_metadata,\n+\t\t\t FIXTURE_DATA(tun_vhost) *self)\n+{\n+\tstruct vhost_vring_state state = { .index = TV_TX_VQ };\n+\tstruct vhost_vring_file file = { .index = TV_TX_VQ };\n+\tstruct vhost_vring_addr addr = { .index = TV_TX_VQ };\n+\tsize_t memsz = sizeof(struct vhost_memory) +\n+\t\t sizeof(struct vhost_memory_region);\n+\tunsigned long long features;\n+\tstruct vhost_memory *mem;\n+\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_OWNER, NULL), 0);\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_GET_FEATURES, \u0026features), 0);\n+\tASSERT_TRUE(features \u0026 (1ULL \u003c\u003c VIRTIO_F_VERSION_1));\n+\tfeatures = 1ULL \u003c\u003c VIRTIO_F_VERSION_1;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_FEATURES, \u0026features), 0);\n+\n+\t/* buffer addresses are passed as is: map them 1:1 */\n+\tmem = calloc(1, memsz);\n+\tASSERT_NE(mem, NULL);\n+\tmem-\u003enregions = 1;\n+\tmem-\u003eregions[0].guest_phys_addr = (unsigned long)self-\u003ebufs;\n+\tmem-\u003eregions[0].userspace_addr = (unsigned long)self-\u003ebufs;\n+\tmem-\u003eregions[0].memory_size = TV_RING_NUM * TV_BUF_SIZE;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_MEM_TABLE, mem), 0);\n+\tfree(mem);\n+\n+\tstate.num = TV_RING_NUM;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_VRING_NUM, \u0026state), 0);\n+\tstate.num = 0;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_VRING_BASE, \u0026state), 0);\n+\taddr.desc_user_addr = (unsigned long)self-\u003evr.desc;\n+\taddr.avail_user_addr = (unsigned long)self-\u003evr.avail;\n+\taddr.used_user_addr = (unsigned long)self-\u003evr.used;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_VRING_ADDR, \u0026addr), 0);\n+\tfile.fd = self-\u003ekick;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_VRING_KICK, \u0026file), 0);\n+\tfile.fd = self-\u003ecall;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_SET_VRING_CALL, \u0026file), 0);\n+\tfile.fd = self-\u003etap;\n+\tASSERT_EQ(ioctl(self-\u003evhost, VHOST_NET_SET_BACKEND, \u0026file), 0);\n+}\n+\n+FIXTURE_SETUP(tun_vhost)\n+{\n+\tstruct ifreq ifr = {};\n+\tint hdrlen = TV_HDR_LEN;\n+\tint sndbuf = 1 \u003c\u003c 20;\n+\tssize_t n;\n+\tint i, fd;\n+\n+\tself-\u003etap = -1;\n+\tself-\u003evhost = open(\"/dev/vhost-net\", O_RDWR);\n+\tif (self-\u003evhost \u003c 0)\n+\t\tSKIP(return, \"no /dev/vhost-net\");\n+\tif (variant-\u003ezerocopy \u0026\u0026 !tv_zerocopy_enabled())\n+\t\tSKIP(return, \"vhost_net experimental_zcopytx not enabled\");\n+\tif (variant-\u003ebatch \u0026\u0026 tv_zerocopy_enabled())\n+\t\tSKIP(return, \"vhost_net does not batch with zerocopy\");\n+\n+\t/* global, and only visible from init_net: keep it open to restore */\n+\tself-\u003ebacklog_fd = open(\"/proc/sys/net/core/netdev_max_backlog\",\n+\t\t\t\tO_RDWR);\n+\tASSERT_GE(self-\u003ebacklog_fd, 0);\n+\tn = read(self-\u003ebacklog_fd, self-\u003ebacklog, sizeof(self-\u003ebacklog) - 1);\n+\tASSERT_GT(n, 0);\n+\tself-\u003ebacklog[n] = '\\0';\n+\tASSERT_EQ(pwrite(self-\u003ebacklog_fd, TV_BACKLOG, strlen(TV_BACKLOG), 0),\n+\t\t strlen(TV_BACKLOG));\n+\n+\tASSERT_EQ(unshare(CLONE_NEWNET), 0);\n+\n+\tself-\u003etap = open(\"/dev/net/tun\", O_RDWR);\n+\tASSERT_GE(self-\u003etap, 0);\n+\tifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR | IFF_NAPI;\n+\tmemcpy(ifr.ifr_name, TV_IFNAME, sizeof(TV_IFNAME));\n+\tASSERT_EQ(ioctl(self-\u003etap, TUNSETIFF, \u0026ifr), 0);\n+\tASSERT_EQ(ioctl(self-\u003etap, TUNSETVNETHDRSZ, \u0026hdrlen), 0);\n+\tif (variant-\u003elimit_sndbuf)\n+\t\tASSERT_EQ(ioctl(self-\u003etap, TUNSETSNDBUF, \u0026sndbuf), 0);\n+\n+\tfd = socket(AF_INET, SOCK_DGRAM, 0);\n+\tASSERT_GE(fd, 0);\n+\tifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;\n+\tmemcpy(ifr.ifr_hwaddr.sa_data, tv_mac_tap, ETH_ALEN);\n+\tASSERT_EQ(ioctl(fd, SIOCSIFHWADDR, \u0026ifr), 0);\n+\tASSERT_EQ(ioctl(fd, SIOCGIFFLAGS, \u0026ifr), 0);\n+\tifr.ifr_flags |= IFF_UP;\n+\tASSERT_EQ(ioctl(fd, SIOCSIFFLAGS, \u0026ifr), 0);\n+\tclose(fd);\n+\n+\t/* every buffer: zeroed vnet header + IPv4 frame for another host,\n+\t * which the stack drops without counting it in rx_dropped\n+\t */\n+\tASSERT_EQ(posix_memalign((void **)\u0026self-\u003ebufs, 4096,\n+\t\t\t\t TV_RING_NUM * TV_BUF_SIZE), 0);\n+\tmemset(self-\u003ebufs, 0, TV_RING_NUM * TV_BUF_SIZE);\n+\tfor (i = 0; i \u003c TV_RING_NUM; i++) {\n+\t\tunsigned char *eth = (unsigned char *)self-\u003ebufs +\n+\t\t\t\t i * TV_BUF_SIZE + TV_HDR_LEN;\n+\n+\t\tmemcpy(eth, tv_mac_dst, ETH_ALEN);\n+\t\tmemcpy(eth + ETH_ALEN, tv_mac_src, ETH_ALEN);\n+\t\teth[12] = ETH_P_IP \u003e\u003e 8;\n+\t\teth[13] = ETH_P_IP \u0026 0xff;\n+\t\teth[14] = 0x45;\n+\t}\n+\n+\tASSERT_EQ(posix_memalign(\u0026self-\u003ering, 4096,\n+\t\t\t\t vring_size(TV_RING_NUM, 4096)), 0);\n+\tmemset(self-\u003ering, 0, vring_size(TV_RING_NUM, 4096));\n+\tvring_init(\u0026self-\u003evr, TV_RING_NUM, self-\u003ering, 4096);\n+\n+\tself-\u003ekick = eventfd(0, EFD_NONBLOCK);\n+\tself-\u003ecall = eventfd(0, EFD_NONBLOCK);\n+\tASSERT_GE(self-\u003ekick, 0);\n+\tASSERT_GE(self-\u003ecall, 0);\n+\n+\ttv_vhost_setup(_metadata, self);\n+}\n+\n+FIXTURE_TEARDOWN(tun_vhost)\n+{\n+\tif (self-\u003etap \u003c 0)\n+\t\treturn;\n+\t/* waits for outstanding zerocopy buffers */\n+\tclose(self-\u003evhost);\n+\tclose(self-\u003etap);\n+\tif (pwrite(self-\u003ebacklog_fd, self-\u003ebacklog, strlen(self-\u003ebacklog),\n+\t\t 0) \u003c 0)\n+\t\tTH_LOG(\"cannot restore netdev_max_backlog to %s\",\n+\t\t self-\u003ebacklog);\n+\tclose(self-\u003ebacklog_fd);\n+}\n+\n+/* queue up to @n buffers, return how many */\n+static int tv_post(FIXTURE_DATA(tun_vhost) *self, int pktlen, int n)\n+{\n+\tint inflight = (unsigned short)(self-\u003eavail_idx - self-\u003eused_idx);\n+\tunsigned long long one = 1;\n+\tint i;\n+\n+\tfor (i = 0; i \u003c n \u0026\u0026 inflight \u003c TV_RING_NUM; i++, inflight++) {\n+\t\tunsigned int id = self-\u003eavail_idx % TV_RING_NUM;\n+\n+\t\tself-\u003evr.desc[id].addr = (unsigned long)self-\u003ebufs +\n+\t\t\t\t\t id * TV_BUF_SIZE;\n+\t\tself-\u003evr.desc[id].len = TV_HDR_LEN + pktlen;\n+\t\tself-\u003evr.desc[id].flags = 0;\n+\t\tself-\u003evr.avail-\u003ering[id] = id;\n+\t\tself-\u003eavail_idx++;\n+\t}\n+\t__atomic_store_n(\u0026self-\u003evr.avail-\u003eidx, self-\u003eavail_idx,\n+\t\t\t __ATOMIC_RELEASE);\n+\tif (i \u0026\u0026 write(self-\u003ekick, \u0026one, sizeof(one)) != sizeof(one))\n+\t\treturn -1;\n+\treturn i;\n+}\n+\n+/* reap returned buffers, waiting up to @ms for at least one */\n+static int tv_reap(FIXTURE_DATA(tun_vhost) *self, int ms)\n+{\n+\tstruct pollfd pfd = { .fd = self-\u003ecall, .events = POLLIN };\n+\tunsigned short used;\n+\tunsigned long long v;\n+\n+\tfor (;;) {\n+\t\tused = __atomic_load_n(\u0026self-\u003evr.used-\u003eidx, __ATOMIC_ACQUIRE);\n+\t\tif (used != self-\u003eused_idx) {\n+\t\t\tint n = (unsigned short)(used - self-\u003eused_idx);\n+\n+\t\t\tself-\u003eused_idx = used;\n+\t\t\treturn n;\n+\t\t}\n+\t\tif (ms \u003c= 0 || poll(\u0026pfd, 1, 100) \u003c 0)\n+\t\t\treturn 0;\n+\t\tif (pfd.revents \u0026 POLLIN \u0026\u0026 read(self-\u003ecall, \u0026v, sizeof(v)) \u003c 0)\n+\t\t\treturn -1;\n+\t\tms -= 100;\n+\t}\n+}\n+\n+TEST_F(tun_vhost, napi_queue_bounded)\n+{\n+\tstruct tv_stats before, after;\n+\tunsigned long long delivered, dropped;\n+\tint posted = 0, reaped = 0, n;\n+\n+\tASSERT_EQ(tv_read_stats(TV_IFNAME, \u0026before), 0);\n+\n+\twhile (reaped \u003c TV_PKTS) {\n+\t\tn = tv_post(self, variant-\u003epktlen, TV_PKTS - posted);\n+\t\tASSERT_GE(n, 0);\n+\t\tposted += n;\n+\t\tn = tv_reap(self, 5000);\n+\t\tASSERT_GE(n, 0);\n+\t\tif (!n) {\n+\t\t\tTH_LOG(\"%d of %d buffers not returned\",\n+\t\t\t posted - reaped, posted);\n+\t\t\tASSERT_GT(n, 0);\n+\t\t}\n+\t\treaped += n;\n+\t}\n+\n+\tASSERT_EQ(tv_read_stats(TV_IFNAME, \u0026after), 0);\n+\tdelivered = after.rx_packets - before.rx_packets;\n+\tdropped = after.rx_dropped - before.rx_dropped;\n+\tTH_LOG(\"sent %d, delivered %llu, dropped %llu\", TV_PKTS, delivered,\n+\t dropped);\n+\t/* bounded, */\n+\tEXPECT_GT(dropped, 0);\n+\t/* still draining, */\n+\tEXPECT_GE(delivered, TV_PKTS / 64);\n+\t/* and every packet accounted for */\n+\tEXPECT_EQ(delivered + dropped, TV_PKTS);\n+}\n+\n+TEST_HARNESS_MAIN\n"
} |
| 2/1 | 2026/11/05 11:13 | agent | patch-evaluator |
12mModel:core Args: null Results: {
"EnableConfigs": [
"TUN",
"INET",
"VHOST_NET"
],
"FocusSymbols": [
"tun_get_user",
"tun_napi_receive",
"tun_napi_poll",
"tun_xdp_one",
"tun_queue_purge"
],
"Reasoning": "The patch modifies the TUN/TAP driver (drivers/net/tun.c) to bound the IFF_NAPI receive queue using net_hotdata.max_backlog. It alters queue management by moving the NAPI processing queue to struct tun_file (napi_process_queue) so leftover skbs are not pushed back onto sk_write_queue, implements packet drop and NAPI scheduling logic when queues are full in tun_get_user() and tun_xdp_one(), and updates queue purging in tun_queue_purge(). TUN/TAP devices and vhost-net are software-emulated virtual network drivers readily reachable in standard virtualized environments. Fuzzing is warranted to detect potential concurrency regressions, memory leaks, double frees, or locking issues during packet queuing, NAPI processing, and driver teardown.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 476baedcb9b3a5e1c53d957010b106174895cec8
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Nov 5 11:13:41 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 770b8fe085c323..ea99ee0aee2bb5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -58,6 +58,7 @@
#include <linux/nsproxy.h>
#include <linux/virtio_net.h>
#include <linux/rcupdate.h>
+#include <net/hotdata.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
#include <net/rtnetlink.h>
@@ -140,6 +141,8 @@ struct tun_file {
unsigned int ifindex;
};
struct napi_struct napi;
+ /* NAPI poll only: skbs taken off sk_write_queue, not yet received */
+ struct sk_buff_head napi_process_queue;
bool napi_enabled;
bool napi_frags_enabled;
struct mutex napi_mutex; /* Protects access to the above napi */
@@ -227,31 +230,40 @@ struct veth {
static void tun_flow_init(struct tun_struct *tun);
static void tun_flow_uninit(struct tun_struct *tun);
+/* In IFF_NAPI mode written packets wait in the tfile's sk_write_queue for the
+ * NAPI poll, which may run later in a kthread or ksoftirqd. Bound that queue
+ * like the per-CPU backlog of netif_rx().
+ */
+static bool tun_napi_queue_full(const struct sk_buff_head *queue)
+{
+ return skb_queue_len_lockless(queue) >
+ READ_ONCE(net_hotdata.max_backlog);
+}
+
static int tun_napi_receive(struct napi_struct *napi, int budget)
{
struct tun_file *tfile = container_of(napi, struct tun_file, napi);
+ struct sk_buff_head *process_queue = &tfile->napi_process_queue;
struct sk_buff_head *queue = &tfile->sk.sk_write_queue;
- struct sk_buff_head process_queue;
struct sk_buff *skb;
int received = 0;
- __skb_queue_head_init(&process_queue);
-
- spin_lock(&queue->lock);
- skb_queue_splice_tail_init(queue, &process_queue);
- spin_unlock(&queue->lock);
-
- while (received < budget && (skb = __skb_dequeue(&process_queue))) {
+ while (received < budget) {
+ /* Refill only when empty: leftovers are not put back on the
+ * queue writers check, so neither queue exceeds the limit.
+ */
+ if (skb_queue_empty(process_queue)) {
+ spin_lock(&queue->lock);
+ skb_queue_splice_tail_init(queue, process_queue);
+ spin_unlock(&queue->lock);
+ if (skb_queue_empty(process_queue))
+ break;
+ }
+ skb = __skb_dequeue(process_queue);
napi_gro_receive(napi, skb);
++received;
}
- if (!skb_queue_empty(&process_queue)) {
- spin_lock(&queue->lock);
- skb_queue_splice(&process_queue, queue);
- spin_unlock(&queue->lock);
- }
-
return received;
}
@@ -572,6 +584,8 @@ static void tun_queue_purge(struct tun_file *tfile)
tun_ptr_free(ptr);
skb_queue_purge(&tfile->sk.sk_write_queue);
+ /* NAPI is disabled by now */
+ __skb_queue_purge(&tfile->napi_process_queue);
skb_queue_purge(&tfile->sk.sk_error_queue);
}
@@ -1856,6 +1870,23 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
zerocopy = true;
}
+ /* NAPI queue full: drop before allocating, and schedule NAPI, which a
+ * MSG_MORE sender may not have done yet. Rechecked under the lock.
+ */
+ if (tfile->napi_enabled &&
+ unlikely(tun_napi_queue_full(&tfile->sk.sk_write_queue))) {
+ local_bh_disable();
+ napi_schedule(&tfile->napi);
+ local_bh_enable();
+ if (msg_control) {
+ struct ubuf_info *uarg = msg_control;
+
+ uarg->ops->complete(NULL, uarg, false);
+ }
+ dev_core_stats_rx_dropped_inc(tun->dev);
+ return total_len;
+ }
+
if (!frags && tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) {
/* For the packet that is not easy to be processed
* (e.g gso or jumbo packet), we will do it at after
@@ -2045,6 +2076,17 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
goto free_skb;
}
+ /* NAPI queue full: drop, as above */
+ if (unlikely(tun_napi_queue_full(queue))) {
+ spin_unlock(&queue->lock);
+ napi_schedule(&tfile->napi);
+ local_bh_enable();
+ rcu_read_unlock();
+ dev_core_stats_rx_dropped_inc(tun->dev);
+ drop_reason = SKB_DROP_REASON_FULL_RING;
+ goto free_skb;
+ }
+
__skb_queue_tail(queue, skb);
queue_len = skb_queue_len(queue);
spin_unlock(&queue->lock);
@@ -2649,6 +2691,17 @@ static int tun_xdp_one(struct tun_struct *tun,
return -EBUSY;
}
+ /* NAPI queue full: drop, and schedule NAPI so that it drains
+ * even if nothing in this batch gets queued
+ */
+ if (unlikely(tun_napi_queue_full(queue))) {
+ spin_unlock(&queue->lock);
+ napi_schedule(&tfile->napi);
+ kfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING);
+ dev_core_stats_rx_dropped_inc(tun->dev);
+ return 0;
+ }
+
__skb_queue_tail(queue, skb);
spin_unlock(&queue->lock);
ret = 1;
@@ -3571,6 +3624,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)
}
mutex_init(&tfile->napi_mutex);
+ __skb_queue_head_init(&tfile->napi_process_queue);
RCU_INIT_POINTER(tfile->tun, NULL);
tfile->flags = 0;
tfile->ifindex = 0;
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index df215e1a62621b..de4cdaac99a037 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -203,6 +203,7 @@ TEST_GEN_PROGS := \
tap \
tcp_port_share \
tls \
+ tun_vhost \
udp_splice_checksum \
# end of TEST_GEN_PROGS
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index cb8cb4696df793..1dce372caf4316 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -136,6 +136,7 @@ CONFIG_TRACEPOINTS=y
CONFIG_TUN=y
CONFIG_USER_NS=y
CONFIG_VETH=y
+CONFIG_VHOST_NET=m
CONFIG_VLAN_8021Q=y
CONFIG_VXLAN=m
CONFIG_XFRM_INTERFACE=m
diff --git a/tools/testing/selftests/net/tun_vhost.c b/tools/testing/selftests/net/tun_vhost.c
new file mode 100644
index 00000000000000..dbf76d324a7e20
--- /dev/null
+++ b/tools/testing/selftests/net/tun_vhost.c
@@ -0,0 +1,361 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Send packets from vhost-net into a tap device with IFF_NAPI and check
+ * that the NAPI queue is bounded by netdev_max_backlog: excess packets
+ * are dropped and counted, and every buffer is returned to the driver,
+ * zerocopy ones included.
+ *
+ * vhost-net passes packets to tun in three ways:
+ * - batch: batches of XDP buffers (tun_xdp_one()), the default when the
+ * socket send buffer is unlimited and zerocopy is disabled
+ * - copy: one packet per sendmsg(), when the send buffer is limited
+ * - zerocopy: one packet per sendmsg() with a ubuf_info to complete,
+ * only with vhost_net experimental_zcopytx=1 (else skipped)
+ *
+ * Tun schedules NAPI only after a batch, or after the last of a series of
+ * MSG_MORE packets, so with a small netdev_max_backlog the queue always
+ * overflows. It must keep draining while the sender keeps sending.
+ *
+ * Author: Antonio Quartulli <antonio@mandelbit.com>
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/if_tun.h>
+#include <linux/vhost.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_net.h>
+#include <linux/virtio_ring.h>
+#include <sys/eventfd.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include "kselftest_harness.h"
+
+#define TV_IFNAME "tvh0"
+#define TV_RING_NUM 256
+#define TV_BUF_SIZE 2048
+#define TV_HDR_LEN sizeof(struct virtio_net_hdr_v1)
+#define TV_PKTS (64 * TV_RING_NUM)
+#define TV_BACKLOG "8"
+#define TV_TX_VQ 1
+
+static const unsigned char tv_mac_tap[ETH_ALEN] = { 2, 0, 0, 0, 0, 1 };
+static const unsigned char tv_mac_dst[ETH_ALEN] = { 2, 0, 0, 0, 0, 2 };
+static const unsigned char tv_mac_src[ETH_ALEN] = { 2, 0, 0, 0, 0, 3 };
+
+struct tv_stats {
+ unsigned long long rx_packets;
+ unsigned long long rx_dropped;
+};
+
+static int tv_read_stats(const char *ifname, struct tv_stats *st)
+{
+ char line[512], *p;
+ FILE *f;
+ int ret = -1;
+
+ f = fopen("/proc/net/dev", "r");
+ if (!f)
+ return -1;
+ while (fgets(line, sizeof(line), f)) {
+ p = strchr(line, ':');
+ if (!p)
+ continue;
+ *p = '\0';
+ if (strcmp(line + strspn(line, " "), ifname))
+ continue;
+ if (sscanf(p + 1, "%*u %llu %*u %llu", &st->rx_packets,
+ &st->rx_dropped) == 2)
+ ret = 0;
+ break;
+ }
+ fclose(f);
+ return ret;
+}
+
+FIXTURE(tun_vhost)
+{
+ int backlog_fd;
+ char backlog[32];
+ int tap;
+ int vhost;
+ int kick;
+ int call;
+ void *ring;
+ struct vring vr;
+ char *bufs;
+ unsigned short avail_idx;
+ unsigned short used_idx;
+};
+
+FIXTURE_VARIANT(tun_vhost)
+{
+ bool batch;
+ bool limit_sndbuf;
+ bool zerocopy;
+ int pktlen;
+};
+
+FIXTURE_VARIANT_ADD(tun_vhost, batch)
+{
+ .batch = true,
+ .pktlen = 64,
+};
+
+FIXTURE_VARIANT_ADD(tun_vhost, copy)
+{
+ .limit_sndbuf = true,
+ .pktlen = 64,
+};
+
+FIXTURE_VARIANT_ADD(tun_vhost, zerocopy)
+{
+ .limit_sndbuf = true,
+ .zerocopy = true,
+ .pktlen = 1000,
+};
+
+static bool tv_zerocopy_enabled(void)
+{
+ char c = '0';
+ int fd;
+
+ fd = open("/sys/module/vhost_net/parameters/experimental_zcopytx",
+ O_RDONLY);
+ if (fd < 0)
+ return false;
+ if (read(fd, &c, 1) != 1)
+ c = '0';
+ close(fd);
+ return c == '1';
+}
+
+static void tv_vhost_setup(struct __test_metadata *_metadata,
+ FIXTURE_DATA(tun_vhost) *self)
+{
+ struct vhost_vring_state state = { .index = TV_TX_VQ };
+ struct vhost_vring_file file = { .index = TV_TX_VQ };
+ struct vhost_vring_addr addr = { .index = TV_TX_VQ };
+ size_t memsz = sizeof(struct vhost_memory) +
+ sizeof(struct vhost_memory_region);
+ unsigned long long features;
+ struct vhost_memory *mem;
+
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_OWNER, NULL), 0);
+ ASSERT_EQ(ioctl(self->vhost, VHOST_GET_FEATURES, &features), 0);
+ ASSERT_TRUE(features & (1ULL << VIRTIO_F_VERSION_1));
+ features = 1ULL << VIRTIO_F_VERSION_1;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_FEATURES, &features), 0);
+
+ /* buffer addresses are passed as is: map them 1:1 */
+ mem = calloc(1, memsz);
+ ASSERT_NE(mem, NULL);
+ mem->nregions = 1;
+ mem->regions[0].guest_phys_addr = (unsigned long)self->bufs;
+ mem->regions[0].userspace_addr = (unsigned long)self->bufs;
+ mem->regions[0].memory_size = TV_RING_NUM * TV_BUF_SIZE;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_MEM_TABLE, mem), 0);
+ free(mem);
+
+ state.num = TV_RING_NUM;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_NUM, &state), 0);
+ state.num = 0;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_BASE, &state), 0);
+ addr.desc_user_addr = (unsigned long)self->vr.desc;
+ addr.avail_user_addr = (unsigned long)self->vr.avail;
+ addr.used_user_addr = (unsigned long)self->vr.used;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_ADDR, &addr), 0);
+ file.fd = self->kick;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_KICK, &file), 0);
+ file.fd = self->call;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_CALL, &file), 0);
+ file.fd = self->tap;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_NET_SET_BACKEND, &file), 0);
+}
+
+FIXTURE_SETUP(tun_vhost)
+{
+ struct ifreq ifr = {};
+ int hdrlen = TV_HDR_LEN;
+ int sndbuf = 1 << 20;
+ ssize_t n;
+ int i, fd;
+
+ self->tap = -1;
+ self->vhost = open("/dev/vhost-net", O_RDWR);
+ if (self->vhost < 0)
+ SKIP(return, "no /dev/vhost-net");
+ if (variant->zerocopy && !tv_zerocopy_enabled())
+ SKIP(return, "vhost_net experimental_zcopytx not enabled");
+ if (variant->batch && tv_zerocopy_enabled())
+ SKIP(return, "vhost_net does not batch with zerocopy");
+
+ /* global, and only visible from init_net: keep it open to restore */
+ self->backlog_fd = open("/proc/sys/net/core/netdev_max_backlog",
+ O_RDWR);
+ ASSERT_GE(self->backlog_fd, 0);
+ n = read(self->backlog_fd, self->backlog, sizeof(self->backlog) - 1);
+ ASSERT_GT(n, 0);
+ self->backlog[n] = '\0';
+ ASSERT_EQ(pwrite(self->backlog_fd, TV_BACKLOG, strlen(TV_BACKLOG), 0),
+ strlen(TV_BACKLOG));
+
+ ASSERT_EQ(unshare(CLONE_NEWNET), 0);
+
+ self->tap = open("/dev/net/tun", O_RDWR);
+ ASSERT_GE(self->tap, 0);
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR | IFF_NAPI;
+ memcpy(ifr.ifr_name, TV_IFNAME, sizeof(TV_IFNAME));
+ ASSERT_EQ(ioctl(self->tap, TUNSETIFF, &ifr), 0);
+ ASSERT_EQ(ioctl(self->tap, TUNSETVNETHDRSZ, &hdrlen), 0);
+ if (variant->limit_sndbuf)
+ ASSERT_EQ(ioctl(self->tap, TUNSETSNDBUF, &sndbuf), 0);
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ ASSERT_GE(fd, 0);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ memcpy(ifr.ifr_hwaddr.sa_data, tv_mac_tap, ETH_ALEN);
+ ASSERT_EQ(ioctl(fd, SIOCSIFHWADDR, &ifr), 0);
+ ASSERT_EQ(ioctl(fd, SIOCGIFFLAGS, &ifr), 0);
+ ifr.ifr_flags |= IFF_UP;
+ ASSERT_EQ(ioctl(fd, SIOCSIFFLAGS, &ifr), 0);
+ close(fd);
+
+ /* every buffer: zeroed vnet header + IPv4 frame for another host,
+ * which the stack drops without counting it in rx_dropped
+ */
+ ASSERT_EQ(posix_memalign((void **)&self->bufs, 4096,
+ TV_RING_NUM * TV_BUF_SIZE), 0);
+ memset(self->bufs, 0, TV_RING_NUM * TV_BUF_SIZE);
+ for (i = 0; i < TV_RING_NUM; i++) {
+ unsigned char *eth = (unsigned char *)self->bufs +
+ i * TV_BUF_SIZE + TV_HDR_LEN;
+
+ memcpy(eth, tv_mac_dst, ETH_ALEN);
+ memcpy(eth + ETH_ALEN, tv_mac_src, ETH_ALEN);
+ eth[12] = ETH_P_IP >> 8;
+ eth[13] = ETH_P_IP & 0xff;
+ eth[14] = 0x45;
+ }
+
+ ASSERT_EQ(posix_memalign(&self->ring, 4096,
+ vring_size(TV_RING_NUM, 4096)), 0);
+ memset(self->ring, 0, vring_size(TV_RING_NUM, 4096));
+ vring_init(&self->vr, TV_RING_NUM, self->ring, 4096);
+
+ self->kick = eventfd(0, EFD_NONBLOCK);
+ self->call = eventfd(0, EFD_NONBLOCK);
+ ASSERT_GE(self->kick, 0);
+ ASSERT_GE(self->call, 0);
+
+ tv_vhost_setup(_metadata, self);
+}
+
+FIXTURE_TEARDOWN(tun_vhost)
+{
+ if (self->tap < 0)
+ return;
+ /* waits for outstanding zerocopy buffers */
+ close(self->vhost);
+ close(self->tap);
+ if (pwrite(self->backlog_fd, self->backlog, strlen(self->backlog),
+ 0) < 0)
+ TH_LOG("cannot restore netdev_max_backlog to %s",
+ self->backlog);
+ close(self->backlog_fd);
+}
+
+/* queue up to @n buffers, return how many */
+static int tv_post(FIXTURE_DATA(tun_vhost) *self, int pktlen, int n)
+{
+ int inflight = (unsigned short)(self->avail_idx - self->used_idx);
+ unsigned long long one = 1;
+ int i;
+
+ for (i = 0; i < n && inflight < TV_RING_NUM; i++, inflight++) {
+ unsigned int id = self->avail_idx % TV_RING_NUM;
+
+ self->vr.desc[id].addr = (unsigned long)self->bufs +
+ id * TV_BUF_SIZE;
+ self->vr.desc[id].len = TV_HDR_LEN + pktlen;
+ self->vr.desc[id].flags = 0;
+ self->vr.avail->ring[id] = id;
+ self->avail_idx++;
+ }
+ __atomic_store_n(&self->vr.avail->idx, self->avail_idx,
+ __ATOMIC_RELEASE);
+ if (i && write(self->kick, &one, sizeof(one)) != sizeof(one))
+ return -1;
+ return i;
+}
+
+/* reap returned buffers, waiting up to @ms for at least one */
+static int tv_reap(FIXTURE_DATA(tun_vhost) *self, int ms)
+{
+ struct pollfd pfd = { .fd = self->call, .events = POLLIN };
+ unsigned short used;
+ unsigned long long v;
+
+ for (;;) {
+ used = __atomic_load_n(&self->vr.used->idx, __ATOMIC_ACQUIRE);
+ if (used != self->used_idx) {
+ int n = (unsigned short)(used - self->used_idx);
+
+ self->used_idx = used;
+ return n;
+ }
+ if (ms <= 0 || poll(&pfd, 1, 100) < 0)
+ return 0;
+ if (pfd.revents & POLLIN && read(self->call, &v, sizeof(v)) < 0)
+ return -1;
+ ms -= 100;
+ }
+}
+
+TEST_F(tun_vhost, napi_queue_bounded)
+{
+ struct tv_stats before, after;
+ unsigned long long delivered, dropped;
+ int posted = 0, reaped = 0, n;
+
+ ASSERT_EQ(tv_read_stats(TV_IFNAME, &before), 0);
+
+ while (reaped < TV_PKTS) {
+ n = tv_post(self, variant->pktlen, TV_PKTS - posted);
+ ASSERT_GE(n, 0);
+ posted += n;
+ n = tv_reap(self, 5000);
+ ASSERT_GE(n, 0);
+ if (!n) {
+ TH_LOG("%d of %d buffers not returned",
+ posted - reaped, posted);
+ ASSERT_GT(n, 0);
+ }
+ reaped += n;
+ }
+
+ ASSERT_EQ(tv_read_stats(TV_IFNAME, &after), 0);
+ delivered = after.rx_packets - before.rx_packets;
+ dropped = after.rx_dropped - before.rx_dropped;
+ TH_LOG("sent %d, delivered %llu, dropped %llu", TV_PKTS, delivered,
+ dropped);
+ /* bounded, */
+ EXPECT_GT(dropped, 0);
+ /* still draining, */
+ EXPECT_GE(delivered, TV_PKTS / 64);
+ /* and every packet accounted for */
+ EXPECT_EQ(delivered + dropped, TV_PKTS);
+}
+
+TEST_HARNESS_MAIN
|
| 3/2 | 2026/11/05 11:13 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9742 output: 29 thoughts: 675 Thoughts: **Fuzzing Evaluation: tun.c Patch** Okay, so the user wants me to assess whether this patch series is worth fuzzing with syzkaller. No problem, this is a standard Linux kernel security triage request. The request is benign; no red flags here. Let's dig in. The patch touches `drivers/net/tun.c` and adds a self-test in `tools/testing/selftests/net/tun_vhost.c`. Looking at `tun.c`, it seems we're seeing some queue management changes: * A `napi_process_queue` is added to the `tun_file` structure. * A `tun_napi_queue_full` helper is introduced. * The `tun_napi_receive` function is refactored, replacing a local stack queue with the new `tfile->napi_process_queue`. Crucially, it only refills the queue when empty and doesn't put leftovers back. * `tun_queue_purge` now purges this new queue. * `tun_get_user` now checks the queue's fullness, dropping skbs and calling `napi_schedule` when full. * `tun_xdp_one` similarly checks and drops based on queue fullness. * `tun_chr_open` initializes the queue. Right, so we're seeing changes to how the TUN device handles network packets, specifically around queue management and NAPI processing. Let's see about reachability. Yes, `drivers/net/tun.c` is totally reachable. TUN/TAP devices are ubiquitous. `/dev/net/tun` is standard, easily emulated in QEMU/GCE, and widely used by syzkaller. That's a huge green light. Now, are there *logic* modifications? Absolutely. We're seeing changes to queue management, locking, skb queueing, NAPI polling, dropping logic, zerocopy completion, and `napi_schedule` calls. This is a refactoring and introduces new queue bounding. All strong indications that this is worth a fuzzing evaluation! **WorthFuzzing: TRUE!** This patch series is a prime candidate for syzkaller. I'll need to check the Kconfig options, or use grepper and focus on potential symbols to confirm that this is true and to ensure good coverage. |
| 4/2 | 2026/11/05 11:15 | tool | grepper |
0mArgs:{
"Expression": "config TUN",
"PathPrefixes": [
"drivers/net/Kconfig"
]
}Results: {
"Output": "drivers/net/Kconfig=386=config RIONET_RX_SIZE\n--\ndrivers/net/Kconfig-390-\ndrivers/net/Kconfig:391:config TUN\ndrivers/net/Kconfig-392-\ttristate \"Universal TUN/TAP device driver support\"\n--\ndrivers/net/Kconfig=415=config TAP\n--\ndrivers/net/Kconfig-420-\ndrivers/net/Kconfig:421:config TUN_VNET_CROSS_LE\ndrivers/net/Kconfig-422-\tbool \"Support for cross-endian vnet headers on little-endian kernels\"\n"
} |
| 5/2 | 2026/11/05 11:15 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11132 output: 34 thoughts: 23 Thoughts: Here's a summary of my thought process, tailored for an expert like you: **Diving into the Network Driver Configuration** Okay, so I need to zero in on a specific area within the kernel's network configuration. The task at hand is likely related to something configured via the Kconfig system. Right, my first thought is to use `read-file` to explore the `drivers/net/Kconfig` file. I'm focusing specifically around line 391. My aim here is to understand the context of the code at that location. I might be looking for a particular feature, option, or perhaps a dependency. Maybe I'm troubleshooting, or looking to add some capability and want to see how that section handles related options. Line 391 should give me the starting point for that exploration. |
| 6/2 | 2026/11/05 11:17 | tool | read-file |
0mArgs:{
"File": "drivers/net/Kconfig",
"FirstLine": 390,
"LineCount": 25
}Results: {
"Contents": " 390:\t\n 391:\tconfig TUN\n 392:\t\ttristate \"Universal TUN/TAP device driver support\"\n 393:\t\tdepends on INET\n 394:\t\tselect CRC32\n 395:\t\thelp\n 396:\t\t TUN/TAP provides packet reception and transmission for user space\n 397:\t\t programs. It can be viewed as a simple Point-to-Point or Ethernet\n 398:\t\t device, which instead of receiving packets from a physical media,\n 399:\t\t receives them from user space program and instead of sending packets\n 400:\t\t via physical media writes them to the user space program.\n 401:\t\n 402:\t\t When a program opens /dev/net/tun, driver creates and registers\n 403:\t\t corresponding net device tunX or tapX. After a program closed above\n 404:\t\t devices, driver will automatically delete tunXX or tapXX device and\n 405:\t\t all routes corresponding to it.\n 406:\t\n 407:\t\t Please read \u003cfile:Documentation/networking/tuntap.rst\u003e for more\n 408:\t\t information.\n 409:\t\n 410:\t\t To compile this driver as a module, choose M here: the module\n 411:\t\t will be called tun.\n 412:\t\n 413:\t\t If you don't know what to use this for, you don't need it.\n 414:\t\n"
} |
| 7/2 | 2026/11/05 11:17 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11755 output: 32 thoughts: 50 Thoughts: **Examining the Dependencies of `CONFIG_TUN` and Network Virtualization** Okay, so I'm digging into the kernel configuration and I see `CONFIG_TUN` has a dependency on `INET`. That makes perfect sense. But I'm also considering the implications for virtual network interfaces, specifically `VHOST_NET`. The question burning in my mind is: does the `vhost_net` module *absolutely* need to be enabled for the tun NAPI functionality to work, or is this particular NAPI support reachable through `TUN` itself? I suspect it's the latter, but I need to be sure. I need to be able to reason about that. The best way to figure this out is to dive into the `tun.c` source code and see exactly how the NAPI (Network API) functionality is enabled and used there. Let me see where the registration and setup for this NAPI piece happens, and that should clarify the dependencies and relationships I'm concerned with. |
| 8/2 | 2026/11/05 11:17 | tool | grepper |
0mArgs:{
"Expression": "IFF_NAPI",
"PathPrefixes": [
"drivers/net/tun.c"
]
}Results: {
"Output": "drivers/net/tun.c=89=static void tun_default_link_ksettings(struct net_device *dev,\n--\ndrivers/net/tun.c-101-#define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \\\ndrivers/net/tun.c:102:\t\t IFF_MULTI_QUEUE | IFF_NAPI | IFF_NAPI_FRAGS | \\\ndrivers/net/tun.c-103-\t\t IFF_BACKPRESSURE)\n--\ndrivers/net/tun.c=231=static void tun_flow_uninit(struct tun_struct *tun);\ndrivers/net/tun.c-232-\ndrivers/net/tun.c:233:/* In IFF_NAPI mode written packets wait in the tfile's sk_write_queue for the\ndrivers/net/tun.c-234- * NAPI poll, which may run later in a kthread or ksoftirqd. Bound that queue\n--\ndrivers/net/tun.c=971=static int tun_net_init(struct net_device *dev)\n--\ndrivers/net/tun.c-999-\tINIT_LIST_HEAD(\u0026tun-\u003edisabled);\ndrivers/net/tun.c:1000:\terr = tun_attach(tun, tun-\u003efile, false, ifr-\u003eifr_flags \u0026 IFF_NAPI,\ndrivers/net/tun.c:1001:\t\t\t ifr-\u003eifr_flags \u0026 IFF_NAPI_FRAGS, false);\ndrivers/net/tun.c-1002-\tif (err \u003c 0) {\n--\ndrivers/net/tun.c=2908=static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)\n--\ndrivers/net/tun.c-2918-\ndrivers/net/tun.c:2919:\tif ((ifr-\u003eifr_flags \u0026 IFF_NAPI_FRAGS)) {\ndrivers/net/tun.c-2920-\t\tif (!capable(CAP_NET_ADMIN))\n--\ndrivers/net/tun.c-2922-\ndrivers/net/tun.c:2923:\t\tif (!(ifr-\u003eifr_flags \u0026 IFF_NAPI) ||\ndrivers/net/tun.c-2924-\t\t (ifr-\u003eifr_flags \u0026 TUN_TYPE_MASK) != IFF_TAP)\n--\ndrivers/net/tun.c-2949-\t\terr = tun_attach(tun, file, ifr-\u003eifr_flags \u0026 IFF_NOFILTER,\ndrivers/net/tun.c:2950:\t\t\t\t ifr-\u003eifr_flags \u0026 IFF_NAPI,\ndrivers/net/tun.c:2951:\t\t\t\t ifr-\u003eifr_flags \u0026 IFF_NAPI_FRAGS, true);\ndrivers/net/tun.c-2952-\t\tif (err \u003c 0)\n--\ndrivers/net/tun.c=3164=static int tun_set_queue(struct file *file, struct ifreq *ifr)\n--\ndrivers/net/tun.c-3180-\t\t\tgoto unlock;\ndrivers/net/tun.c:3181:\t\tret = tun_attach(tun, file, false, tun-\u003eflags \u0026 IFF_NAPI,\ndrivers/net/tun.c:3182:\t\t\t\t tun-\u003eflags \u0026 IFF_NAPI_FRAGS, true);\ndrivers/net/tun.c-3183-\t} else if (ifr-\u003eifr_flags \u0026 IFF_DETACH_QUEUE) {\n"
} |
| 9/2 | 2026/11/05 11:17 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 12935 output: 34 thoughts: 56 Thoughts: Okay, here's my interpretation of these thoughts, summarized in the first person, assuming the audience is another expert: **Investigating the IFF_NAPI Flag and Associated TUN Driver Functions** Right, so `IFF_NAPI`... that's the flag we set using the `TUNSETIFF` ioctl call, isn't it? My immediate thought is, let's trace this through the code. I need to get a clear picture of its impact. Where is this flag actually *used*? Specifically, I want to identify the call sites for `tun_napi_receive`, `tun_get_user`, `tun_xdp_one`, and `tun_queue_purge`. I'm guessing that understanding how `IFF_NAPI` influences the behavior of these functions is key to understanding its overall role in the TUN driver. Essentially, I need to map out the control flow and see how these NAPI-related pieces fit into the bigger picture of packet handling, user-space interaction, and XDP integration. It's a matter of getting a detailed grasp of the interplay between these functions. |
| 10/2 | 2026/11/05 11:17 | tool | grepper |
0mArgs:{
"Expression": "tun_napi_receive",
"PathPrefixes": [
"drivers/net/tun.c"
]
}Results: {
"Output": "drivers/net/tun.c=237=static bool tun_napi_queue_full(const struct sk_buff_head *queue)\n--\ndrivers/net/tun.c-242-\ndrivers/net/tun.c:243:static int tun_napi_receive(struct napi_struct *napi, int budget)\ndrivers/net/tun.c-244-{\n--\ndrivers/net/tun.c=270=static int tun_napi_poll(struct napi_struct *napi, int budget)\n--\ndrivers/net/tun.c-273-\ndrivers/net/tun.c:274:\treceived = tun_napi_receive(napi, budget);\ndrivers/net/tun.c-275-\n"
} |
| 11/2 | 2026/11/05 11:17 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13460 output: 35 thoughts: 12 Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience, and written in the first person: **Diving into `tun_napi_poll`** Alright, time to dig into this. "Let's check `tun_napi_poll`." That's the starting point. My mind immediately begins to parse what that means in the context of network driver optimization, specifically with TUN/TAP devices. `tun_napi_poll` suggests we're dealing with the Network Interface Controller (NIC) Advanced Peripheral Interrupts (NAPI) polling function specific to TUN/TAP. So, what's its role? Is it handling packet reception, transmission completion, or both? Are we looking at a performance bottleneck, or perhaps investigating a potential bug in the interrupt mitigation logic? I need to quickly recall the typical call graph and how it interacts with the rest of the network stack. I'm going to need to remind myself of the data structures involved: the `net_device` struct, `napi_struct`, how `sk_buffs` get handled. Let's see what the code reveals. |
| 12/2 | 2026/11/05 11:18 | tool | read-file |
0mArgs:{
"File": "drivers/net/tun.c",
"FirstLine": 265,
"LineCount": 40
}Results: {
"Contents": " 265:\t\t}\n 266:\t\n 267:\t\treturn received;\n 268:\t}\n 269:\t\n 270:\tstatic int tun_napi_poll(struct napi_struct *napi, int budget)\n 271:\t{\n 272:\t\tunsigned int received;\n 273:\t\n 274:\t\treceived = tun_napi_receive(napi, budget);\n 275:\t\n 276:\t\tif (received \u003c budget)\n 277:\t\t\tnapi_complete_done(napi, received);\n 278:\t\n 279:\t\treturn received;\n 280:\t}\n 281:\t\n 282:\tstatic void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile,\n 283:\t\t\t\t bool napi_en, bool napi_frags)\n 284:\t{\n 285:\t\ttfile-\u003enapi_enabled = napi_en;\n 286:\t\ttfile-\u003enapi_frags_enabled = napi_en \u0026\u0026 napi_frags;\n 287:\t\tif (napi_en) {\n 288:\t\t\tnetif_napi_add_tx(tun-\u003edev, \u0026tfile-\u003enapi, tun_napi_poll);\n 289:\t\t\tnapi_enable(\u0026tfile-\u003enapi);\n 290:\t\t}\n 291:\t}\n 292:\t\n 293:\tstatic void tun_napi_enable(struct tun_file *tfile)\n 294:\t{\n 295:\t\tif (tfile-\u003enapi_enabled)\n 296:\t\t\tnapi_enable(\u0026tfile-\u003enapi);\n 297:\t}\n 298:\t\n 299:\tstatic void tun_napi_disable(struct tun_file *tfile)\n 300:\t{\n 301:\t\tif (tfile-\u003enapi_enabled)\n 302:\t\t\tnapi_disable(\u0026tfile-\u003enapi);\n 303:\t}\n 304:\t\n"
} |
| 13/2 | 2026/11/05 11:18 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14305 output: 33 thoughts: 30 Thoughts: Here's my take on those thoughts, tailored for an expert audience: **Diving into the NAPI Poll and User Data** Okay, so `tun_napi_poll` is the NAPI poll function for the TUN device. Right, got it. Now, my mind immediately jumps to how this interacts with the user-space interface. I need to understand the data flow, and specifically, what parts of the kernel are responsible for bringing data from userland *into* the kernel's TUN driver. Therefore, the next logical step is to map the call graph. Let's trace how the userspace side of a tun device gets data into the kernel side. I need to understand what functions actually *call* `tun_get_user` and where this function is called from, so I can understand the whole data ingress process and figure out where my performance bottleneck may be. |
| 14/2 | 2026/11/05 11:18 | tool | grepper |
0mArgs:{
"Expression": "tun_get_user",
"PathPrefixes": [
"drivers/net/tun.c"
]
}Results: {
"Output": "drivers/net/tun.c=1704=static struct sk_buff *tun_build_skb(struct tun_struct *tun,\n--\ndrivers/net/tun.c-1800-/* Get packet from user space buffer */\ndrivers/net/tun.c:1801:static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\ndrivers/net/tun.c-1802-\t\t\t void *msg_control, struct iov_iter *from,\n--\ndrivers/net/tun.c=2132=static ssize_t tun_chr_write_iter(struct kiocb *iocb, struct iov_iter *from)\n--\ndrivers/net/tun.c-2145-\ndrivers/net/tun.c:2146:\tresult = tun_get_user(tun, tfile, NULL, from, noblock, false);\ndrivers/net/tun.c-2147-\n--\ndrivers/net/tun.c=2725=static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)\n--\ndrivers/net/tun.c-2771-\ndrivers/net/tun.c:2772:\tret = tun_get_user(tun, tfile, ctl ? ctl-\u003eptr : NULL, \u0026m-\u003emsg_iter,\ndrivers/net/tun.c-2773-\t\t\t m-\u003emsg_flags \u0026 MSG_DONTWAIT,\n"
} |
| 15/2 | 2026/11/05 11:18 | llm | patch-evaluator |
2mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14934 output: 34 thoughts: 43 Thoughts: Here's my thought process, as requested: **Investigating Network Driver Interactions** Okay, so I'm digging into this network driver code, specifically looking at how data gets handled. I've noticed that both `tun_chr_write_iter` and `tun_sendmsg` functions are calling `tun_get_user`. That's interesting, I need to understand that relationship. Now, the key is the path the data is traveling. The next key point is to check how `tun_xdp_one` fits into the puzzle, the calls that invoke that function will be key to understanding the data flow. I know this is a key section, and I should have this figured out pretty quickly. Let's see what's connected to it. |
| 16/2 | 2026/11/05 11:21 | tool | grepper |
0mArgs:{
"Expression": "tun_xdp_one",
"PathPrefixes": [
"drivers/net/tun.c"
]
}Results: {
"Output": "drivers/net/tun.c=2570=static void tun_put_page(struct tun_page *tpage)\n--\ndrivers/net/tun.c-2575-\ndrivers/net/tun.c:2576:static int tun_xdp_one(struct tun_struct *tun,\ndrivers/net/tun.c-2577-\t\t struct tun_file *tfile,\n--\ndrivers/net/tun.c=2725=static int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)\n--\ndrivers/net/tun.c-2750-\t\t\txdp = \u0026((struct xdp_buff *)ctl-\u003eptr)[i];\ndrivers/net/tun.c:2751:\t\t\tret = tun_xdp_one(tun, tfile, xdp, \u0026flush, \u0026tpage);\ndrivers/net/tun.c-2752-\t\t\tif (ret \u003e 0)\n"
} |
| 17/2 | 2026/11/05 11:21 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15423 output: 33 thoughts: 29 Thoughts: Okay, here's my take on those thoughts, framed as a first-person expert summary: **Digging into the XDP Packet Flow** Alright, so I'm tracing the data flow here, specifically how XDP packets are handled with the *tun* interface. *tun_xdp_one* is clearly a critical function, and it's being invoked by *tun_sendmsg*. That's the transmission side, making perfect sense. Now, my immediate question is, where's the cleanup happening? Specifically, what function is calling *tun_queue_purge*? I'm betting that's the counterpart to the send process, the mechanism that deals with freeing resources or handling any dropped packets or queued packets that need purging. Understanding *that* is just as, if not more, important than knowing where the packets originate. I want to build a complete picture of the XDP packet lifecycle within this virtual interface context. |
| 18/2 | 2026/11/05 11:22 | tool | grepper |
0mArgs:{
"Expression": "tun_queue_purge",
"PathPrefixes": [
"drivers/net/tun.c"
]
}Results: {
"Output": "drivers/net/tun.c=577=EXPORT_SYMBOL_GPL(tun_ptr_free);\ndrivers/net/tun.c-578-\ndrivers/net/tun.c:579:static void tun_queue_purge(struct tun_file *tfile)\ndrivers/net/tun.c-580-{\n--\ndrivers/net/tun.c=592=static void __tun_detach(struct tun_file *tfile, bool clean)\n--\ndrivers/net/tun.c-633-\t\t/* Drop read queue */\ndrivers/net/tun.c:634:\t\ttun_queue_purge(tfile);\ndrivers/net/tun.c-635-\t\tspin_lock_bh(\u0026ntfile-\u003etx_ring.consumer_lock);\n--\ndrivers/net/tun.c=680=static void tun_detach_all(struct net_device *dev)\n--\ndrivers/net/tun.c-708-\t\t/* Drop read queue */\ndrivers/net/tun.c:709:\t\ttun_queue_purge(tfile);\ndrivers/net/tun.c-710-\t\txdp_rxq_info_unreg(\u0026tfile-\u003exdp_rxq);\n--\ndrivers/net/tun.c-717-\t\ttun_enable_queue(tfile);\ndrivers/net/tun.c:718:\t\ttun_queue_purge(tfile);\ndrivers/net/tun.c-719-\t\txdp_rxq_info_unreg(\u0026tfile-\u003exdp_rxq);\n"
} |
| 19/2 | 2026/11/05 11:22 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16073 output: 31 thoughts: 413 Thoughts: **Analyzing TUN/TAP Driver Functionality and Configuration**
Okay, let's dive into this. I need to understand the changes made in `drivers/net/tun.c`. Specifically, I want to confirm the reachability of these functions in typical virtualized environments like Google Compute Engine (GCE) or QEMU.
I see a list of key functions: `tun_napi_queue_full`, `tun_napi_receive`, `tun_napi_poll`, `tun_queue_purge`, `tun_get_user`, `tun_xdp_one`, and `tun_chr_open`. The good news is that TUN is fully emulated in software; it's a virtual network device, so it should be.
My understanding is that userspace can interact with `/dev/net/tun`, execute `ioctl(fd, TUNSETIFF, ...)` with `IFF_TAP | IFF_NAPI` flags, and then send packets using the standard `write()`/`writev()`/`sendmsg()` calls. This action should trigger several of the functions I initially listed: `tun_chr_write_iter`, `tun_get_user`, `tun_xdp_one`, `tun_napi_poll` (via NAPI softirq/kthread), and `tun_queue_purge` (during device close/detach). Also, I need to keep in mind that `vhost-net` (enabled via `CONFIG_VHOST_NET`) can also interface with tun devices using the `VHOST_NET_SET_BACKEND` ioctl.
Now, let's get into the configuration details. The primary config for TUN is `CONFIG_TUN`. I need to check its dependencies. I'll peek at `drivers/net/Kconfig` to see if it requires anything specific.
Okay, I see:
config TUN
tristate "Universal TUN/TAP device driver support"
depends on INET
select CRC32
So it depends on `INET` and selects `CRC32`. Good to know.
Next, the `VHOST_NET` configuration is important, too. I remember the selftest added in `tools/testing/selftests/net/tun_vhost.c` is used to test tun via vhost-net. I should check `CONFIG_VHOST_NET` in `drivers/vhost/Kconfig` as well, just to be sure.
|
| 20/2 | 2026/11/05 11:23 | tool | grepper |
0mArgs:{
"Expression": "config VHOST_NET",
"PathPrefixes": [
"drivers/vhost/"
]
}Results: {
"Output": "drivers/vhost/Kconfig=32=if VHOST_MENU\ndrivers/vhost/Kconfig-33-\ndrivers/vhost/Kconfig:34:config VHOST_NET\ndrivers/vhost/Kconfig-35-\ttristate \"Host kernel accelerator for virtio net\"\n"
} |
| 21/2 | 2026/11/05 11:23 | llm | patch-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17129 output: 33 thoughts: 19 Thoughts: Here's my thought process, as if I were considering that code: **Diving into the Vhost Driver Configuration** Okay, so I need to understand something about the vhost driver configuration. My first instinct is to zero in on `drivers/vhost/Kconfig`, and specifically, I'm thinking around line 32. That's usually where the core settings or dependencies are defined for a particular driver or feature. I'm going to scan that section – probably looking for the main `config` symbol for the vhost core, or perhaps a section where they define dependencies on other subsystems. Depending on what I find, that'll guide me toward understanding how the vhost driver is enabled and configured within the broader kernel build system. That line number gives me a good starting point; it's specific enough to locate a key decision point, but broad enough to not be too hyper specific. |
| 22/2 | 2026/11/05 11:25 | tool | read-file |
0mArgs:{
"File": "drivers/vhost/Kconfig",
"FirstLine": 1,
"LineCount": 45
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig VHOST_IOTLB\n 3:\t\ttristate\n 4:\t\thelp\n 5:\t\t Generic IOTLB implementation for vhost and vringh.\n 6:\t\t This option is selected by any driver which needs to support\n 7:\t\t an IOMMU in software.\n 8:\t\n 9:\tconfig VHOST_RING\n 10:\t\ttristate\n 11:\t\tselect VHOST_IOTLB\n 12:\t\thelp\n 13:\t\t This option is selected by any driver which needs to access\n 14:\t\t the host side of a virtio ring.\n 15:\t\n 16:\tconfig VHOST_TASK\n 17:\t\tbool\n 18:\t\tdefault n\n 19:\t\n 20:\tconfig VHOST\n 21:\t\ttristate\n 22:\t\tselect VHOST_IOTLB\n 23:\t\tselect VHOST_TASK\n 24:\t\thelp\n 25:\t\t This option is selected by any driver which needs to access\n 26:\t\t the core of vhost.\n 27:\t\n 28:\tmenuconfig VHOST_MENU\n 29:\t\tbool \"VHOST drivers\"\n 30:\t\tdefault y\n 31:\t\n 32:\tif VHOST_MENU\n 33:\t\n 34:\tconfig VHOST_NET\n 35:\t\ttristate \"Host kernel accelerator for virtio net\"\n 36:\t\tdepends on NET \u0026\u0026 EVENTFD \u0026\u0026 (TUN || !TUN) \u0026\u0026 (TAP || !TAP)\n 37:\t\tselect VHOST\n 38:\t\thelp\n 39:\t\t This kernel module can be loaded in host kernel to accelerate\n 40:\t\t guest networking with virtio_net. Not to be confused with virtio_net\n 41:\t\t module itself which needs to be loaded in guest kernel.\n 42:\t\n 43:\t\t To compile this driver as a module, choose M here: the module will\n 44:\t\t be called vhost_net.\n 45:\t\n"
} |
| 23/2 | 2026/11/05 11:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17910 output: 36 thoughts: 1112 Thoughts: **Analysis of TUN Driver Code for Symbol Inclusion** Okay, so I'm looking at the modified code in `drivers/net/tun.c`. Clearly, `CONFIG_TUN` is the primary requirement here, and `CONFIG_INET` is a dependency. `CONFIG_VHOST_NET` is optional, but it's used in the selftests, and the author added `tun_vhost.c` to test it. Including it seems helpful because `tun_xdp_one` is called by `vhost_net` through `tun_sendmsg`, so I'll probably include it. Now, let's make sure I'm following the FocusSymbols guidelines. I need to avoid listing ubiquitous lifecycle hot-paths, and instead focus on feature-specific logic and entrypoints. I don't have to worry about static inline functions in headers here, since it's a `.c` file. Now, let's look at what functions in `drivers/net/tun.c` are relevant: 1. **`tun_napi_receive`**: This is a static function called by `tun_napi_poll`. I'm going to have to make sure it's not getting inlined. Let's trace it back. Okay, so `tun_napi_poll` is the NAPI poll callback registered with `netif_napi_add_tx`. And `tun_napi_poll` is not static inline. The same goes for `tun_napi_receive`. 2. **`tun_get_user`**: This static function handles user packet ingestion, and it's called by `tun_chr_write_iter` and `tun_sendmsg`. It includes the queue bounding check changes and the napi_schedule call. 3. **`tun_xdp_one`**: Another static function implementing ingestion of XDP buffers, called by `tun_sendmsg`. It also contains the modified queue bounding check. 4. **`tun_queue_purge`**: Static function called on queue detach/close via `__tun_detach` and `tun_detach_all`. 5. **`tun_chr_open`**: Character device open handler for `/dev/net/tun`. It initializes `napi_process_queue`. 6. **`tun_chr_write_iter`**: Direct entrypoint for `write()` on `/dev/net/tun`. 7. **`tun_sendmsg`**: Socket `sendmsg` entrypoint for the TUN socket. So, I need to check if these functions are symbols in the kernel image (`vmlinux`) or the module (`tun.ko`), or if any of them are inlined. I can see that `tun_napi_poll` is a function pointer in `netif_napi_add_tx`. So `tun_napi_poll` will have a symbol. `tun_napi_receive` *might* be inlined since it has only one caller, `tun_napi_poll`. Including *both* `tun_napi_poll` and `tun_napi_receive` is probably the safest bet. `tun_get_user` is a large function, called by both `tun_chr_write_iter` and `tun_sendmsg`, so it will likely *not* be inlined. The same probably applies to `tun_xdp_one` and `tun_queue_purge`. I should also check what `tun_sendmsg` itself does, so I'll check line 2725 in `drivers/net/tun.c`. |
| 24/2 | 2026/11/05 11:25 | tool | read-file |
0mArgs:{
"File": "drivers/net/tun.c",
"FirstLine": 2725,
"LineCount": 55
}Results: {
"Contents": "2725:\tstatic int tun_sendmsg(struct socket *sock, struct msghdr *m, size_t total_len)\n2726:\t{\n2727:\t\tint ret, i;\n2728:\t\tstruct tun_file *tfile = container_of(sock, struct tun_file, socket);\n2729:\t\tstruct tun_struct *tun = tun_get(tfile);\n2730:\t\tstruct tun_msg_ctl *ctl = m-\u003emsg_control;\n2731:\t\tstruct xdp_buff *xdp;\n2732:\t\n2733:\t\tif (!tun)\n2734:\t\t\treturn -EBADFD;\n2735:\t\n2736:\t\tif (m-\u003emsg_controllen == sizeof(struct tun_msg_ctl) \u0026\u0026\n2737:\t\t ctl \u0026\u0026 ctl-\u003etype == TUN_MSG_PTR) {\n2738:\t\t\tstruct bpf_net_context __bpf_net_ctx, *bpf_net_ctx;\n2739:\t\t\tstruct tun_page tpage;\n2740:\t\t\tint n = ctl-\u003enum;\n2741:\t\t\tint flush = 0, queued = 0;\n2742:\t\n2743:\t\t\tmemset(\u0026tpage, 0, sizeof(tpage));\n2744:\t\n2745:\t\t\tlocal_bh_disable();\n2746:\t\t\trcu_read_lock();\n2747:\t\t\tbpf_net_ctx = bpf_net_ctx_set(\u0026__bpf_net_ctx);\n2748:\t\n2749:\t\t\tfor (i = 0; i \u003c n; i++) {\n2750:\t\t\t\txdp = \u0026((struct xdp_buff *)ctl-\u003eptr)[i];\n2751:\t\t\t\tret = tun_xdp_one(tun, tfile, xdp, \u0026flush, \u0026tpage);\n2752:\t\t\t\tif (ret \u003e 0)\n2753:\t\t\t\t\tqueued += ret;\n2754:\t\t\t}\n2755:\t\n2756:\t\t\tif (flush)\n2757:\t\t\t\txdp_do_flush();\n2758:\t\n2759:\t\t\tif (tfile-\u003enapi_enabled \u0026\u0026 queued \u003e 0)\n2760:\t\t\t\tnapi_schedule(\u0026tfile-\u003enapi);\n2761:\t\n2762:\t\t\tbpf_net_ctx_clear(bpf_net_ctx);\n2763:\t\t\trcu_read_unlock();\n2764:\t\t\tlocal_bh_enable();\n2765:\t\n2766:\t\t\ttun_put_page(\u0026tpage);\n2767:\t\n2768:\t\t\tret = total_len;\n2769:\t\t\tgoto out;\n2770:\t\t}\n2771:\t\n2772:\t\tret = tun_get_user(tun, tfile, ctl ? ctl-\u003eptr : NULL, \u0026m-\u003emsg_iter,\n2773:\t\t\t\t m-\u003emsg_flags \u0026 MSG_DONTWAIT,\n2774:\t\t\t\t m-\u003emsg_flags \u0026 MSG_MORE);\n2775:\tout:\n2776:\t\ttun_put(tun);\n2777:\t\treturn ret;\n2778:\t}\n2779:\t\n"
} |
| 25/2 | 2026/11/05 11:25 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20695 output: 260 thoughts: 607 Thoughts: **Analyzing the TUN/TAP Device Implementation for Potential Concurrency Issues** Okay, so I'm looking at how TUN devices handle incoming packets, specifically focusing on potential vulnerabilities related to concurrency and resource management. `tun_sendmsg` is the entry point, receiving packets from `vhost_net` or other socket callers. My immediate concern is the queue length check, `tun_napi_queue_full`. It's a small static function, which probably means it gets inlined into the crucial functions – `tun_get_user` and `tun_xdp_one` primarily, but I also see it's relevant to `tun_napi_poll`, `tun_napi_receive`, and `tun_queue_purge`, as well as write entrypoints `tun_chr_write_iter` and `tun_sendmsg`. Let's quickly check the required configurations. It looks like `CONFIG_TUN`, `CONFIG_INET`, and `CONFIG_VHOST_NET` are all relevant here. Good. Now, let's understand exactly what the proposed changes are. The patch modifies `drivers/net/tun.c` by bounding the NAPI packet write queue when `IFF_NAPI` is active, utilizing `net_hotdata.max_backlog`. It replaces the stack-allocated `process_queue` in `tun_napi_receive` with a per-file `napi_process_queue` within the `struct tun_file`. The goal is to avoid putting unbudgeted SKBs back onto `sk_write_queue`. Incoming packets will be dropped when the queue limit is reached, and NAPI scheduling is managed within `tun_get_user` and `tun_xdp_one`. The patch also includes purging the `napi_process_queue` in `tun_queue_purge`. I'm thinking about the fuzzing potential here. TUN/TAP devices are a significant attack surface because they're easily accessible from userspace, even unprivileged, through `/dev/net/tun`, and they're also integral to `vhost-net`. This patch is worth a close look because these code paths are widely used in standard QEMU/KVM virtualized environments, making them ideal for fuzzing. The patch is addressing potential race conditions, skb leaks, double-frees, and locking issues that could arise from concurrent queuing, dropping, NAPI scheduling, zerocopy completion callbacks, and teardown/purging. So, the critical configurations are `TUN`, `INET`, and `VHOST_NET`. The key focus functions for my fuzzing efforts are `tun_get_user`, `tun_napi_receive`, `tun_napi_poll`, `tun_xdp_one`, and `tun_queue_purge`. Alright, I'm ready to move on to setting up my fuzzing tools and get a test environment spun up. |
| 26/2 | 2026/11/05 11:26 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"TUN",
"INET",
"VHOST_NET"
],
"FocusSymbols": [
"tun_get_user",
"tun_napi_receive",
"tun_napi_poll",
"tun_xdp_one",
"tun_queue_purge"
],
"Reasoning": "The patch modifies the TUN/TAP driver (drivers/net/tun.c) to bound the IFF_NAPI receive queue using net_hotdata.max_backlog. It alters queue management by moving the NAPI processing queue to struct tun_file (napi_process_queue) so leftover skbs are not pushed back onto sk_write_queue, implements packet drop and NAPI scheduling logic when queues are full in tun_get_user() and tun_xdp_one(), and updates queue purging in tun_queue_purge(). TUN/TAP devices and vhost-net are software-emulated virtual network drivers readily reachable in standard virtualized environments. Fuzzing is warranted to detect potential concurrency regressions, memory leaks, double frees, or locking issues during packet queuing, NAPI processing, and driver teardown.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"TUN",
"INET",
"VHOST_NET"
],
"FocusSymbols": [
"tun_get_user",
"tun_napi_receive",
"tun_napi_poll",
"tun_xdp_one",
"tun_queue_purge"
],
"Reasoning": "The patch modifies the TUN/TAP driver (drivers/net/tun.c) to bound the IFF_NAPI receive queue using net_hotdata.max_backlog. It alters queue management by moving the NAPI processing queue to struct tun_file (napi_process_queue) so leftover skbs are not pushed back onto sk_write_queue, implements packet drop and NAPI scheduling logic when queues are full in tun_get_user() and tun_xdp_one(), and updates queue purging in tun_queue_purge(). TUN/TAP devices and vhost-net are software-emulated virtual network drivers readily reachable in standard virtualized environments. Fuzzing is warranted to detect potential concurrency regressions, memory leaks, double frees, or locking issues during packet queuing, NAPI processing, and driver teardown.",
"WorthFuzzing": true
} |
| 27/1 | 2026/11/05 11:26 | action | If |
4mArgs:{
"WorthFuzzing": true
}Results: null |
| 28/2 | 2026/11/05 11:26 | agent | kmsan-evaluator |
4mModel:core Args: null Results: {
"KMSANReasoning": "The patch bounds the NAPI skb backlog in drivers/net/tun.c to prevent unbounded memory usage when packets are queued faster than NAPI poll consumes them. It introduces a queue length check against net_hotdata.max_backlog, drops excess packets (handling zerocopy completion when applicable), and moves the temporary splice queue from the stack in tun_napi_receive() into a persistent member in struct tun_file (tfile-\u003enapi_process_queue).\n\nKMSAN vs KASAN Applicability:\n- No uninitialized memory usage: The new queue structure `napi_process_queue` in `struct tun_file` is explicitly initialized with `__skb_queue_head_init()` during `tun_chr_open()`. All conditional logic depends strictly on initialized state (queue lengths, net_hotdata.max_backlog, tfile-\u003enapi_enabled, msg_control).\n- No kernel-to-user info-leak: The patch touches packet queuing and drop paths within the network driver; no uninitialized kernel structures, padding, or buffers are copied to user space.\n- Any bugs introduced by this patch would pertain to synchronization/concurrency, queue starvation, skb lifecycle management (leaks or use-after-free), or socket control flow. These failure modes are covered by standard bug detectors, KASAN, and LOCKDEP rather than KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 476baedcb9b3a5e1c53d957010b106174895cec8
Author: syz-cluster <triage@syzkaller.com>
Date: Thu Nov 5 11:13:41 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 770b8fe085c323..ea99ee0aee2bb5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -58,6 +58,7 @@
#include <linux/nsproxy.h>
#include <linux/virtio_net.h>
#include <linux/rcupdate.h>
+#include <net/hotdata.h>
#include <net/net_namespace.h>
#include <net/netns/generic.h>
#include <net/rtnetlink.h>
@@ -140,6 +141,8 @@ struct tun_file {
unsigned int ifindex;
};
struct napi_struct napi;
+ /* NAPI poll only: skbs taken off sk_write_queue, not yet received */
+ struct sk_buff_head napi_process_queue;
bool napi_enabled;
bool napi_frags_enabled;
struct mutex napi_mutex; /* Protects access to the above napi */
@@ -227,31 +230,40 @@ struct veth {
static void tun_flow_init(struct tun_struct *tun);
static void tun_flow_uninit(struct tun_struct *tun);
+/* In IFF_NAPI mode written packets wait in the tfile's sk_write_queue for the
+ * NAPI poll, which may run later in a kthread or ksoftirqd. Bound that queue
+ * like the per-CPU backlog of netif_rx().
+ */
+static bool tun_napi_queue_full(const struct sk_buff_head *queue)
+{
+ return skb_queue_len_lockless(queue) >
+ READ_ONCE(net_hotdata.max_backlog);
+}
+
static int tun_napi_receive(struct napi_struct *napi, int budget)
{
struct tun_file *tfile = container_of(napi, struct tun_file, napi);
+ struct sk_buff_head *process_queue = &tfile->napi_process_queue;
struct sk_buff_head *queue = &tfile->sk.sk_write_queue;
- struct sk_buff_head process_queue;
struct sk_buff *skb;
int received = 0;
- __skb_queue_head_init(&process_queue);
-
- spin_lock(&queue->lock);
- skb_queue_splice_tail_init(queue, &process_queue);
- spin_unlock(&queue->lock);
-
- while (received < budget && (skb = __skb_dequeue(&process_queue))) {
+ while (received < budget) {
+ /* Refill only when empty: leftovers are not put back on the
+ * queue writers check, so neither queue exceeds the limit.
+ */
+ if (skb_queue_empty(process_queue)) {
+ spin_lock(&queue->lock);
+ skb_queue_splice_tail_init(queue, process_queue);
+ spin_unlock(&queue->lock);
+ if (skb_queue_empty(process_queue))
+ break;
+ }
+ skb = __skb_dequeue(process_queue);
napi_gro_receive(napi, skb);
++received;
}
- if (!skb_queue_empty(&process_queue)) {
- spin_lock(&queue->lock);
- skb_queue_splice(&process_queue, queue);
- spin_unlock(&queue->lock);
- }
-
return received;
}
@@ -572,6 +584,8 @@ static void tun_queue_purge(struct tun_file *tfile)
tun_ptr_free(ptr);
skb_queue_purge(&tfile->sk.sk_write_queue);
+ /* NAPI is disabled by now */
+ __skb_queue_purge(&tfile->napi_process_queue);
skb_queue_purge(&tfile->sk.sk_error_queue);
}
@@ -1856,6 +1870,23 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
zerocopy = true;
}
+ /* NAPI queue full: drop before allocating, and schedule NAPI, which a
+ * MSG_MORE sender may not have done yet. Rechecked under the lock.
+ */
+ if (tfile->napi_enabled &&
+ unlikely(tun_napi_queue_full(&tfile->sk.sk_write_queue))) {
+ local_bh_disable();
+ napi_schedule(&tfile->napi);
+ local_bh_enable();
+ if (msg_control) {
+ struct ubuf_info *uarg = msg_control;
+
+ uarg->ops->complete(NULL, uarg, false);
+ }
+ dev_core_stats_rx_dropped_inc(tun->dev);
+ return total_len;
+ }
+
if (!frags && tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) {
/* For the packet that is not easy to be processed
* (e.g gso or jumbo packet), we will do it at after
@@ -2045,6 +2076,17 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
goto free_skb;
}
+ /* NAPI queue full: drop, as above */
+ if (unlikely(tun_napi_queue_full(queue))) {
+ spin_unlock(&queue->lock);
+ napi_schedule(&tfile->napi);
+ local_bh_enable();
+ rcu_read_unlock();
+ dev_core_stats_rx_dropped_inc(tun->dev);
+ drop_reason = SKB_DROP_REASON_FULL_RING;
+ goto free_skb;
+ }
+
__skb_queue_tail(queue, skb);
queue_len = skb_queue_len(queue);
spin_unlock(&queue->lock);
@@ -2649,6 +2691,17 @@ static int tun_xdp_one(struct tun_struct *tun,
return -EBUSY;
}
+ /* NAPI queue full: drop, and schedule NAPI so that it drains
+ * even if nothing in this batch gets queued
+ */
+ if (unlikely(tun_napi_queue_full(queue))) {
+ spin_unlock(&queue->lock);
+ napi_schedule(&tfile->napi);
+ kfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING);
+ dev_core_stats_rx_dropped_inc(tun->dev);
+ return 0;
+ }
+
__skb_queue_tail(queue, skb);
spin_unlock(&queue->lock);
ret = 1;
@@ -3571,6 +3624,7 @@ static int tun_chr_open(struct inode *inode, struct file * file)
}
mutex_init(&tfile->napi_mutex);
+ __skb_queue_head_init(&tfile->napi_process_queue);
RCU_INIT_POINTER(tfile->tun, NULL);
tfile->flags = 0;
tfile->ifindex = 0;
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index df215e1a62621b..de4cdaac99a037 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -203,6 +203,7 @@ TEST_GEN_PROGS := \
tap \
tcp_port_share \
tls \
+ tun_vhost \
udp_splice_checksum \
# end of TEST_GEN_PROGS
diff --git a/tools/testing/selftests/net/config b/tools/testing/selftests/net/config
index cb8cb4696df793..1dce372caf4316 100644
--- a/tools/testing/selftests/net/config
+++ b/tools/testing/selftests/net/config
@@ -136,6 +136,7 @@ CONFIG_TRACEPOINTS=y
CONFIG_TUN=y
CONFIG_USER_NS=y
CONFIG_VETH=y
+CONFIG_VHOST_NET=m
CONFIG_VLAN_8021Q=y
CONFIG_VXLAN=m
CONFIG_XFRM_INTERFACE=m
diff --git a/tools/testing/selftests/net/tun_vhost.c b/tools/testing/selftests/net/tun_vhost.c
new file mode 100644
index 00000000000000..dbf76d324a7e20
--- /dev/null
+++ b/tools/testing/selftests/net/tun_vhost.c
@@ -0,0 +1,361 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Send packets from vhost-net into a tap device with IFF_NAPI and check
+ * that the NAPI queue is bounded by netdev_max_backlog: excess packets
+ * are dropped and counted, and every buffer is returned to the driver,
+ * zerocopy ones included.
+ *
+ * vhost-net passes packets to tun in three ways:
+ * - batch: batches of XDP buffers (tun_xdp_one()), the default when the
+ * socket send buffer is unlimited and zerocopy is disabled
+ * - copy: one packet per sendmsg(), when the send buffer is limited
+ * - zerocopy: one packet per sendmsg() with a ubuf_info to complete,
+ * only with vhost_net experimental_zcopytx=1 (else skipped)
+ *
+ * Tun schedules NAPI only after a batch, or after the last of a series of
+ * MSG_MORE packets, so with a small netdev_max_backlog the queue always
+ * overflows. It must keep draining while the sender keeps sending.
+ *
+ * Author: Antonio Quartulli <antonio@mandelbit.com>
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <sched.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <linux/if.h>
+#include <linux/if_arp.h>
+#include <linux/if_ether.h>
+#include <linux/if_tun.h>
+#include <linux/vhost.h>
+#include <linux/virtio_config.h>
+#include <linux/virtio_net.h>
+#include <linux/virtio_ring.h>
+#include <sys/eventfd.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include "kselftest_harness.h"
+
+#define TV_IFNAME "tvh0"
+#define TV_RING_NUM 256
+#define TV_BUF_SIZE 2048
+#define TV_HDR_LEN sizeof(struct virtio_net_hdr_v1)
+#define TV_PKTS (64 * TV_RING_NUM)
+#define TV_BACKLOG "8"
+#define TV_TX_VQ 1
+
+static const unsigned char tv_mac_tap[ETH_ALEN] = { 2, 0, 0, 0, 0, 1 };
+static const unsigned char tv_mac_dst[ETH_ALEN] = { 2, 0, 0, 0, 0, 2 };
+static const unsigned char tv_mac_src[ETH_ALEN] = { 2, 0, 0, 0, 0, 3 };
+
+struct tv_stats {
+ unsigned long long rx_packets;
+ unsigned long long rx_dropped;
+};
+
+static int tv_read_stats(const char *ifname, struct tv_stats *st)
+{
+ char line[512], *p;
+ FILE *f;
+ int ret = -1;
+
+ f = fopen("/proc/net/dev", "r");
+ if (!f)
+ return -1;
+ while (fgets(line, sizeof(line), f)) {
+ p = strchr(line, ':');
+ if (!p)
+ continue;
+ *p = '\0';
+ if (strcmp(line + strspn(line, " "), ifname))
+ continue;
+ if (sscanf(p + 1, "%*u %llu %*u %llu", &st->rx_packets,
+ &st->rx_dropped) == 2)
+ ret = 0;
+ break;
+ }
+ fclose(f);
+ return ret;
+}
+
+FIXTURE(tun_vhost)
+{
+ int backlog_fd;
+ char backlog[32];
+ int tap;
+ int vhost;
+ int kick;
+ int call;
+ void *ring;
+ struct vring vr;
+ char *bufs;
+ unsigned short avail_idx;
+ unsigned short used_idx;
+};
+
+FIXTURE_VARIANT(tun_vhost)
+{
+ bool batch;
+ bool limit_sndbuf;
+ bool zerocopy;
+ int pktlen;
+};
+
+FIXTURE_VARIANT_ADD(tun_vhost, batch)
+{
+ .batch = true,
+ .pktlen = 64,
+};
+
+FIXTURE_VARIANT_ADD(tun_vhost, copy)
+{
+ .limit_sndbuf = true,
+ .pktlen = 64,
+};
+
+FIXTURE_VARIANT_ADD(tun_vhost, zerocopy)
+{
+ .limit_sndbuf = true,
+ .zerocopy = true,
+ .pktlen = 1000,
+};
+
+static bool tv_zerocopy_enabled(void)
+{
+ char c = '0';
+ int fd;
+
+ fd = open("/sys/module/vhost_net/parameters/experimental_zcopytx",
+ O_RDONLY);
+ if (fd < 0)
+ return false;
+ if (read(fd, &c, 1) != 1)
+ c = '0';
+ close(fd);
+ return c == '1';
+}
+
+static void tv_vhost_setup(struct __test_metadata *_metadata,
+ FIXTURE_DATA(tun_vhost) *self)
+{
+ struct vhost_vring_state state = { .index = TV_TX_VQ };
+ struct vhost_vring_file file = { .index = TV_TX_VQ };
+ struct vhost_vring_addr addr = { .index = TV_TX_VQ };
+ size_t memsz = sizeof(struct vhost_memory) +
+ sizeof(struct vhost_memory_region);
+ unsigned long long features;
+ struct vhost_memory *mem;
+
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_OWNER, NULL), 0);
+ ASSERT_EQ(ioctl(self->vhost, VHOST_GET_FEATURES, &features), 0);
+ ASSERT_TRUE(features & (1ULL << VIRTIO_F_VERSION_1));
+ features = 1ULL << VIRTIO_F_VERSION_1;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_FEATURES, &features), 0);
+
+ /* buffer addresses are passed as is: map them 1:1 */
+ mem = calloc(1, memsz);
+ ASSERT_NE(mem, NULL);
+ mem->nregions = 1;
+ mem->regions[0].guest_phys_addr = (unsigned long)self->bufs;
+ mem->regions[0].userspace_addr = (unsigned long)self->bufs;
+ mem->regions[0].memory_size = TV_RING_NUM * TV_BUF_SIZE;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_MEM_TABLE, mem), 0);
+ free(mem);
+
+ state.num = TV_RING_NUM;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_NUM, &state), 0);
+ state.num = 0;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_BASE, &state), 0);
+ addr.desc_user_addr = (unsigned long)self->vr.desc;
+ addr.avail_user_addr = (unsigned long)self->vr.avail;
+ addr.used_user_addr = (unsigned long)self->vr.used;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_ADDR, &addr), 0);
+ file.fd = self->kick;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_KICK, &file), 0);
+ file.fd = self->call;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_SET_VRING_CALL, &file), 0);
+ file.fd = self->tap;
+ ASSERT_EQ(ioctl(self->vhost, VHOST_NET_SET_BACKEND, &file), 0);
+}
+
+FIXTURE_SETUP(tun_vhost)
+{
+ struct ifreq ifr = {};
+ int hdrlen = TV_HDR_LEN;
+ int sndbuf = 1 << 20;
+ ssize_t n;
+ int i, fd;
+
+ self->tap = -1;
+ self->vhost = open("/dev/vhost-net", O_RDWR);
+ if (self->vhost < 0)
+ SKIP(return, "no /dev/vhost-net");
+ if (variant->zerocopy && !tv_zerocopy_enabled())
+ SKIP(return, "vhost_net experimental_zcopytx not enabled");
+ if (variant->batch && tv_zerocopy_enabled())
+ SKIP(return, "vhost_net does not batch with zerocopy");
+
+ /* global, and only visible from init_net: keep it open to restore */
+ self->backlog_fd = open("/proc/sys/net/core/netdev_max_backlog",
+ O_RDWR);
+ ASSERT_GE(self->backlog_fd, 0);
+ n = read(self->backlog_fd, self->backlog, sizeof(self->backlog) - 1);
+ ASSERT_GT(n, 0);
+ self->backlog[n] = '\0';
+ ASSERT_EQ(pwrite(self->backlog_fd, TV_BACKLOG, strlen(TV_BACKLOG), 0),
+ strlen(TV_BACKLOG));
+
+ ASSERT_EQ(unshare(CLONE_NEWNET), 0);
+
+ self->tap = open("/dev/net/tun", O_RDWR);
+ ASSERT_GE(self->tap, 0);
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR | IFF_NAPI;
+ memcpy(ifr.ifr_name, TV_IFNAME, sizeof(TV_IFNAME));
+ ASSERT_EQ(ioctl(self->tap, TUNSETIFF, &ifr), 0);
+ ASSERT_EQ(ioctl(self->tap, TUNSETVNETHDRSZ, &hdrlen), 0);
+ if (variant->limit_sndbuf)
+ ASSERT_EQ(ioctl(self->tap, TUNSETSNDBUF, &sndbuf), 0);
+
+ fd = socket(AF_INET, SOCK_DGRAM, 0);
+ ASSERT_GE(fd, 0);
+ ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ memcpy(ifr.ifr_hwaddr.sa_data, tv_mac_tap, ETH_ALEN);
+ ASSERT_EQ(ioctl(fd, SIOCSIFHWADDR, &ifr), 0);
+ ASSERT_EQ(ioctl(fd, SIOCGIFFLAGS, &ifr), 0);
+ ifr.ifr_flags |= IFF_UP;
+ ASSERT_EQ(ioctl(fd, SIOCSIFFLAGS, &ifr), 0);
+ close(fd);
+
+ /* every buffer: zeroed vnet header + IPv4 frame for another host,
+ * which the stack drops without counting it in rx_dropped
+ */
+ ASSERT_EQ(posix_memalign((void **)&self->bufs, 4096,
+ TV_RING_NUM * TV_BUF_SIZE), 0);
+ memset(self->bufs, 0, TV_RING_NUM * TV_BUF_SIZE);
+ for (i = 0; i < TV_RING_NUM; i++) {
+ unsigned char *eth = (unsigned char *)self->bufs +
+ i * TV_BUF_SIZE + TV_HDR_LEN;
+
+ memcpy(eth, tv_mac_dst, ETH_ALEN);
+ memcpy(eth + ETH_ALEN, tv_mac_src, ETH_ALEN);
+ eth[12] = ETH_P_IP >> 8;
+ eth[13] = ETH_P_IP & 0xff;
+ eth[14] = 0x45;
+ }
+
+ ASSERT_EQ(posix_memalign(&self->ring, 4096,
+ vring_size(TV_RING_NUM, 4096)), 0);
+ memset(self->ring, 0, vring_size(TV_RING_NUM, 4096));
+ vring_init(&self->vr, TV_RING_NUM, self->ring, 4096);
+
+ self->kick = eventfd(0, EFD_NONBLOCK);
+ self->call = eventfd(0, EFD_NONBLOCK);
+ ASSERT_GE(self->kick, 0);
+ ASSERT_GE(self->call, 0);
+
+ tv_vhost_setup(_metadata, self);
+}
+
+FIXTURE_TEARDOWN(tun_vhost)
+{
+ if (self->tap < 0)
+ return;
+ /* waits for outstanding zerocopy buffers */
+ close(self->vhost);
+ close(self->tap);
+ if (pwrite(self->backlog_fd, self->backlog, strlen(self->backlog),
+ 0) < 0)
+ TH_LOG("cannot restore netdev_max_backlog to %s",
+ self->backlog);
+ close(self->backlog_fd);
+}
+
+/* queue up to @n buffers, return how many */
+static int tv_post(FIXTURE_DATA(tun_vhost) *self, int pktlen, int n)
+{
+ int inflight = (unsigned short)(self->avail_idx - self->used_idx);
+ unsigned long long one = 1;
+ int i;
+
+ for (i = 0; i < n && inflight < TV_RING_NUM; i++, inflight++) {
+ unsigned int id = self->avail_idx % TV_RING_NUM;
+
+ self->vr.desc[id].addr = (unsigned long)self->bufs +
+ id * TV_BUF_SIZE;
+ self->vr.desc[id].len = TV_HDR_LEN + pktlen;
+ self->vr.desc[id].flags = 0;
+ self->vr.avail->ring[id] = id;
+ self->avail_idx++;
+ }
+ __atomic_store_n(&self->vr.avail->idx, self->avail_idx,
+ __ATOMIC_RELEASE);
+ if (i && write(self->kick, &one, sizeof(one)) != sizeof(one))
+ return -1;
+ return i;
+}
+
+/* reap returned buffers, waiting up to @ms for at least one */
+static int tv_reap(FIXTURE_DATA(tun_vhost) *self, int ms)
+{
+ struct pollfd pfd = { .fd = self->call, .events = POLLIN };
+ unsigned short used;
+ unsigned long long v;
+
+ for (;;) {
+ used = __atomic_load_n(&self->vr.used->idx, __ATOMIC_ACQUIRE);
+ if (used != self->used_idx) {
+ int n = (unsigned short)(used - self->used_idx);
+
+ self->used_idx = used;
+ return n;
+ }
+ if (ms <= 0 || poll(&pfd, 1, 100) < 0)
+ return 0;
+ if (pfd.revents & POLLIN && read(self->call, &v, sizeof(v)) < 0)
+ return -1;
+ ms -= 100;
+ }
+}
+
+TEST_F(tun_vhost, napi_queue_bounded)
+{
+ struct tv_stats before, after;
+ unsigned long long delivered, dropped;
+ int posted = 0, reaped = 0, n;
+
+ ASSERT_EQ(tv_read_stats(TV_IFNAME, &before), 0);
+
+ while (reaped < TV_PKTS) {
+ n = tv_post(self, variant->pktlen, TV_PKTS - posted);
+ ASSERT_GE(n, 0);
+ posted += n;
+ n = tv_reap(self, 5000);
+ ASSERT_GE(n, 0);
+ if (!n) {
+ TH_LOG("%d of %d buffers not returned",
+ posted - reaped, posted);
+ ASSERT_GT(n, 0);
+ }
+ reaped += n;
+ }
+
+ ASSERT_EQ(tv_read_stats(TV_IFNAME, &after), 0);
+ delivered = after.rx_packets - before.rx_packets;
+ dropped = after.rx_dropped - before.rx_dropped;
+ TH_LOG("sent %d, delivered %llu, dropped %llu", TV_PKTS, delivered,
+ dropped);
+ /* bounded, */
+ EXPECT_GT(dropped, 0);
+ /* still draining, */
+ EXPECT_GE(delivered, TV_PKTS / 64);
+ /* and every packet accounted for */
+ EXPECT_EQ(delivered + dropped, TV_PKTS);
+}
+
+TEST_HARNESS_MAIN
|
| 29/3 | 2026/11/05 11:26 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 8954 output: 33 thoughts: 1164 Thoughts: **KMSAN Fuzzing Session Justification: Analyzing the TUN Driver Patch** Alright, let's get down to brass tacks. I need to figure out if this patch series warrants a dedicated KMSAN fuzzing session. The standard KASAN setup is pretty robust, covering a lot of ground with OOB, UAF, and the like. KMSAN only becomes relevant if we're introducing new risks of reading uninitialized memory, either on the stack, heap, or in page allocations, or if we're potentially leaking kernel memory to user space through uninitialized data. If KASAN, LOCKDEP, or any standard bug detectors can catch the issue, we don't need a KMSAN session. I have to apply the rules here: only consider NeedsKMSAN when: 1. Kernel structures go to user space with uninitialized fields. 2. Conditional logic or branching depends on potentially uninitialized variables. 3. We allocate or initialize complex data structures with the potential for uninitialized fields to be read. 4. Bounds checks, lengths, or logic allow access to uninitialized bytes of existing buffers. If the patch primarily deals with OOB, overflows, NULL derefs, or locking issues, we can stick with standard bug detectors. Similarly, if the code zeroes or initializes all introduced structures before reading or copying, we're likely in the clear. So, no risk of uninitialized memory usage or info-leaks, and we can skip KMSAN. Okay, let's dig into the diff. The patch adds a `struct sk_buff_head napi_process_queue` to the `tun_file` struct. It's initialized using `__skb_queue_head_init` in `tun_chr_open` and purged in `tun_queue_purge`. No red flags there. `tun_napi_queue_full` just checks queue length, which should be fine. The big change seems to be in `tun_napi_receive`. It refactors how skbs are handled from `sk.sk_write_queue` to `tfile->napi_process_queue`. Previously, a local `process_queue` was used on the stack, now it's a persistent queue within `tun_file`. The concern, as I see it, is how the new persistent queue is initialized. Let's see if the queue is fully initialized before read/copied. The checks in `tun_get_user` and `tun_xdp_one` call `tun_napi_queue_full`, potentially scheduling `napi` if `tfile->sk.sk_write_queue` is full. Nothing concerning there, it is a conditional check. The addition of tools and testing is good, but it doesn't change the KMSAN analysis. So, the key questions are: Is `tfile` properly initialized at all? Is `napi_process_queue` fully initialized before use? And, given how it's handled, am I dealing with an initialization problem? Let's do some quick grepping. I'll search for allocation of `struct tun_file` or occurrences of `tun_chr_open` to see how the `tun_file` is allocated and initialized. This is the crux of the issue. I need to make sure this new `napi_process_queue` doesn't leave uninitialized memory lying around where it shouldn't. If the tun_file is fully initialized, then we don't have KMSAN issue. |
| 30/3 | 2026/11/05 11:27 | tool | grepper |
0mArgs:{
"Expression": "tun_chr_open",
"PathPrefixes": [
"drivers/net/tun.c"
]
}Results: {
"Output": "drivers/net/tun.c=3588=static int tun_chr_fasync(int fd, struct file *file, int on)\n--\ndrivers/net/tun.c-3611-\ndrivers/net/tun.c:3612:static int tun_chr_open(struct inode *inode, struct file * file)\ndrivers/net/tun.c-3613-{\n--\ndrivers/net/tun.c=3683=static const struct file_operations tun_fops = {\n--\ndrivers/net/tun.c-3691-#endif\ndrivers/net/tun.c:3692:\t.open\t= tun_chr_open,\ndrivers/net/tun.c-3693-\t.release = tun_chr_close,\n"
} |
| 31/3 | 2026/11/05 11:27 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11107 output: 36 thoughts: 21 Thoughts: Okay, let's dive into this. I'm going to pull up `drivers/net/tun.c` and specifically focus on the `tun_chr_open` function. It's the character device open function for the TUN driver, so it's the entry point when a user-space application attempts to create a TUN/TAP interface. I need to understand the initialization process here. What's happening in this function when a user-space application first interacts with the device? Is it allocating a new TUN device structure? Is it handling permissions and access control? Are there any security considerations or potential race conditions that jump out? This is where the magic (or the problems) likely begin for establishing a TUN interface. I expect it's handling things like allocating a file descriptor, setting up a file operation structure, and maybe even registering the new device within the kernel's network stack. I’ll need to see how it ties into the other file operations defined for this driver. Understanding the interaction between `tun_chr_open` and `tun_ioctl` is going to be crucial for understanding the complete control path. Let's get to reading the code... |
| 32/3 | 2026/11/05 11:27 | tool | read-file |
0mArgs:{
"File": "drivers/net/tun.c",
"FirstLine": 3612,
"LineCount": 40
}Results: {
"Contents": "3612:\tstatic int tun_chr_open(struct inode *inode, struct file * file)\n3613:\t{\n3614:\t\tstruct net *net = current-\u003ensproxy-\u003enet_ns;\n3615:\t\tstruct tun_file *tfile;\n3616:\t\n3617:\t\ttfile = (struct tun_file *)sk_alloc(net, AF_UNSPEC, GFP_KERNEL,\n3618:\t\t\t\t\t\t \u0026tun_proto, 0);\n3619:\t\tif (!tfile)\n3620:\t\t\treturn -ENOMEM;\n3621:\t\tif (ptr_ring_init(\u0026tfile-\u003etx_ring, 0, GFP_KERNEL)) {\n3622:\t\t\tsk_free(\u0026tfile-\u003esk);\n3623:\t\t\treturn -ENOMEM;\n3624:\t\t}\n3625:\t\n3626:\t\tmutex_init(\u0026tfile-\u003enapi_mutex);\n3627:\t\t__skb_queue_head_init(\u0026tfile-\u003enapi_process_queue);\n3628:\t\tRCU_INIT_POINTER(tfile-\u003etun, NULL);\n3629:\t\ttfile-\u003eflags = 0;\n3630:\t\ttfile-\u003eifindex = 0;\n3631:\t\n3632:\t\tinit_waitqueue_head(\u0026tfile-\u003esocket.wq.wait);\n3633:\t\n3634:\t\ttfile-\u003esocket.file = file;\n3635:\t\ttfile-\u003esocket.ops = \u0026tun_socket_ops;\n3636:\t\n3637:\t\tsock_init_data_uid(\u0026tfile-\u003esocket, \u0026tfile-\u003esk, current_fsuid());\n3638:\t\n3639:\t\ttfile-\u003esk.sk_write_space = tun_sock_write_space;\n3640:\t\ttfile-\u003esk.sk_sndbuf = INT_MAX;\n3641:\t\n3642:\t\tfile-\u003eprivate_data = tfile;\n3643:\t\tINIT_LIST_HEAD(\u0026tfile-\u003enext);\n3644:\t\n3645:\t\tsock_set_flag(\u0026tfile-\u003esk, SOCK_ZEROCOPY);\n3646:\t\n3647:\t\t/* tun groks IOCB_NOWAIT just fine, mark it as such */\n3648:\t\tfile-\u003ef_mode |= FMODE_NOWAIT;\n3649:\t\treturn 0;\n3650:\t}\n3651:\t\n"
} |
| 33/3 | 2026/11/05 11:27 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 12058 output: 36 thoughts: 972 Thoughts: **Analyzing the Data Flow and Queue Management in the TUN Driver** Okay, let's break this down. First, `sk_alloc` seems to handle allocating and potentially zeroing the `struct sock` or related structures. I need to double-check the zeroing behavior based on `zero_it`, but the initial setup using `kmem_cache_alloc` is clear. Then, `__skb_queue_head_init(&tfile->napi_process_queue)` properly initializes the `napi_process_queue`, setting up the linked list structure (`prev`, `next`, `qlen`, `lock`). I've verified this function's internals – `prev`, `next` both point to the queue itself, `qlen` is zero, and the spinlock is initialized. So, at open time, this queue is ready to go. Next, I examined `tun_queue_purge`. This is where the cleanup happens. It calls `skb_queue_purge` on `sk_write_queue` and `sk_error_queue` as expected, but crucially also calls `__skb_queue_purge` on `napi_process_queue`. This means any packets left in `napi_process_queue` are freed with `kfree_skb`. Now, `tun_napi_receive` is key. I see it uses a loop to receive packets within a given budget. The key is how it moves packets: first, if `process_queue` is empty, it *splices* (atomically moving the list) packets from `sk_write_queue` to `process_queue`. That's efficient. This is where the patch comes in. The code originally had a local stack variable, now it correctly has a proper queue in `struct tun_file`! Once the data has been spliced from `sk_write_queue` to `process_queue`, the `tun_napi_receive` function then dequeues packets, and calls `napi_gro_receive` on each. So `napi_gro_receive` is handling the GRO aggregation, after data is moved from `sk_write_queue` to `napi_process_queue`. Now, the "drop" handling in `tun_get_user` caught my eye. The check `tun_napi_queue_full` and then `napi_schedule` within a `local_bh_disable/enable` block is standard, but the key is that `tun_get_user` *returns* `total_len` if the queue is full and drops data. This is crucial for user-space flow control. It signals to the user that some data was "consumed" (dropped in this case), which is standard network behavior. So the function effectively short-circuits, returning the total length as consumed. I need to examine the context around lines 2045-2095 in `tun_get_user` to understand the full implications of this return path, but this drop mechanism using `napi_schedule` and returning total length to the user is what's important here. |
| 34/3 | 2026/11/05 11:29 | tool | read-file |
0mArgs:{
"File": "drivers/net/tun.c",
"FirstLine": 2040,
"LineCount": 60
}Results: {
"Contents": "2040:\t\t\t/* Exercise flow dissector code path. */\n2041:\t\t\tskb_push(skb, ETH_HLEN);\n2042:\t\t\theadlen = eth_get_headlen(tun-\u003edev, skb-\u003edata,\n2043:\t\t\t\t\t\t skb_headlen(skb));\n2044:\t\n2045:\t\t\tif (unlikely(headlen \u003e skb_headlen(skb))) {\n2046:\t\t\t\tWARN_ON_ONCE(1);\n2047:\t\t\t\terr = -ENOMEM;\n2048:\t\t\t\tdev_core_stats_rx_dropped_inc(tun-\u003edev);\n2049:\tnapi_busy:\n2050:\t\t\t\tnapi_free_frags(\u0026tfile-\u003enapi);\n2051:\t\t\t\trcu_read_unlock();\n2052:\t\t\t\tmutex_unlock(\u0026tfile-\u003enapi_mutex);\n2053:\t\t\t\treturn err;\n2054:\t\t\t}\n2055:\t\n2056:\t\t\tif (likely(napi_schedule_prep(\u0026tfile-\u003enapi))) {\n2057:\t\t\t\tlocal_bh_disable();\n2058:\t\t\t\tnapi_gro_frags(\u0026tfile-\u003enapi);\n2059:\t\t\t\tnapi_complete(\u0026tfile-\u003enapi);\n2060:\t\t\t\tlocal_bh_enable();\n2061:\t\t\t} else {\n2062:\t\t\t\terr = -EBUSY;\n2063:\t\t\t\tgoto napi_busy;\n2064:\t\t\t}\n2065:\t\t\tmutex_unlock(\u0026tfile-\u003enapi_mutex);\n2066:\t\t} else if (tfile-\u003enapi_enabled) {\n2067:\t\t\tstruct sk_buff_head *queue = \u0026tfile-\u003esk.sk_write_queue;\n2068:\t\t\tint queue_len;\n2069:\t\n2070:\t\t\tspin_lock_bh(\u0026queue-\u003elock);\n2071:\t\n2072:\t\t\tif (unlikely(tfile-\u003edetached)) {\n2073:\t\t\t\tspin_unlock_bh(\u0026queue-\u003elock);\n2074:\t\t\t\trcu_read_unlock();\n2075:\t\t\t\terr = -EBUSY;\n2076:\t\t\t\tgoto free_skb;\n2077:\t\t\t}\n2078:\t\n2079:\t\t\t/* NAPI queue full: drop, as above */\n2080:\t\t\tif (unlikely(tun_napi_queue_full(queue))) {\n2081:\t\t\t\tspin_unlock(\u0026queue-\u003elock);\n2082:\t\t\t\tnapi_schedule(\u0026tfile-\u003enapi);\n2083:\t\t\t\tlocal_bh_enable();\n2084:\t\t\t\trcu_read_unlock();\n2085:\t\t\t\tdev_core_stats_rx_dropped_inc(tun-\u003edev);\n2086:\t\t\t\tdrop_reason = SKB_DROP_REASON_FULL_RING;\n2087:\t\t\t\tgoto free_skb;\n2088:\t\t\t}\n2089:\t\n2090:\t\t\t__skb_queue_tail(queue, skb);\n2091:\t\t\tqueue_len = skb_queue_len(queue);\n2092:\t\t\tspin_unlock(\u0026queue-\u003elock);\n2093:\t\n2094:\t\t\tif (!more || queue_len \u003e NAPI_POLL_WEIGHT)\n2095:\t\t\t\tnapi_schedule(\u0026tfile-\u003enapi);\n2096:\t\n2097:\t\t\tlocal_bh_enable();\n2098:\t\t} else if (!IS_ENABLED(CONFIG_4KSTACKS)) {\n2099:\t\t\ttun_rx_batched(tun, tfile, skb, more);\n"
} |
| 35/3 | 2026/11/05 11:29 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14683 output: 36 thoughts: 149 Thoughts: Okay, let me break this down. **Analyzing Lock Ordering and Interrupt Disabling in the Kernel's Network Path** Alright, I'm taking a look at this network code, specifically focusing on the locking and interrupt disabling strategy used with `spin_lock_bh`. I'm seeing a pattern that immediately catches my eye: the paired usage of `spin_lock_bh` followed by `spin_unlock` and `local_bh_enable`. We've got `spin_lock_bh` disabling bottom halves and simultaneously acquiring `queue->lock`. Then, in the "drop path" of processing, the unlock and re-enable is as expected. `spin_unlock(&queue->lock)` releases the lock, `napi_schedule(&tfile->napi)` is called, which *requires* bottom halves to be disabled, and that's precisely what's guaranteed by the `spin_lock_bh` call earlier. Finally, `local_bh_enable()` re-enables bottom halves, putting everything back to a known state. So, this looks perfectly correct and safe. It's the standard, idiomatic use of `spin_lock_bh`. Now, I want to take a quick peek at the `tun_xdp_one` function, specifically around line 2690, just to confirm that the same pattern holds true there and the locking and interrupt state management is consistent throughout the code. |
| 36/3 | 2026/11/05 11:29 | tool | read-file |
0mArgs:{
"File": "drivers/net/tun.c",
"FirstLine": 2680,
"LineCount": 35
}Results: {
"Contents": "2680:\t\tif (!rcu_dereference(tun-\u003esteering_prog) \u0026\u0026 tun-\u003enumqueues \u003e 1 \u0026\u0026\n2681:\t\t !tfile-\u003edetached)\n2682:\t\t\trxhash = __skb_get_hash_symmetric(skb);\n2683:\t\n2684:\t\tif (tfile-\u003enapi_enabled) {\n2685:\t\t\tqueue = \u0026tfile-\u003esk.sk_write_queue;\n2686:\t\t\tspin_lock(\u0026queue-\u003elock);\n2687:\t\n2688:\t\t\tif (unlikely(tfile-\u003edetached)) {\n2689:\t\t\t\tspin_unlock(\u0026queue-\u003elock);\n2690:\t\t\t\tkfree_skb(skb);\n2691:\t\t\t\treturn -EBUSY;\n2692:\t\t\t}\n2693:\t\n2694:\t\t\t/* NAPI queue full: drop, and schedule NAPI so that it drains\n2695:\t\t\t * even if nothing in this batch gets queued\n2696:\t\t\t */\n2697:\t\t\tif (unlikely(tun_napi_queue_full(queue))) {\n2698:\t\t\t\tspin_unlock(\u0026queue-\u003elock);\n2699:\t\t\t\tnapi_schedule(\u0026tfile-\u003enapi);\n2700:\t\t\t\tkfree_skb_reason(skb, SKB_DROP_REASON_FULL_RING);\n2701:\t\t\t\tdev_core_stats_rx_dropped_inc(tun-\u003edev);\n2702:\t\t\t\treturn 0;\n2703:\t\t\t}\n2704:\t\n2705:\t\t\t__skb_queue_tail(queue, skb);\n2706:\t\t\tspin_unlock(\u0026queue-\u003elock);\n2707:\t\t\tret = 1;\n2708:\t\t} else {\n2709:\t\t\tnetif_receive_skb(skb);\n2710:\t\t\tret = 0;\n2711:\t\t}\n2712:\t\n2713:\t\t/* No need to disable preemption here since this function is\n2714:\t\t * always called with bh disabled\n"
} |
| 37/3 | 2026/11/05 11:29 | llm | kmsan-evaluator |
1mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 15713 output: 337 thoughts: 1318 Thoughts: **KMSAN Assessment: tun_napi_receive and Backlog Queue Limiting** Okay, let's break this down. My focus right now is on assessing whether this patch, which introduces backlog queue limiting for the tun driver, introduces any potential issues that KMSAN (Kernel Memory Sanitizer) should be concerned about. First, I'm checking the `tun_napi_receive` function. It looks like the core change involves a new `napi_process_queue` within the `tun_file` struct to handle packets before they are processed, pulling them from `sk_write_queue`. I need to be sure this new queue and the interaction with the existing queues are safe. I have to verify whether the `process_queue` needs locking within `__skb_dequeue` or `skb_queue_empty`. The good news is that `tun_napi_receive` runs within the NAPI poll context. NAPI poll operations are serialized. This means that only one poll will run at a time for a given NAPI struct, which simplifies the concurrency concerns somewhat. The comment in `struct tun_file` confirms this as well: "NAPI poll only: skbs taken off sk_write_queue, not yet received." And the cleanup in `tun_queue_purge` also confirms that both queues are properly handled. I'm now going through the checklist for potential uninitialized memory issues. 1. **Data copied to userspace?** Nope. The code only deals with internal kernel structures. No direct data copying to user space that could lead to information leaks. That's a huge relief. 2. **Conditional logic and uninitialized variables?** I'm checking the variables used in any conditional logic. Everything looks good. The conditions depend on: `tfile->sk.sk_write_queue` (initialized on sock creation), `net_hotdata.max_backlog` (kernel global), `tfile->napi_enabled` (a boolean initialized in tun ioctl/open), `skb_queue_empty(process_queue)` (initialized in `tun_chr_open`), and `msg_control` (from the function caller). All seem properly initialized. 3. **Complex data structure initialization?** The new `napi_process_queue` is added to `struct tun_file`, but crucially, it's initialized with `__skb_queue_head_init(&tfile->napi_process_queue)` in `tun_chr_open()`. That's critical, so the memory is properly set up. 4. **Buffer bounds and length issues?** Nope. This patch does not seem to mess with buffer boundaries or lengths, or alter any offsets. It's just limiting the number of queued packets. So, could any bug introduced be an uninitialized memory bug? No, that is very unlikely. Any potential bugs introduced would be locking issues, packet drops, race conditions, memory leaks (if an skb on `napi_process_queue` was leaked), etc. These are all things that KASAN, LOCKDEP, and general kernel testing would find. KMSAN isn't the right tool here. I'm also noting the selftest changes. The selftests run in userspace, so they're irrelevant for kernel uninitialized memory issues. Okay, let's summarize it. The patch limits the NAPI skb backlog queue using `net_hotdata.max_backlog`, and moves the processing queue into `struct tun_file`. There's no kernel data copied to userspace, the new queue is explicitly initialized, all branch conditions use well-defined values, and there are no changes to buffer bounds or offsets. The risks are related to concurrency, queue management, or memory management, all covered by existing kernel bug detectors. So, I'm confident in concluding that `NeedsKMSAN = false`. I'll run `set-results` now. |
| 38/3 | 2026/11/05 11:30 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch bounds the NAPI skb backlog in drivers/net/tun.c to prevent unbounded memory usage when packets are queued faster than NAPI poll consumes them. It introduces a queue length check against net_hotdata.max_backlog, drops excess packets (handling zerocopy completion when applicable), and moves the temporary splice queue from the stack in tun_napi_receive() into a persistent member in struct tun_file (tfile-\u003enapi_process_queue).\n\nKMSAN vs KASAN Applicability:\n- No uninitialized memory usage: The new queue structure `napi_process_queue` in `struct tun_file` is explicitly initialized with `__skb_queue_head_init()` during `tun_chr_open()`. All conditional logic depends strictly on initialized state (queue lengths, net_hotdata.max_backlog, tfile-\u003enapi_enabled, msg_control).\n- No kernel-to-user info-leak: The patch touches packet queuing and drop paths within the network driver; no uninitialized kernel structures, padding, or buffers are copied to user space.\n- Any bugs introduced by this patch would pertain to synchronization/concurrency, queue starvation, skb lifecycle management (leaks or use-after-free), or socket control flow. These failure modes are covered by standard bug detectors, KASAN, and LOCKDEP rather than KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch bounds the NAPI skb backlog in drivers/net/tun.c to prevent unbounded memory usage when packets are queued faster than NAPI poll consumes them. It introduces a queue length check against net_hotdata.max_backlog, drops excess packets (handling zerocopy completion when applicable), and moves the temporary splice queue from the stack in tun_napi_receive() into a persistent member in struct tun_file (tfile-\u003enapi_process_queue).\n\nKMSAN vs KASAN Applicability:\n- No uninitialized memory usage: The new queue structure `napi_process_queue` in `struct tun_file` is explicitly initialized with `__skb_queue_head_init()` during `tun_chr_open()`. All conditional logic depends strictly on initialized state (queue lengths, net_hotdata.max_backlog, tfile-\u003enapi_enabled, msg_control).\n- No kernel-to-user info-leak: The patch touches packet queuing and drop paths within the network driver; no uninitialized kernel structures, padding, or buffers are copied to user space.\n- Any bugs introduced by this patch would pertain to synchronization/concurrency, queue starvation, skb lifecycle management (leaks or use-after-free), or socket control flow. These failure modes are covered by standard bug detectors, KASAN, and LOCKDEP rather than KMSAN.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|