🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #12933

Re: [PATCH net v2] ipv6: reject routes without an inet6_dev

#12933
From: Hangbin Liu
Date: Mon, 09 Nov 2026 02:02
100 lines
12295 bytes
On Sun, Nov 08, 2026 at 03:09:36PM +0800, Yingjie Wang wrote:
> ip6_route_output() and ip6_route_lookup() can return an error-free route
> whose rt6i_idev is NULL.  Lowering an external nexthop device's MTU below
> IPV6_MIN_MTU tears down its inet6_dev, while fib6_ifdown() leaves routes
> using nexthop objects in the FIB.
> 
> An unprivileged user with CAP_NET_ADMIN in a private user and network
> namespace can construct this state.  Consumers which treat a route without
> an error as usable can then dereference the NULL rt6i_idev.  This was
> reproduced as a KASAN NULL pointer dereference in ip6_tnl_xmit().
> 
> A similar missing inet6_dev check was fixed in commit 1b9b5323725e
> ("netfilter: ip6t_rpfilter: reject routes without inet6_dev").  However,
> the route construction path still marks routes without an inet6_dev as
> successful, leaving every consumer responsible for the same check.
> 
> Acquire the inet6_dev reference before initializing the destination.  If a
> non-reject route has no inet6_dev, initialize it as RTN_UNREACHABLE instead
> of a successful route.  Explicit reject routes keep their original type and
> error.  This establishes that ordinary error-free IPv6 routes have an
> inet6_dev while retaining the existing defensive checks at callers.
> 
> The modified route object builds cleanly with W=1.  A full x86_64 KASAN
> bzImage build completes; it reports two pre-existing kernel-doc warnings
> outside this change.
> 
> Tests:
>   - `make W=1 net/ipv6/route.o`
>   - full x86_64 KASAN `bzImage` build with `W=1`
>   - KASAN QEMU with an unprivileged user and network namespace: after
>     lowering the MTU, the stale route returned `No route to host`, a normal
>     route still resolved, and the collect_md trigger completed without
>     KASAN, oops, or panic
>   - `tools/testing/selftests/net/ip6_tunnel.sh` in the same KASAN QEMU
> 
> Fixes: 5b98324ebe29 ("ipv6: Allow routes to use nexthop objects")
> Closes: https://lore.kernel.org/netdev/tencent_CB9E1044AC97882719FF3A9F5B410A562408@qq.com/
> Link: https://lore.kernel.org/netdev/DMP4WRIOGMBX.3VW2KNLBGDZ0K@gmail.com/

I think it should be

Closes: https://lore.kernel.org/netdev/DMP4WRIOGMBX.3VW2KNLBGDZ0K@gmail.com/

The Link tag usually added by the bot when maintainer apply your patch.

> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Yingjie Wang <1075151112@qq.com>
> ---
> Changes since v1:
>   - Move the invariant into IPv6 route construction following Alexei
>     Starovoitov's review.
>   - Acquire `rt6i_idev` before destination initialization and preserve the
>     existing handling of explicit reject routes.
>   - Update `Fixes:` to the nexthop-object route support commit.
> 
> v1: https://lore.kernel.org/netdev/tencent_CB9E1044AC97882719FF3A9F5B410A562408@qq.com/
> 
>  net/ipv6/route.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv6/route.c b/net/ipv6/route.c
> index 2eb884558c24..a4c792fc55e3 100644
> --- a/net/ipv6/route.c
> +++ b/net/ipv6/route.c
> @@ -1165,6 +1165,12 @@ static void ip6_rt_init_dst(struct rt6_info *rt, const struct fib6_result *res)
>  		return;
>  	}
>  
> +	/* addrconf_ifdown() removed inet6_dev. The device can't do IPv6. */
> +	if (!rt->rt6i_idev) {
> +		ip6_rt_init_dst_reject(rt, RTN_UNREACHABLE);
> +		return;
> +	}
> +
>  	rt->dst.error = 0;
>  	rt->dst.output = ip6_output;
>  
> @@ -1200,10 +1206,10 @@ static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res)
>  	const struct net_device *dev = nh->fib_nh_dev;
>  	struct fib6_info *f6i = res->f6i;
>  
> +	rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
>  	ip6_rt_init_dst(rt, res);
>  
>  	rt->rt6i_dst = f6i->fib6_dst;
> -	rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
>  	rt->rt6i_flags = res->fib6_flags;
>  	if (nh->fib_nh_gw_family) {
>  		rt->rt6i_gateway = nh->fib_nh_gw6;
> 
> base-commit: 30c71476d842b094651bd7712f6c8ee8716147d0
> -- 
> 2.43.0
> 

The change looks good to me.

Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>
Technical Details
Message-ID: <avEpsZOaaT4qU5q5@fedora>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358965-linux-kernel-netdev=dewy.ru
References: <tencent_3049FF6D9F23419F56589E244420973D2708@qq.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-358965-linux-kernel-netdev=dewy.ru
From: hangbin.liu@linux.dev (Hangbin Liu)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v2] ipv6: reject routes without an inet6_dev
Date: Mon, 9 Nov 2026 10:02:25 +0800
Organization: Usenet Network
Message-ID: <avEpsZOaaT4qU5q5@fedora>
References: <tencent_3049FF6D9F23419F56589E244420973D2708@qq.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: usenet.network;
	logging-data="249503"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:XLQ+yu81RCwURKBz66rLWaemL78= sha256:yJrMXjmCZUydFGHqvrhIllAE6udZEYiU++Zo0BQ1Vqg=
	sha1:V8U8+k+ZZJmzUCg/Eru9FkBddNI= sha256:dFByxeY4HBbLyHSFAczVT6OAVnT2E8lZvKNYReXS6oo=
