Skip to content

Commit 1395121

Browse files
edumazetkuba-moo
authored andcommitted
ipv4: use RCU protection in __ip_rt_update_pmtu()
__ip_rt_update_pmtu() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: 2fbc6e8 ("ipv4: Update exception handling for multipath routes via same device") Fixes: 1de6b15 ("Namespaceify min_pmtu sysctl") Signed-off-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 719817c commit 1395121

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

net/ipv4/route.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,9 +1008,9 @@ out: kfree_skb_reason(skb, reason);
10081008
static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
10091009
{
10101010
struct dst_entry *dst = &rt->dst;
1011-
struct net *net = dev_net(dst->dev);
10121011
struct fib_result res;
10131012
bool lock = false;
1013+
struct net *net;
10141014
u32 old_mtu;
10151015

10161016
if (ip_mtu_locked(dst))
@@ -1020,16 +1020,17 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
10201020
if (old_mtu < mtu)
10211021
return;
10221022

1023+
rcu_read_lock();
1024+
net = dev_net_rcu(dst->dev);
10231025
if (mtu < net->ipv4.ip_rt_min_pmtu) {
10241026
lock = true;
10251027
mtu = min(old_mtu, net->ipv4.ip_rt_min_pmtu);
10261028
}
10271029

10281030
if (rt->rt_pmtu == mtu && !lock &&
10291031
time_before(jiffies, dst->expires - net->ipv4.ip_rt_mtu_expires / 2))
1030-
return;
1032+
goto out;
10311033

1032-
rcu_read_lock();
10331034
if (fib_lookup(net, fl4, &res, 0) == 0) {
10341035
struct fib_nh_common *nhc;
10351036

@@ -1043,14 +1044,14 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
10431044
update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock,
10441045
jiffies + net->ipv4.ip_rt_mtu_expires);
10451046
}
1046-
rcu_read_unlock();
1047-
return;
1047+
goto out;
10481048
}
10491049
#endif /* CONFIG_IP_ROUTE_MULTIPATH */
10501050
nhc = FIB_RES_NHC(res);
10511051
update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock,
10521052
jiffies + net->ipv4.ip_rt_mtu_expires);
10531053
}
1054+
out:
10541055
rcu_read_unlock();
10551056
}
10561057

0 commit comments

Comments
 (0)