Skip to contentSkip to conversation

icmp: Fix icmp error source address over xfrm tunnel

PATCH Superseded Antony Antony 5 participants 9 messages Jan 28 – Feb 2

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover 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.

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 | 578 ++++++++++++++++++++++
 3 files changed, 579 insertions(+), 1 deletion(-)
 create mode 100755 tools/testing/selftests/net/xfrm_state.sh

---
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

-antony

#1 lore raw

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

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

maintainer
#2 lore raw

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

Quoted 4 lines · On Wed, 28 Jan 2026 11:25:14 +0100 Antony Antony wrote:

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

Fixes 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")
Cc [email protected] # Avoid false positives in tests

I don't understand what you're trying to express with all these tags. We are sending incorrect ICMP packets, seems like a normal net-worthy fix to me?

#3 lore raw

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

Hi Jakub,

Quoted 9 lines · Jakub Kicinski via Devel
Quoted 4 lines · On Wed, 28 Jan 2026 11:25:14 +0100 Antony Antony wrote:

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

Fixes 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")
Cc [email protected] # Avoid false positives in tests

I don't understand what you're trying to express with all these tags. We are sending incorrect ICMP packets, seems like a normal net-worthy fix to me?

You're right that we're sending incorrect ICMP packets when IPsec/xfrm is enabled and this is a legitimate fix. My concern with backporting is about potential disruption rather than the correctness of the fix itself. The issue is that some existing test scripts and monitoring tools may have hardcoded expectations for the current(incorrect) source address behavior. When this one-line fix gets backported to all maintained kernels, those tests would start failing, potentially triggering regression reports and requests to revert the fix from stable kernels.

Additionally, without the
commit 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages") being present in older kernels, the behavior change could be viewed differently in stable branches.

This is also the sense I got from IPsec users.
Given these considerations, I opted for the safer path of targeting net-next with stable+noautosel, no backporting.

-antony

#4 lore raw

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

Quoted 22 lines · Antony Antony via Devel

Hi Jakub,

Quoted 9 lines · Jakub Kicinski via Devel
Quoted 4 lines · On Wed, 28 Jan 2026 11:25:14 +0100 Antony Antony wrote:

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

Fixes 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")
Cc [email protected] # Avoid false positives in tests

I don't understand what you're trying to express with all these tags. We are sending incorrect ICMP packets, seems like a normal net-worthy fix to me?

You're right that we're sending incorrect ICMP packets when IPsec/xfrm is enabled and this is a legitimate fix. My concern with backporting is about potential disruption rather than the correctness of the fix itself. The issue is that some existing test scripts and monitoring tools may have hardcoded expectations for the current(incorrect) source address behavior. When this one-line fix gets backported to all maintained kernels, those tests would start failing, potentially triggering regression reports and requests to revert the fix from stable kernels.

Quoted 8 lines

Additionally, without the
commit 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages") being present in older kernels, the behavior change could be viewed differently in stable branches.

This is also the sense I got from IPsec users.
Given these considerations, I opted for the safer path of targeting net-next with stable+noautosel, no backporting.

libreswan is unaffected, other than the old code showing a weird unexplainable log message. So we are not really affected by whether or not this get backported. We would slightly prefer the backport just to get proper icmp messages out there (and we might need to fix a few test cases but that is okay with us). If someone reaches out with strong arguments to not backport, we would be fine with not doing it.

Paul

#5 lore raw

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

Quoted 33 lines · Paul Wouters
Quoted 22 lines · Antony Antony via Devel

Hi Jakub,

Quoted 9 lines · Jakub Kicinski via Devel
Quoted 4 lines · On Wed, 28 Jan 2026 11:25:14 +0100 Antony Antony wrote:

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

Fixes 415b3334a21a ("icmp: Fix regression in nexthop resolution during replies.")
Cc [email protected] # Avoid false positives in tests

I don't understand what you're trying to express with all these tags. We are sending incorrect ICMP packets, seems like a normal net-worthy fix to me?

You're right that we're sending incorrect ICMP packets when IPsec/xfrm is enabled and this is a legitimate fix. My concern with backporting is about potential disruption rather than the correctness of the fix itself. The issue is that some existing test scripts and monitoring tools may have hardcoded expectations for the current(incorrect) source address behavior. When this one-line fix gets backported to all maintained kernels, those tests would start failing, potentially triggering regression reports and requests to revert the fix from stable kernels.

Quoted 8 lines