Content-Disposition: inline
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 29CFB113697; Mon,  9 Nov 2026 05:03:51 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id ubHnaUwgalJf;
	Mon,  9 Nov 2026 05:03:47 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-358965-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id CA36F113691; Mon,  9 Nov 2026 05:03:38 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id EE3CA82C0B; Mon,  9 Nov 2026 02:02:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1794189756;
	b=NFecueNrBIsBhPkInwcmygkH+usjZ3bID72sJzb1E3COTA02xJPkUd484DDlIID3z014
	 2jNv0L3N5muDZoBczaYp8t9U1QiSHwqH6CfwTEgNyFstegFKpQ/hUqKyMNr7/tp/D53f6
	 fcWfXO9swJs6SRp536Ldb7ASpFWmvwNhFV2Txpa5hjcR68OuaZyvMeH/OVElpEMRdvjzi
	 47FdFj4+uEyAUp+PhEgGxOzkmm5LI5n2FDZyonSFVwYp+qJRpUA/lxZSUcq9zrvvvc3Nh
	 y3/WneFW+GP9Ovd8XG0NO0EZKN1Hu/MIdEphs61cqZ3T1rBqXsVDwLHdhzrlyy7emKA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794189756;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:
	 Subject:Message-ID:References:X-Mailing-List:List-Id:List-Post:
	 List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence:
	 MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=FCY5yPy879EivQeygPsO+icoEH2zfLSwy7J7X4i8ETA=;
	b=SqeGcqGAZeVao2Jf03LBS2Wz6qTWRe4zcBuMhjew+5A7iejfFoL/8uzMZ0073QTtbIez
	 FVVul9oLDS4Da9XhJHbryqlh2wJvispKtXBwdmtJhyJjshaHqMD1uewUzVwkYQT1znKl3
	 RgDwouxqM7NxZgbJT1I5o0o8xrBPhuV87LxHLp/dqY/CILts6FFbZHxZw1OMI28Vla+66
	 Rx2gdKXPucmwjc2LDrbqNyoAJSmBRFFndmaEaR1Pa6KB4csk9Rcv97EUI8MPvvScsFrxf
	 oMmZT6E9DDsFOdHYJ8llBwwBQtP9sutcPEj0RJfvqKj83IW0E/Kq5pyQ70fyzIvBmmw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=n35zYBd2;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id C6878606A330;
	Mon,  9 Nov 2026 02:02:36 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=n35zYBd2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.75
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794189755;
	b=puti35IzZ1iF6XCP7CHMT0IkO1roqWIe2EfKWMttjLo9AAEtHe5nzGUUseoHbwNeYJyu
	 HNwtDxZgnB+R+Ln9Fy50Wo96qfSv6glHW0zv4QYTK+7Cw36YS93ZH9F51SX2c5o9sOBgZ
	 giEtGORhU3KyMHh0soaugPiwBYrdQYCXNsk99rEzVOheV40z0/AbbCgqAYdrZVf+GVNtu
	 3GvVJehuHovRXsNm/Kl8l6wWXjNfA1xDtASA3qINnLyQjZl2TOcpgxVaFFH0EH58l/VrT
	 o6G9pKtWYFmnUEdyVggpytU5RgpEJPpGE1+mqe5LpwCRDHJgI76+2cDideJuMY0ZUDg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794189755;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID:
	 References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To;
	bh=FCY5yPy879EivQeygPsO+icoEH2zfLSwy7J7X4i8ETA=;
	b=4grLd0m/NBDJvThciw5+9sQKuL8dSuomK8tYtER1Sec2+QmTFeujLafreEQhBinvJLXs
	 R3M/j5WQIVG4L9vUxbQlkv3f155mKGxoLg1b1AG6J3PgrRaI0XyLypxjgOq1BHK6e9i7Q
	 gIbTNLEEMvmGBkhvNb1NaHNPjgdQNdOJA8cfIC0QWY35xET4ppjAi5m7Kk32B0hRJN51P
	 1SaupJCMUtkz0IFztB2tPo46/9EHW7pmHh4hB2g2CXQiDxcymKx83/MNhcSD5Y5kPEea2
	 fEAWphr2Z8t8URyYJSg/0OPTsewAyclBMJsmBVSX3EVrRl017Ho8hPYKOLrNKvBb2wg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=n35zYBd2;
	arc=none smtp.remote-ip=91.218.175.75
X-Received: from mta0.migadu.com (out-75.mta0.migadu.com [91.218.175.75])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F110606A31C
	for <netdev@vger.kernel.org>; Mon,  9 Nov 2026 02:02:33 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3F110606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=GfGHTZ8GhZ/dheS3M4yY8zDNF5VgOSFkCOtjDoC13jo=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1794189752; v=1; x=1794794552;
 b=n35zYBd2zT5DCe4XqZgcKuz+bYL9BqLGHFI/uKBZqD5H+Mqqz2Vzf1MJ2EKZSYAEhJO8HJ6P
 H9XpVYO+KGZMQJucqGiYgvYx2FgS1el23vaG5fifbXeIQxhIRhNUD59lnfLEljw0eCXiTSr+r6x
 QDvEkKZ8Rk0vOg0WsKhVAY1k=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by mta12.migadu.com with ESMTPS id 2413584100e8a086;
	Mon, 09 Nov 2026 02:02:32 +0000
X-Mizu-Trace-ID: 2413584100e8a086
X-Migadu-Flow: FLOW_OUT
X-Cc: netdev@vger.kernel.org, dsahern@kernel.org, idosch@nvidia.com,
	davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
	pabeni@redhat.com, horms@kernel.org, linux-kernel@vger.kernel.org,
	ast@kernel.org
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <tencent_3049FF6D9F23419F56589E244420973D2708@qq.com>