Skip to content

Commit aa56a8b

Browse files
author
Paolo Abeni
committed
neighbour: use RCU protection in __neigh_notify()
JIRA: https://issues.redhat.com/browse/RHEL-87474 Conflicts: \ - different context, as rhel-9 lacks the upstream \ commit c25bdd2 ("neighbour: delete redundant judgment statements") \ - use dev_net() instead of dev_net_rcu() as rhel-9 lacks the upstream \ commit 482ad2a ("net: add dev_net_rcu() helper") Upstream commit: commit becbd58 Author: Eric Dumazet <edumazet@google.com> Date: Fri Feb 7 13:58:35 2025 +0000 neighbour: use RCU protection in __neigh_notify() __neigh_notify() can be called without RTNL or RCU protection. Use RCU protection to avoid potential UAF. Fixes: 426b530 ("[NETNS]: Modify the neighbour table code so it handles multiple network namespaces") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: David Ahern <dsahern@kernel.org> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250207135841.1948589-4-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 818e414 commit aa56a8b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

net/core/neighbour.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,10 +3469,12 @@ static const struct seq_operations neigh_stat_seq_ops = {
34693469
static void __neigh_notify(struct neighbour *n, int type, int flags,
34703470
u32 pid)
34713471
{
3472-
struct net *net = dev_net(n->dev);
34733472
struct sk_buff *skb;
34743473
int err = -ENOBUFS;
3474+
struct net *net;
34753475

3476+
rcu_read_lock();
3477+
net = dev_net(n->dev);
34763478
skb = nlmsg_new(neigh_nlmsg_size(), GFP_ATOMIC);
34773479
if (skb == NULL)
34783480
goto errout;
@@ -3485,10 +3487,12 @@ static void __neigh_notify(struct neighbour *n, int type, int flags,
34853487
goto errout;
34863488
}
34873489
rtnl_notify(skb, net, 0, RTNLGRP_NEIGH, NULL, GFP_ATOMIC);
3488-
return;
3490+
goto out;
34893491
errout:
34903492
if (err < 0)
34913493
rtnl_set_sk_err(net, RTNLGRP_NEIGH, err);
3494+
out:
3495+
rcu_read_unlock();
34923496
}
34933497

34943498
void neigh_app_ns(struct neighbour *n)

0 commit comments

Comments
 (0)