Re: [PATCH net-next v3] net: ip: avoid OOM kills with large UDP sends over loopback
From: Jakub Kicinski <kuba@kernel.org>
Date: 2021-06-23 21:07:20
On Wed, 23 Jun 2021 21:45:55 +0200 Jesper Dangaard Brouer wrote:
quoted
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index c3efc7d658f6..790dd28fd198 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c@@ -1077,7 +1077,9 @@ static int __ip_append_data(struct sock *sk, if ((flags & MSG_MORE) && !(rt->dst.dev->features&NETIF_F_SG)) alloclen = mtu; - else if (!paged) + else if (!paged && + (fraglen + hh_len + 15 < SKB_MAX_ALLOC ||What does the number 15 represent here?
No idea, it's there on the allocation line, so I need to include it on the size check. Looking at super old code (2.4.x) it looks like it may have gotten copy & pasted mistakenly? The hard headers are rounded up to 16B, and there is code which does things like: skb_alloc(size + dev->hard_header_len + 15); skb_reserve(skb, (dev->hard_header_len + 15) & ~15); in other spots. So if I was to guess I'd say someone decided to add the 15B "to be safe" even though hh_len already includes the round up here. But that's just my guess. I can't get this simple patch right, so take that with a grain of salt :/
quoted
+ !(rt->dst.dev->features & NETIF_F_SG))) alloclen = fraglen; else { alloclen = min_t(int, fraglen, MAX_HEADER);diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index ff4f9ebcf7f6..ae8dbd6cdab1 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c@@ -1585,7 +1585,9 @@ static int __ip6_append_data(struct sock *sk, if ((flags & MSG_MORE) && !(rt->dst.dev->features&NETIF_F_SG)) alloclen = mtu; - else if (!paged) + else if (!paged && + (fraglen + hh_len < SKB_MAX_ALLOC ||The number 15 is not use here.quoted
+ !(rt->dst.dev->features & NETIF_F_SG))) alloclen = fraglen; else { alloclen = min_t(int, fraglen, MAX_HEADER);