All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net v3 0/3] net/ipv6: don't route packets with unknown source address
@ 2026-10-28 19:10 Íñigo Huguet
  2026-10-28 19:10 ` [PATCH net v3 1/3] net/ipv6: add ipv6_chk_addr_namespace Íñigo Huguet
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Íñigo Huguet @ 2026-10-28 19:10 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrew Lunn, Andrii Nakryiko, Daniel Borkmann,
	David Ahern, David S. Miller, Eduard Zingerman, Eric Dumazet,
	Florian Westphal, Ido Schimmel, Jakub Kicinski,
	Kumar Kartikeya Dwivedi, Neal Cardwell, Pablo Neira Ayuso,
	Paolo Abeni, Shuah Khan, Willem de Bruijn
  Cc: Íñigo Huguet, bpf, Breno Leitao, coreteam,
	Emil Tsalapatis, Fernando Fernandez Mancera, Ihor Solodrai,
	Jeff Layton, Jiri Olsa, Joe Damato, John Fastabend, Junseo Lim,
	Kees Cook, Kuniyuki Iwashima, Leon Hwang, Li RongQing,
	linux-kselftest, Martin KaFai Lau, netdev, netfilter-devel,
	Phil Sutter, Qi Tang, Sebastian Andrzej Siewior, Simon Horman,
	Song Liu, Stanislav Fomichev, Willem de Bruijn, Xuanqiang Luo,
	Yonghong Song, Íñigo Huguet, Davide Caratti

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


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

end of thread, other threads:[~2026-10-29 19:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 19:10 [PATCH net v3 0/3] net/ipv6: don't route packets with unknown source address Íñigo Huguet
2026-10-28 19:10 ` [PATCH net v3 1/3] net/ipv6: add ipv6_chk_addr_namespace Íñigo Huguet
2026-10-28 19:10 ` [PATCH net v3 2/3] net/ipv6: don't route packets with unknown source address Íñigo Huguet
2026-10-29  0:02   ` Kuniyuki Iwashima
2026-10-29  6:28     ` Íñigo Huguet
2026-10-29 19:12   ` sashiko-bot
2026-10-28 19:10 ` [PATCH net v3 3/3] selftests: net: add tests for saddr, anycast and loopback subnets Íñigo Huguet
2026-10-29 19:12   ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.