Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1276941rdb; Mon, 19 Feb 2024 09:36:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVQI8K6V/OWY57DgXRIkJWDku7zPiTk6RhzVHESFdKMGu3D4lPAwysoeRwRErKvvr0U7qgCkk2OlaMt+ucuNlAVIRDbRfi55046rh+DKw== X-Google-Smtp-Source: AGHT+IElFP4d8uXrm28aVXpIjhmNmNLZ+iXre3X84kzyyqbcI3x3coknm+/q20NDPXCXwX8BLE5E X-Received: by 2002:a17:90a:d816:b0:299:42d1:91df with SMTP id a22-20020a17090ad81600b0029942d191dfmr6579224pjv.14.1708364189617; Mon, 19 Feb 2024 09:36:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708364189; cv=pass; d=google.com; s=arc-20160816; b=Dc6tBYan0KdvUgNlRhLTqFIsgC9ZJt8+p3iWt+A+Ev9YhRTTe7TRTrp1/7KVF+QvX9 vfYzO8DQFtudqx72jBbdiVnFX+I6Ge9B8k7aKwHTywgIn9Ant9xOrS6h58QOTTWW/ubY /3jm42hU20dleQxqJx0Ca/yUkiHgLPjnYThdGMbSXQPpBHnvj/tmlozgSQOF3JOjqGkF T9Q9BQb1vNOeqAQELIddv1qa/IHF+MqKjrvOu4UjO+BP4Vr4STBahL2wfaabkzcQxgTE /Kzsf2PCgghLBjAU9tjK3Du+6wBbjq42G7rBgJwyoL5L77wqcv9vGUT2AmjoVPXQh2p+ c2Yg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=bpH+GG/JxRVKqFjHr33MFZWda+dSzZgj8Xxgn4JwPS8=; fh=wGLnYLXdcWqGYJ+/MPdiAscFqiLe7j2yE733ErEOOSA=; b=Lf4XyBiiasAHivAJvcduIg891+bW8CI1xRHL5kRVaCGCdZOAM1wP8YZkj2zoHMmRfi ZCCTFIIIYNPSrBi5fzEMGPEF4HVnVruL8583irgIK9xllxC0d9Mu4GG99hcICJlFV44r +kJMeL1yjLrhYqTRNuWRH/CJUOtKgK2SMXJimkOwO1/bDBPeP8ZWnWQxiJeH/OBnULaB 4WInWbaXpxjcas10xwQD3PsakOaC4ElsQLv8admOp9R/ZxyGaGMNlCeGyx54/C5MKbrK Em26tq4K5QIJBdvXiJ3XPLWPjSPGSXYLZo2cXTpw376ErM7iOqAJb+SyRSNgLHnzWqWv yCrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qnZR8Mf9; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-71764-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71764-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i8-20020a17090a974800b002997a4298e2si3183762pjw.140.2024.02.19.09.36.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 09:36:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-71764-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=qnZR8Mf9; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-71764-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-71764-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 87E50283BA1 for ; Mon, 19 Feb 2024 17:35:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F3294654B; Mon, 19 Feb 2024 17:35:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="qnZR8Mf9" Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E797545950 for ; Mon, 19 Feb 2024 17:35:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708364148; cv=none; b=fU4uleMzktBAN93G6yF8DMt8gzsv1xpRJTii1h894aBoGrSkQZsyRskp2xTCGYnjpgLyYk/+1XgXsFxS7WY+nSRMSCZot14gJkTO9qJw17sayNSRxIELG1qwWv2m80q/cC1tD1EzYf6KZjeK+7wPxuTBs/Wk05qYwoeoLEewNdM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708364148; c=relaxed/simple; bh=wJCpYntqq8nCglIkq88Zs9qTSRweYslEK0KjbQBa4Bg=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UZWYJJ5SRuMudEx7V8fcQph2R3pKuJuIeey4+YBiTC2G7UJSGgiq3ddXGi52FoDNrErB7xFpTUNdz6hbp6flk0aW8+ZFmh+0qYTtdoMcu4VLjv8VQoHOcRg1Swm+jHmXH053h9gJkzmE6jWx/ezFT8d9xFxGrDWSw3oLcNlZakw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=qnZR8Mf9; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-561f0f116ecso15850a12.0 for ; Mon, 19 Feb 2024 09:35:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1708364145; x=1708968945; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bpH+GG/JxRVKqFjHr33MFZWda+dSzZgj8Xxgn4JwPS8=; b=qnZR8Mf9OXg9M88jTqacpGR0VokQ4cl6dxm4BrwfAqkIhovRA2gUuTEyZfLnhAEcFR Mo9djPgblUq9mIGUmbSlFtdv61274wgtpdJo05I4wr109y9ULgiAGKw1GPFDscQ/38zk YDJ9hkomHCkHZ9UMUWaCflYoPokfEpf/uw5+so3Jo4nbDk9YS8Uq4Ovzq2Bp2q3DGJOt 8E0azaZNDmTnNKhnMUTpG5osWaTJ0OT9q2jtAn+1o/OxJ63OsK6Vhgi54Wua6AZPXNWO ABxCAfNG1ylw8P6sg6xGDNEeQqNm+Su0XA7/FuQ2lOuUtRynVGVJlqxFtcYP67f2bIVQ FhgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708364145; x=1708968945; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bpH+GG/JxRVKqFjHr33MFZWda+dSzZgj8Xxgn4JwPS8=; b=bVtiJT+EmsmqZsGTpDWCoshc1Wy/jwETi10JG30x110p2Rk+SaRZ7UHHMQKwQpQtyz 4pNJ6ssZifJ85nLRyIO5q0vBg7kUwGeWWIIX7sgDZ0Duqc9+L5feIuy1LU3Ag2ubTnqk +gye30fE31Xekk8VKDaXtcK127kVa+wgyapdHFUtey7dMEICeDu7w+kYO8eDJQjtGhnD AHXiUZOQZoN9nH6aRCJS5AIkSQhMlYvt2HQv9PF0Bm7l60kNcNUu+rteukC/Iy9vziqf Au5UnwcAr81F5H3IDqa2W7J8nppJANcaN2VK+2trjtS5TyZjbV5WjxWhYqg1j2MGp4S3 SFJQ== X-Forwarded-Encrypted: i=1; AJvYcCX5l8gLak7S+aC024Rd/9OB9hcI2D1wF30dEJ242AvxlhAx/f/yAB2huMhpbs5aPRlgsrCfXPld7T2jSk0XN9AfbNoAIkuLdCmrJPAi X-Gm-Message-State: AOJu0YznYotUXFQQpExa9ZKQTAbujn3/mljwr7L0UOaBnCcPfZX17jKF saRVU1rfaGwVxcTMCczqGsrPdg/Jl8mUugzYa+r6lnbNSk6PcbQQgEiiKECuWhfdzP/Leh6sLjY bzgu2YbmrgJdeAfHUstyBMveCNNxEgLPuQomQ X-Received: by 2002:a50:a697:0:b0:563:ff57:b7e8 with SMTP id e23-20020a50a697000000b00563ff57b7e8mr322644edc.1.1708364145075; Mon, 19 Feb 2024 09:35:45 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240215-upstream-net-20240215-misc-fixes-v1-0-8c01a55d8f6a@kernel.org> <20240215-upstream-net-20240215-misc-fixes-v1-3-8c01a55d8f6a@kernel.org> In-Reply-To: From: Eric Dumazet Date: Mon, 19 Feb 2024 18:35:31 +0100 Message-ID: Subject: Re: [PATCH net 03/13] mptcp: fix lockless access in subflow ULP diag To: "Matthieu Baerts (NGI0)" Cc: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Jakub Kicinski , Paolo Abeni , Davide Caratti , Shuah Khan , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, stable@vger.kernel.org, Boris Pismenny , John Fastabend Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 19, 2024 at 6:21=E2=80=AFPM Eric Dumazet = wrote: > > On Thu, Feb 15, 2024 at 7:25=E2=80=AFPM Matthieu Baerts (NGI0) > wrote: > > > > 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 *news= k, > > 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 =3D 0; > > + bool slow; > > int err; > > > > start =3D nla_nest_start_noflag(skb, INET_ULP_INFO_MPTCP); > > if (!start) > > return -EMSGSIZE; > > > > + slow =3D lock_sock_fast(sk); > > rcu_read_lock(); > > I am afraid lockdep is not happy with this change. > > Paolo, we probably need the READ_ONCE() annotations after all. Or perhaps something like the following would be enough. diff --git a/net/mptcp/diag.c b/net/mptcp/diag.c index 6ff6f14674aa2941bc04c680bacd9f79fc65060d..7017dd60659dc7133318c1c82e3= f429bea3a5d57 100644 --- a/net/mptcp/diag.c +++ b/net/mptcp/diag.c @@ -21,6 +21,9 @@ static int subflow_get_info(struct sock *sk, struct sk_buff *skb) bool slow; int err; + if (inet_sk_state_load(sk) =3D=3D TCP_LISTEN) + return 0; + start =3D nla_nest_start_noflag(skb, INET_ULP_INFO_MPTCP); if (!start) return -EMSGSIZE;