[PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb()

From: Peilin Ye
Date: Tue Sep 13 2022 - 14:55:15 EST


From: Peilin Ye <peilin.ye@xxxxxxxxxxxxx>

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

Suggested-by: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx>
Signed-off-by: Peilin Ye <peilin.ye@xxxxxxxxxxxxx>
---
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@xxxxxxxxx/

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