🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #27150

[PATCH net-next 05/10] mptcp: annotate lockless access to msk->scaling_ratio

#27150
From: "Matthieu Baerts (NGI0)"
Date: Fri, 04 Dec 2026 21:44
125 lines
13627 bytes
From: Quanye Yang <quanyeyang@proton.me>

mptcp_rcv_rtt_update() writes msk->scaling_ratio from BH while holding
the msk data lock (sk->sk_lock.slock). mptcp_cleanup_rbuf() reads the
same byte via mptcp_win_from_space() after mptcp_release_cb() drops
that lock, so it can run concurrently with the RX path.

KCSAN reports:

  BUG: KCSAN: data-race in mptcp_cleanup_rbuf / mptcp_data_ready

  write to 0xffff888014978790 of 1 bytes by interrupt on cpu 1:
   mptcp_rcv_rtt_update net/mptcp/protocol.c:1045 [inline]
   mptcp_data_ready+0x1c1/0x4d0 net/mptcp/protocol.c:1062
   subflow_data_ready+0x271/0x350 net/mptcp/subflow.c:1536
   tcp_data_ready+0x92/0x2c0 net/ipv4/tcp_input.c:5604
   tcp_data_queue+0x1236/0x26c0 net/ipv4/tcp_input.c:5694
   tcp_rcv_established+0x695/0x1fb0 net/ipv4/tcp_input.c:6689
   tcp_v4_do_rcv+0x356/0x6e0 net/ipv4/tcp_ipv4.c:1854
   tcp_v4_rcv+0x1b04/0x26b0 net/ipv4/tcp_ipv4.c:2248

  read to 0xffff888014978790 of 1 bytes by task 2624 on cpu 0:
   mptcp_win_from_space net/mptcp/protocol.h:421 [inline]
   __mptcp_space net/mptcp/protocol.h:431 [inline]
   mptcp_cleanup_rbuf+0x8a/0x380 net/mptcp/protocol.c:680
   mptcp_release_cb+0x375/0x900 net/mptcp/protocol.c:3889
   release_sock+0x100/0x150 net/core/sock.c:3866
   sk_wait_data+0x141/0x2f0 net/core/sock.c:3314
   mptcp_recvmsg+0x6cd/0xd50 net/mptcp/protocol.c:2496

  value changed: 0xd0 -> 0xd5

  Reported by Kernel Concurrency Sanitizer on:
  CPU: 0 UID: 0 PID: 2624 Comm: syz.7.22 Not tainted 7.3.0-rc1-gbaff4b3d06ef #77 PREEMPT(full)

The u8 EWMA is used only to convert sk_rcvbuf occupancy into an
advertised window. A slightly stale ratio is acceptable, so annotate
the lockless accesses with READ_ONCE()/WRITE_ONCE() instead of
widening the data lock. Do the same in mptcp_space_from_win(), which
reads the same field from DRS and SO_RCVLOWAT.

Fixes: d2000361e4dd ("mptcp: better mptcp-level RTT estimator")
Reported-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/634
Signed-off-by: Quanye Yang <quanyeyang@proton.me>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
To: Steven Rostedt <rostedt@goodmis.org>
To: Masami Hiramatsu <mhiramat@kernel.org>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: linux-trace-kernel@vger.kernel.org
---
 include/trace/events/mptcp.h |  2 +-
 net/mptcp/protocol.c         | 11 ++++++++---
 net/mptcp/protocol.h         |  6 ++++--
 3 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/include/trace/events/mptcp.h b/include/trace/events/mptcp.h
index 22882bd03459..c47fa2672b84 100644
--- a/include/trace/events/mptcp.h
+++ b/include/trace/events/mptcp.h
@@ -229,7 +229,7 @@ TRACE_EVENT(mptcp_rcvbuf_grow,
 		__entry->rcvbuf = sk->sk_rcvbuf;
 		__entry->rcv_wnd = atomic64_read(&msk->rcv_wnd_sent) -
 				   msk->ack_seq;
-		__entry->scaling_ratio = msk->scaling_ratio;
+		__entry->scaling_ratio = READ_ONCE(msk->scaling_ratio);
 		__entry->sport = ntohs(inet->inet_sport);
 		__entry->dport = ntohs(inet->inet_dport);
 		__entry->family = sk->sk_family;
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index 667cbd7895a7..4505f5a75042 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -982,6 +982,7 @@ static void mptcp_rcv_rtt_update(struct mptcp_sock *msk,
 {
 	const struct tcp_sock *tp = tcp_sk(subflow->tcp_sock);
 	u32 rtt_us = tp->rcv_rtt_est.rtt_us;
+	u8 scaling_ratio;
 	int id;
 
 	/* Update once per subflow per rcvwnd to avoid touching the msk
@@ -998,9 +999,13 @@ static void mptcp_rcv_rtt_update(struct mptcp_sock *msk,
 	if (++msk->rcv_rtt_est.next_sample == MPTCP_RTT_SAMPLES)
 		msk->rcv_rtt_est.next_sample = 0;
 
-	/* EWMA among the incoming subflows */
-	msk->scaling_ratio = ((msk->scaling_ratio << 3) - msk->scaling_ratio +
-			     tp->scaling_ratio) >> 3;
+	/* EWMA among the incoming subflows.
+	 * Pairs with READ_ONCE() in mptcp_win_from_space().
+	 */
+	scaling_ratio = READ_ONCE(msk->scaling_ratio);
+	WRITE_ONCE(msk->scaling_ratio,
+		   ((scaling_ratio << 3) - scaling_ratio +
+		    tp->scaling_ratio) >> 3);
 }
 
 void mptcp_data_ready(struct sock *sk, struct sock *ssk)
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 255b2e761f7d..a96b999731a6 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -431,12 +431,14 @@ static inline void msk_owned_by_me(const struct mptcp_sock *msk)
 
 static inline int mptcp_win_from_space(const struct sock *sk, int space)
 {
-	return __tcp_win_from_space(mptcp_sk(sk)->scaling_ratio, space);
+	return __tcp_win_from_space(READ_ONCE(mptcp_sk(sk)->scaling_ratio),
+				    space);
 }
 
 static inline int mptcp_space_from_win(const struct sock *sk, int win)
 {
-	return __tcp_space_from_win(mptcp_sk(sk)->scaling_ratio, win);
+	return __tcp_space_from_win(READ_ONCE(mptcp_sk(sk)->scaling_ratio),
+				    win);
 }
 
 static inline int __mptcp_space(const struct sock *sk)

-- 
2.55.0
Technical Details
Message-ID: <20261204-net-next-mptcp-misc-feat-7-5-v1-5-1449de51adae@kernel.org>
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377654-linux-kernel-netdev=dewy.ru
References: <20261204-net-next-mptcp-misc-feat-7-5-v1-0-1449de51adae@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377654-linux-kernel-netdev=dewy.ru
From: matttbe@kernel.org ("Matthieu Baerts (NGI0)")
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next 05/10] mptcp: annotate lockless access to
 msk->scaling_ratio
Date: Fri, 04 Dec 2026 22:44:37 +0100
Organization: Usenet Network
Message-ID: <20261204-net-next-mptcp-misc-feat-7-5-v1-5-1449de51adae@kernel.org>
References: <20261204-net-next-mptcp-misc-feat-7-5-v1-0-1449de51adae@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="2878485"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:AYNk8muUPaTjMGn0u6QPKQcuIKw= sha256:ui2U45bgrCYy2K2E3cBJD1hHBw31L5f/ZcZYMLKmbks=
	sha1:6yxbT3xUHmsAxPdnTW3p4Y58oVg= sha256:Pge4O4fgQ5K8DXb62ZtrlFpuAR1PGEWxqHeuyF3sHdo=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 0415F117A66; Sat,  5 Dec 2026 00:45:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.542
X-Spam-Status: No, score=-3.542 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id VDJxubKx0rpi;
	Sat,  5 Dec 2026 00:45:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377654-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id E4A78117CF4; Sat,  5 Dec 2026 00:45:21 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 918292B89F; Fri,  4 Dec 2026 21:45:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796420715;
	b=INRtnunU/CDMKar+x2wdUF+TUpon5KPd+b4Nuia/+dKJC+dIQ8lSC3yoh27D8rFtb/N+
	 2HUgwhX0lpkO7dVklVWROEAIESBGphYuD1J6MylvhFGLtj4D3nW0RE9cGM+jdQLmV0z9K
	 yyIkt0dKlLe9j3VZfUxIATsSjMQ94WmMv+bn+zhOrm7NXcE9h2hIvIh3GOCcZEl9Z2DoV
	 PsTeOrokJX/Tk11ojfg2IvAseUSSIuk4k5pqSHsPjLLREM0bXwGx3elPmfWFES3bsVWat
	 jNmCQA00HO5ddGn7gFp6ncddFrdu141LodGdfm3bL3Fh4Xq8B/X5no93VyuUFVWXSAQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796420715;
	h=X-Original-To:Received:Received:DKIM-Signature:From:Date:Subject:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer:X-Developer-Signature:X-Developer-Key;
	bh=NWKHM7M44Z9Yd9bVMZM3XGr7V6dGzAFzSVxZlo6gsO0=;
	b=e07ZPTRduGgGWUC6Bi0NDj7wXnH+KJNvBofLx5Qox+YQEwG945ZJO/NUlccdQBCPa1Eb
	 YbmJo18NECU3gbi80aXauHTVOx0almIB+OA0GJEV/G9oq9PR1x4l6jz1nK1GBsCAvoIpl
	 W6EyGK/qDVV3fmKAYsjHw6ulREDiCYtcV/W8uY+2WL66OLuinz4Vpv2aVpIl8xej+gTFO
	 sZVJkpdg3iEmf//Bwgo+ul5W/qG+/LghTDy9S66fa4f7Jaj91HSMFL2dTEOreVNf5mG3z
	 GfLZhbcpJgFv+JQNmN1l4WGmSjH/tzZXAT05Xp0UpIYgrQXJE/K5pbv98X5LdvTDqnA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="OJzH2OM/";
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 56AF5606A681;
	Fri,  4 Dec 2026 21:45:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=OJzH2OM/
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796420714;
	b=Jp+F7gSY0vjQZUHm6EDXT+uWjpcrcmjisf4A60L8ITHtSa+Q/sMzViLy1mShhB0LKOTU
	 OAYrtmrCM/0YEFhqdOxt6puiniJaqIa36uyGKck8owhVy5mgvxTJB/J2EfeoQ0xcKfnCi
	 it+LQtW2gpd+WwM8xMI9wHXboHCjgtp5yu3xTrGXCKWZNFMnJxqltWMNGZKX1SP5bvIV+
	 1cmMCg0AGBmaSzb59uMEBbakZtZEujb0HJBT4JlKHpHKzNdIztW+6JJFlGgrxg/SvyoSe
	 ZMM1vyHHjQE7tTH+asKA4eIS040u/7YLOxlMAe0hPaebtIPK8whKZW+VQAhgY2iwphw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796420714;
	h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type:
	 Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc:
	 X-Mailer:X-Developer-Signature:X-Developer-Key;
	bh=NWKHM7M44Z9Yd9bVMZM3XGr7V6dGzAFzSVxZlo6gsO0=;
	b=4x5kCv0WBdN1YHWNdkCbRIYqX14sw7PIKd9B3dOxFIv9ly9owbe93qhnyXlPHb+DrwkI
	 Iu2synbrHmiUmKCy+1crCI6su0uRb90kd8K/zUzDjjun0oVGcRfuOhsDnWNQgtnqmNwzW
	 hi22z1OBZ4s4LdLzIWTwuj5TmX2m9nmu24nE0Bl0I+LR2QUZPO/5nck/yOwjpgSiL9uAk
	 yZk0XaIQ/TGEewg/X2+mRrq9NGYMTkdiOJLCNdfjApqITeOCa+94Wdrj2sjQfO/utofyl
	 40hdgshZWlnTqJD05ZAzXdzArgTKTIIMXLJjkCIhLU3qQnCYi8/VQ0A2Pm3GM9tGzCw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="OJzH2OM/";
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74BD1606A330;
	Fri,  4 Dec 2026 21:45:14 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B15BF1F00A06;
	Fri,  4 Dec 2026 21:45:10 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1796420714;
	bh=NWKHM7M44Z9Yd9bVMZM3XGr7V6dGzAFzSVxZlo6gsO0=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=OJzH2OM/TSjTstO0rbTfpAs/ZvuVI5OfP6RjCNO3mbMeLckS0FVzVlI/OTmuHfW+4
	 BrSwgSJynMrvHu7luskJSdAPA7OwrJRaHuFnj2SMr/CmqTZSjgc0amk/14EARQjbG/
	 AkeAMyosHazw8gqyncmEdxBgSbvwyvgblHpQ0jXEHE9VrwN8Zf+i9lkpMMe5I1pbJb
	 xb5Ib8J6MXqvqb2bBbSTknFqKvl6aEh25HPlboGfSoqvcyeRfgBi85ah0b4oV8OLqh
	 UNuYFNQbycGD6E07TnHlW1ZJM8DgPbKcCp9+Py3PYY4TadacwhNFmmZX0eYZZ4ZRan
	 fxpdpSay/e1IQ==
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <20261204-net-next-mptcp-misc-feat-7-5-v1-0-1449de51adae@kernel.org>
X-Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, 
 linux-kselftest@vger.kernel.org, 
 "Matthieu Baerts (NGI0)" <matttbe@kernel.org>, 
 Quanye Yang <quanyeyang@proton.me>, Steven Rostedt <rostedt@goodmis.org>, 
 Masami Hiramatsu <mhiramat@kernel.org>, 
 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>, 
 linux-trace-kernel@vger.kernel.org
X-Mailer: b4 0.16.0
X-Developer-Signature: v=1; a=openpgp-sha256; l=5071; i=matttbe@kernel.org;
 h=from:subject:message-id; bh=mHhGhGc+gdhznL0rqUjAIT5dEQmps+TK03UI5Spg3q4=;
 b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLKFTYJ6939Y8v1TqGnbtsAfN5ceXn6263lmoZnzthOpC
 7Q57/663FHKwiDGxSArpsgi3RaZP/N5FW+Jl58FzBxWJpAhDFycAjCRY+kM/5QDrs5c4jfhqvIZ
 6ZU2CXOvSupLyH9RiBXi5uhpfSPGF8jI8NR1ZfW+cz0vFxzSaE9xuVscf6Fz1ctlxz5uTJxx7PR
 MHRYA
X-Developer-Key: i=matttbe@kernel.org; a=openpgp;
 fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073