]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: treat possible_net_t net pointer as an RCU one and add read_pnet_rcu()
authorJiri Pirko <jiri@nvidia.com>
Fri, 13 Oct 2023 12:10:23 +0000 (14:10 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:21 +0000 (12:47 +0100)
[ Upstream commit 2034d90ae41ae93e30d492ebcf1f06f97a9cfba6 ]

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>
Stable-dep-of: dd205fcc33d9 ("ipv4: use RCU protection in rt_is_expired()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/net/net_namespace.h

index c41e922fdd97e2cae7757cae97af6695b22b55d1..0dfcf2f0ef62a3ea89a0a60ef48bbd854a1a250e 100644 (file)
@@ -320,21 +320,30 @@ static inline int check_net(const struct net *net)
 
 typedef struct {
 #ifdef CONFIG_NET_NS
-       struct net *net;
+       struct net __rcu *net;
 #endif
 } possible_net_t;
 
 static inline void write_pnet(possible_net_t *pnet, struct net *net)
 {
 #ifdef CONFIG_NET_NS
-       pnet->net = net;
+       rcu_assign_pointer(pnet->net, net);
 #endif
 }
 
 static inline struct net *read_pnet(const possible_net_t *pnet)
 {
 #ifdef CONFIG_NET_NS
-       return pnet->net;
+       return rcu_dereference_protected(pnet->net, true);
+#else
+       return &init_net;
+#endif
+}
+
+static inline struct net *read_pnet_rcu(possible_net_t *pnet)
+{
+#ifdef CONFIG_NET_NS
+       return rcu_dereference(pnet->net);
 #else
        return &init_net;
 #endif