Additionally, without the
commit 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages") being present in older kernels, the behavior change could be viewed differently in stable branches.

This is also the sense I got from IPsec users.
Given these considerations, I opted for the safer path of targeting net-next with stable+noautosel, no backporting.

Quoted 6 lines

libreswan is unaffected, other than the old code showing a weird unexplainable log message. So we are not really affected by whether or not this get backported. We would slightly prefer the backport just to get proper icmp messages out there (and we might need to fix a few test cases but that is okay with us). If someone reaches out with strong arguments to not backport, we would be fine with not doing it.

I think the main concern is that without Antony's patch that adds ICMP forwarding via reverse lookup (63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages")), which was not backported, packets with the correct source IP will not get tunneled if the gateway's IP is not contained in the traffic selectors. So if at all, backporting should only be considered to v6.9+ and not anything earlier (the commit Antony's Fixes tag references, 415b3334a21a, was released with v3.1).

Regards,
Tobias

#6 lore raw

PATCH v4 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
v2->v3 : fix test script. The IFS, space, got mangled. v3->v4 : added MTU tests
- fix test script based on reviews

---
 tools/testing/selftests/net/Makefile      |   1 +
 tools/testing/selftests/net/xfrm_state.sh | 578 ++++++++++++++++++++++
 2 files changed, 579 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 +578 -0

578 lines not on this page · raw message

--
2.39.5

maintainer
#7 lore raw

Re: [PATCH net-next v4 2/2] selftests: net: add ICMP error source address test over xfrm tunnel

Quoted 3 lines · On Wed, 28 Jan 2026 11:20:45 +0100 Antony Antony wrote:

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

could you check / fix shellcheck warnings?

+In xfrm_state.sh line 115:
+ $ksft_skip)
+ ^--------^ SC2254 (warning): Quote expansions in case patterns to match literally rather than as a glob.

+In xfrm_state.sh line 157:
+ [ -n "${NS_R1}" ] && ns_r1="ip netns exec ${NS_R1}" && ns_active="${ns_active} $NS_R1"
+ ^---^ SC2034 (warning): ns_r1 appears unused. Verify use (or export if used externally).
+
+
+In xfrm_state.sh line 162:
+ [ -n "${NS_B}" ] && ns_b="ip netns exec ${NS_B}" && ns_active="${ns_active} $NS_B"
+ ^--^ SC2034 (warning): ns_b appears unused. Verify use (or export if used externally).

+In xfrm_state.sh line 166:
+ local ns_cmd=$(nscmd $1)
+ ^----^ SC2155 (warning): Declare and assign separately to avoid masking return values.

Signature · 1 line
pw-bot: cr
#8 lore raw

Re: [devel-ipsec] Re: [PATCH net-next v4 2/2] selftests: net: add ICMP error source address test over xfrm tunnel

Quoted 6 lines · Jakub Kicinski via Devel
Quoted 3 lines · On Wed, 28 Jan 2026 11:20:45 +0100 Antony Antony wrote:

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

could you check / fix shellcheck warnings?

lots of warnings. It looks like x-mas lights are still on:)

Review

Quoted 4 lines
(quoted diff) +3 -0
+In xfrm_state.sh line 115:
+	$ksft_skip)
+        ^--------^ SC2254 (warning): Quote expansions in case patterns to match literally rather than as a glob.

I will add quotes to. Thare 30-40 of those!

Review

Quoted 13 lines
(quoted diff) +11 -0
+In xfrm_state.sh line 157:
+	[ -n "${NS_R1}" ] && ns_r1="ip netns exec ${NS_R1}" && ns_active="${ns_active} $NS_R1"
+                             ^---^ SC2034 (warning): ns_r1 appears unused. Verify use (or export if used externally).
+
+
+In xfrm_state.sh line 162:
+	[ -n "${NS_B}" ] && ns_b="ip netns exec ${NS_B}" && ns_active="${ns_active} $NS_B"
+                            ^--^ SC2034 (warning): ns_b appears unused. Verify use (or export if used externally).
 
+In xfrm_state.sh line 166:
+	local ns_cmd=$(nscmd $1)
+              ^----^ SC2155 (warning): Declare and assign separately to avoid masking return values.

other shell checks are harder to fix.

+In xfrm_state.sh line 417:
test_unreachable_ipv6() {
^-- SC2329 (info): This function is never invoked. Check usage (or ignored if invoked indirectly).

those are invoked indirectly. eval code I would like to keep. Would that work for you? are you aiming fori strictly zero warnings?

regards,
-antony