From patchwork Tue Nov 19 08:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879489 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 D2D1E19C57C; Tue, 19 Nov 2024 08:35:58 +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=1732005359; cv=none; b=OTPNx1HDg1CfH0IkXlE4p62BwQjaR2JfqKCu51yGP5gdfpw3N5YCFWzrn7jDpSUwQFJyOX9yrFsacSCNyc6x5A6yAVshY7PvldgmKa73WrAbIJT4qfegGTzN3lAdm8Gzum2/TqSobyFq0oFAFC8NLj1O5Z++M7yviypiAz6pvBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005359; c=relaxed/simple; bh=SVigSOPIPTXyWyW3BHK5VjXaJj/wyC6EsOpbOIAqhW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cn3+WCEjMEzxyK10JmoFdzf1eOSPaNjXk8bR80DpWRMABHzzX5gYsPefOKMHfBLtj4EPg95gq5GMDWUZ55FYyXnaeoSMDQsvbDd+CDP8uAfztwjtmhOObbD25EdQLVEJx62Qr+EGLDjNu/vJAJOndnPXi8bg/JUCinNbdfoDpb4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rLCddbFR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rLCddbFR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C905BC4CED1; Tue, 19 Nov 2024 08:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005358; bh=SVigSOPIPTXyWyW3BHK5VjXaJj/wyC6EsOpbOIAqhW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rLCddbFR9XKjSisnOP68hCYBjwOcauLCCI/5Mjx5tNKI1bjlHBlCQ/u6GyN00oq3I qVT3dOpbCzql0WAHDxCICRXr2baLp+tRQizrjZVdD7UYq9Vo0d5U2JfrWpLuOR/YYr TVN216mHn+Uruo1UhYA6YhXYDAeY67pr0a+n2y18LlZNXpg3K/ov66j2F9iCIHXsyU kngOKRTtWW2Ws16zj3YhJoOFG/PfKpGA54IVVvZ2NPbu7HQJz7zmOLxnxnMZPL8Qde 3j8g1LweJ8E0QQPF6dHz1X8VvJ7h53+kGLHm9BIZK7c9Ooef1yQbG1qYwSVVNCInpw pTEE5UA52ZNYg== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: Paolo Abeni , sashal@kernel.org, Matthieu Baerts , Jakub Kicinski Subject: [PATCH 6.1.y 1/7] mptcp: cope racing subflow creation in mptcp_rcv_space_adjust Date: Tue, 19 Nov 2024 09:35:49 +0100 Message-ID: <20241119083547.3234013-10-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1792; i=matttbe@kernel.org; h=from:subject; bh=NsYKbmCRaB8Vh/E7YFJfPDwZvCqJdiPN1sl2VILwj2I=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3jgfPmg0lZ3X480DwZ5pHtLcNIkzaLE7c3u fmnp0fQx0yJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN4wAKCRD2t4JPQmmg cxL+D/9g3IfLS3G6xyH4MgL/eXC6TXEfLs2nXWQFcXroMVEiJOUNBBXlWV8sTr/EY/xFrwirJf7 J888HhFrP8g4F6Ri3ZlBzr2/QCQCKz4SDEuXAwLnigdU8b8JHpv4g/V4JKCsPbdKjQtEW5/MwPZ iRHXs6jrQBQZf01i0asqgR3Qc4gq2nl2EX8BNLX5FfdVrNW0Evl1Zrk9MPNFnj8vmSJri1a9Jc3 KW/dih115JPnQCfMbAmoFNOhktVjWQxJtWEy6Q0C+kKSMJAHl3TM9JhGOHN2IFdz6tUvv46oTST xfKhxAAtnvq+6j+PcV/FWnGZfcie4TLi7enQBpFPiRtJP79LdddUnKefmxRbBSDXi6FT2+LuM7J dsyHN3nPPnbNjcn9cUGu5VELITL66D6/212/SozrfQZJqN72YE+zM+uOr/G+uPgGxNDUf3xHAYN +YVUTixSRSRo0pVflWDk30RP57BpOhKBWkc6zFfAmrhsJtdddZN6HBlWv7Y033fVxyVgjcbWrcJ pwUyvUbRevECgLO4Qja4lr9wkRarfZLUyFULAo1RW/QsPfHK8IBi3aE5JXSztwVRp4tPGK7F47+ BfYodf/gfuUMdXWIy/ade6JBkHtu5JhjRGBvWBnDR4OQTxOhK2ylgw0EKhq4r5xfS5l8B8DgkQR Tj0D7cAd7IVH9Og== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Paolo Abeni commit ce7356ae35943cc6494cc692e62d51a734062b7d upstream. Additional active subflows - i.e. created by the in kernel path manager - are included into the subflow list before starting the 3whs. A racing recvmsg() spooling data received on an already established subflow would unconditionally call tcp_cleanup_rbuf() on all the current subflows, potentially hitting a divide by zero error on the newly created ones. Explicitly check that the subflow is in a suitable state before invoking tcp_cleanup_rbuf(). Fixes: c76c6956566f ("mptcp: call tcp_cleanup_rbuf on subflows") Signed-off-by: Paolo Abeni Reviewed-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/02374660836e1b52afc91966b7535c8c5f7bafb0.1731060874.git.pabeni@redhat.com Signed-off-by: Jakub Kicinski [ Conflicts in protocol.c, because commit f410cbea9f3d ("tcp: annotate data-races around tp->window_clamp") has not been backported to this version. The conflict is easy to resolve, because only the context is different, but not the line to modify. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c index 78ac5c538e13..1acd4e37a0ea 100644 --- a/net/mptcp/protocol.c +++ b/net/mptcp/protocol.c @@ -2057,7 +2057,8 @@ static void mptcp_rcv_space_adjust(struct mptcp_sock *msk, int copied) slow = lock_sock_fast(ssk); WRITE_ONCE(ssk->sk_rcvbuf, rcvbuf); tcp_sk(ssk)->window_clamp = window_clamp; - tcp_cleanup_rbuf(ssk, 1); + if (tcp_can_send_ack(ssk)) + tcp_cleanup_rbuf(ssk, 1); unlock_sock_fast(ssk, slow); } } From patchwork Tue Nov 19 08:35:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879490 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 17B9B19E838; Tue, 19 Nov 2024 08:36:00 +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=1732005361; cv=none; b=BFFCPERUmUpEr+sSeG5279Y/mlvOBVsugr9QrH3TkVrbJhj3PhklXJ1Rc97aO0Etn88D6sP/AbSBNyz6Yuwfzxxkx0n9C+0QWRK9aIyC7S7+Jn2yRQ4EhtYFZwFT8Ylh58B9flGYs6i08+kNouNILkMUPLICfLSsFKBqJaauqRw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005361; c=relaxed/simple; bh=RAVK/hc3PBBjJKvUp742l4IpMrbyZ6g+SMVTNWnphmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MV0onoepU9oW7wTI4BHUCqx38XZdXSMwDtRzhE//CbdUzq9uUS4KC3qtlFh8PAXxydidOrujCjxL9VLT8h6P8gDTKlRmoMd3mYaa4TgFZx1xl4EqJMIC51vpIKf/gILk1k1q95q9NkvPjfpvK2vJxE8+gkSkgVU/snSW9WVEadI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sN/NqR2e; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="sN/NqR2e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CDBC5C4CECF; Tue, 19 Nov 2024 08:35:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005360; bh=RAVK/hc3PBBjJKvUp742l4IpMrbyZ6g+SMVTNWnphmg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sN/NqR2eZ1nBYp+Zfneb6MyZIbYK1GtrgKzeoOmqRgjv+3g8C6CkorKIjAA6zaQRg jmawV+jCVJeGScHrEoGDmhVT60jYPwHixrP6cXBHgD/qeo1PZlDEePmqlks1Kn4/fa UKbn8uXhIDRtf1Xlv5WLuv8psreHVDh5O89ikeQr7h29D2wepYdi/s1W6hkwUYh/sG pzw9Qs6nYNcwH/KTg+37zqnXnvHmIuiyh5rsXfxk/8Nfpy54KuSSWl5EF1//Xx6KjR qgdR/AUFekULyZf8XV6DX5dLRt0t8X/Yf74xZ7qegtV+6AEczEwHZou4ukZDZep1Jj PSk5uiEY6RWNg== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: Geliang Tang , sashal@kernel.org, Matthieu Baerts , Mat Martineau , Jakub Kicinski Subject: [PATCH 6.1.y 2/7] mptcp: define more local variables sk Date: Tue, 19 Nov 2024 09:35:50 +0100 Message-ID: <20241119083547.3234013-11-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4507; i=matttbe@kernel.org; h=from:subject; bh=03IMwEUCz9FS+2ebJybY6rBqT1z4qneYqsTP7bcV6r4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3kX9pqXsh8gYNKWLmDRU/bdAZlUPBT+BZN4 5B0LFST4QOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN5AAKCRD2t4JPQmmg cwg6EADuJZAwLLneAsXqEJPcJbo3XAoCMSZmU3s6iwSGvpV2r8wfWg0CsC7XLpaHGKBateLI7Ae boW9ayl52rkzkTLUD0o2bhXrOUcUEqrwMC2O64u+sJ7P7sW3IjjAHWmE48Eq7xwW8yCXiEgGQrD 0XQ625vKsvWzBrOR1cOmsMO7wb4JNIGFcHmLr0KS3eFOcN63tgO7H5jLGI8nhDfmhfGItqB+ZOg jykH/fUTNYhzZp2wzEdrytEj/Guvnii683fRKegUOsoYZJhDKoL5kdvSHoR/Slx4T3Thu/RSFLN /hD8JdBlqEoxsgNMTEAJXLCaMlGSTclIzfCIPQ8+Iz+ahBTHWbMa0taKueTjeb2du9UZ39O+48G lq9XAxyhR1W0bzyc6xAa5Xn7YyU/5DbuwogfUDuCQhgMfmKX9JaUM9HszQohpyJS6cvRcFtyiXy g0sMmeEyTk7+VNK3tImgS9+b8wZSMvTzJreXSjloFSePOnJ9LMs8Frho3Uvgh6mLSPI/BA26zOS ymnnZsUx7NCK83//RxSZTJamUnnC1tKQgR/OxnWlwAwvuI4jZQM4RA3XsZ4bTTfOH+7WxG41QVi J8A3YvXO+jzf+YZ3GcQd9R70mnv6B/47ro5DVzh65yWHDcmkdnpsD2uJt30wHTJ/5kAkRuTPCVs jyuqrWzc/qlBJLA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang commit 14cb0e0bf39bd10429ba14e9e2f905f1144226fc upstream. '(struct sock *)msk' is used several times in mptcp_nl_cmd_announce(), mptcp_nl_cmd_remove() or mptcp_userspace_pm_set_flags() in pm_userspace.c, it's worth adding a local variable sk to point it. Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau Link: https://lore.kernel.org/r/20231025-send-net-next-20231025-v1-8-db8f25f798eb@kernel.org Signed-off-by: Jakub Kicinski Stable-dep-of: 06afe09091ee ("mptcp: add userspace_pm_lookup_addr_by_id helper") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 748e3876ec6d..530f414e57d6 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -185,6 +185,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info) struct mptcp_pm_addr_entry addr_val; struct mptcp_sock *msk; int err = -EINVAL; + struct sock *sk; u32 token_val; if (!addr || !token) { @@ -200,6 +201,8 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info) return err; } + sk = (struct sock *)msk; + if (!mptcp_pm_is_userspace(msk)) { GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); goto announce_err; @@ -223,7 +226,7 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info) goto announce_err; } - lock_sock((struct sock *)msk); + lock_sock(sk); spin_lock_bh(&msk->pm.lock); if (mptcp_pm_alloc_anno_list(msk, &addr_val.addr)) { @@ -233,11 +236,11 @@ int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info) } spin_unlock_bh(&msk->pm.lock); - release_sock((struct sock *)msk); + release_sock(sk); err = 0; announce_err: - sock_put((struct sock *)msk); + sock_put(sk); return err; } @@ -284,6 +287,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) struct mptcp_sock *msk; LIST_HEAD(free_list); int err = -EINVAL; + struct sock *sk; u32 token_val; u8 id_val; @@ -301,6 +305,8 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) return err; } + sk = (struct sock *)msk; + if (!mptcp_pm_is_userspace(msk)) { GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); goto remove_err; @@ -311,7 +317,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) goto remove_err; } - lock_sock((struct sock *)msk); + lock_sock(sk); list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { if (entry->addr.id == id_val) { @@ -322,7 +328,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); - release_sock((struct sock *)msk); + release_sock(sk); goto remove_err; } @@ -330,15 +336,15 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) mptcp_pm_remove_addrs(msk, &free_list); - release_sock((struct sock *)msk); + release_sock(sk); list_for_each_entry_safe(match, entry, &free_list, list) { - sock_kfree_s((struct sock *)msk, match, sizeof(*match)); + sock_kfree_s(sk, match, sizeof(*match)); } err = 0; remove_err: - sock_put((struct sock *)msk); + sock_put(sk); return err; } @@ -560,6 +566,7 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, { struct mptcp_sock *msk; int ret = -EINVAL; + struct sock *sk; u32 token_val; token_val = nla_get_u32(token); @@ -568,6 +575,8 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, if (!msk) return ret; + sk = (struct sock *)msk; + if (!mptcp_pm_is_userspace(msk)) goto set_flags_err; @@ -575,11 +584,11 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, rem->addr.family == AF_UNSPEC) goto set_flags_err; - lock_sock((struct sock *)msk); + lock_sock(sk); ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, &rem->addr, bkup); - release_sock((struct sock *)msk); + release_sock(sk); set_flags_err: - sock_put((struct sock *)msk); + sock_put(sk); return ret; } From patchwork Tue Nov 19 08:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879491 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 287981885BF; Tue, 19 Nov 2024 08:36:02 +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=1732005363; cv=none; b=lEbI70P5s1Yd08o7iGiAB8soPR4Bya2uAktazvZnwgX/9CVSxSbfAYA0WYEy+jEJOeRdRPJ9pRO39x8QTXTVEYPq7uIvCy/A3vpj8q4KKN2/C4/8j6t2jBMr0ZeOrNCLkl9zQEHdy4NU0Rowj1ffHqeTXVJyNS41rD+ouxIROgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005363; c=relaxed/simple; bh=yoV13LCX/YLZSPLOTNaEryit6zsTgZsfdIqDfrKEfjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YhDv4mD9+tv60pecri8Mtn1daa5qly9K/Eo85+u4aLEoz35+uRZ3XoVLFYS2Km/DlQAxY0LhCY4ZMlHf7bYJlCaE52NoOP3s2S/Oz7R9rdOCHvGEl2oSO4dWerXgtHYVcG8ji29qy+FdIcsOwNlY2nhqqbsjwv0U+N0+vvom81M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f4CMfl2H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f4CMfl2H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08C95C4CED2; Tue, 19 Nov 2024 08:36:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005362; bh=yoV13LCX/YLZSPLOTNaEryit6zsTgZsfdIqDfrKEfjE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f4CMfl2Ha36YJlE5I4VDRatzM2A+7azf2QasIKx+wEyZY8DWoTqoVL9dVg/a4USU+ z2WiHNCl/l26ZUfQOe+hh0X7hkFTYOgiD3hpi5QT8FLLMCG0DY1Cne+YQvAdb2BOxA PBmxOQk+QYi3fxFf/rbUTDN37/EZZzZUk+esxYEu4VnTm+a8edUxoEE/qpNKp/SIX1 kW6caioh6Mj0BJTp2OzEwJUO0GglHONrkWMMAb6r6Bzag2DRKpt/EPaEcOYTJ7kt+d 9mdiG/nkCUX0Qx0qHHeVLdDd1AKlJGEu0qxG14g40WsulnT/vAb6W6brk9RKCtF1Ub Bsvw0Kbzlvi7g== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: Geliang Tang , sashal@kernel.org, Matthieu Baerts , Mat Martineau , "David S . Miller" Subject: [PATCH 6.1.y 3/7] mptcp: add userspace_pm_lookup_addr_by_id helper Date: Tue, 19 Nov 2024 09:35:51 +0100 Message-ID: <20241119083547.3234013-12-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2868; i=matttbe@kernel.org; h=from:subject; bh=RD/camdCYp9STQGdE0voBHs/a0Sj2Bm+bXEiUo1pazg=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3kgzWvrJRWiysXbFfRPEsN2WnsSNkLcyrDL SdcdtGWpKOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN5AAKCRD2t4JPQmmg c+M/D/9Xg09wJVKBNo7OoGdB27tNnXb/wFW1BcSLFE1btHIBjUwjPpwMIkyhLIIWF9UmfTQF41i QgomwDea2ZTH6oem57i2WPLPoSuT4aFdjwSaFH9IHdZb2piOtoVH8DBM8Gi6tAywvoitb5s6em7 O7WiQAnjmDr/b8bus4UJSFTwY/D51Z27zlJjClPhSIqYdpKjCNjuCPQ+wrtwd25AT19ODfrAgTK 4PQqrjBZo/HE3bBODBYsACyCkrykOQau9EPZ/vZrmhCfIDcTtLmoSrXS3dmMIu4p05UctWWrRUX DctxsEnuFI+XgTnPSTrcAlm1dJPzaJKyqJ/ShPQmLbRXvLsig8vUlz+NU0LUmkW9/B1T53Kg98X +i9U0fNE//t0NvymjwIIY2DousrsaLM8AdGZDuj0UksR7eEpt3vFRpHeojusWY8ZqHSSEhrEUZ3 CV+N2VmLZ8l84/avFcf1AKbLtBbRHRtg+VVcLm2vOjZgsv7HoYRd383zLFbyfabN41yT4+Hvhxy BahPBiK2eu2uX2dnAIMKKaU46WdC5tzlyF12t1db0cYC7Q/EmJVcdOYAJHo0x3S0qzkoG0aEnd/ CoeBTqhiYEKiJ8N7x+1OI2os4PpP471sJWTOKbSBG7NDqLcUxyTum/CR43dB9F4An9cAjmwe8ay RXgtmXEb8wF6Vrw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang commit 06afe09091ee69dc7ab058b4be9917ae59cc81e5 upstream. Corresponding __lookup_addr_by_id() helper in the in-kernel netlink PM, this patch adds a new helper mptcp_userspace_pm_lookup_addr_by_id() to lookup the address entry with the given id on the userspace pm local address list. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Signed-off-by: David S. Miller Stable-dep-of: f642c5c4d528 ("mptcp: hold pm lock when deleting entry") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 530f414e57d6..ca3e452d4edb 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -106,22 +106,29 @@ static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk, return -EINVAL; } +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (entry->addr.id == id) + return entry; + } + return NULL; +} + int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, u8 *flags, int *ifindex) { - struct mptcp_pm_addr_entry *entry, *match = NULL; + struct mptcp_pm_addr_entry *match; *flags = 0; *ifindex = 0; spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (id == entry->addr.id) { - match = entry; - break; - } - } + match = mptcp_userspace_pm_lookup_addr_by_id(msk, id); spin_unlock_bh(&msk->pm.lock); if (match) { *flags = match->flags; @@ -282,7 +289,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) { struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID]; - struct mptcp_pm_addr_entry *match = NULL; + struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; LIST_HEAD(free_list); @@ -319,13 +326,7 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) lock_sock(sk); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (entry->addr.id == id_val) { - match = entry; - break; - } - } - + match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); release_sock(sk); From patchwork Tue Nov 19 08:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879492 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 431B71885BF; Tue, 19 Nov 2024 08:36:04 +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=1732005365; cv=none; b=q3JTQSml5c8Kcco8G4q5GaFRfGkJ/ZJTdI0w7eEDoApCWB3iuOfBlL5cMs9nawCfOO0gGai3DXqXvfs3n4qfCePhjDb86R4+BV/Ie/bhQXmYPJILSj6tk+S2CiXxwFFZS1j8ZfFWY1i6jCr66Y2FXMSO2xBXHPVU31Kgo9RSSyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005365; c=relaxed/simple; bh=6pSt/3agggkzfOOflqIswigaRjWoWiwPtgZJNnrCLVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tfJTw6LpF3C7rtWGg5D6Sx9W7eqKIFHPRayR69DMAe/U1TlZtsd2sEh3rVan5tvvXf70U63rHCrY51AuQn86SDI4qcfLGQURlHBYmYWyeZtcOnI7Mg0vQoJWZlnIllDKeJqqXiJnVgORQ+CT50qcjTkY4XnwlAiTVuZWBtqC7yA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Krn2GXSo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Krn2GXSo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38943C4CED1; Tue, 19 Nov 2024 08:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005364; bh=6pSt/3agggkzfOOflqIswigaRjWoWiwPtgZJNnrCLVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Krn2GXSoYT+aZqFlnlIfnz0JQL4YEejqCpJscyLhC6ET6gbQ0vEPxWWvCfXOWFBDt 0hqCCgcVlEhwh5CU4DWU8reREFTXRPLkRgahYPRm6O/BGiZIxxoeBPwh+CeOdKs1Tq qe1fsC8J/X60NTbvZPmct6/oVfkv7pBuZKtXW0GpRniCo3UdP0OxXVwsi3p5udBWZb mzoLhbfuvW6F51VYP6qDbFbHOXLv/KLgruw5fJ0u/jwiK0Et3/TLUXKWRfZtlW0SkS 2ENliqdpwtgT8SanNC/IFJJyva3eWn74vyONaX30miQYKwTTE97Zd/8wv7y/R+IgT/ U8xw4mmE6Bi7w== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: Geliang Tang , sashal@kernel.org, Matthieu Baerts , Jakub Kicinski Subject: [PATCH 6.1.y 4/7] mptcp: update local address flags when setting it Date: Tue, 19 Nov 2024 09:35:52 +0100 Message-ID: <20241119083547.3234013-13-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2411; i=matttbe@kernel.org; h=from:subject; bh=7CKnHeiIcL2LfHx3nubHzjydY6n8OUTlxZHPcUInqK4=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3krtpRCr369o62piZrMcFDC9vXsT2UrmOZ4 v3E7XZT0u2JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN5AAKCRD2t4JPQmmg c542D/9jjvgYMP6dkLr3vFz66VCMYelHJIjYbWIvhSlsTWaH0/Wnls8w8UcD3FzBoiwqVG7eknt LiT9vonAd27UgFEfq8W2RyufFikdjqDiUx6s1JgudlT9F5TRGFKuZZhXfAcLJAzJmtTKkdfEm90 6mrGlYXQSaFMxbBl/a1KVMp33nAuchR1if0HJ//8DhaEYB5h76AIld4GqOccypecBxEGsf9nbGN dCpbWq80rhOpxb1XnDzNb2WX4O3vO9ZRZnc2DACLO7baSro2DfwgO6AfvgBPga/HGTegFVtNH95 6MI3+1pk1Esl8Lriilfc0o+EDMW/4EJ04HCVb+SOX7HAA4LekifjnIVDhBWYf8wfuJcCHgilPXp o2IVFd6DnQxlj8QhApHX5kDIAo5BjBiDl6K7NYlC9OfOvDVNkcUwBKdurH0VDWNlnqlY3oEoItC 1iIGVul2TuGfIHHQJoPKjPS0jQ8LXyQDseBPwR0sxwOJfZzra+jtx1JCZiy48I5Ed3lKAMNganR igDgJvmeWxMmJQmPgcC1T2eGC+A1FYZmifUV+HbUjzvydVa32iGpU/VBrlCCmxWF6jeYkffArRX 5917quCdvc5kOn+Mz2I3AGZOzE1gSepuIuI6OtvxUkfrQGDiqfxucCp+dOnNnI8bjHM0IYjnWjq yzuXA9rAssDJjMA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang commit e0266319413d5d687ba7b6df7ca99e4b9724a4f2 upstream. Just like in-kernel pm, when userspace pm does set_flags, it needs to send out MP_PRIO signal, and also modify the flags of the corresponding address entry in the local address list. This patch implements the missing logic. Traverse all address entries on userspace_pm_local_addr_list to find the local address entry, if bkup is true, set the flags of this entry with FLAG_BACKUP, otherwise, clear FLAG_BACKUP. Fixes: 892f396c8e68 ("mptcp: netlink: issue MP_PRIO signals from userspace PMs") Cc: stable@vger.kernel.org Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20241112-net-mptcp-misc-6-12-pm-v1-1-b835580cefa8@kernel.org Signed-off-by: Jakub Kicinski [ Conflicts in pm_userspace.c, because commit 6a42477fe449 ("mptcp: update set_flags interfaces"), is not in this version, and causes too many conflicts when backporting it. The same code can still be added at the same place, before sending the ACK. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index ca3e452d4edb..195f84f16b97 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -565,6 +565,7 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, struct mptcp_pm_addr_entry *loc, struct mptcp_pm_addr_entry *rem, u8 bkup) { + struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; int ret = -EINVAL; struct sock *sk; @@ -585,6 +586,17 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, rem->addr.family == AF_UNSPEC) goto set_flags_err; + spin_lock_bh(&msk->pm.lock); + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (mptcp_addresses_equal(&entry->addr, &loc->addr, false)) { + if (bkup) + entry->flags |= MPTCP_PM_ADDR_FLAG_BACKUP; + else + entry->flags &= ~MPTCP_PM_ADDR_FLAG_BACKUP; + } + } + spin_unlock_bh(&msk->pm.lock); + lock_sock(sk); ret = mptcp_pm_nl_mp_prio_send_ack(msk, &loc->addr, &rem->addr, bkup); release_sock(sk); From patchwork Tue Nov 19 08:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879493 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 4C17D1885BF; Tue, 19 Nov 2024 08:36:06 +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=1732005367; cv=none; b=KsZEUQQ6QWVdF8ou9hTIT+K6biVeBhdl+1cH9Ke/sh26vYOlv5sHFlsmOv+t+k9aP3nlbWJChao/8fTgR+C+vFxoG3+8gfbCSeS+bwd+0GwVQSof6HtFMDk8wqWH23O4iYtnFeypx/Z+YhCGxzcde8TJpYI6HmsNwchqOuoW4hI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005367; c=relaxed/simple; bh=20Lj9jc3IvytiHT8Hf9XMs0G3Qm7XasUxrotdB9Zr/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wk6xeS6R75l+ScvXe5PkXey5ykWaEtQV/J0bIT9/vxoJd0bBjTUxPLpWBGgH8rtgjd9MmVywJUnTZ9uu8UqwuFYbj1pWEkJ1BXiMr1iwMHASxW0FWqp4QsmhtzwkUOZFYhOXe1pdeVDwQiHRczO4hcEFGdIDyx1EDgs1U9720p0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rjvk4O8V; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rjvk4O8V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AA38C4CED2; Tue, 19 Nov 2024 08:36:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005366; bh=20Lj9jc3IvytiHT8Hf9XMs0G3Qm7XasUxrotdB9Zr/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjvk4O8VTqoNkqY+izB4ZMlGuCGoQ2HxS3/GwO1gxLQ0Yp6DquJ3nr756+S2/E1R9 t4b6my/w33n9TKk/pfZcW59OWu5JR3PCzuUAzyoxgR09zTE2zyrZO114jTYiSSOCX/ dhmrdAQgAR+z9dl5rZGOGy3dz2tU3rTFwstJ8On/EqLMZSshLMuTAw/tN5nvUm1pX6 4s7q0lKjW1UIuh/9GLWyFhPHWkQstq9FT+d9wtLUXG4hKzYR5vhPuGCWRSQnlf+Ix9 2BJ2vbMsZSm/BExLP00/IMn+R/Kinm5PXicFUsMfno7hNnw6LdaQ9rEs5TRVfE+EO0 TYTdC9pi3P6vw== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: Geliang Tang , sashal@kernel.org, Matthieu Baerts , Jakub Kicinski Subject: [PATCH 6.1.y 5/7] mptcp: hold pm lock when deleting entry Date: Tue, 19 Nov 2024 09:35:53 +0100 Message-ID: <20241119083547.3234013-14-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1570; i=matttbe@kernel.org; h=from:subject; bh=aMO5NOvmxw6Q0jjN75Cvmc36iLaQOTTBJf/lO1QIrKE=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3kdOwNK/w7Ko20Wu6zD7aFhm6aH50aBRFdu Af96CAVY6+JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN5AAKCRD2t4JPQmmg c7fKEADGAHXSguz/4Yui/U5piMFsIG2TWGliuvnGuqKP1oEgq8XjqN9QkGSRPirPha3qg2RK6Oz 1XHvHo0i+sJsJp4DK3W9qGAlA9EMULUB1lHgfogxnXsEqapS4BVH2jBBqkGJ4wfw4p1z5kaxar9 51ItMTv10lzUBH1endKWsr0UDx+2XAE0nZIYpeJyPkNsQ/WdGm23wRyAFhuI6tegnUe7NXvMj3e h/kduWEyShTK9eXr1wSKaM5b3/MZwQgC2VWMurVn9gvALhsqrkGPR1fDKRgNH69yfqQmhoC8OSf 8/9KWvDxdE4gKOC8asyJG4m0SH6QtPSwlDMXncQkqM49rtAo8gYmwbdijPAHVR+QjxExD9bcBlK vshJf30yPVm0ACor2NLef8WY/hxzG4w71qM6RQyz9ODRYIzPhLwsu+VyyrgNc41FxSprZ3tQuRz /R/hXRPBPfEqBh9OEyO2v+Rb/wDSxtPAcvd1eZ5PHx8CN5Ws0laIue+AJ6EgMPEft7XJVN/hZMK DZSoxCGKD5Ms9ObbibauomhJG6Lq9aVuny3DL25L9Gmr9lfydcp6bXtPdAdfNLK1LbqqBbr1APz 8eUB43DxSBssxAyBt+NvGYc6fTVWQSvT2NSS8g/BmGklgKCl/eZGPtDCtasrJV9B8ru3dLPMfIi rQWrGnpkPIj8HgQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang commit f642c5c4d528d11bd78b6c6f84f541cd3c0bea86 upstream. When traversing userspace_pm_local_addr_list and deleting an entry from it in mptcp_pm_nl_remove_doit(), msk->pm.lock should be held. This patch holds this lock before mptcp_userspace_pm_lookup_addr_by_id() and releases it after list_move() in mptcp_pm_nl_remove_doit(). Fixes: d9a4594edabf ("mptcp: netlink: Add MPTCP_PM_CMD_REMOVE") Cc: stable@vger.kernel.org Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20241112-net-mptcp-misc-6-12-pm-v1-2-b835580cefa8@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 195f84f16b97..9016f8900c19 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -326,14 +326,17 @@ int mptcp_nl_cmd_remove(struct sk_buff *skb, struct genl_info *info) lock_sock(sk); + spin_lock_bh(&msk->pm.lock); match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); + spin_unlock_bh(&msk->pm.lock); release_sock(sk); goto remove_err; } list_move(&match->list, &free_list); + spin_unlock_bh(&msk->pm.lock); mptcp_pm_remove_addrs(msk, &free_list); From patchwork Tue Nov 19 08:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879494 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 365ED198E6D; Tue, 19 Nov 2024 08:36:08 +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=1732005369; cv=none; b=lKuwHPLzWB2edWbtc627OvPpVU+MbJ1i6cwwjRkQ5bzGHZhvwCmqcQ0LsP/WaV2oqFyCxsAtrMvHP2x/z5yFJ+iQFhbwWbJkp0mSXznzrk91EKE9YRuHK+OZJLJGzPIik6bZkoU7IG+OJDViybENq+acwEA332gogciWH9L1PIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005369; c=relaxed/simple; bh=/15lH2bJJx8m56lJc0D3hesy+1WKaqPuHBeEP9sIy5s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=F8ebAhdBt8bL7jN/aYH9g6i5aU8D6i1cAhXloRgql8PgAThm8CxpfJLNf+s2qof/PoD4ZHpcFVcFS8E/lxyL6wr5D869Z+h0EoaM1IntcEbdGLvt9GwVGq5cA80b34xI8EuSH3I8IP344boin0WixaUL2Kd/Nz5GyKF7t1ij9T4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Cz+SnKpz; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Cz+SnKpz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3D63AC4CED1; Tue, 19 Nov 2024 08:36:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005368; bh=/15lH2bJJx8m56lJc0D3hesy+1WKaqPuHBeEP9sIy5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Cz+SnKpzAEUCsLEmGmt8LOzm5jRDWKkcSah1GwqKAdCI1rBlXyXAaRyPTQChxuaXe q8FScICj14HQ5Mom2zMO253utAWSBGSfzN5GjXAzq71F95imaYhcZ7tug/qefAQ1Xh Bp+tNdgw0eDk9Dl+otNcQfoP6p2jgEAkkKzQI43eYeTd7etRGS8xOj9f0C03xcLn1q 6x3MtEXKEqTpBwTMxC4XusJdj7M6O+Sfgh/UtBs3+AKPv85zlWKEQHnXpbPQi8N7pM tXR50QPdSoefsW40SzmXY88uxVzdOfSvL9mVpXYCBO/jTeb/39dRAOHM4WqA3lRdf/ pwMzc8Ykiou7A== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: Geliang Tang , sashal@kernel.org, Matthieu Baerts , Jakub Kicinski Subject: [PATCH 6.1.y 6/7] mptcp: drop lookup_by_id in lookup_addr Date: Tue, 19 Nov 2024 09:35:54 +0100 Message-ID: <20241119083547.3234013-15-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2956; i=matttbe@kernel.org; h=from:subject; bh=xlm5qZmphQDWhCVQKl29IglZRURRJ3MKIL7gFVz2pOM=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3kFsZXe/P1WN/oeKuP0B4mcmjGoT3Kaas4O X4kIv7PyiOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN5AAKCRD2t4JPQmmg c9aTD/9Xst4sIxQJ6epjSnbFgWZzIf2nbZvZDx1KrbpY5cuwXHcJb5mNSKtQIC5cfPzaE11vmr3 HdVg0BrXk56BbTx/jmq96JiLYbX5ADkpkW+g/P6fSFQu/G7ImDBbr98wc91104VL+LrccFOPbLE x6tPQL9sNEYZDVjflUNJ63DHWKhu9shyOGkWOZJyEDA/NpdP7T/PYYUTMbTofI5LMJ8aSDtOtx2 HZC9GIZpNy7ves28OMVFuGOrZ6DJf2BD2t/FbTrVYlSTSZSL8LdcAliC8Jd24ELCOtsxnclz/qE e/l3EJofJsBNH/ZITWO+DTzDZx4bi4Ou6oYQXu/Y38ISvr8VmxjPB8USeDKYpweR2VcLaQaUr92 MTftOvma5nQ7uXpBq7i/aOa+HUq7h+wznIaOGSJhDva8vVd/N0MbdU1IT95vWPmqO129dAUsH56 W8ZLSUg/pGrsv7WaoYXY6D4aCrV1Oa7dZGWRwGrV062RIv1t3/8Va87hGUIQGGXWJJ70xjx8R85 fKXVBvarce5qrprUoXLDta3HRhszVtXBVifVYIhvN13wDDK4aW3ZOgzoP4Rw8Vl7dt8bwu1uRjo hnTXWQw6Yokzlr7YyTbApi8kMlsJ3Hlv9Go60+cBi+LBg1hswJISpJjMIvq4iH2NM2zAKG7uayR t5H8tHdB/hZP4cQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang commit af250c27ea1c404e210fc3a308b20f772df584d6 upstream. When the lookup_by_id parameter of __lookup_addr() is true, it's the same as __lookup_addr_by_id(), it can be replaced by __lookup_addr_by_id() directly. So drop this parameter, let __lookup_addr() only looks up address on the local address list by comparing addresses in it, not address ids. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) Link: https://lore.kernel.org/r/20240305-upstream-net-next-20240304-mptcp-misc-cleanup-v1-4-c436ba5e569b@kernel.org Signed-off-by: Jakub Kicinski Stable-dep-of: db3eab8110bc ("mptcp: pm: use _rcu variant under rcu_read_lock") [ Conflicts in pm_netlink.c, because commit 6a42477fe449 ("mptcp: update set_flags interfaces") is not in this version, and causes too many conflicts when backporting it. The conflict is easy to resolve: addr is a pointer here here in mptcp_pm_nl_set_flags(), the rest of the code is the same. ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 49e8156f5388..9b65d9360976 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -525,15 +525,12 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id) } static struct mptcp_pm_addr_entry * -__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info, - bool lookup_by_id) +__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info) { struct mptcp_pm_addr_entry *entry; list_for_each_entry(entry, &pernet->local_addr_list, list) { - if ((!lookup_by_id && - mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) || - (lookup_by_id && entry->addr.id == info->id)) + if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) return entry; } return NULL; @@ -564,7 +561,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk) mptcp_local_address((struct sock_common *)msk->first, &mpc_addr); rcu_read_lock(); - entry = __lookup_addr(pernet, &mpc_addr, false); + entry = __lookup_addr(pernet, &mpc_addr); if (entry) { __clear_bit(entry->addr.id, msk->pm.id_avail_bitmap); msk->mpc_endpoint_id = entry->addr.id; @@ -2081,7 +2078,8 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) token, &addr, &remote, bkup); spin_lock_bh(&pernet->lock); - entry = __lookup_addr(pernet, &addr.addr, lookup_by_id); + entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr.addr.id) : + __lookup_addr(pernet, &addr.addr); if (!entry) { spin_unlock_bh(&pernet->lock); return -EINVAL; From patchwork Tue Nov 19 08:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13879495 X-Patchwork-Delegate: matthieu.baerts@tessares.net 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 5F7F7198A17; Tue, 19 Nov 2024 08:36:10 +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=1732005371; cv=none; b=BcSbASrT4sGCGEXOvkL5jPaXBfU3qwz6IBv+dhmWn8WUyhK2Ep3eboNe4vJ3XMSVYKzX8NwDHoeu3TYtH8ai9YBJqOwQZ8Rzr4BZ9Q3S5/oCnwdqXAZqm8udo4p4ZZMICrd35g73pEJZPbRwFidwSHbte1JMQ1SJ4Rq5zoN26Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732005371; c=relaxed/simple; bh=3AMU3wdCDVm5tVBiothvkIyHUAqsTq8A8UY0redF5Z0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cH8t/VVuXoMtSWgwW68q54DSQiHPBfhQvvlGwLk7OCzKjCWTu1fUhmhj3vt2BxUG7kbLd8ZS93ePvxsGHjTGz4wyESWXTc4N5m67qHAU5pzXoehELC+7JJ0pQO2vc5oBX5fOvIJEJLKm1KVoMktysXmDD7NOKp2fqSPKIuD62Rk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=doxeka68; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="doxeka68" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40ABCC4CED6; Tue, 19 Nov 2024 08:36:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732005370; bh=3AMU3wdCDVm5tVBiothvkIyHUAqsTq8A8UY0redF5Z0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=doxeka68YbwmxL66JgPGJzbu1nuwjNmbNV4DMl8ebHKnT2fUzTM2ZkjpWQe9TCyWD xCx16QiNXLWf3VqkB0qRtrft1SzgBq/S2efSD41eoE8HCaqPKhUW2JgSHcOEfEweJO gpTGbYUVlX5xAVKjLEPGssGpbn2n3dNAL8VTPQqXwNG/DeJetBKza94W/K5IhwWoav zcX4goDBYHBHFS2HfDU0aIeOQp+5x8aYm8yim+eo8LdiTCWyx1pEjL6v9Q4R3O9EPa T866z/lnvDPaTxSuw1w6fEKRIaUp8hFZysnZYcetgAxaWL5ZO5L+BaqTxxRQfraoAK IKc6QX1lgbnWg== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: "Matthieu Baerts (NGI0)" , sashal@kernel.org, Geliang Tang , Jakub Kicinski Subject: [PATCH 6.1.y 7/7] mptcp: pm: use _rcu variant under rcu_read_lock Date: Tue, 19 Nov 2024 09:35:55 +0100 Message-ID: <20241119083547.3234013-16-matttbe@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241119083547.3234013-9-matttbe@kernel.org> References: <20241119083547.3234013-9-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1770; i=matttbe@kernel.org; h=from:subject; bh=3AMU3wdCDVm5tVBiothvkIyHUAqsTq8A8UY0redF5Z0=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBnPE3kpcUzql7unpgDC1+yMvbNybGpiD38BF8gM QHbIRiAgtOJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZzxN5AAKCRD2t4JPQmmg c5jgEADLvhabaRG2tpo+/4jChu5phYD7gxelnYKGYDsrD1TBZ+4ckhdkXExg5AjmyTi0rZeBruB B44J6TgCVBi6K6/G0hcCQbNasv2pinsqirCBBfoJ9A1dsLpbqmA6Y4uV3vEWINOkKVMFzkmXbVX cZZXV6vahXMFQUXuHHYXdIQWLB5La05DfqSU0adaxuLUOW8hnkYV4+ko/bcCNhRMrYQAVvrNRvb 5iPTKYSMXxkdz/7gCQ3xeaybQuj7ZvgJZyULShuJr2P7D6DzGRtui1mn/qzb2FJZNz97TAtbvfy VoyASV/Kx2NNWffi4WeU32iwuTC6X52WGXSl8Y1otRDU1UxuxUVK2EDzI/Xf4GvuVYD+spf82Xs +KGaHfzsPTpgO+9z/bHfSBU+AyZ2oByqw7SrNsDyNrEroZMGd/hIz25b75AvrAMVtjn3EPDhGjH heOjoZ+DjyO5fe+ZHZ3zOK0udXgF2aTa0HjIXloEJtVoZNifM1VGsMHuc+VFUpr0hpRidC53iWZ OBezT4Z15+DeBy5YCN03clzXjeUmGQ4VkIntcmuRJdjipWU1E6n2uBYeCl1d2RLo2ErjkF+jjgp 1VDxm2CHDRtWH40vCOxX16OAHSaHIaY9NKxzVwiOWBzkg2NHxcbbKnnC9V6bayx70pIa+Pwaa8j Ev656Mv/cdjjjPQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 commit db3eab8110bc0520416101b6a5b52f44a43fb4cf upstream. In mptcp_pm_create_subflow_or_signal_addr(), rcu_read_(un)lock() are used as expected to iterate over the list of local addresses, but list_for_each_entry() was used instead of list_for_each_entry_rcu() in __lookup_addr(). It is important to use this variant which adds the required READ_ONCE() (and diagnostic checks if enabled). Because __lookup_addr() is also used in mptcp_pm_nl_set_flags() where it is called under the pernet->lock and not rcu_read_lock(), an extra condition is then passed to help the diagnostic checks making sure either the associated spin lock or the RCU lock is held. Fixes: 86e39e04482b ("mptcp: keep track of local endpoint still available for each msk") Cc: stable@vger.kernel.org Reviewed-by: Geliang Tang Signed-off-by: Matthieu Baerts (NGI0) Link: https://patch.msgid.link/20241112-net-mptcp-misc-6-12-pm-v1-3-b835580cefa8@kernel.org Signed-off-by: Jakub Kicinski Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 9b65d9360976..3fd7de56a30f 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -529,7 +529,8 @@ __lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info) { struct mptcp_pm_addr_entry *entry; - list_for_each_entry(entry, &pernet->local_addr_list, list) { + list_for_each_entry_rcu(entry, &pernet->local_addr_list, list, + lockdep_is_held(&pernet->lock)) { if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) return entry; }