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 B267F80027 for ; Thu, 19 Nov 2026 06:36:57 +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 6AJ6ZgfM002759; Thu, 19 Nov 2026 09:35:43 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ6ZgfM002759 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="MOGbpATa" Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AJ6ZT0d002728 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Thu, 19 Nov 2026 09:35:29 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AJ6ZT0d002728 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-48e0389d6f9so1192893f8f.1 for ; Wed, 18 Nov 2026 22:35:29 -0800 (PST) X-Gm-Message-State: APuU4Z9eqYTTgV2af6KfLbpRc0JbRSyIpBitbcyjpg18I0rEIbty70kp HhG9y16SVo0Uwo2I/5dpN1npWH7cy2SIDj5xC7hkkCdJwJUCfTtGe7OIr3hWndpO5tfFgh8oV6K AVQQGIX5nTeQFaQxDEl+0V0Xn/2iKE9WV24MgnNvdHA/berWO/6jizg== X-Gm-Gg: AZFdTZfp/a3eHA1Ar3lz2zU3esSeB241KN0GAFzTkFz80sZHwWHHIjKOrriZ7jLnc8j r/HxTdGiBTHnG31ZTpa7+yp0OgN1A7xdw0cYMtHyTqUEdQY2V81GoOg6dwKLAuV0nSRiPNqzJr3 rnkc3VmZIaMXI9NigEHu53rTWTnpoasSemU2GlP/E/w0cfy0amqGCZ7ZiHgh0gJ2XJStiJ09hJ9 /Ga/n/ypLNOiznMRNV/rZCjtitE77txCb4QUgOHiBjJhAMBxZYxMPr8BPMrTPGqiOSYxkfUxE/9 yfKXJD4aLLz/kKlDd8AHVke6GWf1LYBiAtyHOEaz9Bw17qB91a2rXFyU8PVrjkrWJpaiahGm20F pd5TFmvy1W/jRNeGQfW75siut1A== X-Received: by 2002:a05:6000:2506:b0:48e:7e1f:8cee with SMTP id ffacd0b85a97d-4a6389ec598mr11359372f8f.12.1795070128993; Wed, 18 Nov 2026 22:35:28 -0800 (PST) X-Received: by 2002:a05:6000:2506:b0:48e:7e1f:8cee with SMTP id ffacd0b85a97d-4a6389ec598mr11359328f8f.12.1795070128436; Wed, 18 Nov 2026 22:35:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795070128; cv=none; d=google.com; s=arc-20260327; b=RH95nsuvP8MUd/gBEdaWOuWQgzOQGHowwf8DIX8h4k69W8KmkSUzuaB65mUQ/05y/j b/JOWfQqq8yVu49AF9pRlvA8jjKI2xwB+n4MlOGcIThbcLZAbdRoeGs6BZxt1KGFCHS2 Ochu9PbFGuIoUEF8v2jlw/FM0MqQKlMKZ4NSycq06uonghnLdehTs2d7sozyc+h9M8FT 1YPY/vxET4lXfEcRBoldNVOoDc1gLUMsK87eCO1eMHTaFVTerWTBBevQgsUamHIquw/r WssWOY+cN0i/Y8zHHB9blleKC1J0tEJn86qn8EmZAEC2+nK4L7dwxvFyLgI/eG8tYv8B Z8rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=PTr9G495INhC9PLDEdeJBcp0lfBDw7FW4u24gpY7bg4=; fh=/QSWnKFFIPNLStgUoDwCQRaXnWcMIG7fyKJgHY+VEpU=; b=oEWk2bzjhqNIqmwro/t0dmBBTyTp2xfuZCWklLpmPWoTkH1YbIZHBzSgfJiUrtfx4r XFQTRM03idacEMK1KB8t+ipei0L1LlPsJukobQ+7OuHFKscirWD7L1/jf/lWCwkrpX+n YLHaFbxdGMI2TsPY1PJgEkFUWTssNWwgz4O9QuQ8Uh0fcy2/C6zBMMOMByzrBs+/C2WL KbrYCiuA/k46SJCZwO/Gn/Liud9LdaR9fyQvY77qG0RpueKy/qok6AKLbMp3dcqCznSc bU0SXTWY9ie9Wg1SGuJFmFkEQlR1W53CitzWwLDAVq4UGaX+frSMK+hwaw0tB5AjQ2yf iKgQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=MOGbpATa; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@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 ffacd0b85a97d-4a658ca2b56si9451020f8f.256.2026.11.18.22.35.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2026 22:35:28 -0800 (PST) Received-SPF: pass (google.com: domain of eva.kurchatova@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=MOGbpATa; spf=pass (google.com: domain of eva.kurchatova@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=eva.kurchatova@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=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=PTr9G495INhC9PLDEdeJBcp0lfBDw7FW4u24gpY7bg4=; b=MOGbpATaOwzA 4JfEufajEmH7y+m3w8jBKyOQ2+WUyvKJGm2bjUZeLI9Bl9fLLcYUCJ+gAexg589iH7a0M2Z2l1jCl iEz9bnlVCI2cydx4bZwwB0F/2YolevC+KEXo6bfH6PioZIKEMrPa9BXVw3YLGixhuAxzo7G2npNdE CnJ65wmoROGvC45GI+wTqnflEJE+cIkHZ8jdkxv2lgs3QQq0EgvboQPkG2WZBynY8iYsatvEtNazl BT312HlZI91g7aWb0WR2urOU+owCgbgf5j/JSW5RG6/whO2apKBpsrGY+TUDbNIcNlbx4wtfF4CpZ 9lB/fHtTps36+YkxiaF59g==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=LekKit-T14) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xTvfg-0072sc-3B; Thu, 19 Nov 2026 07:35:26 +0100 From: Eva Kurchatova To: khorenko@virtuozzo.com, vladimir.riabchun@virtuozzo.com Date: Thu, 19 Nov 2026 08:32:28 +0200 Message-ID: <20261119063525.1233606-4-eva.kurchatova@virtuozzo.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261119063525.1233606-1-eva.kurchatova@virtuozzo.com> References: <20261119063525.1233606-1-eva.kurchatova@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.2 3/4] ms/mptcp: hold MP_JOIN msk ref when cloning reqsk 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: Ruide Cao [ Upstream commit c9c90cf437a9e6597611b6d3aad6e255fad22867 ] TCP request migration clones pending request sockets with inet_reqsk_clone(). For MPTCP MP_JOIN requests this byte-copies subflow_req->msk, but the clone does not own a reference. The original and cloned requests can consequently drop the same msk reference, leaving one request with a dangling pointer. This manifests as a KASAN slab-use-after-free in subflow_req_destructor(): BUG: KASAN: slab-use-after-free in subflow_req_destructor (net/mptcp/subflow.c:45) Write of size 4 at addr ff1100010e008d40 by task swapper/0/0 CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.2.0-rc5-00353-gc27e36054537 #10 PREEMPT(full) Call Trace: subflow_req_destructor (net/mptcp/subflow.c:45) subflow_v4_req_destructor (net/mptcp/subflow.c:694) __reqsk_free (net/ipv4/inet_connection_sock.c:906) reqsk_timer_handler (include/net/request_sock.h:137 net/ipv4/inet_connection_sock.c:1147) Allocated by task 10014: sk_prot_alloc (net/core/sock.c:2246) sk_clone (net/core/sock.c:2488) mptcp_sk_clone_init (include/net/sock.h:1848 net/mptcp/protocol.c:3564) subflow_syn_recv_sock (net/mptcp/subflow.c:883) tcp_check_req (net/ipv4/tcp_minisocks.c:934) Freed by task 0: slab_free_after_rcu_debug (include/linux/kasan.h:235 mm/slub.c:2677 mm/slub.c:6439) rcu_core (kernel/rcu/tree.c:2645 kernel/rcu/tree.c:2897) Last potentially related work creation: kmem_cache_free (mm/slub.c:2638 mm/slub.c:6377 mm/slub.c:6504) __sk_destruct (net/core/sock.c:2289 net/core/sock.c:2391) sk_destruct (net/core/sock.c:2419) __sk_free (net/core/sock.c:2430) sk_free (net/core/sock.c:2441) mptcp_close (include/net/sock.h:2020 net/mptcp/protocol.c:3399) inet_release (net/ipv4/af_inet.c:442) The buggy address belongs to the cache MPTCP of size 2968 The buggy address is 128 bytes inside a freed 2968-byte region A non-NULL subflow_req->msk means that the request owns one reference. The third ACK can concurrently transfer the original request reference to the child and release it, so taking an unconditional hold on the copied pointer is unsafe. MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all current inet_reqsk_clone() callers run in an RCU read-side critical section. Document and lockdep-check that calling-context requirement. Read the pointer from the original request and acquire a reference only if it is still live. Use refcount_inc_not_zero_acquire() so the subsequent ownership validation cannot be reordered before the try-get, then re-read the original request to verify that it still owns the same msk. If either check fails, clear the clone pointer; otherwise its normal destructor balances the new reference. Mark the ownership-transfer store with WRITE_ONCE() to match the lockless reads. The following patch completes the clone fixup for MP_CAPABLE token ownership. Both patches carry the same Fixes tag and are required for stable backports. Fixes: c905dee62232 ("tcp: Migrate TCP_NEW_SYN_RECV requests at retransmitting SYN+ACKs.") Cc: stable@vger.kernel.org Reported-by: Kyle Zeng Reported-by: David Lee Reported-by: Vega Closes: https://lore.kernel.org/all/20260804095051.715355-1-david.lee@trailofbits.com/ Signed-off-by: Ruide Cao Signed-off-by: Ren Wei Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20261013-net-mptcp-misc-fixes-7-3-rc8-v1-3-932c9b182fc7@kernel.org Signed-off-by: Jakub Kicinski [ sashal: Adjusted the MPTCP include placement because the TCP ECN header is absent. ] Signed-off-by: Sasha Levin (cherry picked from commit 23f917d95b88a73d1498dd00456cec418dd355c4) https://virtuozzo.atlassian.net/browse/VSTOR-155530 Feature: fix ms/net Signed-off-by: Eva Kurchatova --- include/net/mptcp.h | 9 +++++++++ net/ipv4/inet_connection_sock.c | 4 ++++ net/mptcp/subflow.c | 35 ++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index e9832a8f981e..0ad9c1b5f840 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -205,6 +205,9 @@ int mptcp_subflow_init_cookie_req(struct request_sock *req, struct request_sock *mptcp_subflow_reqsk_alloc(const struct request_sock_ops *ops, struct sock *sk_listener, bool attach_listener); +/* Caller must hold an RCU read-side lock. */ +void mptcp_subflow_reqsk_clone(struct request_sock *req, + struct request_sock *new_req); __be32 mptcp_get_reset_option(const struct sk_buff *skb); @@ -300,6 +303,12 @@ static inline struct request_sock *mptcp_subflow_reqsk_alloc(const struct reques return NULL; } +/* Caller must hold an RCU read-side lock. */ +static inline void mptcp_subflow_reqsk_clone(struct request_sock *req, + struct request_sock *new_req) +{ +} + static inline __be32 mptcp_reset_option(const struct sk_buff *skb) { return htonl(0u); } static inline void mptcp_active_detect_blackhole(struct sock *sk, bool expired) { } diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 96a73fc5d3d9..2de09acc56ea 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -993,6 +994,9 @@ static struct request_sock *inet_reqsk_clone(struct request_sock *req, if (sk->sk_protocol == IPPROTO_TCP && tcp_rsk(nreq)->tfo_listener) rcu_assign_pointer(tcp_sk(nreq->sk)->fastopen_rsk, nreq); + if (rsk_is_mptcp(req)) + mptcp_subflow_reqsk_clone(req, nreq); + return nreq; } diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index eeb4c926a66b..d89f49fcaaf2 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -47,6 +47,39 @@ static void subflow_req_destructor(struct request_sock *req) mptcp_token_destroy_request(req); } +void mptcp_subflow_reqsk_clone(struct request_sock *req, + struct request_sock *new_req) +{ + struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req); + struct mptcp_subflow_request_sock *new_subflow_req; + struct mptcp_sock *msk; + + new_subflow_req = mptcp_subflow_rsk(new_req); + RCU_LOCKDEP_WARN(!rcu_read_lock_any_held(), + "MPTCP reqsk clone called without RCU"); + + /* A non-NULL ->msk means the request owns one reference. The clone + * copied only the pointer, while the original request can concurrently + * transfer its reference to the child. Acquire a reference for the + * clone, then verify that the original request still owns the same msk. + * MPTCP sockets use SLAB_TYPESAFE_BY_RCU and all clone callers run in + * an RCU read-side critical section, keeping the memory stable here. + */ + msk = READ_ONCE(subflow_req->msk); + if (msk) { + struct sock *sk = (struct sock *)msk; + + if (!refcount_inc_not_zero_acquire(&sk->sk_refcnt)) { + msk = NULL; + } else if (READ_ONCE(subflow_req->msk) != msk) { + sock_put(sk); + msk = NULL; + } + } + + new_subflow_req->msk = msk; +} + static void subflow_generate_hmac(u64 key1, u64 key2, u32 nonce1, u32 nonce2, void *hmac) { @@ -922,7 +955,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, } /* move the msk reference ownership to the subflow */ - subflow_req->msk = NULL; + WRITE_ONCE(subflow_req->msk, NULL); ctx->conn = (struct sock *)owner; if (subflow_use_different_sport(owner, sk)) { -- 2.56.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel