🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #8347

[PATCH net v3 0/3] net/ipv6: don't route packets with unknown source address

#8347
From: Íñigo Huguet
Date: Wed, 28 Oct 2026 19:10
104 lines
14242 bytes
Don't allow routing packets with a source address that is not configured
in the host. Allow it only in certain cases like when using a
transparent socket, by setting the ANYSRC flag in flowi_flags.

Main reasons (see full explanation in the 2nd patch):
- Alignment with IPv4 stack
- Compliance with RFC 4862 (an invalid address MUST NOT be used as the
  source address of outbound packets)
- Meet expectations of stop using an address after removing it or its
  expiration lifetime.

Added selftests covering the patch, and also its IPv4 counterpart which
had no tests covering it. I also added selftests covering 2 features
that were impacted by v2 and discovered at review: anycast and loopback
subnets.

The change in the netfilter's ip6_route_me_harder function is the one
that I'm more unsure about. It was not clear to me the reason why it was
done like this in the IPv4 counterpart. Please review carefully.

Testing: tested with a manual reproducer executing the steps described
in the patch. Tested also with transparent sockets to ensure that the
packets are sent in that case. Also executed the following selftests
to prevent potential regressions: net/*, net/forwarding/* and
net/netfilter/*. I also ran Sashiko locally and applied most of its
change proposals.

I ignored on purpose some review comments from Sashiko saying that
the ANYSRC flag must be set in some additional places. The reasoning
to ignore them is that they are neither set in IPv4. If they were
not needed in IPv4 where the source address check has been in place
for many years, probably they are neither needed in the IPv6
counterpart. These are the functions where I ignored Sashiko's
comments:
- sctp_v6_get_dst
- nat_keepalive_send_ipv6
- rxe_find_route6
- tipc_udp_xmit

Signed-off-by: Íñigo Huguet <ihuguet@riseup.net>

---

v3:
 - Fixed errors in the selftest xfrm_state by setting ANYSRC in
   icmpv6_route_lookup.
 - Fixed errors in the selftest vrf_route_leaking by searching the
   address in the entire namespace, not in a specific L3 domain.
 - Fixed loopback subnets (AnyIP) by adding a fallback to FIB local
   routes if the exact address is not present.
 - Fixed anycast address as source address by using ipv6_chk_acast_addr_src.
 - Fixed TCP responses in timewait sockets by using inet_sk_transparent
   if !sk_fullsock.
 - Added forgotten flag in the IPv6 branch of bpf_skb_set_tunnel_key.
 - Added many selftests:
   - No tests existed for "check source address on ongoing packets",
     neither for IPv4. Added them.
   - No tests existed for anycast and loopback subnets, so I didn't
     detected it in v2. Added tests for both features.
v2: https://lore.kernel.org/netdev/20260903121057.80006-1-ihuguet@riseup.net/
v1: https://lore.kernel.org/netdev/20260901115021.50057-1-ihuguet@riseup.net/

Íñigo Huguet (3):
  net/ipv6: add ipv6_chk_addr_namespace
  net/ipv6: don't route packets with unknown source address
  selftests: net: add tests for saddr, anycast and loopback subnets

 drivers/net/vrf.c                             |   1 +
 include/net/addrconf.h                        |   4 +-
 net/core/filter.c                             |   1 +
 net/core/lwt_bpf.c                            |   1 +
 net/ipv6/addrconf.c                           |  76 ++-
 net/ipv6/af_inet6.c                           |   1 +
 net/ipv6/anycast.c                            |   2 +-
 net/ipv6/datagram.c                           |   3 +-
 net/ipv6/icmp.c                               |   5 +
 net/ipv6/inet6_connection_sock.c              |   2 +
 net/ipv6/ip6_output.c                         |  38 ++
 net/ipv6/ip6_tunnel.c                         |  10 +-
 net/ipv6/ip6_udp_tunnel.c                     |   1 +
 net/ipv6/ndisc.c                              |   2 +-
 net/ipv6/netfilter.c                          |  11 +-
 net/ipv6/ping.c                               |   1 +
 net/ipv6/raw.c                                |   1 +
 net/ipv6/route.c                              |   4 +-
 net/ipv6/syncookies.c                         |   1 +
 net/ipv6/tcp_ipv6.c                           |   7 +-
 net/ipv6/udp.c                                |   1 +
 net/l2tp/l2tp_ip6.c                           |   2 +
 tools/testing/selftests/net/.gitignore        |   1 +
 tools/testing/selftests/net/Makefile          |   4 +
 tools/testing/selftests/net/ip_saddr.c        | 557 +++++++++++++++++
 tools/testing/selftests/net/ip_saddr.sh       | 575 ++++++++++++++++++
 tools/testing/selftests/net/ipv6_anycast.sh   |  68 +++
 .../testing/selftests/net/loopback_subnet.sh  | 135 ++++
 28 files changed, 1472 insertions(+), 43 deletions(-)
 create mode 100644 tools/testing/selftests/net/ip_saddr.c
 create mode 100755 tools/testing/selftests/net/ip_saddr.sh
 create mode 100755 tools/testing/selftests/net/ipv6_anycast.sh
 create mode 100755 tools/testing/selftests/net/loopback_subnet.sh

-- 
2.54.0
Technical Details
Message-ID: <20261028191103.623156-1-ihuguet@riseup.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-353003-linux-kernel-netdev=dewy.ru

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-353003-linux-kernel-netdev=dewy.ru
From: ihuguet@riseup.net (Íñigo Huguet)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3 0/3] net/ipv6: don't route packets with unknown source address
Date: Wed, 28 Oct 2026 20:10:54 +0100
Organization: Usenet Network
Message-ID: <20261028191103.623156-1-ihuguet@riseup.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1853891"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:qsS/p3RCMqqY+IKZNehoHvsVzic= sha256:2l49XzKQ6rg1ap80951CNFiVB5jROSSH/Z18h80OCo4=
	sha1:mt7GWCNGtTpuu+Y2ZUxj+2fpsLY= sha256:DCfPBvhek+DKF1NpR7laKAzNX4gNQJsKTbaU+tluf4Q=
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 D830C125C46; Wed, 28 Oct 2026 22:43:43 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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.25,
	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=riseup.net
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 AMxXI2_M8pfJ;
	Wed, 28 Oct 2026 22:43:36 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-353003-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=riseup.net
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id 76C1D125C44; Wed, 28 Oct 2026 22:43:24 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 8973A31B03; Wed, 28 Oct 2026 19:13:47 +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=1793214736;
	b=sfvk9aRq7JbrrwJg9D6UvtxuyibITEklkiDAT78Nja7lOAl5JQCk2JD03umcpeIw9tTn
	 X3Z1xeKYnu2d7zR3lLr0OIDpMapOFpz6XhCslpg7vssPevNWZLl49lTDoH24k2KbckAAq
	 L65sJpn/xNiX4jDquHen2KmR6RUMdNkZ73cG8Yv4NGFLWdOv31xQtTwu43k5S0vimVHbB
	 eOsRVvtYTYAghip0BdqDvmQNrnMnuXbVJsi7DmykQFEL3fM3/T1YvX9lgIR5HXyGRnGvv
	 F0wgAjxm+d2dGf0akFRny4RYrpQc7v1zc7+t+rKnVhFI0DQ7JC/J+mquiAEanJ29IWQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793214736;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:Received:
	 X-Riseup-User-ID:Received:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=5jfLFSb5rkOZeeRJ6bNDFFfzg/eaqfFeembrXBnz8dw=;
	b=o1EWzhU3moTw7weF59ND1FwSji32CPoGH5EUcPOw8OJ2vRG9xu63476/JGDlIyJ9mMYt
	 C91e02gUmXK8t3t84G+5edPEttp8Bt+aiXKGzUE03lUq46mZZPaJrc2UhveJ+8+ezZrAV
	 J0vJbhVXB9A/ovLSylALyXgB0gxQ4y71KZUX91legZ/5mzNfoTLWwP9ukyNTrvYFIwrjY
	 VVqcCTJBQAeKKXtcNFjuYqwqqmGxDFy45nZ8lwYmQqNjLyZQqFQxXm6d7jBjPWUijfyeW
	 6Sgm4SL75lXqGXz9LZ4CUUQEudxEsiwVWH4vBh2R+QXnjQ4lw22g7K28AeXdPI4NRNw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=riseup.net header.i=@riseup.net header.a=rsa-sha256 header.s=squak header.b=BtlwtGs3;
	dmarc=pass header.from=riseup.net;
	spf=pass smtp.mailfrom=riseup.net;
	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 0128F60A2609;
	Wed, 28 Oct 2026 19:12:16 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=riseup.net header.i=@riseup.net header.a=rsa-sha256 header.s=squak header.b=BtlwtGs3
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.252.153.6
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793214725;
	b=ckz48ooUWvEenWGCBv0pAcIrOttBZIT5PrPu4C7OhfEHivHXkxzCzBp3s9OHLMGakCJW
	 O0TKzaP96o+4OWY0tEl4Hx5KikUaLFs44dNq7viP1G3iT3rMEbcYVybhccjEogE7pZ0i0
	 uRCeQPhhoCA+k+yxJddUgPvFzOvO+Vl+BZBQOLXYO4QrM3el58LdMoECx7+zXE2rYKzpD
	 hL5ScQM+cae56GiQradrbERFshdfGdlhOMqGYYfnl5n1n06OBPfwmPwczKd5CScc0le/n
	 6j0Rmpxn41NvXE+Jh97i+qcLdV+AiUhzJvT/khiroEYJE5l6YVmmmZz9nyuNOlPcOKg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793214725;
	h=DMARC-Filter:DKIM-Signature:Received:X-Riseup-User-ID:Received:From:
	 To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type:
	 Content-Transfer-Encoding;
	bh=5jfLFSb5rkOZeeRJ6bNDFFfzg/eaqfFeembrXBnz8dw=;
	b=34ooYuRMmrAZJK0LW+edIGucWLhQYIgRH4DjiONef9RsBU89oCzj01Jd7mfVsaagFBMC
	 1FuhVukA9kE0R72JoevpRqdI5WhhIj2RxVROC7Fhkz5e2Aocq4OQ1L/mYWW4omebQ1oN2
	 Z3l+bNbym1T0oZQzUw/NpAUxHQNoYzoffFHL4KvrNZ/BHLtVr4jaqtkFSULkyhMWwUI6x
	 PYiMty658WSrY/q5MwF6ryr83gH5QM5s9SEOSloXIxyOfLPqarvaspxBHTqePDN6VuGvF
	 7PG2nKLS6hCAjNYqZ3pisDFcFYDLIzjuULSf/N89xW4AK8GHX4PH9elnh+DsVJTHtfw==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=riseup.net;
	spf=pass smtp.mailfrom=riseup.net;
	dkim=pass header.d=riseup.net header.i=@riseup.net header.a=rsa-sha256 header.s=squak header.b=BtlwtGs3;
	arc=none smtp.remote-ip=198.252.153.6
X-Received: from mx0.riseup.net (mx0.riseup.net [198.252.153.6])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 903FD606AB00;
	Wed, 28 Oct 2026 19:12:04 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 903FD606AB00
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=riseup.net
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=riseup.net
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=riseup.net; s=squak;
	t=1793214717; bh=5jfLFSb5rkOZeeRJ6bNDFFfzg/eaqfFeembrXBnz8dw=;
	h=From:To:Cc:Subject:Date:From;
	b=BtlwtGs3uTGuD5fwzLJnT3tkyvDzA1IAJWvU/2HikUtU2OQuL1Jt8twHziCEQQs8V
	 mgYz2TmqcXOekJWmSphzTWDhR25n9U8kuNG1X+onPk46PI7tx6MICKVIe9lKuCiojD
	 G44cKbqF6+H2PtCZq7LkdfJj0xsNHVtwQLiE21C4=
X-Received: from fews04-sea.riseup.net (fews04-sea-pn.riseup.net [10.0.1.154])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256)
	(No client certificate requested)
	by mx0.riseup.net (Postfix) with ESMTPS id 4jFH6N1swmz9rwx;
	Wed, 28 Oct 2026 19:11:56 +0000 (UTC)
X-Riseup-User-ID: BAF92B9D2CC73FFBF175A220C2F1BA822621BEA57DEEA305E4C26A286727E6F4
X-Received: from [127.0.0.1] (localhost [127.0.0.1])
	 by fews04-sea.riseup.net (Postfix) with ESMTPSA id 4jFH672P44z5vSY;
	Wed, 28 Oct 2026 19:11:43 +0000 (UTC)
X-Cc: Íñigo Huguet <ihuguet@riseup.net>,
	bpf@vger.kernel.org,
	Breno Leitao <leitao@debian.org>,
	coreteam@netfilter.org,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Fernando Fernandez Mancera <fmancera@suse.de>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	Jeff Layton <jlayton@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>,
	Joe Damato <joe@dama.to>,
	John Fastabend <john.fastabend@gmail.com>,
	Junseo Lim <zirajs7@gmail.com>,
	Kees Cook <kees@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Leon Hwang <leon.hwang@linux.dev>,
	Li RongQing <lirongqing@baidu.com>,
	linux-kselftest@vger.kernel.org,
	Martin KaFai Lau <martin.lau@linux.dev>,
	netdev@vger.kernel.org,
	netfilter-devel@vger.kernel.org,
	Phil Sutter <phil@nwl.cc>,
	Qi Tang <tpluszz77@gmail.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Simon Horman <horms@kernel.org>,
	Song Liu <song@kernel.org>,
	Stanislav Fomichev <sdf@fomichev.me>,
	Willem de Bruijn <willemb@google.com>,
	Xuanqiang Luo <luoxuanqiang@kylinos.cn>,
	Yonghong Song <yonghong.song@linux.dev>,
	Íñigo Huguet <ihuguet@redhat.com>,
	Davide Caratti <dcaratti@redhat.com>
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