Skip to content

Commit 1bd5437

Browse files
edumazetgregkh
authored andcommitted
ipv4: better IP_MAX_MTU enforcement
[ Upstream commit c780a049f9bf442314335372c9abc4548bfe3e44 ] While working on yet another syzkaller report, I found that our IP_MAX_MTU enforcements were not properly done. gcc seems to reload dev->mtu for min(dev->mtu, IP_MAX_MTU), and final result can be bigger than IP_MAX_MTU :/ This is a problem because device mtu can be changed on other cpus or threads. While this patch does not fix the issue I am working on, it is probably worth addressing it. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7e1fe00 commit 1bd5437

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

include/net/ip.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
314314
!forwarding)
315315
return dst_mtu(dst);
316316

317-
return min(dst->dev->mtu, IP_MAX_MTU);
317+
return min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);
318318
}
319319

320320
static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
@@ -327,7 +327,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
327327
return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding);
328328
}
329329

330-
return min(skb_dst(skb)->dev->mtu, IP_MAX_MTU);
330+
return min(READ_ONCE(skb_dst(skb)->dev->mtu), IP_MAX_MTU);
331331
}
332332

333333
u32 ip_idents_reserve(u32 hash, int segs);

net/ipv4/route.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
12411241
if (mtu)
12421242
return mtu;
12431243

1244-
mtu = dst->dev->mtu;
1244+
mtu = READ_ONCE(dst->dev->mtu);
12451245

12461246
if (unlikely(dst_metric_locked(dst, RTAX_MTU))) {
12471247
if (rt->rt_uses_gateway && mtu > 576)

0 commit comments

Comments
 (0)