Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp636962rdb; Thu, 15 Feb 2024 10:27:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU/g8Jpq3FbAyzM//dZy4Y7iMnrne9C7kIZl3tndUhE/2f2VF8g+XsvYctcwo+4Lthue7/da8tuClqvWRTxU6WlSW6FQ0SiMjelQjHUcw== X-Google-Smtp-Source: AGHT+IHJmO1ET60y7I2Jd/3bSsNzLj1lNd690vuvOfIr8aWZmErn47EkfCcDyO5MQSdLa55xVdaw X-Received: by 2002:a17:906:e0d1:b0:a3c:d134:5e15 with SMTP id gl17-20020a170906e0d100b00a3cd1345e15mr1896180ejb.33.1708021624978; Thu, 15 Feb 2024 10:27:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708021624; cv=pass; d=google.com; s=arc-20160816; b=l1ruT8WR1ZKQGkdwDI6gtlA6YmC9J39i4DMT8qVJQGKJ8CS3a59k0wPGUXN8ZBmKVe NMpi4jNJr+v4WSNHlBfoBB1pypPKuZ2v2lmeqfWU0iLVp0nArJPD1M4qkMsodFlG/JCM s//keYfCfiZ+k1fm5kU/0kYlv18N1RKKnXS+ceF9yh7qZvDyMC64B7O7+WxFB6hHt5GA Fmx2vHimdBGvVrCqykpoKtNHjUxExaUG8yaloxh6oFWrHfuLOfmrbTj5U9y2/clxKIvE Ov23BVjXNQH2N9/HXPTosHnQbw9PD3wxYkJDv++kHOxoVWvW/0Kwjq+6x6S07uUVbBGY ivIA== 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=L6lIoGryQ0LDRyNW48v27i1rlHfcHYdFthdLA3f9QII=; fh=KHm+5J6+rvFM2Sm0w04dr96065e5NgZLO7CcIOTCxTg=; b=Y0Rg4CCX93k1gGkyuk4DQoNxw7gxAkA06+j54SL+38KuTvhCHIYjnZNAppxlz8+BJ1 lvuScSxPfDFt0/DH22N5bgRWaMo7p1wUJM/TXV629prjDMf2wrka/ghmamUj6IA8qtUp bQQgkjNRPDfSh0I89Wzhg7GJWgIGdGoXk4CO7El3D3yhZy/X/QZSTJaETk3Gg/Brl6dX ZaLh8Caoo7I1oNoQ9JNx5j1paq4+ffPo3b4WSUn5S8i2BA4kuLeUtrIICm797pDbhPoQ jP8KIhLIXseApopP8forxVxmV2kQ3Iw5Y9FtNfbOnq1CV1L8ijoWwH/YUifsCR7/gN5u DfUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hqdgbkKA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67494-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67494-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lf17-20020a170906ae5100b00a3d5bb9d2c8si850768ejb.720.2024.02.15.10.27.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:27:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67494-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hqdgbkKA; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67494-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67494-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id F30461F2203A for ; Thu, 15 Feb 2024 18:26:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD2A31386BB; Thu, 15 Feb 2024 18:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hqdgbkKA" 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 CB24913A86C; Thu, 15 Feb 2024 18:25:47 +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=1708021547; cv=none; b=FwOhGb34KXwflr+5CBFmMw0Mfubf5+KPQ8DEW2WjPIbGOPhYvDWh1XoXnk6W/J+IZDV7j5PIFMa8xW3yWmhUseZKqObQfh1QrGnP01B65EvSuXSFVnAKA+yW7H11wWraQpfkrmyQmnyazzx/nYvI/irC5/hALUoBVGflqIbVFGk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021547; c=relaxed/simple; bh=O9TaPCeVsjOq9jAAugHSwpNIaCX6JMv1ouUykBv8gj4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XrC0uxlfJV+BErA7XvBrUIUiS5RjkRrcdQNbs9Q+wvRRsHAZITMkWK6fMCasa7JZDS8SRZfDOtcaSvsCC7YFumlPKuOkNyj2oGixEJBb16C/kW6wxqHfdwanZyRSShVI3srkdR2H+46Tb7P54ChU+BFYsaiLJ5xcxtzyNzsltNg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hqdgbkKA; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77328C43609; Thu, 15 Feb 2024 18:25:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708021547; bh=O9TaPCeVsjOq9jAAugHSwpNIaCX6JMv1ouUykBv8gj4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hqdgbkKAclztcu1xQRYG5SwRNJ7ZTkGqDGETsTIo85MclM/Y+UlJmyJFDI+lhumWL ZOxv2dd/1qSHYPuFazvJBD5EDLz0NXcwX8UmSkZP79zygVUbkxXRr51z8fcTNTn7Iv MKIXrQG/GYm6NRL4z2VHRrjjvYOboYe4RRe3oXLqFGTbukkF2ncBaPG+o48tHopYrB GmDqT0esOcC01P3siGojYFcKyedjUuXGCCOgtwyMteCXjXqCsV1tkhxRddCpESewXa Og5CX31merFzpt8biF5tqb26ZKAjNiEYWRVHneSnNQPLDgiWJDPYijgzXe3pWKroZJ gr91bOtOZE9UQ== From: "Matthieu Baerts (NGI0)" Date: Thu, 15 Feb 2024 19:25:30 +0100 Subject: [PATCH net 03/13] mptcp: fix lockless access in subflow ULP diag Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240215-upstream-net-20240215-misc-fixes-v1-3-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, Boris Pismenny , John Fastabend X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3080; i=matttbe@kernel.org; h=from:subject:message-id; bh=xtj9AwzwqPCqP5Friqh0vCOkOhD544GhNiZf9ekwIjU=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlzlcc3yITjm+xGd3bhfD6bwGDlnT5JnEpdqxGj PhywDxO5umJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZc5XHAAKCRD2t4JPQmmg c56hD/4jXp5hKXebFuJVEHHOfdxqoyu+ghz9oB7ej8NcNVkhVR71JwrdGzHhiOtZ5VHdCcioCrT snpg2EkpSCaNk0rj3FWP622w2st+18qVuicEQ4KM77Dl8lxFeQRgYWWWXuHanuH7YSsYl0lKudW T4IsCOgKJybSYMTlXxR8MgOVOPeVaEXG5qYmHDxB4itbeVbJoU9Py2PEl9N5h+3KrMqlqNzTxYW DHR3ZeBjz+6J4/OrxL1xUnK6KovOqZ8IEJIb/lFRicruFZcx5P41qyylcFfp7OKYEvw1t5UaopQ FlnPJvkZZVDeNXEhNf1SEsXGUG/MIReDU3MhToj5sHrw0npRicV+H2QazESpa3jgrR2z0GtemRi dTgN8ZZ6b1BrUik+FCLDPCdcbj7RQvzUalUkIktJAyUKoOhnlJWsYhz/Mt04Xi4BhH2hOGTTdTZ vjVdh/1Rr8OorQA7zSglQosfdtuXTrzd4+cQD2SuhrYPkMJy2iepEfgCZzBZlc30MeXRAd6g+8p X2i18RDY34ZT/GmHA/rsq1FswcULdaIjcf4jy8ibt946SIMff923FweP4OjYp24dFH2IgMbJve4 GG8j+/vDfkYKf8oRPj+cEESKJFmWE5zGEAs0n90PevE0DIaHcAn11CZxEKdl1ic1062ABiwho1z YbJXY9Lv8sojGlQ== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Paolo Abeni Since the introduction of the subflow ULP diag interface, the dump callback accessed all the subflow data with lockless. We need either to annotate all the read and write operation accordingly, or acquire the subflow socket lock. Let's do latter, even if slower, to avoid a diffstat havoc. Fixes: 5147dfb50832 ("mptcp: allow dumping subflow context to userspace") Cc: stable@vger.kernel.org Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- Notes: - This patch modifies the existing ULP API. No better solutions have been found for -net, and there is some similar prior art, see commit 0df48c26d841 ("tcp: add tcpi_bytes_acked to tcp_info"). Please also note that TLS ULP Diag has likely the same issue. To: Boris Pismenny To: John Fastabend --- include/net/tcp.h | 2 +- net/mptcp/diag.c | 6 +++++- net/tls/tls_main.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index dd78a1181031..f6eba9652d01 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -2506,7 +2506,7 @@ struct tcp_ulp_ops { /* cleanup ulp */ void (*release)(struct sock *sk); /* diagnostic */ - int (*get_info)(const struct sock *sk, struct sk_buff *skb); + int (*get_info)(struct sock *sk, struct sk_buff *skb); size_t (*get_info_size)(const struct sock *sk); /* clone ulp */ void (*clone)(const struct request_sock *req, struct sock *newsk, diff --git a/net/mptcp/diag.c b/net/mptcp/diag.c index a536586742f2..e57c5f47f035 100644 --- a/net/mptcp/diag.c +++ b/net/mptcp/diag.c @@ -13,17 +13,19 @@ #include #include "protocol.h" -static int subflow_get_info(const struct sock *sk, struct sk_buff *skb) +static int subflow_get_info(struct sock *sk, struct sk_buff *skb) { struct mptcp_subflow_context *sf; struct nlattr *start; u32 flags = 0; + bool slow; int err; start = nla_nest_start_noflag(skb, INET_ULP_INFO_MPTCP); if (!start) return -EMSGSIZE; + slow = lock_sock_fast(sk); rcu_read_lock(); sf = rcu_dereference(inet_csk(sk)->icsk_ulp_data); if (!sf) { @@ -69,11 +71,13 @@ static int subflow_get_info(const struct sock *sk, struct sk_buff *skb) } rcu_read_unlock(); + unlock_sock_fast(sk, slow); nla_nest_end(skb, start); return 0; nla_failure: rcu_read_unlock(); + unlock_sock_fast(sk, slow); nla_nest_cancel(skb, start); return err; } diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 1c2c6800949d..b4674f03d71a 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c @@ -1003,7 +1003,7 @@ static u16 tls_user_config(struct tls_context *ctx, bool tx) return 0; } -static int tls_get_info(const struct sock *sk, struct sk_buff *skb) +static int tls_get_info(struct sock *sk, struct sk_buff *skb) { u16 version, cipher_type; struct tls_context *ctx; -- 2.43.0