🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #21011

[PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6 listener

#21011
From: "Matthieu Baerts (NGI0)"
Date: Mon, 23 Nov 2026 13:24
111 lines
12538 bytes
From: Chris Mason <mason@kernel.org>

With SELinux, an IPv6 MPTCP listener and its children can cause a double
free of one CIPSO option, and then a use-after-free read of it, if
NetLabel uses CIPSO for IPv4 and selects the IPv6 labels by address.

mptcp_sk_clone_init() creates the child of a listener with
sk_clone_lock(), as a byte copy of the listener, so each pointer in the
copy that the socket destructor frees has to be replaced or cleared.
mptcp_copy_ip_options() duplicates inet_opt, the IPv4 options, for
AF_INET, and mptcp_copy_ip6_options() duplicates the IPv6 options for
AF_INET6. But an AF_INET6 socket has an inet_opt pointer too, and its
child keeps the listener's pointer.

MPTCP does not support setsockopt(IP_OPTIONS), so that pointer is
usually NULL. But if connect() gets a struct sockaddr_in,
netlbl_conn_setattr() does not look at the family of the socket, so the
connect() hook of SELinux can store a CIPSO option in inet_opt of an
AF_INET6 MPTCP listener. inet_sock_destruct() then passes that option to
kfree_rcu() for each child and again for the listener, and after a child
has freed it, another such connect() on the listener reads it in
cipso_v4_sock_setattr().

The fix used here is to clear inet_opt of the child in
mptcp_copy_ip6_options().

This issue has been found with the help of an LLM, and reproduced in a
VM, with the reproducer shared with the original version of this patch,
with SELinux, NetLabel -- CIPSO for some IPv4 addresses, and the
address-based selection used for IPv6 too -- and KASAN: an unprivileged
user calls connect() with an IPv4 address on an IPv6 MPTCP listener.
Without this patch, an object is freed twice:

  BUG: KASAN: double-free in rcu_free_sheaf+0x23/0x100
  Free of addr ffff888012c27a80 by task kworker/1:1/50
  CPU: 1 UID: 0 PID: 50 Comm: kworker/1:1 Not tainted 7.4.0-rc1+ #1 PREEMPT(full)
  Workqueue: events mptcp_worker
  Call Trace:
   <IRQ>
   kasan_report_invalid_free+0xd4/0x1b0
   check_slab_allocation+0xc2/0xf0
   __rcu_free_sheaf_prepare+0x102/0x2a0
   rcu_free_sheaf+0x23/0x100
   rcu_do_batch+0x29a/0xf80
   rcu_core+0x33c/0x830
   handle_softirqs+0x212/0x980
   do_softirq+0xb4/0xf0
   </IRQ>
   <TASK>
   __local_bh_enable_ip+0x11c/0x150
   mptcp_token_destroy+0x1c9/0x360
   mptcp_destroy_common+0x2d9/0x430
   mptcp_destroy+0x86/0x110
   __mptcp_destroy_sock+0x176/0x350
   mptcp_worker+0xbb5/0xf80
  [...]
  Allocated by task 176:
  [...]
   cipso_v4_sock_setattr+0x9b/0x3d0
   netlbl_conn_setattr+0x3ac/0x500
   selinux_netlbl_socket_connect_locked+0x102/0x210
   selinux_netlbl_socket_connect+0x23/0x40
   security_socket_connect+0x2e/0x60
   __sys_connect_file+0xcb/0x200
  [...]

In another case, the CIPSO option is used after having been freed:

  BUG: KASAN: slab-use-after-free in cipso_v4_sock_setattr+0x3c7/0x3d0
  Read of size 1 at addr ffff8880161c2f18 by task python3/177
  CPU: 1 UID: 65534 PID: 177 Comm: python3 Not tainted 7.4.0-rc1+ #1 PREEMPT(full)
  Call Trace:
   <TASK>
   kasan_report+0x101/0x140
   cipso_v4_sock_setattr+0x3c7/0x3d0
   netlbl_conn_setattr+0x3ac/0x500
   selinux_netlbl_socket_connect_locked+0x102/0x210
   selinux_netlbl_socket_connect+0x23/0x40
   security_socket_connect+0x2e/0x60
   __sys_connect_file+0xcb/0x200
   __sys_connect+0xfd/0x130
   __x64_sys_connect+0x72/0xd0
  [...]

Fixes: cf7da0d66cc1 ("mptcp: Create SUBFLOW socket for incoming connections")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
[ Commit message: how the issue was found, and its symptoms ]
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/protocol.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index fd88104f0631..50c294d925b0 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -3677,6 +3677,9 @@ static void mptcp_copy_ip6_options(struct sock *newsk, const struct sock *sk)
 
 	newnp = inet6_sk(newsk);
 
+	/* The IPv4 options belong to the listener, which frees them */
+	RCU_INIT_POINTER(inet_sk(newsk)->inet_opt, NULL);
+
 	rcu_read_lock();
 	opt = rcu_dereference(np->opt);
 	if (opt) {

-- 
2.55.0
Technical Details
Message-ID: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-3-278042217e8d@kernel.org>
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369392-linux-kernel-netdev=dewy.ru
References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-can.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369392-linux-kernel-netdev=dewy.ru
From: matttbe@kernel.org ("Matthieu Baerts (NGI0)")
Newsgroups: linux.kernel.netdev
Subject: [PATCH net 03/10] mptcp: clear inet_opt in the child of an IPv6
 listener
Date: Mon, 23 Nov 2026 14:24:51 +0100
Organization: Usenet Network
Message-ID: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-3-278042217e8d@kernel.org>
References: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Injection-Info: usenet.network;
	logging-data="3887673"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:fJP3e437j6+Ze4R7fPB9VfVcYfo= sha256:XQ8QTK9cj8/Q1molrprhg6tWiI9gAL+/SPwl1BzQahg=
	sha1:ANYqsTWXRNb2MJodjNyTpMSxB/s= sha256:IB4gy4dlpJ0vqkMlDCkKk7Tj9OOTCVkc8ohHUAbRhoQ=
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 5B53E125DB2; Mon, 23 Nov 2026 16:25:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, 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 JHXt4_lHDsXA;
	Mon, 23 Nov 2026 16:25:50 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369392-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 3A555125DB1; Mon, 23 Nov 2026 16:25:42 +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 364A523311; Mon, 23 Nov 2026 13:25:36 +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=1795440335;
	b=AKQiHXdlA9wrb7oxBhk7vgp6cVrHfjI46J1ypRR58Hn/LsXkY48aAhtXk89IH+lPRRXz
	 JvrmJJXNikMz/JjVOMqBzNSHq0HO1S7jnBxvSDgSI/lP7Z8T2ceTg0LDOUdKqZmWW3dZz
	 Z/us5CDHEtzObcTe5sLA/znns2XE6ZMGtx1gBrY6MLxdXrDLn9PhOlx98ZdZe2sblanJ4
	 dYeRSvIHRsihxxlALk1712xXFeRbw3dRvCpGUWCSBk4QibXOS4MaMToQSlojjiHSKk5iE
	 6HNraOr1mxMIW9x+Ui1RkQK804whLRiQF0BiLQE585+zNIq/8zvOW5m6WgDOBMxZovw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795440335;
	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=j6NoxPUSnIuQNQok+UdtQrawTTFukTWkIuqhw/dxpKQ=;
	b=vtQ1ypvYf7EZ/KcfIm+RpB9c1hWS2XAXj05oxvOEBJlSAWD53TPwaDr7SxS16Ays/iIJ
	 IKXQPVAYPjfe5qSRj+aLke4dnHRfAHA++wF7A7JGeIF5iEiveEGgYmTMC+otGosxr7JK1
	 RlS/Wbie/ZsJlHz//OhugcKRH+9oLP2iGtKZhqOncniHDnhOW7n6oSWYj3RkOArdIldy7
	 fWjZBcEe1RKb/ph3rQlADe5p5XT7AzTszXYluUk3tIMg8gtpsXMsmy0j9UvyA7ZnGMLlQ
	 l8z5RODmNnp6qehdZvc/VpIF5LVR7GgH2AdqGx4M2Uu2eu5BBuDcrEJuIUntIqOnB1Q==
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=jBb+bgSg;
	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 CC9E5606A330;
	Mon, 23 Nov 2026 13:25:35 +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=jBb+bgSg
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=1795440335;
	b=JswmGWWFnpg4AnE3DnigcSWA0nPHioLZ3Jqq+BffDdMwgI9e0Yg/6odZXZZQRG/fAQyL
	 r5fyzSGB6VO2bz8yP7/66ciJyCQ6Th1ADoO+6fPwLG/Gjt885r/DLDly3A6g0rc/h7l8V
	 C9rL1ZyybK+YjjKXT/wm/4BYEfb/NJNJKpnIV3K9EvGHdpXJKV6kWL+Y4qrCPcPe9ky6b
	 XeIaOyU+sLn7rQtrD6hrLPWSco0x0yFCwPPwYvR7XkH4MK0B8aQ7Ik12o545qHJTaeSrn
	 TUHMfxkYAl98NlEhthRt65UX2HjlYGeK1mcpCpXPSDxTo0RdTPozl6GPMjrjxIlwA9w==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795440335;
	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=j6NoxPUSnIuQNQok+UdtQrawTTFukTWkIuqhw/dxpKQ=;
	b=wBoyJIkpxAErpJGT5ddRHvkNg3u2yG8gLXStBZZMmCOaQ2LoR1DC+sicsZg6hO1Gm7Il
	 LU2qOo0OBq9ahly+ePDiGjS4kAysb/6MhR7I5qMZBM6ryBNcf91CFwwaqbGpNXijLQiMx
	 +BDmLJct4feX7yFrqQ9WLUvAZtWhpjUC0VkYVrxS05l5x1bNGXb2VucjeZld7nrJ5x4nI
	 MqcEnLArOaCjpCHvFRPDJNwT+dLxu5/YPGlrFKR7y8pXvggYyvuhfW8c4AkzsFa41qh/J
	 T63JFdIB5q+hlzikyhrD97QtdcIa9lJLQIhYV6fapns3Z/stdxHmZxRV7EhouZVf6/A==
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=jBb+bgSg;
	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 EAD01606A31F;
	Mon, 23 Nov 2026 13:25:34 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB4F81F000D2;
	Mon, 23 Nov 2026 13:25:31 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795440334;
	bh=j6NoxPUSnIuQNQok+UdtQrawTTFukTWkIuqhw/dxpKQ=;
	h=From:Date:Subject:References:In-Reply-To:To:Cc;
	b=jBb+bgSgMY2lc48tNZAdlsxl56nZrYBG7+DAqYWHLKpkgdbYTR1PH8+ajZCxEUFYK
	 MZ49Ht5t6ZojMkhMa0oPRA/44QpjjivN1G1+T3UTPERQTbroGBfVU+jRgt0H2OsK04
	 9YkXrX+R/exMIwSBLQaYvaDkql8+WTVQwRkZPm+QOPaemrTmylUUm+KkE3FUv0i9kv
	 lQE7uSfeAQxcfh10cJ1qsPAxmpi5p4nr4Xe+inHqkux9ILNrHwd00VTB73VQV803ph
	 ibzicA56I81zvR3bJjNr2OKaJfeDsaVAUMPo3RK3OSYhhR2sX5Z9SRqo4a3eGY/WgH
	 pxRgiWJM8Yh6g==
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: <20261123-net-mptcp-misc-fixes-7-4-rc5-v1-0-278042217e8d@kernel.org>
X-Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, 
 Davide Caratti <dcaratti@redhat.com>, 
 "Matthieu Baerts (NGI0)" <matttbe@kernel.org>, 
 Chris Mason <mason@kernel.org>, stable@vger.kernel.org
X-Mailer: b4 0.16.0
X-Developer-Signature: v=1; a=openpgp-sha256; l=4207; i=matttbe@kernel.org;
 h=from:subject:message-id; bh=xK7mk0IXLH6lvQit6O/NTnaAI29UyNNxOopnuSz9I3s=;
 b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGLJZ7HZdjnPY+ejGEsbJ7BbFmzfmdQZsk7sWJf3J4l7/0
 XMKO47c6ChlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZgI7y5Ghs77Uur37vyQDnfa
 OP2G8bu7yScSLu9MCbvOvjq79bTHR1lGhsYN2280l4jXzuK9tJabJclHR95pzyxZDX1HsTdFpxk
 U+QE=
X-Developer-Key: i=matttbe@kernel.org; a=openpgp;
 fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073