netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
@ 2025-12-19  2:51 Jiayuan Chen
  2025-12-22  8:50 ` Eric Dumazet
  0 siblings, 1 reply; 5+ messages in thread
From: Jiayuan Chen @ 2025-12-19  2:51 UTC (permalink / raw)
  To: netdev
  Cc: Jiayuan Chen, syzbot+9b35e9bc0951140d13e6, David S. Miller,
	David Ahern, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Sebastian Andrzej Siewior, Clark Williams,
	Steven Rostedt, 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:
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()")
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>

---
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..9e7afda7cba2 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.
+		 */
+		BUG_ON(!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] 5+ messages in thread

* Re: [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
  2025-12-19  2:51 [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT Jiayuan Chen
@ 2025-12-22  8:50 ` Eric Dumazet
  2025-12-22 17:16   ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2025-12-22  8:50 UTC (permalink / raw)
  To: Jiayuan Chen
  Cc: netdev, syzbot+9b35e9bc0951140d13e6, David S. Miller, David Ahern,
	Jakub Kicinski, Paolo Abeni, Simon Horman,
	Sebastian Andrzej Siewior, Clark Williams, Steven Rostedt,
	linux-kernel, linux-rt-devel

On Fri, Dec 19, 2025 at 3:52 AM Jiayuan Chen <jiayuan.chen@linux.dev> 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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
  2025-12-22  8:50 ` Eric Dumazet
@ 2025-12-22 17:16   ` Steven Rostedt
  2025-12-22 17:26     ` Steven Rostedt
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2025-12-22 17:16 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jiayuan Chen, netdev, syzbot+9b35e9bc0951140d13e6,
	David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Sebastian Andrzej Siewior, Clark Williams,
	linux-kernel, linux-rt-devel

On Mon, 22 Dec 2025 09:50:58 +0100
Eric Dumazet <edumazet@google.com> wrote:

> > 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.

Ack!

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
  2025-12-22 17:16   ` Steven Rostedt
@ 2025-12-22 17:26     ` Steven Rostedt
  2025-12-23  2:38       ` Jiayuan Chen
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2025-12-22 17:26 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jiayuan Chen, netdev, syzbot+9b35e9bc0951140d13e6,
	David S. Miller, David Ahern, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Sebastian Andrzej Siewior, Clark Williams,
	linux-kernel, linux-rt-devel

On Mon, 22 Dec 2025 12:16:39 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Mon, 22 Dec 2025 09:50:58 +0100
> Eric Dumazet <edumazet@google.com> wrote:
> 
> > > 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.  
> 
> Ack!

Fixes: d2d6422f8bd1 ("x86: Allow to enable PREEMPT_RT.")

That was the first commit to enable PREEMPT_RT on any architecture (just
happened to be x86).

-- Steve

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT
  2025-12-22 17:26     ` Steven Rostedt
@ 2025-12-23  2:38       ` Jiayuan Chen
  0 siblings, 0 replies; 5+ messages in thread
From: Jiayuan Chen @ 2025-12-23  2:38 UTC (permalink / raw)
  To: Steven Rostedt, Eric Dumazet
  Cc: netdev, syzbot+9b35e9bc0951140d13e6, David S. Miller, David Ahern,
	Jakub Kicinski, Paolo Abeni, Simon Horman,
	Sebastian Andrzej Siewior, Clark Williams, linux-kernel,
	linux-rt-devel

December 23, 2025 at 01:26, "Steven Rostedt" <rostedt@goodmis.org mailto:rostedt@goodmis.org?to=%22Steven%20Rostedt%22%20%3Crostedt%40goodmis.org%3E > wrote:


> 
> On Mon, 22 Dec 2025 12:16:39 -0500
> Steven Rostedt <rostedt@goodmis.org> wrote:
> 
> > 
> > On Mon, 22 Dec 2025 09:50:58 +0100
> >  Eric Dumazet <edumazet@google.com> wrote:
> >  
> >  > 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. 
> >  
> >  Ack!
> > 
> Fixes: d2d6422f8bd1 ("x86: Allow to enable PREEMPT_RT.")
> 
> That was the first commit to enable PREEMPT_RT on any architecture (just
> happened to be x86).
> 
> -- Steve
>

Thanks Steve, it helped a lot !

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-12-23  2:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-19  2:51 [PATCH net v2] ipv6: fix a BUG in rt6_get_pcpu_route() under PREEMPT_RT Jiayuan Chen
2025-12-22  8:50 ` Eric Dumazet
2025-12-22 17:16   ` Steven Rostedt
2025-12-22 17:26     ` Steven Rostedt
2025-12-23  2:38       ` Jiayuan Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).