* [PATCH net v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
@ 2025-12-23 5:14 Jiayuan Chen
2025-12-30 11:20 ` patchwork-bot+netdevbpf
2026-01-12 15:49 ` Sebastian Andrzej Siewior
0 siblings, 2 replies; 3+ messages in thread
From: Jiayuan Chen @ 2025-12-23 5:14 UTC (permalink / raw)
To: netdev, jiayuan.chen
Cc: syzbot+9b35e9bc0951140d13e6, David S. Miller, David Ahern,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
Thomas Gleixner, linux-kernel, linux-rt-devel
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: d2d6422f8bd1 ("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>
---
v2 -> v4: Use correct Fixes tag; Replace BUG_ON by WARN_ON_ONCE.
https://lore.kernel.org/netdev/20251219025140.77695-1-jiayuan.chen@linux.dev/
v1 -> v2: Drop migrate_{disable, enabled} suggested by Steven and Paolo.
https://lore.kernel.org/all/20251209124805.379112-1-jiayuan.chen@linux.dev/T/
---
net/ipv6/route.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index aee6a10b112a..a3e051dc66ee 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -1470,7 +1470,18 @@ static struct rt6_info *rt6_make_pcpu_route(struct net *net,
p = this_cpu_ptr(res->nh->rt6i_pcpu);
prev = cmpxchg(p, NULL, pcpu_rt);
- BUG_ON(prev);
+ if (unlikely(prev)) {
+ /*
+ * Another task on this CPU already installed a pcpu_rt.
+ * This can happen on PREEMPT_RT where preemption is possible.
+ * Free our allocation and return the existing one.
+ */
+ WARN_ON_ONCE(!IS_ENABLED(CONFIG_PREEMPT_RT));
+
+ dst_dev_put(&pcpu_rt->dst);
+ dst_release(&pcpu_rt->dst);
+ return prev;
+ }
if (res->f6i->fib6_destroying) {
struct fib6_info *from;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH net v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
2025-12-23 5:14 [PATCH net v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT Jiayuan Chen
@ 2025-12-30 11:20 ` patchwork-bot+netdevbpf
2026-01-12 15:49 ` Sebastian Andrzej Siewior
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-12-30 11:20 UTC (permalink / raw)
To: Jiayuan Chen
Cc: netdev, syzbot+9b35e9bc0951140d13e6, davem, dsahern, edumazet,
kuba, pabeni, horms, bigeasy, clrkwllms, rostedt, tglx,
linux-kernel, linux-rt-devel
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Tue, 23 Dec 2025 13:14:12 +0800 you 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().
>
> [...]
Here is the summary with links:
- [net,v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
https://git.kernel.org/netdev/net/c/1adaea51c61b
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH net v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
2025-12-23 5:14 [PATCH net v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT Jiayuan Chen
2025-12-30 11:20 ` patchwork-bot+netdevbpf
@ 2026-01-12 15:49 ` Sebastian Andrzej Siewior
1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2026-01-12 15:49 UTC (permalink / raw)
To: stable-rt
Cc: Jiayuan Chen, Clark Williams, Steven Rostedt, Thomas Gleixner,
linux-rt-devel
On 2025-12-23 13:14:12 [+0800], Jiayuan Chen 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 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: d2d6422f8bd1 ("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>
This is upstream as commit
1adaea51c61b5 ("ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT")
and should be backported down to v6.12 due to the fixes tag. RT wise it
should be broken since its introduction so if the stable team could take
it down to v5.10-rt, that would be nice.
Sebastian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-01-12 15:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23 5:14 [PATCH net v4] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT Jiayuan Chen
2025-12-30 11:20 ` patchwork-bot+netdevbpf
2026-01-12 15:49 ` Sebastian Andrzej Siewior
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox