Skip to content

Commit da9e915

Browse files
jrfastabborkmann
authored andcommitted
bpf, sockmap: Do not inc copied_seq when PEEK flag set
When data is peek'd off the receive queue we shouldn't considered it copied from tcp_sock side. When we increment copied_seq this will confuse tcp_data_ready() because copied_seq can be arbitrarily increased. From application side it results in poll() operations not waking up when expected. Notice tcp stack without BPF recvmsg programs also does not increment copied_seq. We broke this when we moved copied_seq into recvmsg to only update when actual copy was happening. But, it wasn't working correctly either before because the tcp_data_ready() tried to use the copied_seq value to see if data was read by user yet. See fixes tags. Fixes: e5c6de5 ("bpf, sockmap: Incorrectly handling copied_seq") Fixes: 04919be ("tcp: Introduce tcp_read_skb()") Signed-off-by: John Fastabend <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Jakub Sitnicki <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 9b7177b commit da9e915

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

net/ipv4/tcp_bpf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
222222
int *addr_len)
223223
{
224224
struct tcp_sock *tcp = tcp_sk(sk);
225+
int peek = flags & MSG_PEEK;
225226
u32 seq = tcp->copied_seq;
226227
struct sk_psock *psock;
227228
int copied = 0;
@@ -311,7 +312,8 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
311312
copied = -EAGAIN;
312313
}
313314
out:
314-
WRITE_ONCE(tcp->copied_seq, seq);
315+
if (!peek)
316+
WRITE_ONCE(tcp->copied_seq, seq);
315317
tcp_rcv_space_adjust(sk);
316318
if (copied > 0)
317319
__tcp_cleanup_rbuf(sk, copied);

0 commit comments

Comments
 (0)