{"id":71116,"date":"2025-10-07T19:45:52","date_gmt":"2025-10-07T16:15:52","guid":{"rendered":"https:\/\/afaghhosting.net\/blog\/cve-2023-53685-tun-fix-memory-leak-for-detached-napi-queue\/"},"modified":"2025-10-07T19:45:52","modified_gmt":"2025-10-07T16:15:52","slug":"cve-2023-53685-tun-fix-memory-leak-for-detached-napi-queue","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/cve-2023-53685-tun-fix-memory-leak-for-detached-napi-queue\/","title":{"rendered":"CVE-2023-53685 &#8211; tun: Fix memory leak for detached NAPI queue."},"content":{"rendered":"<p>CVE ID : CVE-2023-53685<\/p>\n<p>Published :  Oct. 7, 2025, 4:15 p.m. | 19\u00a0minutes ago<\/p>\n<p>Description : In the Linux kernel, the following vulnerability has been resolved:<\/p>\n<p>tun: Fix memory leak for detached NAPI queue.<\/p>\n<p>syzkaller reported [0] memory leaks of sk and skb related to the TUN<br \/>\ndevice with no repro, but we can reproduce it easily with:<\/p>\n<p>  struct ifreq ifr = {}<br \/>\n  int fd_tun, fd_tmp;<br \/>\n  char buf[4] = {};<\/p>\n<p>  fd_tun = openat(AT_FDCWD, &#8220;\/dev\/net\/tun&#8221;, O_WRONLY, 0);<br \/>\n  ifr.ifr_flags = IFF_TUN | IFF_NAPI | IFF_MULTI_QUEUE;<br \/>\n  ioctl(fd_tun, TUNSETIFF, &amp;ifr);<\/p>\n<p>  ifr.ifr_flags = IFF_DETACH_QUEUE;<br \/>\n  ioctl(fd_tun, TUNSETQUEUE, &amp;ifr);<\/p>\n<p>  fd_tmp = socket(AF_PACKET, SOCK_PACKET, 0);<br \/>\n  ifr.ifr_flags = IFF_UP;<br \/>\n  ioctl(fd_tmp, SIOCSIFFLAGS, &amp;ifr);<\/p>\n<p>  write(fd_tun, buf, sizeof(buf));<br \/>\n  close(fd_tun);<\/p>\n<p>If we enable NAPI and multi-queue on a TUN device, we can put skb into<br \/>\ntfile-&gt;sk.sk_write_queue after the queue is detached.  We should prevent<br \/>\nit by checking tfile-&gt;detached before queuing skb.<\/p>\n<p>Note this must be done under tfile-&gt;sk.sk_write_queue.lock because write()<br \/>\nand ioctl(IFF_DETACH_QUEUE) can run concurrently.  Otherwise, there would<br \/>\nbe a small race window:<\/p>\n<p>  write()                             ioctl(IFF_DETACH_QUEUE)<br \/>\n  `- tun_get_user                     `- __tun_detach<br \/>\n     |- if (tfile-&gt;detached)             |- tun_disable_queue<br \/>\n     |  `-&gt; false                        |  `- tfile-&gt;detached = tun<br \/>\n     |                                   `- tun_queue_purge<br \/>\n     |- spin_lock_bh(&amp;queue-&gt;lock)<br \/>\n     `- __skb_queue_tail(queue, skb)<\/p>\n<p>Another solution is to call tun_queue_purge() when closing and<br \/>\nreattaching the detached queue, but it could paper over another<br \/>\nproblems.  Also, we do the same kind of test for IFF_NAPI_FRAGS.<\/p>\n[0]:<br \/>\nunreferenced object 0xffff88801edbc800 (size 2048):<br \/>\n  comm &#8220;syz-executor.1&#8221;, pid 33269, jiffies 4295743834 (age 18.756s)<br \/>\n  hex dump (first 32 bytes):<br \/>\n    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  &#8230;&#8230;&#8230;&#8230;&#8230;.<br \/>\n    00 00 07 40 00 00 00 00 00 00 00 00 00 00 00 00  &#8230;@&#8230;&#8230;&#8230;&#8230;<br \/>\n  backtrace:<br \/>\n    [] __do_kmalloc_node mm\/slab_common.c:965 [inline]\n    [] __kmalloc+0x4a\/0x130 mm\/slab_common.c:979<br \/>\n    [] kmalloc include\/linux\/slab.h:563 [inline]\n    [] sk_prot_alloc+0xef\/0x1b0 net\/core\/sock.c:2035<br \/>\n    [] sk_alloc+0x36\/0x2f0 net\/core\/sock.c:2088<br \/>\n    [] tun_chr_open+0x3d\/0x190 drivers\/net\/tun.c:3438<br \/>\n    [] misc_open+0x1a6\/0x1f0 drivers\/char\/misc.c:165<br \/>\n    [] chrdev_open+0x111\/0x300 fs\/char_dev.c:414<br \/>\n    [] do_dentry_open+0x2f9\/0x750 fs\/open.c:920<br \/>\n    [] do_open fs\/namei.c:3636 [inline]\n    [] path_openat+0x143f\/0x1a30 fs\/namei.c:3791<br \/>\n    [] do_filp_open+0xce\/0x1c0 fs\/namei.c:3818<br \/>\n    [] do_sys_openat2+0xf0\/0x260 fs\/open.c:1356<br \/>\n    [] do_sys_open fs\/open.c:1372 [inline]\n    [] __do_sys_openat fs\/open.c:1388 [inline]\n    [] __se_sys_openat fs\/open.c:1383 [inline]\n    [] __x64_sys_openat+0x83\/0xf0 fs\/open.c:1383<br \/>\n    [] do_syscall_x64 arch\/x86\/entry\/common.c:50 [inline]\n    [] do_syscall_64+0x3c\/0x90 arch\/x86\/entry\/common.c:80<br \/>\n    [] entry_SYSCALL_64_after_hwframe+0x72\/0xdc<\/p>\n<p>unreferenced object 0xffff88802f671700 (size 240):<br \/>\n  comm &#8220;syz-executor.1&#8221;, pid 33269, jiffies 4295743854 (age 18.736s)<br \/>\n  hex dump (first 32 bytes):<br \/>\n    68 c9 db 1e 80 88 ff ff 68 c9 db 1e 80 88 ff ff  h&#8230;&#8230;.h&#8230;&#8230;.<br \/>\n    00 c0 7b 2f 80 88 ff ff 00 c8 db 1e 80 88 ff ff  ..{\/&#8230;&#8230;&#8230;&#8230;<br \/>\n  backtrace:<br \/>\n    [] __alloc_skb+0x223\/0x250 net\/core\/skbuff.c:644<br \/>\n    [] alloc_skb include\/linux\/skbuff.h:1288 [inline]\n    [] alloc_skb_with_frags+0x6f\/0x350 net\/core\/skbuff.c:6378<br \/>\n    [] sock_alloc_send_pskb+0x3ac\/0x3e0 net\/core\/sock.c:2729<br \/>\n    [] tun_alloc_skb drivers\/net\/tun.c:1529 [inline]\n    [<br \/>\nSeverity: 0.0 | NA<\/p>\n<p>Visit the link for more details, such as CVSS details, affected products, timeline, and more&#8230;\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CVE ID : CVE-2023-53685 Published : Oct. 7, 2025, 4:15 p.m. | 19\u00a0minutes ago Description : In the Linux kernel, the following vulnerability has been resolved: tun: Fix memory leak for detached NAPI queue. syzkaller reported [0] memory leaks of sk and skb related to the TUN device with no repro, but we can reproduce &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-71116","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/71116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=71116"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/71116\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=71116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=71116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=71116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}