1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00
linux/include
Jiayuan Chen 36b62df568 bpf: Fix wrong copied_seq calculation
'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’t 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: e5c6de5fa0 ("bpf, sockmap: Incorrectly handling copied_seq")
Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Jiayuan Chen <mrpre@163.com>
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://patch.msgid.link/20250122100917.49845-3-mrpre@163.com
2025-01-29 13:32:23 -08:00
..
acpi LoongArch changes for v6.14 2025-01-28 08:52:01 -08:00
asm-generic The various patchsets are summarized below. Plus of course many 2025-01-26 18:36:23 -08:00
clocksource KVM/arm64 updates for 6.14 2025-01-28 09:01:36 -08:00
crypto crypto: skcipher - document skcipher_walk_done() and rename some vars 2025-01-14 11:38:32 +08:00
cxl
drm drm/bridge: fix documentation for the hdmi_audio_prepare() callback 2025-01-15 12:32:47 +02:00
dt-bindings Char/Misc/IIO driver updates for 6.14-rc1 2025-01-27 16:51:51 -08:00
hyperv hyperv: Add new Hyper-V headers in include/hyperv 2025-01-10 00:54:20 +00:00
keys keys: drop shadowing dead prototype 2025-01-21 11:25:23 +02:00
kunit linux_kselftest-kunit-6.14-rc1 2025-01-22 12:32:39 -08:00
kvm Merge branch kvm-arm64/pkvm-memshare-declutter into kvmarm-master/next 2025-01-17 11:05:18 +00:00
linux bpf: Fix wrong copied_seq calculation 2025-01-29 13:32:23 -08:00
math-emu
media media: cec: include linux/debugfs.h and linux/seq_file.h where needed 2025-01-07 12:21:38 +01:00
memory
misc
net bpf: Fix wrong copied_seq calculation 2025-01-29 13:32:23 -08:00
pcmcia
ras
rdma RDMA/core: Support link status events dispatching 2024-12-24 05:22:18 -05:00
rv rv: Reset per-task monitors also for idle tasks 2025-01-23 12:16:04 -05:00
scsi Driver core and debugfs updates 2025-01-28 12:25:12 -08:00
soc soc: driver updates for 6.14 2025-01-24 14:56:59 -08:00
sound sound updates for 6.14-rc1 2025-01-24 07:54:34 -08:00
target
trace f2fs-for-6.14-rc1 2025-01-27 20:58:58 -08:00
uapi NFSD 6.14 Release Notes 2025-01-27 17:27:24 -08:00
ufs scsi: Revert "scsi: ufs: core: Probe for EXT_IID support" 2025-01-10 16:38:21 -05:00
vdso vdso: Correct typo in PAGE_SHIFT comment 2025-01-15 11:07:08 +01:00
video
xen