All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb()
@ 2022-08-17 19:54 Cong Wang
  2022-08-17 19:54 ` [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb() Cong Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Cong Wang @ 2022-08-17 19:54 UTC (permalink / raw)
  To: netdev; +Cc: bpf, Cong Wang

From: Cong Wang <cong.wang@bytedance.com>

This patchset contains 3 bug fixes and 1 minor refactor patch for
tcp_read_skb(). V1 only had the first patch, as Eric prefers to fix all
of them together, I have to group them together. Please see each patch
description for more details.

---
v2: add more patches
v3: simplify empty receive queue case

Cong Wang (4):
  tcp: fix sock skb accounting in tcp_read_skb()
  tcp: fix tcp_cleanup_rbuf() for tcp_read_skb()
  tcp: refactor tcp_read_skb() a bit
  tcp: handle pure FIN case correctly

 net/core/skmsg.c |  5 +++--
 net/ipv4/tcp.c   | 49 +++++++++++++++++++++++-------------------------
 2 files changed, 26 insertions(+), 28 deletions(-)

-- 
2.34.1


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

* [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb()
  2022-08-17 19:54 [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() Cong Wang
@ 2022-08-17 19:54 ` Cong Wang
  2022-08-24  8:17   ` Jakub Sitnicki
  2022-08-17 19:54 ` [Patch net v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb() Cong Wang
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Cong Wang @ 2022-08-17 19:54 UTC (permalink / raw)
  To: netdev
  Cc: bpf, Cong Wang, syzbot+a0e6f8738b58f7654417, Stanislav Fomichev,
	Eric Dumazet, John Fastabend, Jakub Sitnicki

From: Cong Wang <cong.wang@bytedance.com>

Before commit 965b57b469a5 ("net: Introduce a new proto_ops
->read_skb()"), skb was not dequeued from receive queue hence
when we close TCP socket skb can be just flushed synchronously.

After this commit, we have to uncharge skb immediately after being
dequeued, otherwise it is still charged in the original sock. And we
still need to retain skb->sk, as eBPF programs may extract sock
information from skb->sk. Therefore, we have to call
skb_set_owner_sk_safe() here.

Fixes: 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()")
Reported-and-tested-by: syzbot+a0e6f8738b58f7654417@syzkaller.appspotmail.com
Tested-by: Stanislav Fomichev <sdf@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/ipv4/tcp.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 970e9a2cca4a..05da5cac080b 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1760,6 +1760,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 		int used;
 
 		__skb_unlink(skb, &sk->sk_receive_queue);
+		WARN_ON(!skb_set_owner_sk_safe(skb, sk));
 		used = recv_actor(sk, skb);
 		if (used <= 0) {
 			if (!copied)
-- 
2.34.1


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

* [Patch net v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb()
  2022-08-17 19:54 [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() Cong Wang
  2022-08-17 19:54 ` [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb() Cong Wang
@ 2022-08-17 19:54 ` Cong Wang
  2022-08-25  8:31   ` Jakub Sitnicki
  2022-08-17 19:54 ` [Patch net v3 3/4] tcp: refactor tcp_read_skb() a bit Cong Wang
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Cong Wang @ 2022-08-17 19:54 UTC (permalink / raw)
  To: netdev; +Cc: bpf, Cong Wang, Eric Dumazet, John Fastabend, Jakub Sitnicki

From: Cong Wang <cong.wang@bytedance.com>

tcp_cleanup_rbuf() retrieves the skb from sk_receive_queue, it
assumes the skb is not yet dequeued. This is no longer true for
tcp_read_skb() case where we dequeue the skb first.

Fix this by introducing a helper __tcp_cleanup_rbuf() which does
not require any skb and calling it in tcp_read_skb().

Fixes: 04919bed948d ("tcp: Introduce tcp_read_skb()")
Cc: Eric Dumazet <edumazet@google.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/ipv4/tcp.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 05da5cac080b..181a0d350123 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1567,17 +1567,11 @@ static int tcp_peek_sndq(struct sock *sk, struct msghdr *msg, int len)
  * calculation of whether or not we must ACK for the sake of
  * a window update.
  */
-void tcp_cleanup_rbuf(struct sock *sk, int copied)
+static void __tcp_cleanup_rbuf(struct sock *sk, int copied)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
 	bool time_to_ack = false;
 
-	struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
-
-	WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq),
-	     "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n",
-	     tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt);
-
 	if (inet_csk_ack_scheduled(sk)) {
 		const struct inet_connection_sock *icsk = inet_csk(sk);
 
@@ -1623,6 +1617,17 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied)
 		tcp_send_ack(sk);
 }
 
+void tcp_cleanup_rbuf(struct sock *sk, int copied)
+{
+	struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
+	struct tcp_sock *tp = tcp_sk(sk);
+
+	WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq),
+	     "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n",
+	     tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt);
+	__tcp_cleanup_rbuf(sk, copied);
+}
+
 static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
 {
 	__skb_unlink(skb, &sk->sk_receive_queue);
@@ -1771,20 +1776,19 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 		copied += used;
 
 		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
-			consume_skb(skb);
 			++seq;
 			break;
 		}
