Article View: linux.kernel.netdev
Article #7524[PATCH net v2] mptcp: protect listener backlog reads in diagnostics
From: Cen Zhang
Date: Mon, 26 Oct 2026 14:48
Date: Mon, 26 Oct 2026 14:48
118 lines
15616 bytes
15616 bytes
mptcp_diag_get_info() reports the accept queue of a listening MPTCP
socket by reading msk->first. The token based dump and the exact token
query only hold a reference on the MPTCP socket, which pins neither the
first subflow nor the listener hash bucket, and __mptcp_close_ssk()
drops the last reference on the first subflow before clearing
msk->first.
An application can disconnect a connected MPTCP socket with AF_UNSPEC,
which removes the token but retains the first subflow, listen on it
again and close it. A dump that obtained the MPTCP socket before the
disconnect then reads the backlog of a freed TCP listener:
Token diagnostic Application
mptcp_token_iter_next()
retain MPTCP socket
connect(AF_UNSPEC)
remove token, retain first
listen()
reuse first
mptcp_diag_get_info()
observe TCP_LISTEN
lsk = msk->first
close()
mptcp_destroy()
__mptcp_close_ssk()
release first
read lsk->sk_ack_backlog
The report below was decoded with scripts/decode_stacktrace.sh against
the 7.2.0-rc5 based test kernel that produced it, with the line numbers
mapped to this tree; only the relevant frames are kept:
BUG: KASAN: slab-use-after-free in mptcp_diag_get_info (net/mptcp/mptcp_diag.c:209)
Read of size 4 at addr ffff888111763818 by task python3/499
Call Trace:
mptcp_diag_get_info (net/mptcp/mptcp_diag.c:209)
inet_sk_diag_fill (net/ipv4/inet_diag.c:330)
mptcp_diag_dump (net/mptcp/mptcp_diag.c:23 net/mptcp/mptcp_diag.c:177)
__inet_diag_dump (net/ipv4/inet_diag.c:823)
netlink_dump (net/netlink/af_netlink.c:2351)
Allocated by task 497:
sk_alloc (net/core/sock.c:2337)
inet_create (net/ipv4/af_inet.c:333)
__sock_create (net/socket.c:1679)
mptcp_subflow_create_socket (net/mptcp/subflow.c:1836)
__mptcp_nmpc_sk (net/mptcp/protocol.c:111 net/mptcp/protocol.c:143)
mptcp_setsockopt (net/mptcp/sockopt.c:313 net/mptcp/sockopt.c:916)
Freed by task 0:
slab_free_after_rcu_debug (mm/slub.c:6571)
rcu_core (kernel/rcu/tree.c:2919)
Second to last potentially related work creation:
__call_rcu_common.constprop.0 (kernel/rcu/tree.c:3287)
sk_destruct (net/core/sock.c:2446)
__sk_free (net/core/sock.c:2459)
sk_free (net/core/sock.c:2470)
__mptcp_close_ssk (include/net/sock.h:2024 net/mptcp/protocol.c:2721)
mptcp_destroy_common (net/mptcp/protocol.c:3579)
mptcp_destroy (net/mptcp/protocol.c:3815)
__mptcp_destroy_sock (net/mptcp/protocol.c:3421)
__mptcp_close (net/mptcp/protocol.c:3523)
mptcp_close (net/mptcp/protocol.c:3538)
inet_release (net/ipv4/af_inet.c:442)
The first subflow is a TCP socket: TCP listeners carry SOCK_RCU_FREE
and tcp_prot/tcpv6_prot sockets live in SLAB_TYPESAFE_BY_RCU caches, so
reading the two backlog counters under rcu_read_lock() is safe, and a
stale value is acceptable for diagnostics. mptcp_diag_dump_listeners()
already runs the formatter inside an RCU read-side section; only the
token dump and mptcp_diag_dump_one() reach it without one. Take
rcu_read_lock() around the msk->first snapshot and the backlog reads.
Fixes: 4fa39b701ce9 ("mptcp: listen diag dump support")
Suggested-by: Eric Dumazet <edumazet@kernel.org>
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
Assisted-by: LLM
---
Changes in v2:
- Take rcu_read_lock() around the first subflow reads instead of the MPTCP
data lock plus an owner check, as suggested by Eric Dumazet; this avoids
the new msk slock -> listener hash lock nesting and keeps ss reporting the
accept queue while the socket is owned.
- Decode the stack trace with scripts/decode_stacktrace.sh, map the line
numbers to this tree and keep only the relevant frames.
Link to v1: https://lore.kernel.org/r/pm-mptcp-objects-candidate-0066-v3-73df72b7a543d4cada0e@gmail.com
net/mptcp/mptcp_diag.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/mptcp/mptcp_diag.c b/net/mptcp/mptcp_diag.c
index 136c2d05c0ee..28a42eee6651 100644
--- a/net/mptcp/mptcp_diag.c
+++ b/net/mptcp/mptcp_diag.c
@@ -200,8 +200,10 @@ static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
r->idiag_wqueue = sk_wmem_alloc_get(sk);
if (inet_sk_state_load(sk) == TCP_LISTEN) {
- struct sock *lsk = READ_ONCE(msk->first);
+ struct sock *lsk;
+ rcu_read_lock();
+ lsk = READ_ONCE(msk->first);
if (lsk) {
/* override with settings from tcp listener,
* so Send-Q will show accept queue.
@@ -209,6 +211,7 @@ static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
r->idiag_rqueue = READ_ONCE(lsk->sk_ack_backlog);
r->idiag_wqueue = READ_ONCE(lsk->sk_max_ack_backlog);
}
+ rcu_read_unlock();
}
if (!info)
Technical Details
Message-ID:
<pm-mptcp-objects-candidate-0066-v5-4d1b83d62fcde2d57e8d@gmail.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351948-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-351948-linux-kernel-netdev=dewy.ru
From: zzzccc427@gmail.com (Cen Zhang)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v2] mptcp: protect listener backlog reads in diagnostics
Date: Mon, 26 Oct 2026 22:48:16 +0800
Organization: Usenet Network
Message-ID: <pm-mptcp-objects-candidate-0066-v5-4d1b83d62fcde2d57e8d@gmail.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1330338"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:h5zSfGu2q/rQxaG8AcgiRQf/5MY= sha256:N7cfMmd8fU+pdTeFRoC2U4VpI3TkcRqixKAMHg8v+Wo=
sha1:WmbssZjD5N4r8upCy4KmYaofShQ= sha256:bTH5TtlO8OSpjrINEboSHz24whPTmFRvpVgRoKXRjfE=
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 08D52125BAD; Mon, 26 Oct 2026 17:52:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.049
X-Spam-Status: No, score=-2.049 tagged_above=-9999 required=6.31
tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
HK_RANDOM_FROM=0.999, 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=gmail.com
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 4Nc0Zb1umdwa;
Mon, 26 Oct 2026 17:52:33 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-351948-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id D1150125BA9; Mon, 26 Oct 2026 17:52:24 +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 177842730B; Mon, 26 Oct 2026 14:48:28 +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=1793026108;
b=KFpzz2pVuBzZEoynGq/7WHBcE3A9nDHM48Ni8cM4iRWQxe2hQeDFkwbGmu/YBQVVHo54
o7PrrtwK0IAGVkJE+x+j6uHeRAGLaCFy7KEQmpIHI4xFjcfl2VaqC4/Nf6qksIjJw3JnG
WjFKM0xyaJe/xNO76594iqiq8flCeaxJWMYcQf8A3M0WA9+fgMlSWExzEKpFG978gzFBi
jhX/PZDB2vGRdUm7WEdUiEqbYF+TfviE68ucBfaZTrI6NK8DZ3yblLbddixkoOqu/8FV+
I/XvpiqAeWAgAxgXE3Hd9gZCyuQhzK8zph6rao5fKkkaSpPxDVdo01f10U3i6neaJkA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793026108;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:Date:Message-Id:
X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=442TJjXt4vKnHWbQnMiG4TV2+d8tX1KqEwlL9mdaH/k=;
b=1w+K5CESyvEr880hgirKwdIvNetH5btcs1D4RvvGev/Jo1xUEQDqUhml4f3QU7XHU9os
0O8iQRDgusrVRhqzZ21N7ZGCafTsZtcxnuzICpn0dK3x9O3xFRCY82FqmsGkKNWGCZeYr
lCbJmYjt9XxtVAl3GMUYaJD2Y9JZOvGhR6pnW2RpxER/4jWSmgW4fCsRTUcoWfhJOAOau
GtPBD9T7GyFVLCDEoxm1DhHMwAFT3QPgHFVsxRNe2KXLy4/w8s8Q84DaGOsRY8czpSZ+p
Y5RJhe8hMU6Eilken2u8P9e3E/oI0MC1/19Hj7cGfu8j9OymqsMOan+xZUhKa3pIUlA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=eibNHlAv;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
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 E325D606A327;
Mon, 26 Oct 2026 14:48:27 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=eibNHlAv
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.173
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1793026107;
b=3DjhWjsxFJC3VSUXX4KrMyltqEwrAQYR3R4W0Mw42xBEJM/2mfe1npIo/o3D3RgXSBOv
0svZl9/TKwJSjGhzlsUAhm/pSi2w9TtUjgPC9mOUrJ5YVCH/jEqfHjc4I6iwg0xR/LDZY
pbhQ92JU8p0AfNyC1kIjhSzx9TcP7vwDv4hI4oGgiXXKKTWIMFQ3MiZ3FpizjHA/tKg5r
tc1UEGdHPh4BknsXJkZJ7GKsH997OMGnf5AvH/sq/1eXM1Lo0r/qpGeYjwXCVBwAT/Yys
kg/E/lsW4K94BuvZf0S4bUJt53hspRhDgZ658RyB0vSCJQQh+tmjxSqvqUcTse3yiDw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1793026107;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received:
From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version:
Content-Transfer-Encoding;
bh=442TJjXt4vKnHWbQnMiG4TV2+d8tX1KqEwlL9mdaH/k=;
b=DnfNe3GNXy6HIUu0fmzkQQXlkahDkvIrfWL40RGf+IBkHgKgkAcLu/n+tCCyUfZBhbeH
ohqOcDX2vtsIRtVwvA2HCgplN3BeZa4uKUJH27NUaz+8sd8+SI8MGW2A/qy+PguahBIwV
tevRjZiKMf3LwcJMwaBBXIQdekt6kSM90v/9zXQE1UXAQcw1/VmYSzFVYVy7E4ya5JobC
/xW5dWxKsGMfXsDvVp9w12xO8qVDg/jDYoR0LiXsMISQX/GiGnIZn4TMPIkKrGD+i9k9o
uv2AJt90ShLoOLrLaJ0ciCS69REr0xKaXWO9iI/x4v1iT3QxQysvPJUZ8UHQ+psA/EQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=eibNHlAv;
arc=none smtp.remote-ip=209.85.214.173
X-Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id B41BE606A31D
for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 14:48:26 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B41BE606A31D
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2ea138a3497so20169595ad.2
for <netdev@vger.kernel.org>; Mon, 26 Oct 2026 07:48:26 -0700 (PDT)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20251104; t=1793026106; x=1793630906; darn=vger.kernel.org;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:from:to:cc:subject:date:message-id:reply-to:content-type;
bh=442TJjXt4vKnHWbQnMiG4TV2+d8tX1KqEwlL9mdaH/k=;
b=eibNHlAvtye8ze+fjqlWmQ/QzN6w7RSu/QYc7xyQurO8SYf4+rIjdzaMPmDxg+rotq
Gg8jRxzz9HbeLXimQqyVZpWXUswfkssAf6n/aCeHxgXCgZ6vOVftHpTO/HuadlCEwleH
iwnygPo7DX4Dz2BhDzyZZLWujcydwyXBe6O4ZJxlYfWONgzOMGZnawF0Wo8jkh6Dr3MO
2E7Nf3gA346nF/k+VvLyq7Kljpot18ysqNdJKKrNGt2OVW4FgwNdWC7OCYPFVbeYsNtm
ed/7jyiRckC5I2PV3s6P0ElXXvJk3hsv83tp9kb6xM9AjPl0nu2Zb5wEIm/U4qdf06Gf
+Z7Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1793026106; x=1793630906;
h=content-transfer-encoding:mime-version:message-id:date:subject:cc
:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to:content-type;
bh=442TJjXt4vKnHWbQnMiG4TV2+d8tX1KqEwlL9mdaH/k=;
b=ueRnTmfNPKchx5asH4RW/52IWD3BPxe65znD9HEVxZMeM22p21rGM9QU+Q7vZ4Kipv
eI0N6T5OLMEeGNtrm/G1Hu9/fGC6Ir//xZKF3+oD3inDYBaPtqoNRzLRzPaoy5NYN0JT
HkzQxj27dE5oFxJ87DQO4I/GSu/Y62fo5TMeMJ3Sxet9sxZAnNVju9wJU6N0L2ox/RSx
BB/N3AmHihEKFH2SdlJVgGFywLKBhlvVVyPzdQ7UiWmgXGcPD82hM+Gonym23TzwUydW
EUgBU6OUIkKJ4ADeZY7Wil4zEdPeaTzkPfz5mqJXnm9/Bt6H9jIC+q0pR4XFzmtY9lYK
rhxQ==
X-Forwarded-Encrypted: i=1; AKwUvBw+ZfnO/nh5fTCAKFO2InExLl1Ic3Z14m9hoKOVknWjA3MxFYEwVuUdIObAUELt5vyYodhidPM=@vger.kernel.org
X-Gm-Message-State: AFq9FYLJWDqy36kcpA+3KHcm8ThMMes+bSSERaTSMxzKILXvBVIt2yip
XqSAzCO7cK3YLhT9+27n0qRleLqhMtrixEvxwaQz298+9djKzQ6zpmYx
X-Gm-Gg: AYBFou2QifELvzTDtlG6YsAQJcSF71D0R/yPbhgQL+MGFf4zFueXvoL/NThNYUhh1qa
DCpbyNuDOwekAfJ2wz4j+pGLhXdmmCEsppMYBYWfpafjNkZPntKF+QawslPjj03LrZQVI+Pn6bZ
g9yQJDTaDPrFtUb28AzQeEnCVKSQcN4GbqcNweTVeOjeqZakMc7nNP0FS8NIh0ekBKgGGrnmamR
Bo71ldSA/dbocrUQfHRREptBNeu3Ci71pOWeO9Zhhz8VH8nhjcORrbC5w/2qfkTAUITX7ez4cGc
ZoJX7DXIMh1+Yf7WF3RqfSzKblqNUJmfBh3N3t1RaasnmhOfMVLES9Hq1M+LCmFS3JxrFQd1ZNb
/sRvwnbhWdK0xDKH1x7cp0Rin5WBkP8TSGfPfcFWifJweBZqMg9PpSyRG/jCXxMzR4Png3fwsAk
8W53RbHy1sHzjqHnmtNW9BmwNXa3z08DZWs250us3HfwC0zSYNzMgs5sXfZLqcV59ecMwR9Byn0
pXI/aHLfjSGnuXL1F68KKVmquzK4I/qV6uAd8NX6ADJhWXCDE8=
X-Received: by 2002:a17:902:eccf:b0:2e2:be61:a882 with SMTP id d9443c01a7336-2ea9c6c8bc8mr60967235ad.11.1793026105945;
Mon, 26 Oct 2026 07:48:25 -0700 (PDT)
X-Received: from localhost ([111.228.63.84])
by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ea9b1499c4sm18570185ad.31.2026.10.26.07.48.21
(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
Mon, 26 Oct 2026 07:48:25 -0700 (PDT)
X-Cc: geliang@kernel.org,
horms@kernel.org,
netdev@vger.kernel.org,
mptcp@lists.linux.dev,
linux-kernel@vger.kernel.org,
baijiaju1990@gmail.com,
jjzuming@gmail.com,
zzzccc427@gmail.com
X-Mailer: git-send-email 2.34.1
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