Skip to content

Commit 39fe564

Browse files
committed
net: add dev_net_rcu() helper
jira VULN-54026 cve-pre CVE-2025-21764 commit-author Eric Dumazet <edumazet@google.com> commit 482ad2a dev->nd_net can change, readers should either use rcu_read_lock() or RTNL. We currently use a generic helper, dev_net() with no debugging support. We probably have many hidden bugs. Add dev_net_rcu() helper for callers using rcu_read_lock() protection. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250205155120.1676781-2-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> (cherry picked from commit 482ad2a) Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
1 parent a3b244a commit 39fe564

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/linux/netdevice.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,6 +2470,12 @@ struct net *dev_net(const struct net_device *dev)
24702470
return read_pnet(&dev->nd_net);
24712471
}
24722472

2473+
static inline
2474+
struct net *dev_net_rcu(const struct net_device *dev)
2475+
{
2476+
return read_pnet_rcu(&dev->nd_net);
2477+
}
2478+
24732479
static inline
24742480
void dev_net_set(struct net_device *dev, struct net *net)
24752481
{

include/net/net_namespace.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static inline struct net *read_pnet(const possible_net_t *pnet)
368368
#endif
369369
}
370370

371-
static inline struct net *read_pnet_rcu(possible_net_t *pnet)
371+
static inline struct net *read_pnet_rcu(const possible_net_t *pnet)
372372
{
373373
#ifdef CONFIG_NET_NS
374374
return rcu_dereference(pnet->net);

0 commit comments

Comments
 (0)