netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf v9 0/5] bpf: fix wrong copied_seq calculation and add tests
@ 2025-01-22 10:09 Jiayuan Chen
  2025-01-22 10:09 ` [PATCH bpf v9 1/5] strparser: add read_sock callback Jiayuan Chen
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Jiayuan Chen @ 2025-01-22 10:09 UTC (permalink / raw)
  To: bpf, jakub, john.fastabend
  Cc: netdev, martin.lau, ast, edumazet, davem, dsahern, kuba, pabeni,
	linux-kernel, song, andrii, mhal, yonghong.song, daniel,
	xiyou.wangcong, horms, corbet, eddyz87, cong.wang, shuah, mykolal,
	jolsa, haoluo, sdf, kpsingh, linux-doc, linux-kselftest,
	Jiayuan Chen

A previous commit described in this topic
http://lore.kernel.org/bpf/20230523025618.113937-9-john.fastabend@gmail.com
directly updated 'sk->copied_seq' 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.

That commit 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 duplicated
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.

Also we added test cases for bpf + strparser and separated them from
sockmap_basic, as strparser has more encapsulation and parsing
capabilities compared to sockmap.

---
V8 -> v9
https://lore.kernel.org/bpf/20250121050707.55523-1-mrpre@163.com/
Fixed some issues suggested by Jakub Sitnicki.

V7 -> V8
https://lore.kernel.org/bpf/20250116140531.108636-1-mrpre@163.com/
Avoid using add read_sock to psock. (Jakub Sitnicki)
Avoid using warpper function to check whether strparser is supported.

V3 -> V7:
https://lore.kernel.org/bpf/20250109094402.50838-1-mrpre@163.com/
https://lore.kernel.org/bpf/20241218053408.437295-1-mrpre@163.com/
Avoid introducing new proto_ops. (Jakub Sitnicki).
Add more edge test cases for strparser + bpf.
Fix patchwork fail of test cases code.
Fix psock fetch without rcu lock.
Move code of modifying to tcp_bpf.c.

V1 -> V3:
https://lore.kernel.org/bpf/20241209152740.281125-1-mrpre@163.com/
Fix patchwork fail by adding Fixes tag.
Save skb data offset for ENOMEM. (John Fastabend)
---

Jiayuan Chen (5):
  strparser: add read_sock callback
  bpf: fix wrong copied_seq calculation
  bpf: disable non stream socket for strparser
  selftests/bpf: fix invalid flag of recv()
  selftests/bpf: add strparser test for bpf

 Documentation/networking/strparser.rst        |   9 +-
 include/linux/skmsg.h                         |   2 +
 include/net/strparser.h                       |   2 +
 include/net/tcp.h                             |   8 +
 net/core/skmsg.c                              |   7 +
 net/core/sock_map.c                           |   5 +-
 net/ipv4/tcp.c                                |  29 +-
 net/ipv4/tcp_bpf.c                            |  36 ++
 net/strparser/strparser.c                     |  11 +-
 .../selftests/bpf/prog_tests/sockmap_basic.c  |  59 +--
 .../selftests/bpf/prog_tests/sockmap_strp.c   | 454 ++++++++++++++++++
 .../selftests/bpf/progs/test_sockmap_strp.c   |  53 ++
 12 files changed, 610 insertions(+), 65 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/sockmap_strp.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_sockmap_strp.c

-- 
2.43.5


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2025-01-29 22:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-22 10:09 [PATCH bpf v9 0/5] bpf: fix wrong copied_seq calculation and add tests Jiayuan Chen
2025-01-22 10:09 ` [PATCH bpf v9 1/5] strparser: add read_sock callback Jiayuan Chen
2025-01-26 14:03   ` Jakub Sitnicki
2025-01-22 10:09 ` [PATCH bpf v9 2/5] bpf: fix wrong copied_seq calculation Jiayuan Chen
2025-01-26 14:10   ` Jakub Sitnicki
2025-01-22 10:09 ` [PATCH bpf v9 3/5] bpf: disable non stream socket for strparser Jiayuan Chen
2025-01-26 14:11   ` Jakub Sitnicki
2025-01-22 10:09 ` [PATCH bpf v9 4/5] selftests/bpf: fix invalid flag of recv() Jiayuan Chen
2025-01-26 14:12   ` Jakub Sitnicki
2025-01-22 10:09 ` [PATCH bpf v9 5/5] selftests/bpf: add strparser test for bpf Jiayuan Chen
2025-01-26 14:15   ` Jakub Sitnicki
2025-01-26 14:16 ` [PATCH bpf v9 0/5] bpf: fix wrong copied_seq calculation and add tests Jakub Sitnicki
2025-01-27 16:04   ` John Fastabend
2025-01-29 22:00 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).