Patch "bpf, sockmap: Do not inc copied_seq when PEEK flag set" has been added to the 6.5-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpf, sockmap: Do not inc copied_seq when PEEK flag set

to the 6.5-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpf-sockmap-do-not-inc-copied_seq-when-peek-flag-set.patch
and it can be found in the queue-6.5 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 4c7577da359b1848b7ebe21ad1273bcbb999b140
Author: John Fastabend <john.fastabend@xxxxxxxxx>
Date:   Mon Sep 25 20:52:59 2023 -0700

    bpf, sockmap: Do not inc copied_seq when PEEK flag set
    
    [ Upstream commit da9e915eaf5dadb1963b7738cdfa42ed55212445 ]
    
    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: e5c6de5fa0258 ("bpf, sockmap: Incorrectly handling copied_seq")
    Fixes: 04919bed948dc ("tcp: Introduce tcp_read_skb()")
    Signed-off-by: John Fastabend <john.fastabend@xxxxxxxxx>
    Signed-off-by: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
    Reviewed-by: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20230926035300.135096-3-john.fastabend@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c
index 81f0dff69e0b6..3272682030015 100644
--- a/net/ipv4/tcp_bpf.c
+++ b/net/ipv4/tcp_bpf.c
@@ -222,6 +222,7 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
 				  int *addr_len)
 {
 	struct tcp_sock *tcp = tcp_sk(sk);
+	int peek = flags & MSG_PEEK;
 	u32 seq = tcp->copied_seq;
 	struct sk_psock *psock;
 	int copied = 0;
@@ -311,7 +312,8 @@ static int tcp_bpf_recvmsg_parser(struct sock *sk,
 		copied = -EAGAIN;
 	}
 out:
-	WRITE_ONCE(tcp->copied_seq, seq);
+	if (!peek)
+		WRITE_ONCE(tcp->copied_seq, seq);
 	tcp_rcv_space_adjust(sk);
 	if (copied > 0)
 		__tcp_cleanup_rbuf(sk, copied);



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux