Skip to contentSkip to conversation

icmp: Fix icmp error source address over xfrm tunnel

PATCH Applied Antony Antony 4 participants 6 messages Feb 26 – Feb 28

Subsystems (4)
lore
Share & tools
lore
#1 lore raw

PATCH v5 1/2 icmp: fix ICMP error source address when xfrm policy matches

In reply to Antony Antony

When an IPsec gateway generates an ICMP error (e.g., Destination Host Unreachable), the source address incorrectly shows the unreachable destination instead of the gateway's address. IPv6 behaves correctly.

Before fix:
ping 10.1.6.3
From 10.1.6.3 icmp_seq=1 Destination Host Unreachable (wrong - 10.1.6.3 is the unreachable host)

After fix:
ping 10.1.6.3
From 10.1.5.2 icmp_seq=1 Destination Host Unreachable (correct - 10.1.5.2 is the gateway)

The fix removes the memcpy that overwrote fl4 with fl4_dec after xfrm_lookup(). A follow-up commit adds a selftest.

Fixes 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")
Cc [email protected] # Avoid false positives in tests
---
 net/ipv4/icmp.c | 1 -
 1 file changed, 1 deletion(-)
net/ipv4/icmp.c +0 -1
index 19c9c838967f..4bd421208ce0 100644
@@ -569,7 +569,6 @@ static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4,
 	rt2 = dst_rtable(dst2);
 	if (!IS_ERR(dst2)) {
 		dst_release(&rt->dst);
-		memcpy(fl4, &fl4_dec, sizeof(*fl4));
 		rt = rt2;
 	} else if (PTR_ERR(dst2) == -EPERM) {
 		if (rt)

--
2.39.5

#3 lore raw

PATCH v5 2/2 selftests: net: add ICMP error source address test over xfrm tunnel

In reply to Antony Antony

Test that ICMP error messages generated by an IPsec gateway use the correct source address (the gateway's address, not the unreachable destination).

---
v1->v2 : add kernel selftest script, Jakub's feedbak
v2->v3 : fix test script. The IFS, space, got mangled. v3->v4 : added MTU tests
- fix test script based on reviews
https://lore.kernel.org/all/f820e0e9f80b1467f97d1408f00f61b1fdb1b986.1769595011.git.antony.antony@secunet.com/
v4->v5 : fix shellcheck reported warnings and errors, Jakub's feedbak

---
 tools/testing/selftests/net/Makefile      |   1 +
 tools/testing/selftests/net/xfrm_state.sh | 613 ++++++++++++++++++++++
 2 files changed, 614 insertions(+)
 create mode 100755 tools/testing/selftests/net/xfrm_state.sh
tools/testing/selftests/net/Makefile +1 -0
index afdea6d95bde..c8f4d5e19d19 100644
@@ -119,6 +119,7 @@ TEST_PROGS := \
 	vrf_route_leaking.sh \
 	vrf_strict_mode_test.sh \
 	xfrm_policy.sh \
+	xfrm_state.sh \
 # end of TEST_PROGS
 
 TEST_PROGS_EXTENDED := \
tools/testing/selftests/net/xfrm_state.sh new file +613 -0

613 lines not on this page · raw message

--
2.39.5

#0 lore raw

v5 cover icmp: Fix icmp error source address over xfrm tunnel

icmp: Fix icmp error source address over xfrm tunnel

This fix, originally sent to XFRM/IPsec, has been recommended by Steffen Klassert to submit to the net tree, since it changes ICMP behavior.

The patch addresses a minor issue related to the IPv4 source address of ICMP error messages. The bug only occurs when xfrm policies are configured. It originated from an old 2011 commit:

commit 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")

Submitting to net-next with a selftest.

v1->v2 : add kernel selftest script
v2->v3 : fix test script.
v3->v4 : fix test script based on reviews
- clarify commit message
- Changed subsystem prefix to icmp: since fix is in net/ipv4/icmp.c
v4->v5 : fix shellcheck warnings

Antony Antony (2):
icmp: fix ICMP error source address when xfrm policy matches
selftests: net: add ICMP error source address test over xfrm tunnel

 net/ipv4/icmp.c                           |   1 -
 tools/testing/selftests/net/Makefile      |   1 +
 tools/testing/selftests/net/xfrm_state.sh | 613 ++++++++++++++++++++++
 3 files changed, 614 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/xfrm_state.sh

--
2.39.5

#4 lore raw
Quoted 11 lines · Antony Antony via Devel


icmp: Fix icmp error source address over xfrm tunnel

This fix, originally sent to XFRM/IPsec, has been recommended by Steffen Klassert to submit to the net tree, since it changes ICMP behavior.

Quoted 6 lines

The patch addresses a minor issue related to the IPv4 source address of ICMP error messages. The bug only occurs when xfrm policies are configured. It originated from an old 2011 commit:

commit 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")

This bug has been confusing me for many years and I slays blamed libreswan for it. Thanks for fixing it!

Paul

maintainer Reviewed-by on v5 1/2
#2 lore raw

Re: [PATCH net-next v5 1/2] icmp: fix ICMP error source address when xfrm policy matches

In reply to Antony Antony
Quoted 17 lines · Antony Antony

When an IPsec gateway generates an ICMP error (e.g., Destination Host Unreachable), the source address incorrectly shows the unreachable destination instead of the gateway's address. IPv6 behaves correctly.

Before fix:
ping 10.1.6.3
From 10.1.6.3 icmp_seq=1 Destination Host Unreachable (wrong - 10.1.6.3 is the unreachable host)

After fix:
ping 10.1.6.3
From 10.1.5.2 icmp_seq=1 Destination Host Unreachable (correct - 10.1.5.2 is the gateway)

The fix removes the memcpy that overwrote fl4 with fl4_dec after xfrm_lookup(). A follow-up commit adds a selftest.

Quoted 8 lines
Fixes 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")
Cc [email protected] # Avoid false positives in tests
---
 net/ipv4/icmp.c | 1 -
 1 file changed, 1 deletion(-)
#5 lore raw
In reply to Antony Antony
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Thu, 26 Feb 2026 11:29:51 +0100 you wrote:

icmp: Fix icmp error source address over xfrm tunnel

This fix, originally sent to XFRM/IPsec, has been recommended by Steffen Klassert to submit to the net tree, since it changes ICMP behavior.

The patch addresses a minor issue related to the IPv4 source address of ICMP error messages. The bug only occurs when xfrm policies are configured. It originated from an old 2011 commit:

[...]

Here is the summary with links:
- [net-next,v5,1/2] icmp: fix ICMP error source address when xfrm policy matches

    https://git.kernel.org/netdev/net-next/c/595da751c822
  - [net-next,v5,2/2] selftests: net: add ICMP error source address test over xfrm tunnel
    https://git.kernel.org/netdev/net-next/c/5b43d35e571f

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html