Skip to content

Commit 4693085

Browse files
edumazetkuba-moo
authored andcommitted
ipv4: add RCU protection to ip4_dst_hoplimit()
ip4_dst_hoplimit() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: fa50d97 ("ipv4: Namespaceify ip_default_ttl sysctl knob") 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 482ad2a commit 4693085

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

include/net/route.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,15 @@ static inline int inet_iif(const struct sk_buff *skb)
382382
static inline int ip4_dst_hoplimit(const struct dst_entry *dst)
383383
{
384384
int hoplimit = dst_metric_raw(dst, RTAX_HOPLIMIT);
385-
struct net *net = dev_net(dst->dev);
386385

387-
if (hoplimit == 0)
386+
if (hoplimit == 0) {
387+
const struct net *net;
388+
389+
rcu_read_lock();
390+
net = dev_net_rcu(dst->dev);
388391
hoplimit = READ_ONCE(net->ipv4.sysctl_ip_default_ttl);
392+
rcu_read_unlock();
393+
}
389394
return hoplimit;
390395
}
391396

0 commit comments

Comments
 (0)