mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@nvidia.com>
To: "Xiang Mei (Microsoft)" <xmei5@asu.edu>
Cc: David Ahern <dsahern@kernel.org>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	AutonomousCodeSecurity@microsoft.com,
	tgopinath@linux.microsoft.com, kys@microsoft.com
Subject: Re: [PATCH net 1/2] nexthop: take nh->lock for f6i_list walks in replace check and notify
Date: Thu, 23 Jul 2026 22:19:59 +0300	[thread overview]
Message-ID: <20260723191959.GA3531265@shredder> (raw)
In-Reply-To: <20260722002951.2614721-1-xmei5@asu.edu>

On Wed, Jul 22, 2026 at 12:29:50AM +0000, Xiang Mei (Microsoft) wrote:
> fib6_check_nh_list() and __nexthop_replace_notify() walk nh->f6i_list
> during an RTNL-serialized nexthop replace without holding nh->lock. IPv6
> RTM_NEWROUTE/RTM_DELROUTE run without RTNL and mutate that list under
> nh->lock (fib6_add_rt2node_nh(), fib6_purge_rt()), so both walks race a
> concurrent route delete that unlinks and frees a fib6_info:
> 
>   BUG: KASAN: slab-use-after-free in rt6_fill_node.isra.0 (net/ipv6/route.c:5799)
>   Read of size 4 at addr ffff888014607e64 by task exploit/143
>    rt6_fill_node.isra.0 (net/ipv6/route.c:5799)
>    fib6_rt_update (net/ipv6/route.c:6412)
>    __nexthop_replace_notify (net/ipv4/nexthop.c:2542)
>    rtm_new_nexthop (net/ipv4/nexthop.c:2554)
>    rtnetlink_rcv_msg (net/core/rtnetlink.c:7076)
> 
>   BUG: KASAN: slab-use-after-free in fib6_check_nh_list (net/ipv4/nexthop.c:1605)
>   Read of size 8 at addr ffff888014a7d068 by task exploit/142
>    fib6_check_nh_list (net/ipv4/nexthop.c:1605)
>    rtm_new_nexthop (net/ipv4/nexthop.c:2575)
>    rtnetlink_rcv_msg (net/core/rtnetlink.c:7076)
> 
> Both walks only read the entries and take no tb6_lock, so protect them
> with nh->lock; fib6_rt_update() uses gfp_any(), which returns GFP_ATOMIC
> under the lock.
> 
> Fixes: 081efd18326e ("ipv6: Protect nh->f6i_list with spinlock and flag.")
> Reported-by: AutonomousCodeSecurity@microsoft.com
> Signed-off-by: Xiang Mei (Microsoft) <xmei5@asu.edu>
> ---
>  net/ipv4/nexthop.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 6205bd57aa85..c1d3b7d7100d 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c
> @@ -1597,14 +1597,21 @@ static int fib6_check_nh_list(struct nexthop *old, struct nexthop *new,
>  			      struct netlink_ext_ack *extack)
>  {
>  	struct fib6_info *f6i;
> +	int err = 0;
>  
>  	if (list_empty(&old->f6i_list))
>  		return 0;
>  
> +	spin_lock_bh(&old->lock);
>  	list_for_each_entry(f6i, &old->f6i_list, nh_list) {
> -		if (check_src_addr(&f6i->fib6_src.addr, extack) < 0)
> -			return -EINVAL;
> +		err = check_src_addr(&f6i->fib6_src.addr, extack);
> +		if (err)
> +			break;
>  	}
> +	spin_unlock_bh(&old->lock);
> +
> +	if (err)
> +		return err;
>  
>  	return fib6_check_nexthop(new, NULL, extack);
>  }
> @@ -2538,8 +2545,10 @@ static void __nexthop_replace_notify(struct net *net, struct nexthop *nh,
>  			fi->nh_updated = false;
>  	}
>  
> +	spin_lock_bh(&nh->lock);
>  	list_for_each_entry(f6i, &nh->f6i_list, nh_list)
>  		fib6_rt_update(net, f6i, info);
> +	spin_unlock_bh(&nh->lock);

I read the feedback from Sashiko, but even if we convert this list to
RCU we would need GFP_ATOMIC. I don't find __nexthop_replace_notify()
too interesting given that modern systems unset
net.ipv4.nexthop_compat_mode, which means that this function is never
called.

Reviewed-by: Ido Schimmel <idosch@nvidia.com>

>  }
>  
>  /* send RTM_NEWROUTE with REPLACE flag set for all FIB entries
> -- 
> 2.43.0
> 

  parent reply	other threads:[~2026-07-23 19:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  0:29 Xiang Mei (Microsoft)
2026-07-22  0:29 ` [PATCH net 2/2] nexthop: avoid unlocked f6i_list walk in nh_rt_cache_flush Xiang Mei (Microsoft)
2026-07-23 19:20   ` Ido Schimmel
2026-07-23 19:19 ` Ido Schimmel [this message]
2026-07-24 22:10 ` [PATCH net 1/2] nexthop: take nh->lock for f6i_list walks in replace check and notify patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260723191959.GA3531265@shredder \
    --to=idosch@nvidia.com \
    --cc=AutonomousCodeSecurity@microsoft.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=tgopinath@linux.microsoft.com \
    --cc=xmei5@asu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®