From: Eric Dumazet Date: Wed, 5 Feb 2025 15:51:14 +0000 (+0000) Subject: ipv4: use RCU protection in inet_select_addr() X-Git-Tag: v5.10.235~181 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c7665524a6b1f21a79ac56fe5ad48fcd3fcdbc25;p=thirdparty%2Fkernel%2Fstable.git ipv4: use RCU protection in inet_select_addr() [ Upstream commit 719817cd293e4fa389e1f69c396f3f816ed5aa41 ] inet_select_addr() must use RCU protection to make sure the net structure it reads does not disappear. Fixes: c4544c724322 ("[NETNS]: Process inet_select_addr inside a namespace.") Signed-off-by: Eric Dumazet Link: https://patch.msgid.link/20250205155120.1676781-7-edumazet@google.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 6918b3ced6713..2dc94109fc0ea 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -1317,10 +1317,11 @@ __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope) __be32 addr = 0; unsigned char localnet_scope = RT_SCOPE_HOST; struct in_device *in_dev; - struct net *net = dev_net(dev); + struct net *net; int master_idx; rcu_read_lock(); + net = dev_net_rcu(dev); in_dev = __in_dev_get_rcu(dev); if (!in_dev) goto no_in_dev;