From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 384A914F104 for ; Sun, 26 Jan 2025 14:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737900654; cv=none; b=c8ngoZ3jJ2Qh7wiaFKAjBhsx117Oww7QLoNHWz+lEb0hGOVon2Re7ub0CbfJV9Q0ai249O0t+US8OYJZScLIWp9VUaS2Un4oJ+7s7sPuljirNGm1qLVFs71NZMeslCUGLp12CypR3QOie9VElpT+enoLTmisxGEvUejs/QafoNo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737900654; c=relaxed/simple; bh=M5WLy1DxNP8qgUCHlq9+eiJMlU/LVKdDp0LRxkwAU9Y=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=MoSWboSnietvcm6zKuF0cR+Y3iKlICPjGWVFqXW/tpuX8hCYBuc3aDfMq/J1M0Kdv1lLjS9+GWOYPst+ogmtYEOYNol9FyIWPbLjS5ik5lNwHfScFfIOA2IV8LbiQT/NpVjcQJMzkzrjbMEqzxrJX8/gk53glCa28eClNCtaFFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com; spf=pass smtp.mailfrom=cloudflare.com; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b=U4xemzTi; arc=none smtp.client-ip=209.85.208.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cloudflare.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cloudflare.com header.i=@cloudflare.com header.b="U4xemzTi" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5d3f65844deso6525845a12.0 for ; Sun, 26 Jan 2025 06:10:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google09082023; t=1737900650; x=1738505450; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=M5WLy1DxNP8qgUCHlq9+eiJMlU/LVKdDp0LRxkwAU9Y=; b=U4xemzTi6t5tcTns93W9iamQrcXEKYsP0/lJOvT2Yf/2l1YMtwNQz709HGrHNXiOgv tdVcgAE0Jn/bUSpKyDoE/qVfpDtGyVLaT730VWxZlo6iGeZqXcB1VTDpznLUF/4FmxER cyvTHjMicqTzsJegFj7SDioxNQrnljZAa4fs1J8K4GTq0I0naPqWAmH9kxK8HyBTob90 jYzfLUrefp7sQpfemcJDEyGOTN+qx/+EM0B+T3+k7vpGbFEfBKxk1Da172805Rrxcng4 4UxCk7FIRRsQeo+8BcwTMbBndCGJWnxn6UU1oEWEPog8FeD9d6HM/fuRIx5wPeAqxMod PxWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737900650; x=1738505450; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M5WLy1DxNP8qgUCHlq9+eiJMlU/LVKdDp0LRxkwAU9Y=; b=nzVpVYSqoWOZEkcw2vXMCd6u9gUvv2g6SGcU6TPRr4DU8opTYSDmKx9KCOpG6M/0rm /mXLtvGrdDQIs3WXetf4nqUyaAJNI80+qd0iqhNL/jcw8QF7ehZ3+cUike+N4Od4u4Z5 KDHRD/60U8bVZgMyii79uVLuQ1CVgQ1QrID2ei4/iFGOC7YPCqu4xh5Zow+E/GPxhn3z hJRjYP0QaD6CrRUc8rWdkOBZ6Ch69oLyq1R3DoJwK+yxYFjq8I8x5sanyHLuEG2FJOtX qhs9RWuLjEV0fS7/eHvLPDGrVDjeZ/78CJwJRP7/sI5EyGG0zpoXdbPMCaOqitLWF9TS B3Jg== X-Forwarded-Encrypted: i=1; AJvYcCX0JALaXSkUvNEr9gS9IUFxsUsWc/Tqp4wa1QKVVDg8XnxkyX+9ryGi8cAwvfJtk0R5+YdN9aQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yx61ACmMy2HvZLCcbNKZsriFKjOgRAouHawHR7MB/ZnlwE8ZQ+a zcEbdhdMdGNp+8V3Kxg9KT7SINbjahZCqlTMuD9ylGwEDLIePmT7gcfwd1nQB8I= X-Gm-Gg: ASbGnctLilhwsKK7IDqkFPvdKsPYEI13NZgQvqCMCqrPFn+XqDkp1AhoZ2mETQOCCfy TbpuWBp+Xv6e42qb+OIJJ/tN/OC+qJ8EVwrHYEvnEjQYh0THmgbWZz6wD8Cwq827V7ZI6mxeEG0 rCNM6UTGJX+hiQBCuiq5FN79y+fCsbxu3E7kIJ/Cyp71+yMxh2F8eNWbRh9S2aPa6X0VHUuuXCc iuef78o/76lAg8OsjgWBkr1J1CVm54Ewlp+vhAPkXz5w/RJ4MMpvB0SrWabH5Y7Mn2Xm5OYXQ== X-Google-Smtp-Source: AGHT+IHmiL1x/cK57mDrEyZlSiKzsVH7Pb4ZWh6Me4KnpzE8zDPhlrVO8QVqTEA/mMnO8vlAwtv50g== X-Received: by 2002:a05:6402:34c7:b0:5d8:253:b7df with SMTP id 4fb4d7f45d1cf-5db7db086cfmr33360402a12.27.1737900650420; Sun, 26 Jan 2025 06:10:50 -0800 (PST) Received: from cloudflare.com ([2a09:bac5:506b:2432::39b:69]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5dc186d895bsm4010079a12.68.2025.01.26.06.10.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2025 06:10:48 -0800 (PST) From: Jakub Sitnicki To: Eric Dumazet , Jiayuan Chen Cc: bpf@vger.kernel.org, john.fastabend@gmail.com, netdev@vger.kernel.org, martin.lau@linux.dev, ast@kernel.org, davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org, pabeni@redhat.com, linux-kernel@vger.kernel.org, song@kernel.org, andrii@kernel.org, mhal@rbox.co, yonghong.song@linux.dev, daniel@iogearbox.net, xiyou.wangcong@gmail.com, horms@kernel.org, corbet@lwn.net, eddyz87@gmail.com, cong.wang@bytedance.com, shuah@kernel.org, mykolal@fb.com, jolsa@kernel.org, haoluo@google.com, sdf@fomichev.me, kpsingh@kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH bpf v9 2/5] bpf: fix wrong copied_seq calculation In-Reply-To: <20250122100917.49845-3-mrpre@163.com> (Jiayuan Chen's message of "Wed, 22 Jan 2025 18:09:14 +0800") References: <20250122100917.49845-1-mrpre@163.com> <20250122100917.49845-3-mrpre@163.com> Date: Sun, 26 Jan 2025 15:10:45 +0100 Message-ID: <87r04pd5sq.fsf@cloudflare.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Jan 22, 2025 at 06:09 PM +08, Jiayuan Chen wrote: > 'sk->copied_seq' was updated in the tcp_eat_skb() function when the action > of a BPF program was SK_REDIRECT. For other actions, like SK_PASS, the > update logic for 'sk->copied_seq' was moved to tcp_bpf_recvmsg_parser() > to ensure the accuracy of the 'fionread' feature. > > It works for a single stream_verdict scenario, as it also modified > sk_data_ready->sk_psock_verdict_data_ready->tcp_read_skb > to remove updating 'sk->copied_seq'. > > However, for programs where both stream_parser and stream_verdict are > active (strparser purpose), tcp_read_sock() was used instead of > tcp_read_skb() (sk_data_ready->strp_data_ready->tcp_read_sock). > tcp_read_sock() now still updates 'sk->copied_seq', leading to duplicate > updates. > > In summary, for strparser + SK_PASS, copied_seq is redundantly calculated > in both tcp_read_sock() and tcp_bpf_recvmsg_parser(). > > The issue causes incorrect copied_seq calculations, which prevent > correct data reads from the recv() interface in user-land. > > We do not want to add new proto_ops to implement a new version of > tcp_read_sock, as this would introduce code complexity [1]. > > We could have added noack and copied_seq to desc, and then called > ops->read_sock. However, unfortunately, other modules didn=E2=80=99t fully > initialize desc to zero. So, for now, we are directly calling > tcp_read_sock_noack() in tcp_bpf.c. > > [1]: https://lore.kernel.org/bpf/20241218053408.437295-1-mrpre@163.com > Fixes: e5c6de5fa025 ("bpf, sockmap: Incorrectly handling copied_seq") > Suggested-by: Jakub Sitnicki > Signed-off-by: Jiayuan Chen > --- I'm happy with how this turned out, but let's run it by Eric. Reviewed-by: Jakub Sitnicki