From patchwork Thu Feb 15 18:25:32 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: 201710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp53511dyb; Thu, 15 Feb 2024 10:59:23 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU6fsWLJ/BHHuwPQTPJpqb+o3u8U3blbon9mBqiO5OQ6n5f/iPrE0e5j5NxM2zql+Lk/W4clE7/mREjzi8QwqtWZ2THVg== X-Google-Smtp-Source: AGHT+IEC4Zq5hl53ZGgr8JDMBtLksU1yTRWrWm2ySMKzQgi3Q2nvCrlIGWnAKFai2TlJgT44fKo1 X-Received: by 2002:a17:902:e551:b0:1d9:bff2:67d3 with SMTP id n17-20020a170902e55100b001d9bff267d3mr3478889plf.0.1708023563532; Thu, 15 Feb 2024 10:59:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708023563; cv=pass; d=google.com; s=arc-20160816; b=W41AkIb7TKC1T64A362sVv8BDqH9aAeWIm7si831ndjjqZSUPVSVvj2DMx4NNWYqn9 FkbsjgReqDtqdFicdeZoB+T5qR4t6BEYt1ES8e8hHipiSrDR11243BSvSDyusDuHNmW7 AFFriXiWXj2+v1ji+4eQaWwTLBANFAug0RxfHaRPuHAYKNLPRjpAICJQJrMB1842E2qP bPUsvQ9Lo/Wwl0zMkpq0b/bwHvPXCwMSLkANBekD22nwK4HXdTGm6A0xVzt9XT0uIMc1 CASXV+xm4EKYKOrV8Ws6HmjL4zcHo37AlH64Unwwk4B0pJu5lHq6tcz3+bPNX16s6X3V qlkw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=6fM9T5TQvYHmSDtNNaxarAfvJSXrt/ZD4csLZgGM0vQ=; fh=YLls1mWwoBtdGDVDLSS7Y7vfTx1qtyt00TdtmrttUI0=; b=g0ob9bL7OeOOvRHh6gJLDa+Jzl/d57gWZroer1Nfbuy0/upZCleRWPcmu7ew1ggCmS fbvSvet9yrZtvCg1FY3CJTSrQX8NUGWC14s7OjOoZWHvvNG2R71jFew8y7g3ATDBjfzW OP0oUasoabz5dpgFWtFVzfZ5Yy2Ko9I1/R9B31jCnN5yMLJ+xNmscg7JbIXMxgW7V4Ew UuXuG//fEKHbkU6kLSCBztw1z0rs7u69tNDCxnNRCUlDZqWe2Ch8xjFQM1faxq/Wr4XW f27d1v0V/YsyEItD0LnwSlOahe1m7SSOV68lvMgifhrlv6llO6JuMr3D3972Qd4UmUk6 0Gdg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rCTe4gVp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67496-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67496-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id p10-20020a170902e74a00b001db2ad61b6dsi1586172plf.538.2024.02.15.10.59.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:59:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67496-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rCTe4gVp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67496-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67496-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DDD26B26561 for ; Thu, 15 Feb 2024 18:27:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 75D4313B29B; Thu, 15 Feb 2024 18:25:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rCTe4gVp" 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 A60E213AA4B; Thu, 15 Feb 2024 18:25:54 +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=1708021554; cv=none; b=HaFZxdRYkjF3VmwyGoxMXsc1KTS777qFf3JSlEh/cM+9m5Djb1ZhTXCdikAWHTAN7deNLWHMJ8UvrGi8nNsgPGn+mEIoht4cZmu6ix1960H3MBjv0yW4Bi5L8lSsSDGG70cnFRQVINJBrIsTJvbzwMkOBPVW6AnaMBpLdB7gpoE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021554; c=relaxed/simple; bh=oQx74ogq8XEWhaDeCHKcAvhTLzjLFWuQ3CeAwMCbB/M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sG1S54HCd+G795QWw7bTDf4yUo/FDu/PL/GCZ5JB39e1tEq/C6jzT9+Xaf3O1RS5GgL1+o6Y/hZREKfhSaufcDyfzr8i8R/YXH/l/buabKPR3kSWBtMc7FeXBX9B15MewObbVWlCi7/iThSqBhob4SVI1lDFfZHW5yxfqpmoZ20= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rCTe4gVp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E495C433F1; Thu, 15 Feb 2024 18:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708021554; bh=oQx74ogq8XEWhaDeCHKcAvhTLzjLFWuQ3CeAwMCbB/M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rCTe4gVp3CgS+5NYJZPr8ydUw7L3eNImhP1pM3nXsljdmr7vQTt5G13VGoUxkJOZG GpE9m4KEb/6rFifYRfV5YnV6zqzFRYM6tYEpvkB08CV1iLkMf3lt9n21UO8I5yRWaj DFY7cvTDmfqh25od7keu8vgT/8nfXa5eVLv112XPZFf9kZnoOzYsz/nJySITFxt3hx AqfKossX4NslglEexcO0dExXsBEIB0xJ2cHYPeyUjOjfwyZTBwE85X7X0ylkbm+vt1 SnNCbpMDMuApQWMT/iyohC3AbD+7waZPDqEL3ItlmO4JENvN8apNqbW7uGgY0lzFy1 68dCT1yp9qlmw== From: "Matthieu Baerts (NGI0)" Date: Thu, 15 Feb 2024 19:25:32 +0100 Subject: [PATCH net 05/13] mptcp: fix data races on remote_id Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240215-upstream-net-20240215-misc-fixes-v1-5-8c01a55d8f6a@kernel.org> References: <20240215-upstream-net-20240215-misc-fixes-v1-0-8c01a55d8f6a@kernel.org> In-Reply-To: <20240215-upstream-net-20240215-misc-fixes-v1-0-8c01a55d8f6a@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Davide Caratti , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" , stable@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3453; i=matttbe@kernel.org; h=from:subject:message-id; bh=Phzggd1e3xH9VcpIMW2JwQ4VlATGqfBwFCcy2ByLV7k=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlzlcc5DkIVpcVyJl8wBeZ/NcTkynzax2nJW0c/ DoLIIyEekGJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZc5XHAAKCRD2t4JPQmmg c82OD/4xprG1PGn0dVQ5wAZz0Pt56+fB/JkibVoLaGb448l91a7iJJCAs0BW3CxGW2KdxjbSKLZ geqGcWFges6Hv3MpOr/Iklulh10dsdWBKf9pYTt5fj8miEgtV9VJcJBb8TP0ec2wzlXv745vZim dcK+cxLtxVa8ulu5tJULQkdVehYPTDdNU1a+u4ujKgot4sIPDSn1Twk3QSbYxRyOv1JqTZ4Clla Y3GDLj+WPAT38Qx9Ayapb6l0Y9j6pX3+qR7bAgyXyK75m0cjP00UOH9+C7ekmwRdZqVOzDcAJC5 ArKPNcrVjXKaYNsj6jDQeYnKJ5S+sSI320PwzQCUuXMYmmLqmI4MJkX+AhNWXSj8CWKEpDkit6B pj6doKqX1/iFLhxfI42twmMNGOGLANGjLyXl8S0kr2uKEF/p8/5wOZejEHyHfFdl04m+rWU9kda WA2qjDdq+VlGGNhJ4xpxZ8AP4OykPEzR6lLf4oYgNrUMrwLlPbb2EeSkwD//MKn/hymcxG9t8lE xZ+i5hhdZKYASKtNtuHJzyWYcYWar3/UBnNEo89Z9RrkJbH3vSXIfw2tzxG0+sAF2fDpCr8Z/o7 MbKNpN7EVQSMTsInf7sc/tPir4tCYtwABMCeI01//JD9tmATYW23r1vH4zsraaEBs6XSrIYYBL5 LSJubHk7NEqp4zA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790992516082669352 X-GMAIL-MSGID: 1790992516082669352 From: Paolo Abeni Similar to the previous patch, address the data race on remote_id, adding the suitable ONCE annotations. Fixes: bedee0b56113 ("mptcp: address lookup improvements") Cc: stable@vger.kernel.org Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 8 ++++---- net/mptcp/subflow.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 912e25077437..ed6983af1ab2 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -443,7 +443,7 @@ static unsigned int fill_remote_addresses_vec(struct mptcp_sock *msk, mptcp_for_each_subflow(msk, subflow) { ssk = mptcp_subflow_tcp_sock(subflow); remote_address((struct sock_common *)ssk, &addrs[i]); - addrs[i].id = subflow->remote_id; + addrs[i].id = READ_ONCE(subflow->remote_id); if (deny_id0 && !addrs[i].id) continue; @@ -799,18 +799,18 @@ static void mptcp_pm_nl_rm_addr_or_subflow(struct mptcp_sock *msk, mptcp_for_each_subflow_safe(msk, subflow, tmp) { struct sock *ssk = mptcp_subflow_tcp_sock(subflow); + u8 remote_id = READ_ONCE(subflow->remote_id); int how = RCV_SHUTDOWN | SEND_SHUTDOWN; u8 id = subflow_get_local_id(subflow); - if (rm_type == MPTCP_MIB_RMADDR && subflow->remote_id != rm_id) + if (rm_type == MPTCP_MIB_RMADDR && remote_id != rm_id) continue; if (rm_type == MPTCP_MIB_RMSUBFLOW && !mptcp_local_id_match(msk, id, rm_id)) continue; pr_debug(" -> %s rm_list_ids[%d]=%u local_id=%u remote_id=%u mpc_id=%u", rm_type == MPTCP_MIB_RMADDR ? "address" : "subflow", - i, rm_id, id, subflow->remote_id, - msk->mpc_endpoint_id); + i, rm_id, id, remote_id, msk->mpc_endpoint_id); spin_unlock_bh(&msk->pm.lock); mptcp_subflow_shutdown(sk, ssk, how); diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c index 015184bbf06c..71ba86246ff8 100644 --- a/net/mptcp/subflow.c +++ b/net/mptcp/subflow.c @@ -535,7 +535,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb) subflow->backup = mp_opt.backup; subflow->thmac = mp_opt.thmac; subflow->remote_nonce = mp_opt.nonce; - subflow->remote_id = mp_opt.join_id; + WRITE_ONCE(subflow->remote_id, mp_opt.join_id); pr_debug("subflow=%p, thmac=%llu, remote_nonce=%u backup=%d", subflow, subflow->thmac, subflow->remote_nonce, subflow->backup); @@ -1567,7 +1567,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, pr_debug("msk=%p remote_token=%u local_id=%d remote_id=%d", msk, remote_token, local_id, remote_id); subflow->remote_token = remote_token; - subflow->remote_id = remote_id; + WRITE_ONCE(subflow->remote_id, remote_id); subflow->request_join = 1; subflow->request_bkup = !!(flags & MPTCP_PM_ADDR_FLAG_BACKUP); subflow->subflow_id = msk->subflow_id++; @@ -1974,7 +1974,7 @@ static void subflow_ulp_clone(const struct request_sock *req, new_ctx->fully_established = 1; new_ctx->remote_key_valid = 1; new_ctx->backup = subflow_req->backup; - new_ctx->remote_id = subflow_req->remote_id; + WRITE_ONCE(new_ctx->remote_id, subflow_req->remote_id); new_ctx->token = subflow_req->token; new_ctx->thmac = subflow_req->thmac;