CVE-2023-53489

Severity CVSS v4.0:
Pending analysis
Type:
Unavailable / Other
Publication date:
01/10/2025
Last modified:
02/10/2025

Description

In the Linux kernel, the following vulnerability has been resolved:<br /> <br /> tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.<br /> <br /> syzkaller reported [0] memory leaks of an UDP socket and ZEROCOPY<br /> skbs. We can reproduce the problem with these sequences:<br /> <br /> sk = socket(AF_INET, SOCK_DGRAM, 0)<br /> sk.setsockopt(SOL_SOCKET, SO_TIMESTAMPING, SOF_TIMESTAMPING_TX_SOFTWARE)<br /> sk.setsockopt(SOL_SOCKET, SO_ZEROCOPY, 1)<br /> sk.sendto(b&amp;#39;&amp;#39;, MSG_ZEROCOPY, (&amp;#39;127.0.0.1&amp;#39;, 53))<br /> sk.close()<br /> <br /> sendmsg() calls msg_zerocopy_alloc(), which allocates a skb, sets<br /> skb-&gt;cb-&gt;ubuf.refcnt to 1, and calls sock_hold(). Here, struct<br /> ubuf_info_msgzc indirectly holds a refcnt of the socket. When the<br /> skb is sent, __skb_tstamp_tx() clones it and puts the clone into<br /> the socket&amp;#39;s error queue with the TX timestamp.<br /> <br /> When the original skb is received locally, skb_copy_ubufs() calls<br /> skb_unclone(), and pskb_expand_head() increments skb-&gt;cb-&gt;ubuf.refcnt.<br /> This additional count is decremented while freeing the skb, but struct<br /> ubuf_info_msgzc still has a refcnt, so __msg_zerocopy_callback() is<br /> not called.<br /> <br /> The last refcnt is not released unless we retrieve the TX timestamped<br /> skb by recvmsg(). Since we clear the error queue in inet_sock_destruct()<br /> after the socket&amp;#39;s refcnt reaches 0, there is a circular dependency.<br /> If we close() the socket holding such skbs, we never call sock_put()<br /> and leak the count, sk, and skb.<br /> <br /> TCP has the same problem, and commit e0c8bccd40fc ("net: stream:<br /> purge sk_error_queue in sk_stream_kill_queues()") tried to fix it<br /> by calling skb_queue_purge() during close(). However, there is a<br /> small chance that skb queued in a qdisc or device could be put<br /> into the error queue after the skb_queue_purge() call.<br /> <br /> In __skb_tstamp_tx(), the cloned skb should not have a reference<br /> to the ubuf to remove the circular dependency, but skb_clone() does<br /> not call skb_copy_ubufs() for zerocopy skb. So, we need to call<br /> skb_orphan_frags_rx() for the cloned skb to call skb_copy_ubufs().<br /> <br /> [0]:<br /> BUG: memory leak<br /> unreferenced object 0xffff88800c6d2d00 (size 1152):<br /> comm "syz-executor392", pid 264, jiffies 4294785440 (age 13.044s)<br /> hex dump (first 32 bytes):<br /> 00 00 00 00 00 00 00 00 cd af e8 81 00 00 00 00 ................<br /> 02 00 07 40 00 00 00 00 00 00 00 00 00 00 00 00 ...@............<br /> backtrace:<br /> [] sk_prot_alloc+0x64/0x2a0 net/core/sock.c:2024<br /> [] sk_alloc+0x3b/0x800 net/core/sock.c:2083<br /> [] inet_create net/ipv4/af_inet.c:319 [inline]<br /> [] inet_create+0x31e/0xe40 net/ipv4/af_inet.c:245<br /> [] __sock_create+0x2ab/0x550 net/socket.c:1515<br /> [] sock_create net/socket.c:1566 [inline]<br /> [] __sys_socket_create net/socket.c:1603 [inline]<br /> [] __sys_socket_create net/socket.c:1588 [inline]<br /> [] __sys_socket+0x138/0x250 net/socket.c:1636<br /> [] __do_sys_socket net/socket.c:1649 [inline]<br /> [] __se_sys_socket net/socket.c:1647 [inline]<br /> [] __x64_sys_socket+0x73/0xb0 net/socket.c:1647<br /> [] do_syscall_x64 arch/x86/entry/common.c:50 [inline]<br /> [] do_syscall_64+0x38/0x90 arch/x86/entry/common.c:80<br /> [] entry_SYSCALL_64_after_hwframe+0x63/0xcd<br /> <br /> BUG: memory leak<br /> unreferenced object 0xffff888017633a00 (size 240):<br /> comm "syz-executor392", pid 264, jiffies 4294785440 (age 13.044s)<br /> hex dump (first 32 bytes):<br /> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................<br /> 00 00 00 00 00 00 00 00 00 2d 6d 0c 80 88 ff ff .........-m.....<br /> backtrace:<br /> [] __alloc_skb+0x229/0x320 net/core/skbuff.c:497<br /> [] alloc_skb include/linux/skbuff.h:1265 [inline]<br /> [] sock_omalloc+0xaa/0x190 net/core/sock.c:2596<br /> [] msg_zerocopy_alloc net/core/skbuff.c:1294 [inline]<br /> []<br /> ---truncated---

Impact