From nobody Wed Dec 4 19:18:28 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BD513224; Sun, 8 Sep 2024 13:06:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725800815; cv=none; b=E3RRtI3rUFHT10Nogx9eScA+ZluM8GZIk+na72LN3jVB6qbO3UdZb0isXK/Sp07hdLwApCG2BjeP1XbhLY7wfwX8o2LeG9I9Y7JPVt+hLmGgaGZ17LOVjYA9iMT4beZfT52U0iDAf/i7klpWUwk9Ow27PrZVGJPR433GCHln0LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725800815; c=relaxed/simple; bh=jt+bQ3VUv/ur8EGgKmAuYknv3+QNJ56HXrgmTyyfuVk=; h=Subject:To:Cc:From:Date:In-Reply-To:Message-ID:MIME-Version: Content-Type; b=MijOW7UayKK5LIMByJ4LT9UCosmtpudaw2QaGT+EsjnFjbcYo8SvNBtkJpEkL1mXNs/8+1TZQqCfrEYdYYEXxZYbAmX528bdD64Pz7HGDch9sBO8bhjkzDHH0bqaG9cfLOtNvO98wxVSblnsi6V/dDw9tu19x88RAgJZZVbUh30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=07/d3w0a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="07/d3w0a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 24979C4CEC3; Sun, 8 Sep 2024 13:06:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1725800815; bh=jt+bQ3VUv/ur8EGgKmAuYknv3+QNJ56HXrgmTyyfuVk=; h=Subject:To:Cc:From:Date:In-Reply-To:From; b=07/d3w0aaa19y9EqzvmxZU+vk7HPL502lo+UflO/H1ZCSCj0bUmLEgnY+NIzrAG4v BTZHN8Zy9C63vVJVSbz9rryMXkTEXskV+Ipv8RQR2ZRT8rGBc83I3vQyg6sspd8wQX 2AH8oTyfPrqnBq4L1HVznDs3G+2FOBKsoJAn63Zk= Subject: Patch "mptcp: pm: avoid possible UaF when selecting endp" has been added to the 5.15-stable tree To: gregkh@linuxfoundation.org,kuba@kernel.org,martineau@kernel.org,matttbe@kernel.org,mptcp@lists.linux.dev,pabeni@redhat.com Cc: From: Date: Sun, 08 Sep 2024 15:06:45 +0200 In-Reply-To: <20240906083151.1768557-4-matttbe@kernel.org> Message-ID: <2024090843-wife-sizzle-e238@gregkh> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-stable: commit X-Patchwork-Hint: ignore Content-Type: text/plain; charset="utf-8" This is a note to let you know that I've just added the patch titled mptcp: pm: avoid possible UaF when selecting endp to the 5.15-stable tree which can be found at: http://www.kernel.org/git/?p=3Dlinux/kernel/git/stable/stable-queue.git= ;a=3Dsummary The filename of the patch is: mptcp-pm-avoid-possible-uaf-when-selecting-endp.patch and it can be found in the queue-5.15 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let know about it. From stable+bounces-73735-greg=3Dkroah.com@vger.kernel.org Fri Sep 6 10:32= :28 2024 From: "Matthieu Baerts (NGI0)" Date: Fri, 6 Sep 2024 10:31:53 +0200 Subject: mptcp: pm: avoid possible UaF when selecting endp To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: MPTCP Upstream , "Matthieu Baerts (NGI0)" , Paolo Abeni , Mat Martineau , Jakub Kicinski Message-ID: <20240906083151.1768557-4-matttbe@kernel.org> From: "Matthieu Baerts (NGI0)" commit 48e50dcbcbaaf713d82bf2da5c16aeced94ad07d upstream. select_local_address() and select_signal_address() both select an endpoint entry from the list inside an RCU protected section, but return a reference to it, to be read later on. If the entry is dereferenced after the RCU unlock, reading info could cause a Use-after-Free. A simple solution is to copy the required info while inside the RCU protected section to avoid any risk of UaF later. The address ID might need to be modified later to handle the ID0 case later, so a copy seems OK to deal with. Reported-by: Paolo Abeni Closes: https://lore.kernel.org/45cd30d3-7710-491c-ae4d-a1368c00beb1@redhat= .com Fixes: 01cacb00b35c ("mptcp: add netlink-based PM") Cc: stable@vger.kernel.org Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20240819-net-mptcp-pm-reusing-id-v1-14-38035= d40de5b@kernel.org Signed-off-by: Jakub Kicinski [ Conflicts in pm_netlink.c, because quite a bit of new code has been added around since commit 86e39e04482b ("mptcp: keep track of local endpoint still available for each msk"). But the issue is still there. The conflicts have been resolved using the same way: by adding a new parameter to select_local_address() and select_signal_address(), and use it instead of the pointer they were previously returning. The code is simpler in this version, this conflict resolution looks safe. ] Signed-off-by: Matthieu Baerts (NGI0) Signed-off-by: Greg Kroah-Hartman --- net/mptcp/pm_netlink.c | 47 ++++++++++++++++++++++++++------------------= --- 1 file changed, 26 insertions(+), 21 deletions(-) --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -158,12 +158,14 @@ static bool lookup_subflow_by_daddr(cons return false; } =20 -static struct mptcp_pm_addr_entry * +static bool select_local_address(const struct pm_nl_pernet *pernet, - struct mptcp_sock *msk) + struct mptcp_sock *msk, + struct mptcp_pm_addr_entry *new_entry) { const struct sock *sk =3D (const struct sock *)msk; - struct mptcp_pm_addr_entry *entry, *ret =3D NULL; + struct mptcp_pm_addr_entry *entry; + bool found =3D false; =20 msk_owned_by_me(msk); =20 @@ -187,18 +189,22 @@ select_local_address(const struct pm_nl_ * pending join */ if (!lookup_subflow_by_saddr(&msk->conn_list, &entry->addr)) { - ret =3D entry; + *new_entry =3D *entry; + found =3D true; break; } } rcu_read_unlock(); - return ret; + + return found; } =20 -static struct mptcp_pm_addr_entry * -select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos) +static bool +select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos, + struct mptcp_pm_addr_entry *new_entry) { - struct mptcp_pm_addr_entry *entry, *ret =3D NULL; + struct mptcp_pm_addr_entry *entry; + bool found =3D false; int i =3D 0; =20 rcu_read_lock(); @@ -211,12 +217,14 @@ select_signal_address(struct pm_nl_perne if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) continue; if (i++ =3D=3D pos) { - ret =3D entry; + *new_entry =3D *entry; + found =3D true; break; } } rcu_read_unlock(); - return ret; + + return found; } =20 unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk) @@ -474,7 +482,7 @@ __lookup_addr(struct pm_nl_pernet *perne static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) { struct sock *sk =3D (struct sock *)msk; - struct mptcp_pm_addr_entry *local; + struct mptcp_pm_addr_entry local; unsigned int add_addr_signal_max; unsigned int local_addr_max; struct pm_nl_pernet *pernet; @@ -493,13 +501,11 @@ static void mptcp_pm_create_subflow_or_s =20 /* check first for announce */ if (msk->pm.add_addr_signaled < add_addr_signal_max) { - local =3D select_signal_address(pernet, - msk->pm.add_addr_signaled); - - if (local) { - if (mptcp_pm_alloc_anno_list(msk, local)) { + if (select_signal_address(pernet, msk->pm.add_addr_signaled, + &local)) { + if (mptcp_pm_alloc_anno_list(msk, &local)) { msk->pm.add_addr_signaled++; - mptcp_pm_announce_addr(msk, &local->addr, false); + mptcp_pm_announce_addr(msk, &local.addr, false); mptcp_pm_nl_addr_send_ack(msk); } } else { @@ -514,9 +520,8 @@ static void mptcp_pm_create_subflow_or_s if (msk->pm.local_addr_used < local_addr_max && msk->pm.subflows < subflows_max && !READ_ONCE(msk->pm.remote_deny_join_id0)) { - local =3D select_local_address(pernet, msk); - if (local) { - bool fullmesh =3D !!(local->flags & MPTCP_PM_ADDR_FLAG_FULLMESH); + if (select_local_address(pernet, msk, &local)) { + bool fullmesh =3D !!(local.flags & MPTCP_PM_ADDR_FLAG_FULLMESH); struct mptcp_addr_info addrs[MPTCP_PM_ADDR_MAX]; int i, nr; =20 @@ -525,7 +530,7 @@ static void mptcp_pm_create_subflow_or_s nr =3D fill_remote_addresses_vec(msk, fullmesh, addrs); spin_unlock_bh(&msk->pm.lock); for (i =3D 0; i < nr; i++) - __mptcp_subflow_connect(sk, &local->addr, &addrs[i]); + __mptcp_subflow_connect(sk, &local.addr, &addrs[i]); spin_lock_bh(&msk->pm.lock); return; } Patches currently in stable-queue which might be from matttbe@kernel.org are queue-5.15/mptcp-pm-avoid-possible-uaf-when-selecting-endp.patch queue-5.15/mptcp-pm-only-decrement-add_addr_accepted-for-mpj-req.patch queue-5.15/mptcp-pm-fullmesh-select-the-right-id-later.patch queue-5.15/mptcp-pm-skip-connecting-to-already-established-sf.patch queue-5.15/mptcp-pm-re-using-id-of-unused-flushed-subflows.patch queue-5.15/mptcp-pm-add_addr-0-is-not-a-new-address.patch queue-5.15/mptcp-constify-a-bunch-of-of-helpers.patch queue-5.15/mptcp-pm-do-not-remove-already-closed-subflows.patch queue-5.15/mptcp-pr_debug-add-missing-n-at-the-end.patch queue-5.15/mptcp-pm-check-add_addr_accept_max-before-accepting-new-add_addr= .patch queue-5.15/mptcp-close-subflow-when-receiving-tcp-fin.patch queue-5.15/mptcp-avoid-duplicated-sub_closed-events.patch queue-5.15/mptcp-pm-send-ack-on-an-active-subflow.patch