Skip to contentSkip to conversation

pull request (net): ipsec 2025-09-22

PATCH Applied Steffen Klassert 2 participants 4 messages Sep 22, 2025 – Sep 23, 2025

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

cover pull request (net): ipsec 2025-09-22

1) Fix 0 assignment for SPIs. 0 is not a valid SPI, it means no SPI assigned.

2) Fix offloading for inter address family tunnels.

Both fixes from Sabrina Dubroca.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 52565a935213cd6a8662ddb8efe5b4219343a25d:

net: kcm: Fix race condition in kcm_unattach() (2025-08-13 18:18:33 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git tags/ipsec-2025-09-22

for you to fetch changes up to 91d8a53db2199eefc73ecf3682e0665ea6895696:

xfrm: fix offloading of cross-family tunnels (2025-09-15 11:35:06 +0200)

----------------------------------------------------------------
ipsec-2025-09-22

----------------------------------------------------------------
Sabrina Dubroca (2):
xfrm: xfrm_alloc_spi shouldn't use 0 as SPI
xfrm: fix offloading of cross-family tunnels

 net/xfrm/xfrm_device.c | 2 +-
 net/xfrm/xfrm_state.c  | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)
author maintainer
#1 lore raw

PATCH 1/2 xfrm: xfrm_alloc_spi shouldn't use 0 as SPI

From: Sabrina Dubroca <[email protected]>

x->id.spi == 0 means "no SPI assigned", but since commit 94f39804d891 ("xfrm: Duplicate SPI Handling"), we now create states and add them to the byspi list with this value.

__xfrm_state_delete doesn't remove those states from the byspi list, since they shouldn't be there, and this shows up as a UAF the next time we go through the byspi list.

---
 net/xfrm/xfrm_state.c | 3 +++
 1 file changed, 3 insertions(+)
net/xfrm/xfrm_state.c +3 -0
index 78fcbb89cf32..d213ca3653a8 100644
@@ -2583,6 +2583,8 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
 
 	for (h = 0; h < range; h++) {
 		u32 spi = (low == high) ? low : get_random_u32_inclusive(low, high);
+		if (spi == 0)
+			goto next;
 		newspi = htonl(spi);
 
 		spin_lock_bh(&net->xfrm.xfrm_state_lock);
@@ -2598,6 +2600,7 @@ int xfrm_alloc_spi(struct xfrm_state *x, u32 low, u32 high,
 		xfrm_state_put(x0);
 		spin_unlock_bh(&net->xfrm.xfrm_state_lock);
 
+next:
 		if (signal_pending(current)) {
 			err = -ERESTARTSYS;
 			goto unlock;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/2] xfrm: xfrm_alloc_spi shouldn't use 0 as SPI

This series was applied to netdev/net.git (main) by Steffen Klassert <[email protected]>:

Hello:

This series was applied to netdev/net.git (main) by Steffen Klassert <[email protected]>:

Quoted 11 lines · On Mon, 22 Sep 2025 09:34:52 +0200 you wrote:

From: Sabrina Dubroca <[email protected]>

x->id.spi == 0 means "no SPI assigned", but since commit 94f39804d891 ("xfrm: Duplicate SPI Handling"), we now create states and add them to the byspi list with this value.

__xfrm_state_delete doesn't remove those states from the byspi list, since they shouldn't be there, and this shows up as a UAF the next time we go through the byspi list.

[...]

Here is the summary with links:
- [1/2] xfrm: xfrm_alloc_spi shouldn't use 0 as SPI

    https://git.kernel.org/netdev/net/c/cd8ae32e4e46
  - [2/2] xfrm: fix offloading of cross-family tunnels
    https://git.kernel.org/netdev/net/c/91d8a53db219

You are awesome, thank you!

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

PATCH 2/2 xfrm: fix offloading of cross-family tunnels

In reply to Steffen Klassert

From: Sabrina Dubroca <[email protected]>

Xiumei reported a regression in IPsec offload tests over xfrmi, where the traffic for IPv6 over IPv4 tunnels is processed in SW instead of going through crypto offload, after commit
cc18f482e8b6 ("xfrm: provide common xdo_dev_offload_ok callback implementation").

Commit cc18f482e8b6 added a generic version of existing checks attempting to prevent packets with IPv4 options or IPv6 extension headers from being sent to HW that doesn't support offloading such packets. The check mistakenly uses x->props.family (the outer family) to determine the inner packet's family and verify if options/extensions are present.

In the case of IPv6 over IPv4, the check compares some of the traffic class bits to the expected no-options ihl value (5). The original check was introduced in commit 2ac9cfe78223 ("net/mlx5e: IPSec, Add Innova IPSec offload TX data path"), and then duplicated in the other drivers. Before commit cc18f482e8b6, the loose check (ihl > 5) passed because those traffic class bits were not set to a value that triggered the no-offload codepath. Packets with options/extension headers that should have been handled in SW went through the offload path, and were likely dropped by the NIC or incorrectly processed. Since commit cc18f482e8b6, the check is now strict (ihl != 5), and in a basic setup (no traffic class configured), all packets go through the no-offload codepath.

The commits that introduced the incorrect family checks in each driver
are:
2ac9cfe78223 ("net/mlx5e: IPSec, Add Innova IPSec offload TX data path") 8362ea16f69f ("crypto: chcr - ESN for Inline IPSec Tx")
859a497fe80c ("nfp: implement xfrm callbacks and expose ipsec offload feature to upper layer") 32188be805d0 ("cn10k-ipsec: Allow ipsec crypto offload for skb with SA") [ixgbe/ixgbevf commits are ignored, as that HW does not support tunnel
mode, thus no cross-family setups are possible]

Fixes cc18f482e8b6 ("xfrm: provide common xdo_dev_offload_ok callback implementation")
---
 net/xfrm/xfrm_device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/xfrm/xfrm_device.c +1 -1
index c7a1f080d2de..44b9de6e4e77 100644
@@ -438,7 +438,7 @@ bool xfrm_dev_offload_ok(struct sk_buff *skb, struct xfrm_state *x)
 
 	check_tunnel_size = x->xso.type == XFRM_DEV_OFFLOAD_PACKET &&
 			    x->props.mode == XFRM_MODE_TUNNEL;
-	switch (x->props.family) {
+	switch (x->inner_mode.family) {
 	case AF_INET:
 		/* Check for IPv4 options */
 		if (ip_hdr(skb)->ihl != 5)
Signature · 1 line
2.43.0