Skip to content

Commit a3b244a

Browse files
committed
net: treat possible_net_t net pointer as an RCU one and add read_pnet_rcu()
jira VULN-54026 cve-pre CVE-2025-21764 commit-author Jiri Pirko <jiri@nvidia.com> commit 2034d90 Make the net pointer stored in possible_net_t structure annotated as an RCU pointer. Change the access helpers to treat it as such. Introduce read_pnet_rcu() helper to allow caller to dereference the net pointer under RCU read lock. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 2034d90) Signed-off-by: Brett Mastbergen <bmastbergen@ciq.com>
1 parent 245a185 commit a3b244a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

include/net/net_namespace.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,21 +348,30 @@ static inline void put_net_track(struct net *net, netns_tracker *tracker)
348348

349349
typedef struct {
350350
#ifdef CONFIG_NET_NS
351-
struct net *net;
351+
struct net __rcu *net;
352352
#endif
353353
} possible_net_t;
354354

355355
static inline void write_pnet(possible_net_t *pnet, struct net *net)
356356
{
357357
#ifdef CONFIG_NET_NS
358-
pnet->net = net;
358+
rcu_assign_pointer(pnet->net, net);
359359
#endif
360360
}
361361

362362
static inline struct net *read_pnet(const possible_net_t *pnet)
363363
{
364364
#ifdef CONFIG_NET_NS
365-
return pnet->net;
365+
return rcu_dereference_protected(pnet->net, true);
366+
#else
367+
return &init_net;
368+
#endif
369+
}
370+
371+
static inline struct net *read_pnet_rcu(possible_net_t *pnet)
372+
{
373+
#ifdef CONFIG_NET_NS
374+
return rcu_dereference(pnet->net);
366375
#else
367376
return &init_net;
368377
#endif

0 commit comments

Comments
 (0)