From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 396CA8017D for ; Wed, 18 Nov 2026 21:06:01 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIL4hcd029338; Thu, 19 Nov 2026 00:04:44 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIL4hcd029338 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="pW6+Jy/L" Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AIL4gPA029334 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 00:04:42 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AIL4gPA029334 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-49953abe51fso9859195e9.1 for ; Wed, 18 Nov 2026 13:04:42 -0800 (PST) X-Gm-Message-State: APuU4Z+Q6AtnSYV/tTpoXmLLnVqUSo3lv4AKdLVXFrBVEZmhiAAaKeTC p0kM/EHtiHl+NEq6Nr8d0TOTYEBjsXcQO3X91P8Tdb/23nUzTMM1U1QxkIgNb/isi3Io04AU8VB lV0/SUl1NK1hRHvvl7zTKQhAu66ixAwjEL46wSA3WlLDAQJ7oZ3p3Vg== X-Gm-Gg: AYBFou2mHUxub22uD5SMwJ864OcTMvUpD3omoJ4q2+HeVW6PuDa6xG0IxTHVZ3cQbTg 3Tt+xm9MLUf6z+NvKgqNJ7NKAAqN5KryL0DC7nSVc5n+tlLPmfUJM7vZ0cofxtWeP7ChSqE3LAT Rj8tAnMOafBiVtU7vIwllf+ScQWzqLqLystekSqhymJb/Ky1hWpqhsDMFKUUlLNBwiQ/2MmJ9Me cVmmYM7zoWxV38fTw6zuT7z4hXH30wgHuJ/d82crMZVwuH/QEEBNU1rQJk2APIMvBAvcq1gOT16 zuceS9mUyP0hEaevF/K/lKrr0MzDE71hU+7NXIa5APbwEuyKbxIyn+oLL6p624ekTmVDjFRmWgG mR3AKc2p7cECuJSLO X-Received: by 2002:a05:600c:83cf:b0:4a0:1c0e:b057 with SMTP id 5b1f17b1804b1-4bb7d6cd41amr71488605e9.4.1795035881720; Wed, 18 Nov 2026 13:04:41 -0800 (PST) X-Received: by 2002:a05:600c:83cf:b0:4a0:1c0e:b057 with SMTP id 5b1f17b1804b1-4bb7d6cd41amr71488255e9.4.1795035881200; Wed, 18 Nov 2026 13:04:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795035881; cv=none; d=google.com; s=arc-20260327; b=LbETpgAfAuF6VHzWjkW7JADJnf27W6DZ837ARqi3Dl150hBsVZmHNrKjE8D0+Vo93E soVqiRMpuSV6+7ePfMSKcIyKpOGOTDqfygP+2bew/nDJJL3FmeO1rPC3bZUBYDRuSN39 OuPpXscMvp/fpxd+r2ltkO026ZQTbEbCa27WxsI0kRbatuyA3moBW82XJiCcXfrSP0Dr oW4sHs+2+DRbUmx+rKrSeSQkf0A8b9IEix7mReatawUPZFKL9+sIELQWPcrHJXuDZF/u SoRk49jCUBDdAGoyXx9/JfDg2qpFQXOrLy6CJuySdRrxIea5X8FEG8jaXiOdS+aLr7KQ THPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:dkim-signature; bh=HxWcOcFxJN8/hDA7hULbs2heVXyr1n1cIKQ+TVYJCQU=; fh=26FXTO6eY/S3gvyMXNKNKTFHQ0lD1bPkQ8wRpe0tMZI=; b=LNPX+uFds+w7fYayJ+GQY8LjMIhHQ1NMcpA3dbjhR8KumXzWWHO08HwP3o1LNyo5mH 2hKmzlJRMDVo68pOUmQNy+8WPxhNMEfPTt64b0Swm4fO0VOZDhn/VU41oHuyKJRdAtqH lpOWVNArQg7NFr65iXvwtZfOvyzSdJHDkO3RdeMTxMCmKWpcbNJpBTF97FFSfsf+d1m7 nO8xIKF5JoRTUM/QPoFNU8fngUYKpcyaNs3r9+Xg166hxUFH+KiNhmJwjqNRTBwtMOtv Bm5RGom31L1psLKZO05BqXcC4CqO3KdE5yNKKNZi57FqsilUD7H8Qo/NwyLzphOkOrn9 gZDA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="pW6+Jy/L"; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id 5b1f17b1804b1-4bb8325f288si12771195e9.9.2026.11.18.13.04.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 13:04:41 -0800 (PST) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b="pW6+Jy/L"; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=HxWcOcFxJN8/hDA7hULbs2heVXyr1n1cIKQ+TVYJCQU=; b=pW6+Jy/Lo/UNliFc5jx A3h78x5HNy4psRxxslH9OWrjihd1/HADVFFEfHEl930dbATid8BE+aGS5siE3u2jN8fUo/AtvW6FX 3NKnhGJqGH4QLXO/Yi6Qx14vb3fTaw47iCAvNjCEqDvQFiPbQV8gb89WChA/FB7slhMqlKzti018t 2jsBvnCEeuLp2CTc5niLck5uxj2fKyv/JHJAet+4MdyreRKG8ASuZEH3CaHc3L2tTXe1zLxwYyVmB NhP2dR4dsmGw3Fa5aMSDJ3C1vwav9OyqH9GQKodai9xaI2HndZYINqqf5Is42zLCasHAggbVaZ2Kh RBqkuyvo/Yuz1RQ==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTmlK-00Do8y-0N; Wed, 18 Nov 2026 22:04:39 +0100 From: Konstantin Khorenko Date: Wed, 18 Nov 2026 22:04:36 +0100 MIME-Version: 1.0 Message-Id: <20261118-b4-prep-khorenko-vstor-155948-sock-gettstamp-lock-v1-1-edadf747dbc6@virtuozzo.com> X-B4-Tracking: v=1; b=H4sIAOMS/moC/yWNQQ6CMBBFr0Jm7SQUWy1exbiAdoCK0qZTGyPh7 hZdvp/891Zgio4YLtUKkbJj55cC4lCBmbplJHS2MDR1cxJCaOwlhkgB58lHWmaPmZOPKJRqpUb 2ZsaRUuLUPQM+dmxJHm2vBquHGoq33Af3/jWvkD9nuP1HfvV3MmmvwbZ9ASOP43maAAAA X-Change-ID: 20261118-b4-prep-khorenko-vstor-155948-sock-gettstamp-lock-9e43db5fd8f0 To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=9592; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=BP+y01uHWpUUO7YsCT0LOQNm3ZMp2aUsCWXFpsmrqdE=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBq/hLo5dadIN/pUTZVPgYYPIPL4aju4bU0R2Xwj Xg9rbHKizKJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCav4S6AAKCRBRlgpH+WFc KqNSD/9G+ZHbCUmTZ1nYwycRppblCTxVik42RloGtC8+KLCpp2J+rPXBUeJKYdwH1pT1o9twrCT YQhwHM9Em2h69iA/eMqn/FF3uDvsHzeZlFCWG1u2986U6GojUbqruITtS39HBf24bZam7s8y2R4 iDCwj98iiTFNW2yGQgwx6v4tMWJsuKbpPQV5js6emQxmXOotjQ1BDwO0H8xMbzvuaUoE7kcumiE NgfNnt5IG8/7y+IknFPOoyXiKLJJX45GR61UsWImDx8Dv8hMGwpIHjG+8AkymbQP5OJiG2DWuPy MG135WIY2CjY5qv7zM0Z4qL2qQbjcRXWPYdIMi+0aKrphYfU3h6gjJ7I2RdG1D/HcPPvSJE9p5v 5quQk1Rr4spsK9GDN91zciym4DqGXqYiBMioYyuhpJ+31h8nvWS4B0Jpo3nTkUwPv8D9wFLrBWd mJy3Nb4cIqpUb1BV+SzTYjv7toIHlQYH1AQzMAMi1RV4wp7taqQblp9bIyjOg3kaTETkIHvfxQH psqgVvgqi3yFIKf1VKOYkF9DVfU82EYrJjV/feFyLhjKCELtJQ85+SQ9vkOROfcPZyTzRjZMKg9 ex76WA73u0lwaZsEGOQIx+hpOJuDJ6vcw1aFl/uS7o2s789yuyha3WygkEuU0g4lAs68EM3jsNC kIiKBaWroWFPagw== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH vz7] ms/net: lock the socket in sock_gettstamp() X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Eric Dumazet sk->sk_flags must only be changed while holding the socket lock, because sock_set_flag() and sock_reset_flag() use non atomic operations (__set_bit() and __clear_bit()). sock_gettstamp() is one of the last places where a bit of sk->sk_flags is changed from a syscall without owning the socket lock, through sock_enable_timestamp(sk, SOCK_TIMESTAMP). sk_set_memalloc() and sk_clear_memalloc() also change sk->sk_flags without the socket lock, but their callers (nbd, iscsi_tcp, nvme-tcp, sunrpc, wireguard) need a careful audit, this will be addressed in a separate patch. Jungwoo Lee and Wongi Lee reported an UDP socket use-after-free caused by this bug: a SIOCGSTAMPNS_NEW ioctl racing with bind() can cancel the SOCK_RCU_FREE bit that udp_lib_get_port() just set, because both threads perform a read-modify-write on the same word. CPU 0 (bind) CPU 1 (SIOCGSTAMPNS_NEW) -------------------------------- ---------------------------- read sk_flags = F read sk_flags = F compute F | BIT(SOCK_RCU_FREE) compute F | BIT(SOCK_TIMESTAMP) store F | BIT(SOCK_RCU_FREE) sk_add_node_rcu(sk, ...) store F | BIT(SOCK_TIMESTAMP) After the lost update, SOCK_RCU_FREE is clear while the socket is visible to lockless UDP receive lookups. sk_destruct() then frees the socket immediately instead of waiting for a RCU grace period, while the receive path still holds a reference-less pointer to it: BUG: KASAN: slab-use-after-free in ipv4_pktinfo_prepare+0x30/0x410 Read of size 8 at addr ffff888008806610 by task exploit/207 CPU: 0 UID: 1000 PID: 207 Comm: exploit Not tainted 6.12.95+ #1 ipv4_pktinfo_prepare+0x30/0x410 udp_queue_rcv_one_skb+0x51c/0x1180 udp_unicast_rcv_skb+0x109/0x350 ip_protocol_deliver_rcu+0x14b/0x310 ip_local_deliver_finish+0x29d/0x390 ip_local_deliver+0x24d/0x2a0 Only grab the socket lock when SOCK_TIMESTAMP has to be set, to keep the common case lockless. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: Jungwoo Lee Reported-by: Wongi Lee Signed-off-by: Eric Dumazet Reviewed-by: Simon Horman Link: https://patch.msgid.link/20260915043055.3441600-1-edumazet@google.com Signed-off-by: Jakub Kicinski (cherry picked from commit 9ed55f3dbef4f4adfe65eb03b0c35c53229a8490) Backport notes: - sock_gettstamp() does not exist here, the change goes to sock_get_timestamp() and sock_get_timestampns(); - compat_sock_get_timestamp() and compat_sock_get_timestampns() get the same change; - ax25_ioctl(), ipx_ioctl() and nr_ioctl() call the helpers without the socket lock. ms commit c7cbdbf29f48 ("net: rework SIOCGSTAMP ioctl handling") in v5.2 folded the per-protocol SIOCGSTAMP(NS) handling and the compat helpers into sock_gettstamp(). Here every protocol ioctl still calls one of the four helpers. The compat ones in net/compat.c set SOCK_TIMESTAMP on their own and are used by ATM and X25. ax25_ioctl(), ipx_ioctl() and nr_ioctl() call the helpers under lock_sock(). With the lock taken inside, the nested lock_sock() would wait forever in __lock_sock() for the socket the task itself owns. None of the three is enabled in the vz7 configs, so this only keeps the code correct. c7cbdbf29f48 removed these cases from ax25 and netrom, which call sock_gettstamp() without the lock since then, and IPX was gone from ms before that. All other protocols here call the helpers unlocked too. The closest stable backport is 5.10.y commit 18899e2e4023: https://git.kernel.org/stable/c/18899e2e4023369a8f7739c2255a59a9748d8d17 CVE-2026-98276 https://virtuozzo.atlassian.net/browse/VSTOR-155948 Signed-off-by: Konstantin Khorenko --- CVE-2026-98276 fix for the vz7 kernel. https://virtuozzo.atlassian.net/browse/VSTOR-155948 Assisted-by: LLM --- net/ax25/af_ax25.c | 13 +++++-------- net/compat.c | 16 ++++++++++++++-- net/core/sock.c | 16 ++++++++++++++-- net/ipx/af_ipx.c | 6 +++--- net/netrom/af_netrom.c | 11 ++--------- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index 1cf964d43259a..57d2424b47ba5 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -1686,6 +1686,11 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) void __user *argp = (void __user *)arg; int res = 0; + if (cmd == SIOCGSTAMP) + return sock_get_timestamp(sk, argp); + if (cmd == SIOCGSTAMPNS) + return sock_get_timestampns(sk, argp); + lock_sock(sk); switch (cmd) { case TIOCOUTQ: { @@ -1708,14 +1713,6 @@ static int ax25_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) break; } - case SIOCGSTAMP: - res = sock_get_timestamp(sk, argp); - break; - - case SIOCGSTAMPNS: - res = sock_get_timestampns(sk, argp); - break; - case SIOCAX25ADDUID: /* Add a uid to the uid/call map table */ case SIOCAX25DELUID: /* Delete a uid from the uid/call map table */ case SIOCAX25GETUID: { diff --git a/net/compat.c b/net/compat.c index 9a93420d96dea..991341faa88f1 100644 --- a/net/compat.c +++ b/net/compat.c @@ -461,8 +461,14 @@ int compat_sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) ctv = (struct compat_timeval __user *) userstamp; err = -ENOENT; - if (!sock_flag(sk, SOCK_TIMESTAMP)) + /* sk->sk_flags must only be changed under the socket lock, + * because sock_set_flag() uses non atomic operations. + */ + if (!sock_flag(sk, SOCK_TIMESTAMP)) { + lock_sock(sk); sock_enable_timestamp(sk, SOCK_TIMESTAMP); + release_sock(sk); + } tv = ktime_to_timeval(sk->sk_stamp); if (tv.tv_sec == -1) return err; @@ -489,8 +495,14 @@ int compat_sock_get_timestampns(struct sock *sk, struct timespec __user *usersta ctv = (struct compat_timespec __user *) userstamp; err = -ENOENT; - if (!sock_flag(sk, SOCK_TIMESTAMP)) + /* sk->sk_flags must only be changed under the socket lock, + * because sock_set_flag() uses non atomic operations. + */ + if (!sock_flag(sk, SOCK_TIMESTAMP)) { + lock_sock(sk); sock_enable_timestamp(sk, SOCK_TIMESTAMP); + release_sock(sk); + } ts = ktime_to_timespec(sk->sk_stamp); if (ts.tv_sec == -1) return err; diff --git a/net/core/sock.c b/net/core/sock.c index 130ac5ae31072..bd7ed76d4359e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2614,8 +2614,14 @@ EXPORT_SYMBOL(lock_sock_fast); int sock_get_timestamp(struct sock *sk, struct timeval __user *userstamp) { struct timeval tv; - if (!sock_flag(sk, SOCK_TIMESTAMP)) + /* sk->sk_flags must only be changed under the socket lock, + * because sock_set_flag() uses non atomic operations. + */ + if (!sock_flag(sk, SOCK_TIMESTAMP)) { + lock_sock(sk); sock_enable_timestamp(sk, SOCK_TIMESTAMP); + release_sock(sk); + } tv = ktime_to_timeval(sk->sk_stamp); if (tv.tv_sec == -1) return -ENOENT; @@ -2630,8 +2636,14 @@ EXPORT_SYMBOL(sock_get_timestamp); int sock_get_timestampns(struct sock *sk, struct timespec __user *userstamp) { struct timespec ts; - if (!sock_flag(sk, SOCK_TIMESTAMP)) + /* sk->sk_flags must only be changed under the socket lock, + * because sock_set_flag() uses non atomic operations. + */ + if (!sock_flag(sk, SOCK_TIMESTAMP)) { + lock_sock(sk); sock_enable_timestamp(sk, SOCK_TIMESTAMP); + release_sock(sk); + } ts = ktime_to_timespec(sk->sk_stamp); if (ts.tv_sec == -1) return -ENOENT; diff --git a/net/ipx/af_ipx.c b/net/ipx/af_ipx.c index 7d6d51073cf89..6ea1fc25c0641 100644 --- a/net/ipx/af_ipx.c +++ b/net/ipx/af_ipx.c @@ -1849,6 +1849,9 @@ static int ipx_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) struct sock *sk = sock->sk; void __user *argp = (void __user *)arg; + if (cmd == SIOCGSTAMP) + return sock_get_timestamp(sk, argp); + lock_sock(sk); switch (cmd) { case TIOCOUTQ: @@ -1895,9 +1898,6 @@ static int ipx_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) rc = get_user(ipx_sk(sk)->ipx_ncp_conn, (const unsigned short __user *)argp); break; - case SIOCGSTAMP: - rc = sock_get_timestamp(sk, argp); - break; case SIOCGIFDSTADDR: case SIOCSIFDSTADDR: case SIOCGIFBRDADDR: diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c index a3322646a6674..9045640b56914 100644 --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c @@ -1193,7 +1193,6 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) { struct sock *sk = sock->sk; void __user *argp = (void __user *)arg; - int ret; switch (cmd) { case TIOCOUTQ: { @@ -1220,16 +1219,10 @@ static int nr_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) } case SIOCGSTAMP: - lock_sock(sk); - ret = sock_get_timestamp(sk, argp); - release_sock(sk); - return ret; + return sock_get_timestamp(sk, argp); case SIOCGSTAMPNS: - lock_sock(sk); - ret = sock_get_timestampns(sk, argp); - release_sock(sk); - return ret; + return sock_get_timestampns(sk, argp); case SIOCGIFADDR: case SIOCSIFADDR: --- base-commit: 78c10c447efc7633a8e4260fe7dc33e1cb4bb4d2 change-id: 20261118-b4-prep-khorenko-vstor-155948-sock-gettstamp-lock-9e43db5fd8f0 Best regards, -- Konstantin Khorenko, Virtuozzo Linux Kernel Team _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel