Skip to content

Commit 071d801

Browse files
edumazetkuba-moo
authored andcommitted
ipv4: use RCU protection in ip_dst_mtu_maybe_forward()
ip_dst_mtu_maybe_forward() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: f87c10a ("ipv4: introduce ip_dst_mtu_maybe_forward and protect forwarding path against pmtu spoofing") Signed-off-by: Eric Dumazet <[email protected]> Reviewed-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 4693085 commit 071d801

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

include/net/ip.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,12 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
471471
bool forwarding)
472472
{
473473
const struct rtable *rt = dst_rtable(dst);
474-
struct net *net = dev_net(dst->dev);
475-
unsigned int mtu;
474+
unsigned int mtu, res;
475+
struct net *net;
476+
477+
rcu_read_lock();
476478

479+
net = dev_net_rcu(dst->dev);
477480
if (READ_ONCE(net->ipv4.sysctl_ip_fwd_use_pmtu) ||
478481
ip_mtu_locked(dst) ||
479482
!forwarding) {
@@ -497,7 +500,11 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
497500
out:
498501
mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
499502

500-
return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
503+
res = mtu - lwtunnel_headroom(dst->lwtstate, mtu);
504+
505+
rcu_read_unlock();
506+
507+
return res;
501508
}
502509

503510
static inline unsigned int ip_skb_dst_mtu(struct sock *sk,

0 commit comments

Comments
 (0)