Re: [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
From: Eric Dumazet
Date: Mon Dec 22 2025 - 03:51:11 EST
On Fri, Dec 19, 2025 at 3:52 AM Jiayuan Chen <jiayuan.chen@xxxxxxxxx> wrote:
>
> 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:
> 1. Removing the BUG_ON and instead handling the race gracefully by
> freeing our allocation and returning the existing pcpu_rt when
> cmpxchg() fails.
> 2. Keeping the BUG_ON for non-PREEMPT_RT kernels, since preemption
> should not occur in this context and a cmpxchg failure would
> indicate a real bug.
>
> Link: https://syzkaller.appspot.com/bug?extid=9b35e9bc0951140d13e6
> Fixes: 951f788a80ff ("ipv6: fix a BUG in rt6_get_pcpu_route()")
I would rather find when PREEMPT_RT was added/enabled, there is no
point blaming such an old commit
which was correct at the time, and forcing pointless backports to old
linux kernels.