ipv4: raw: check sk->sk_rcvbuf earlier
authorEric Dumazet <edumazet@google.com>
Thu, 7 Mar 2024 16:30:20 +0000 (16:30 +0000)
committerJakub Kicinski <kuba@kernel.org>
Fri, 8 Mar 2024 19:39:44 +0000 (11:39 -0800)
There is no point cloning an skb and having to free the clone
if the receive queue of the raw socket is full.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://lore.kernel.org/r/20240307163020.2524409-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/raw.c

index 494a6284bd7ee346a4fca7a161477e6dc5ed5021..42ac434cfcfa677ee58408297f4d3ac05d98b546 100644 (file)
@@ -175,6 +175,13 @@ static int raw_v4_input(struct net *net, struct sk_buff *skb,
                if (!raw_v4_match(net, sk, iph->protocol,
                                  iph->saddr, iph->daddr, dif, sdif))
                        continue;
+
+               if (atomic_read(&sk->sk_rmem_alloc) >=
+                   READ_ONCE(sk->sk_rcvbuf)) {
+                       atomic_inc(&sk->sk_drops);
+                       continue;
+               }
+
                delivered = 1;
                if ((iph->protocol != IPPROTO_ICMP || !icmp_filter(sk, skb)) &&
                    ip_mc_sf_allow(sk, iph->daddr, iph->saddr,