]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ipv4: use RCU protection in inet_select_addr()
authorEric Dumazet <edumazet@google.com>
Wed, 5 Feb 2025 15:51:14 +0000 (15:51 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:21 +0000 (12:47 +0100)
[ 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 <edumazet@google.com>
Link: https://patch.msgid.link/20250205155120.1676781-7-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv4/devinet.c

index 6918b3ced67137dc1ffe8b757e0f969eee52eb2e..2dc94109fc0eac146da089d60afa816bde9dcfbf 100644 (file)
@@ -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;