Skip to content

bpf, sockmap: fix copied_seq after partial TCP read

Dong Chenchen bpf netdev 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf, sockmap: account only unread data in tcp_eat_skbnet/ipv4/tcp_bpf.c+5 -40 replies
2/2selftests/bpf: cover sockmap drop after partial TCP readtools/testing/selftests/bpf/prog_tests/sockmap_basic.c+73 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH net 0/2] bpf, sockmap: fix copied_seq after partial TCP read

tcp_eat_skb() assumes that an skb dequeued by the sockmap verdict path has not previously been consumed. However, a socket can be inserted into a sockmap after userspace has partially read the skb at the head of its receive queue.

When new data invokes the verdict path, tcp_eat_skb() advances copied_seq by the full skb length. This counts the already-read prefix twice, moves copied_seq beyond rcv_nxt, and makes later native TCP reads fail. TCP_ZEROCOPY_RECEIVE then triggers the tcp_recvmsg_locked() sequence warning reported by syzbot.

TCP recvmsg seq # bug 2: copied AA28C633, seq AA28C601, rcvnxt AA28C602

WARNING: net/ipv4/tcp.c:2745 at tcp_recvmsg_locked
RIP: 0010:tcp_recvmsg_locked (net/ipv4/tcp.c:2745)
Call Trace:
<TASK>
tcp_zerocopy_receive (net/ipv4/tcp.c:1995 net/ipv4/tcp.c:2227)

do_tcp_getsockopt (net/ipv4/tcp.c:4771) tcp_getsockopt (net/ipv4/tcp.c:4869) do_sock_getsockopt (net/socket.c:2487) __sys_getsockopt (net/socket.c:2518) __x64_sys_getsockopt (net/socket.c:2525 net/socket.c:2522) do_syscall_64 (arch/x86/entry/syscall_64.c:63) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121)

Patch 1 advances copied_seq to the skb end sequence and accounts only the unread sequence-space delta during receive-buffer cleanup.

Patch 2 adds a deterministic regression test which reproduces the tcp_recvmsg_locked() warning on the unpatched kernel.

Dong Chenchen (2):
bpf, sockmap: account only unread data in tcp_eat_skb selftests/bpf: cover sockmap drop after partial TCP read

 net/ipv4/tcp_bpf.c                            |  9 ++-
 .../selftests/bpf/prog_tests/sockmap_basic.c  | 73 +++++++++++++++++++
 2 files changed, 78 insertions(+), 4 deletions(-)
Signature · 1 line
2.43.0