Skip to content

Commit 8745e32

Browse files
zhengguoyongKernel Patches Daemon
authored andcommitted
bpf, sockmap: Fix tp->copied_seq update in, tcp_bpf_strp_read_sock
In the tcp_read_sock_noack function, received packets may be destined for either the current sk or another sk. In my test case, the first packet of the connection is sent to the current sk, while subsequent packets are sent to another sk. When the first packet is forwarded, tp->copied_seq is updated in tcp_bpf_recvmsg_parser. However, since psock->copied_seq accumulates the length of every processed packet, using psock->copied_seq to update tp->copied_seq when processing the second packet would lead to incorrect behavior. Therefore, we only need to update tp->copied_seq in cases where packets are forwarded to another sk. Signed-off-by: GuoYong Zheng <[email protected]>
1 parent baaa336 commit 8745e32

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

net/ipv4/tcp_bpf.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,11 @@ int tcp_bpf_strp_read_sock(struct strparser *strp, read_descriptor_t *desc,
676676
* For SK_REDIRECT, we need to ack the frame immediately but for
677677
* SK_PASS, we want to delay the ack until tcp_bpf_recvmsg_parser().
678678
*/
679-
tp->copied_seq = psock->copied_seq - psock->ingress_bytes;
680-
tcp_rcv_space_adjust(sk);
681-
__tcp_cleanup_rbuf(sk, copied - psock->ingress_bytes);
679+
if (!psock->ingress_bytes) {
680+
tp->copied_seq += copied;
681+
tcp_rcv_space_adjust(sk);
682+
__tcp_cleanup_rbuf(sk, copied);
683+
}
682684
out:
683685
rcu_read_unlock();
684686
return copied;

0 commit comments

Comments
 (0)