-		consume_skb(skb);
 		break;
 	}
+	consume_skb(skb);
 	WRITE_ONCE(tp->copied_seq, seq);
 
 	tcp_rcv_space_adjust(sk);
 
 	/* Clean up data we have read: This will do ACK frames. */
 	if (copied > 0)
-		tcp_cleanup_rbuf(sk, copied);
+		__tcp_cleanup_rbuf(sk, copied);
 
 	return copied;
 }
-- 
2.34.1


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

* [Patch net v3 3/4] tcp: refactor tcp_read_skb() a bit
  2022-08-17 19:54 [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() Cong Wang
  2022-08-17 19:54 ` [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb() Cong Wang
  2022-08-17 19:54 ` [Patch net v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb() Cong Wang
@ 2022-08-17 19:54 ` Cong Wang
  2022-08-17 19:54 ` [Patch net v3 4/4] tcp: handle pure FIN case correctly Cong Wang
  2022-08-18 18:30 ` [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() patchwork-bot+netdevbpf
  4 siblings, 0 replies; 13+ messages in thread
From: Cong Wang @ 2022-08-17 19:54 UTC (permalink / raw)
  To: netdev; +Cc: bpf, Cong Wang, Eric Dumazet, John Fastabend, Jakub Sitnicki

From: Cong Wang <cong.wang@bytedance.com>

As tcp_read_skb() only reads one skb at a time, the while loop is
unnecessary, we can turn it into an if. This also simplifies the
code logic.

Cc: Eric Dumazet <edumazet@google.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/ipv4/tcp.c | 26 +++++++++-----------------
 1 file changed, 9 insertions(+), 17 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 181a0d350123..56a554b49caa 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1761,25 +1761,17 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 	if (sk->sk_state == TCP_LISTEN)
 		return -ENOTCONN;
 
-	while ((skb = tcp_recv_skb(sk, seq, &offset)) != NULL) {
-		int used;
-
-		__skb_unlink(skb, &sk->sk_receive_queue);
-		WARN_ON(!skb_set_owner_sk_safe(skb, sk));
-		used = recv_actor(sk, skb);
-		if (used <= 0) {
-			if (!copied)
-				copied = used;
-			break;
-		}
-		seq += used;
-		copied += used;
+	skb = tcp_recv_skb(sk, seq, &offset);
+	if (!skb)
+		return 0;
 
-		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
+	__skb_unlink(skb, &sk->sk_receive_queue);
+	WARN_ON(!skb_set_owner_sk_safe(skb, sk));
+	copied = recv_actor(sk, skb);
+	if (copied > 0) {
+		seq += copied;
+		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			++seq;
-			break;
-		}
-		break;
 	}
 	consume_skb(skb);
 	WRITE_ONCE(tp->copied_seq, seq);
-- 
2.34.1


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

* [Patch net v3 4/4] tcp: handle pure FIN case correctly
  2022-08-17 19:54 [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() Cong Wang
                   ` (2 preceding siblings ...)
  2022-08-17 19:54 ` [Patch net v3 3/4] tcp: refactor tcp_read_skb() a bit Cong Wang
@ 2022-08-17 19:54 ` Cong Wang
  2022-08-18 18:30 ` [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() patchwork-bot+netdevbpf
  4 siblings, 0 replies; 13+ messages in thread
From: Cong Wang @ 2022-08-17 19:54 UTC (permalink / raw)
  To: netdev; +Cc: bpf, Cong Wang, Eric Dumazet, John Fastabend, Jakub Sitnicki

From: Cong Wang <cong.wang@bytedance.com>

When skb->len==0, the recv_actor() returns 0 too, but we also use 0
for error conditions. This patch amends this by propagating the errors
to tcp_read_skb() so that we can distinguish skb->len==0 case from
error cases.

Fixes: 04919bed948d ("tcp: Introduce tcp_read_skb()")
Reported-by: Eric Dumazet <edumazet@google.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/core/skmsg.c | 5 +++--
 net/ipv4/tcp.c   | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/core/skmsg.c b/net/core/skmsg.c
index f47338d89d5d..59e75ffcc1f4 100644
--- a/net/core/skmsg.c
+++ b/net/core/skmsg.c
@@ -1194,8 +1194,9 @@ static int sk_psock_verdict_recv(struct sock *sk, struct sk_buff *skb)
 		ret = bpf_prog_run_pin_on_cpu(prog, skb);
 		ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb));
 	}
-	if (sk_psock_verdict_apply(psock, skb, ret) < 0)
-		len = 0;
+	ret = sk_psock_verdict_apply(psock, skb, ret);
+	if (ret < 0)
+		len = ret;
 out:
 	rcu_read_unlock();
 	return len;
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 56a554b49caa..bbe218753662 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1768,7 +1768,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 	__skb_unlink(skb, &sk->sk_receive_queue);
 	WARN_ON(!skb_set_owner_sk_safe(skb, sk));
 	copied = recv_actor(sk, skb);
-	if (copied > 0) {
+	if (copied >= 0) {
 		seq += copied;
 		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN)
 			++seq;
-- 
2.34.1


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

* Re: [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb()
  2022-08-17 19:54 [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() Cong Wang
                   ` (3 preceding siblings ...)
  2022-08-17 19:54 ` [Patch net v3 4/4] tcp: handle pure FIN case correctly Cong Wang
@ 2022-08-18 18:30 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-08-18 18:30 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, bpf, cong.wang

Hello:

This series was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 17 Aug 2022 12:54:41 -0700 you wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> This patchset contains 3 bug fixes and 1 minor refactor patch for
> tcp_read_skb(). V1 only had the first patch, as Eric prefers to fix all
> of them together, I have to group them together. Please see each patch
> description for more details.
> 
> [...]

Here is the summary with links:
  - [net,v3,1/4] tcp: fix sock skb accounting in tcp_read_skb()
    https://git.kernel.org/netdev/net/c/e9c6e7976026
  - [net,v3,2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb()
    https://git.kernel.org/netdev/net/c/c457985aaa92
  - [net,v3,3/4] tcp: refactor tcp_read_skb() a bit
    https://git.kernel.org/netdev/net/c/a8688821f385
  - [net,v3,4/4] tcp: handle pure FIN case correctly
    https://git.kernel.org/netdev/net/c/2e23acd99efa

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

* Re: [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb()
  2022-08-17 19:54 ` [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb() Cong Wang
@ 2022-08-24  8:17   ` Jakub Sitnicki
  2022-09-08 23:15     ` [PATCH net] tcp: Use WARN_ON_ONCE() " Peilin Ye
  0 siblings, 1 reply; 13+ messages in thread
From: Jakub Sitnicki @ 2022-08-24  8:17 UTC (permalink / raw)
  To: Cong Wang
  Cc: netdev, bpf, Cong Wang, syzbot+a0e6f8738b58f7654417,
	Stanislav Fomichev, Eric Dumazet, John Fastabend

On Wed, Aug 17, 2022 at 12:54 PM -07, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
>
> Before commit 965b57b469a5 ("net: Introduce a new proto_ops
> ->read_skb()"), skb was not dequeued from receive queue hence
> when we close TCP socket skb can be just flushed synchronously.
>
> After this commit, we have to uncharge skb immediately after being
> dequeued, otherwise it is still charged in the original sock. And we
> still need to retain skb->sk, as eBPF programs may extract sock
> information from skb->sk. Therefore, we have to call
> skb_set_owner_sk_safe() here.
>
> Fixes: 965b57b469a5 ("net: Introduce a new proto_ops ->read_skb()")
> Reported-and-tested-by: syzbot+a0e6f8738b58f7654417@syzkaller.appspotmail.com
> Tested-by: Stanislav Fomichev <sdf@google.com>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> ---
>  net/ipv4/tcp.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 970e9a2cca4a..05da5cac080b 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1760,6 +1760,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
>  		int used;
>  
>  		__skb_unlink(skb, &sk->sk_receive_queue);
> +		WARN_ON(!skb_set_owner_sk_safe(skb, sk));
>  		used = recv_actor(sk, skb);
>  		if (used <= 0) {
>  			if (!copied)

That is a frequent operation.

Don't we want WARN_ON_ONCE like in tcp_read_sock?

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

* Re: [Patch net v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb()
  2022-08-17 19:54 ` [Patch net v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb() Cong Wang
@ 2022-08-25  8:31   ` Jakub Sitnicki
  0 siblings, 0 replies; 13+ messages in thread
From: Jakub Sitnicki @ 2022-08-25  8:31 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, bpf, Cong Wang, Eric Dumazet, John Fastabend

On Wed, Aug 17, 2022 at 12:54 PM -07, Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
>
> tcp_cleanup_rbuf() retrieves the skb from sk_receive_queue, it
> assumes the skb is not yet dequeued. This is no longer true for
> tcp_read_skb() case where we dequeue the skb first.
>
> Fix this by introducing a helper __tcp_cleanup_rbuf() which does
> not require any skb and calling it in tcp_read_skb().
>
> Fixes: 04919bed948d ("tcp: Introduce tcp_read_skb()")
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: John Fastabend <john.fastabend@gmail.com>
> Cc: Jakub Sitnicki <jakub@cloudflare.com>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> ---
>  net/ipv4/tcp.c | 24 ++++++++++++++----------
>  1 file changed, 14 insertions(+), 10 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 05da5cac080b..181a0d350123 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1567,17 +1567,11 @@ static int tcp_peek_sndq(struct sock *sk, struct msghdr *msg, int len)
>   * calculation of whether or not we must ACK for the sake of
>   * a window update.
>   */
> -void tcp_cleanup_rbuf(struct sock *sk, int copied)
> +static void __tcp_cleanup_rbuf(struct sock *sk, int copied)
>  {
>  	struct tcp_sock *tp = tcp_sk(sk);
>  	bool time_to_ack = false;
>  
> -	struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
> -
> -	WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq),
> -	     "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n",
> -	     tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt);
> -
>  	if (inet_csk_ack_scheduled(sk)) {
>  		const struct inet_connection_sock *icsk = inet_csk(sk);
>  
> @@ -1623,6 +1617,17 @@ void tcp_cleanup_rbuf(struct sock *sk, int copied)
>  		tcp_send_ack(sk);
>  }
>  
> +void tcp_cleanup_rbuf(struct sock *sk, int copied)
> +{
> +	struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
> +	struct tcp_sock *tp = tcp_sk(sk);
> +
> +	WARN(skb && !before(tp->copied_seq, TCP_SKB_CB(skb)->end_seq),
> +	     "cleanup rbuf bug: copied %X seq %X rcvnxt %X\n",
> +	     tp->copied_seq, TCP_SKB_CB(skb)->end_seq, tp->rcv_nxt);
> +	__tcp_cleanup_rbuf(sk, copied);
> +}
> +
>  static void tcp_eat_recv_skb(struct sock *sk, struct sk_buff *skb)
>  {
>  	__skb_unlink(skb, &sk->sk_receive_queue);
> @@ -1771,20 +1776,19 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
>  		copied += used;
>  
>  		if (TCP_SKB_CB(skb)->tcp_flags & TCPHDR_FIN) {
> -			consume_skb(skb);
>  			++seq;
>  			break;
>  		}
> -		consume_skb(skb);
>  		break;
>  	}
> +	consume_skb(skb);
>  	WRITE_ONCE(tp->copied_seq, seq);
>  
>  	tcp_rcv_space_adjust(sk);
>  
>  	/* Clean up data we have read: This will do ACK frames. */
>  	if (copied > 0)
> -		tcp_cleanup_rbuf(sk, copied);
> +		__tcp_cleanup_rbuf(sk, copied);
>  
>  	return copied;
>  }

This seems to be fixing 2 different problems, but the commit description
mentions just one.

consume_skb() got pulled out of the `while' body. And thanks to that we
are not leaving a dangling skb ref if recv_actor, sk_psock_verdict_recv
in this case, returns 0.

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

* [PATCH net] tcp: Use WARN_ON_ONCE() in tcp_read_skb()
  2022-08-24  8:17   ` Jakub Sitnicki
@ 2022-09-08 23:15     ` Peilin Ye
  2022-09-13 18:40       ` [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb() Peilin Ye
  2022-09-16 14:40       ` [PATCH net] tcp: Use WARN_ON_ONCE() in tcp_read_skb() patchwork-bot+netdevbpf
  0 siblings, 2 replies; 13+ messages in thread
From: Peilin Ye @ 2022-09-08 23:15 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Hideaki YOSHIFUJI, David Ahern,
	Jakub Kicinski, Paolo Abeni
  Cc: Peilin Ye, Cong Wang, Jakub Sitnicki, netdev, linux-kernel, Peilin Ye

From: Peilin Ye <peilin.ye@bytedance.com>

Prevent tcp_read_skb() from flooding the syslog.

Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
---
 net/ipv4/tcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 8230be00ecca..9251c99d3cfd 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1766,7 +1766,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 		return 0;
 
 	__skb_unlink(skb, &sk->sk_receive_queue);
-	WARN_ON(!skb_set_owner_sk_safe(skb, sk));
+	WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
 	copied = recv_actor(sk, skb);
 	if (copied >= 0) {
 		seq += copied;
-- 
2.20.1


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

* [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb()
  2022-09-08 23:15     ` [PATCH net] tcp: Use WARN_ON_ONCE() " Peilin Ye
@ 2022-09-13 18:40       ` Peilin Ye
  2022-09-13 19:30         ` Peilin Ye
  2022-09-16 14:40       ` [PATCH net] tcp: Use WARN_ON_ONCE() in tcp_read_skb() patchwork-bot+netdevbpf
  1 sibling, 1 reply; 13+ messages in thread
From: Peilin Ye @ 2022-09-13 18:40 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Hideaki YOSHIFUJI, David Ahern,
	Jakub Kicinski, Paolo Abeni
  Cc: Peilin Ye, Cong Wang, netdev, linux-kernel, Peilin Ye

From: Peilin Ye <peilin.ye@bytedance.com>

Prevent tcp_read_skb() and udp_read_skb() from flooding the syslog.

Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
---
change since v1:
  - do the same to udp_read_skb() (Cong Wang)

Cong's tcp_read_skb() fix [1] depends on this patch.

[1] https://lore.kernel.org/netdev/20220912173553.235838-1-xiyou.wangcong@gmail.com/

Thanks,
Peilin Ye

 net/ipv4/tcp.c | 2 +-
 net/ipv4/udp.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 8230be00ecca..9251c99d3cfd 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -1766,7 +1766,7 @@ int tcp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 		return 0;
 
 	__skb_unlink(skb, &sk->sk_receive_queue);
-	WARN_ON(!skb_set_owner_sk_safe(skb, sk));
+	WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
 	copied = recv_actor(sk, skb);
 	if (copied >= 0) {
 		seq += copied;
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index cd72158e953a..560d9eadeaa5 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1821,7 +1821,7 @@ int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor)
 			continue;
 		}
 
-		WARN_ON(!skb_set_owner_sk_safe(skb, sk));
+		WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk));
 		used = recv_actor(sk, skb);
 		if (used <= 0) {
 			if (!copied)
-- 
2.20.1


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

* Re: [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb()
  2022-09-13 18:40       ` [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb() Peilin Ye
@ 2022-09-13 19:30         ` Peilin Ye
  2022-09-14  7:51           ` Peilin Ye
  0 siblings, 1 reply; 13+ messages in thread
From: Peilin Ye @ 2022-09-13 19:30 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Hideaki YOSHIFUJI, David Ahern,
	Jakub Kicinski, Paolo Abeni
  Cc: Peilin Ye, Cong Wang, netdev, linux-kernel

On Tue, Sep 13, 2022 at 11:40:16AM -0700, Peilin Ye wrote:
> Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
> Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>

Sorry, I forgot to add Fixes: tag.

Those WARN_ON() come from different commits.  I will split this into two
in v3 to make it easier.

Thanks,
Peilin Ye


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

* Re: [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb()
  2022-09-13 19:30         ` Peilin Ye
@ 2022-09-14  7:51           ` Peilin Ye
  0 siblings, 0 replies; 13+ messages in thread
From: Peilin Ye @ 2022-09-14  7:51 UTC (permalink / raw)
  To: Eric Dumazet, David S. Miller, Hideaki YOSHIFUJI, David Ahern,
	Jakub Kicinski, Paolo Abeni
  Cc: Peilin Ye, Cong Wang, netdev, linux-kernel

On Tue, Sep 13, 2022 at 12:30:50PM -0700, Peilin Ye wrote:
> On Tue, Sep 13, 2022 at 11:40:16AM -0700, Peilin Ye wrote:
> > Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
> > Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
> 
> Sorry, I forgot to add Fixes: tag.
> 
> Those WARN_ON() come from different commits.  I will split this into two
> in v3 to make it easier.

Cong suggested not sending v3 since this is not fixing a bug, and thus
no need to add Fixes: tags.


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

* Re: [PATCH net] tcp: Use WARN_ON_ONCE() in tcp_read_skb()
  2022-09-08 23:15     ` [PATCH net] tcp: Use WARN_ON_ONCE() " Peilin Ye
  2022-09-13 18:40       ` [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb() Peilin Ye
@ 2022-09-16 14:40       ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 13+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-16 14:40 UTC (permalink / raw)
  To: Peilin Ye
  Cc: edumazet, davem, yoshfuji, dsahern, kuba, pabeni, peilin.ye,
	cong.wang, jakub, netdev, linux-kernel

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Thu,  8 Sep 2022 16:15:23 -0700 you wrote:
> From: Peilin Ye <peilin.ye@bytedance.com>
> 
> Prevent tcp_read_skb() from flooding the syslog.
> 
> Suggested-by: Jakub Sitnicki <jakub@cloudflare.com>
> Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
> 
> [...]

Here is the summary with links:
  - [net] tcp: Use WARN_ON_ONCE() in tcp_read_skb()
    https://git.kernel.org/netdev/net/c/96628951869c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-09-16 14:40 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-17 19:54 [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() Cong Wang
2022-08-17 19:54 ` [Patch net v3 1/4] tcp: fix sock skb accounting in tcp_read_skb() Cong Wang
2022-08-24  8:17   ` Jakub Sitnicki
2022-09-08 23:15     ` [PATCH net] tcp: Use WARN_ON_ONCE() " Peilin Ye
2022-09-13 18:40       ` [PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb() Peilin Ye
2022-09-13 19:30         ` Peilin Ye
2022-09-14  7:51           ` Peilin Ye
2022-09-16 14:40       ` [PATCH net] tcp: Use WARN_ON_ONCE() in tcp_read_skb() patchwork-bot+netdevbpf
2022-08-17 19:54 ` [Patch net v3 2/4] tcp: fix tcp_cleanup_rbuf() for tcp_read_skb() Cong Wang
2022-08-25  8:31   ` Jakub Sitnicki
2022-08-17 19:54 ` [Patch net v3 3/4] tcp: refactor tcp_read_skb() a bit Cong Wang
2022-08-17 19:54 ` [Patch net v3 4/4] tcp: handle pure FIN case correctly Cong Wang
2022-08-18 18:30 ` [Patch net v3 0/4] tcp: some bug fixes for tcp_read_skb() patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.