Skip to content

Commit 1adaea5

Browse files
mrprePaolo Abeni
authored andcommitted
ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
On PREEMPT_RT kernels, after rt6_get_pcpu_route() returns NULL, the current task can be preempted. Another task running on the same CPU may then execute rt6_make_pcpu_route() and successfully install a pcpu_rt entry. When the first task resumes execution, its cmpxchg() in rt6_make_pcpu_route() will fail because rt6i_pcpu is no longer NULL, triggering the BUG_ON(prev). It's easy to reproduce it by adding mdelay() after rt6_get_pcpu_route(). Using preempt_disable/enable is not appropriate here because ip6_rt_pcpu_alloc() may sleep. Fix this by handling the cmpxchg() failure gracefully on PREEMPT_RT: free our allocation and return the existing pcpu_rt installed by another task. The BUG_ON is replaced by WARN_ON_ONCE for non-PREEMPT_RT kernels where such races should not occur. Link: https://syzkaller.appspot.com/bug?extid=9b35e9bc0951140d13e6 Fixes: d2d6422 ("x86: Allow to enable PREEMPT_RT.") Reported-by: syzbot+9b35e9bc0951140d13e6@syzkaller.appspotmail.com Closes: https://lore.kernel.org/all/6918cd88.050a0220.1c914e.0045.GAE@google.com/T/ Signed-off-by: Jiayuan Chen <jiayuan.chen@linux.dev> Link: https://patch.msgid.link/20251223051413.124687-1-jiayuan.chen@linux.dev Signed-off-by: Paolo Abeni <pabeni@redhat.com>
1 parent 6595beb commit 1adaea5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

net/ipv6/route.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,18 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
14701470

14711471
p = this_cpu_ptr(res->nh->rt6i_pcpu);
14721472
prev = cmpxchg(p, NULL, pcpu_rt);
1473-
BUG_ON(prev);
1473+
if (unlikely(prev)) {
1474+
/*
1475+
* Another task on this CPU already installed a pcpu_rt.
1476+
* This can happen on PREEMPT_RT where preemption is possible.
1477+
* Free our allocation and return the existing one.
1478+
*/
1479+
WARN_ON_ONCE(!IS_ENABLED(CONFIG_PREEMPT_RT));
1480+
1481+
dst_dev_put(&pcpu_rt->dst);
1482+
dst_release(&pcpu_rt->dst);
1483+
return prev;
1484+
}
14741485

14751486
if (res->f6i->fib6_destroying) {
14761487
struct fib6_info *from;

0 commit comments

Comments
 (0)