Skip to contentSkip to conversation

pull request (net): ipsec 2024-05-02

PATCH Applied Steffen Klassert 3 participants 7 messages May 2, 2024 – May 3, 2024

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

cover pull request (net): ipsec 2024-05-02

1) Fix an error pointer dereference in xfrm_in_fwd_icmp. From Antony Antony.

2) Preserve vlan tags for ESP transport mode software GRO. From Paul Davey.

3) Fix a spelling mistake in an uapi xfrm.h comment. From Anotny Antony.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit bccb798e07f8bb8b91212fe8ed1e421685449076:

octeontx2-pf: Fix transmit scheduler resource leak (2024-04-07 15:45:56 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git tags/ipsec-2024-05-02

for you to fetch changes up to b6d2e438e16c7d4dbde08cfb2b95b0f3f325ba40:

xfrm: Correct spelling mistake in xfrm.h comment (2024-04-29 07:52:40 +0200)

----------------------------------------------------------------
ipsec-2024-05-02

----------------------------------------------------------------
Antony Antony (2):
xfrm: fix possible derferencing in error path
xfrm: Correct spelling mistake in xfrm.h comment

Paul Davey (1):
xfrm: Preserve vlan tags for transport mode software GRO

 include/linux/skbuff.h    | 15 +++++++++++++++
 include/net/xfrm.h        |  3 +++
 include/uapi/linux/xfrm.h |  2 +-
 net/ipv4/xfrm4_input.c    |  6 +++++-
 net/ipv6/xfrm6_input.c    |  6 +++++-
 net/xfrm/xfrm_input.c     |  8 ++++++++
 net/xfrm/xfrm_policy.c    |  2 ++
 7 files changed, 39 insertions(+), 3 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 xfrm: fix possible derferencing in error path

From: Antony Antony <[email protected]>

Fix derferencing pointer when xfrm_policy_lookup_bytype returns an
error.

Fixes 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages")
---
 net/xfrm/xfrm_policy.c | 2 ++
 1 file changed, 2 insertions(+)
net/xfrm/xfrm_policy.c +2 -0
index 6affe5cd85d8..53d8fabfa685 100644
@@ -3593,6 +3593,8 @@ xfrm_policy *xfrm_in_fwd_icmp(struct sk_buff *skb,
 			return pol;
 
 		pol = xfrm_policy_lookup(net, &fl1, family, XFRM_POLICY_FWD, if_id);
+		if (IS_ERR(pol))
+			pol = NULL;
 	}
 
 	return pol;
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/3] xfrm: fix possible derferencing in error path

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 5 lines · On Thu, 2 May 2024 10:48:36 +0200 you wrote:

From: Antony Antony <[email protected]>

Fix derferencing pointer when xfrm_policy_lookup_bytype returns an
error.

Quoted 7 lines
Fixes 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages")

[...]

Here is the summary with links:
- [1/3] xfrm: fix possible derferencing in error path

    https://git.kernel.org/netdev/net/c/8b06a24bb625
  - [2/3] xfrm: Preserve vlan tags for transport mode software GRO
    https://git.kernel.org/netdev/net/c/58fbfecab965
  - [3/3] xfrm: Correct spelling mistake in xfrm.h comment
    https://git.kernel.org/netdev/net/c/b6d2e438e16c

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/3 xfrm: Preserve vlan tags for transport mode software GRO

In reply to Steffen Klassert

From: Paul Davey <[email protected]>

The software GRO path for esp transport mode uses skb_mac_header_rebuild prior to re-injecting the packet via the xfrm_napi_dev. This only copies skb->mac_len bytes of header which may not be sufficient if the packet contains 802.1Q tags or other VLAN tags. Worse copying only the initial header will leave a packet marked as being VLAN tagged but without the corresponding tag leading to mangling when it is later untagged.

The VLAN tags are important when receiving the decrypted esp transport mode packet after GRO processing to ensure it is received on the correct interface.

Therefore record the full mac header length in xfrm*_transport_input for later use in corresponding xfrm*_transport_finish to copy the entire mac header when rebuilding the mac header for GRO. The skb->data pointer is left pointing skb->mac_header bytes after the start of the mac header as is expected by the network stack and network and transport header offsets reset to this location.

Fixes 7785bba299a8 ("esp: Add a software GRO codepath")
---
 include/linux/skbuff.h | 15 +++++++++++++++
 include/net/xfrm.h     |  3 +++
 net/ipv4/xfrm4_input.c |  6 +++++-
 net/ipv6/xfrm6_input.c |  6 +++++-
 net/xfrm/xfrm_input.c  |  8 ++++++++
 5 files changed, 36 insertions(+), 2 deletions(-)
include/linux/skbuff.h +15 -0
index 9d24aec064e8..4ff48eda3f64 100644
@@ -3031,6 +3031,21 @@ static inline void skb_mac_header_rebuild(struct sk_buff *skb)
 	}
 }
 
+/* Move the full mac header up to current network_header.
+ * Leaves skb->data pointing at offset skb->mac_len into the mac_header.
+ * Must be provided the complete mac header length.
+ */
+static inline void skb_mac_header_rebuild_full(struct sk_buff *skb, u32 full_mac_len)
+{
+	if (skb_mac_header_was_set(skb)) {
+		const unsigned char *old_mac = skb_mac_header(skb);
+
+		skb_set_mac_header(skb, -full_mac_len);
+		memmove(skb_mac_header(skb), old_mac, full_mac_len);
+		__skb_push(skb, full_mac_len - skb->mac_len);
+	}
+}
+
 static inline int skb_checksum_start_offset(const struct sk_buff *skb)
 {
 	return skb->csum_start - skb_headroom(skb);
include/net/xfrm.h +3 -0
index 57c743b7e4fe..cb4841a9fffd 100644
@@ -1049,6 +1049,9 @@ struct xfrm_offload {
 #define CRYPTO_INVALID_PACKET_SYNTAX		64
 #define CRYPTO_INVALID_PROTOCOL			128
 
+	/* Used to keep whole l2 header for transport mode GRO */
+	__u32			orig_mac_len;
+
 	__u8			proto;
 	__u8			inner_ipproto;
 };
net/ipv4/xfrm4_input.c +5 -1
index dae35101d189..86382e08140e 100644
@@ -63,7 +63,11 @@ int xfrm4_transport_finish(struct sk_buff *skb, int async)
 	ip_send_check(iph);
 
 	if (xo && (xo->flags & XFRM_GRO)) {
-		skb_mac_header_rebuild(skb);
+		/* The full l2 header needs to be preserved so that re-injecting the packet at l2
+		 * works correctly in the presence of vlan tags.
+		 */
+		skb_mac_header_rebuild_full(skb, xo->orig_mac_len);
+		skb_reset_network_header(skb);
 		skb_reset_transport_header(skb);
 		return 0;
 	}
net/ipv6/xfrm6_input.c +5 -1
index a17d783dc7c0..c6b8e132e10a 100644
@@ -58,7 +58,11 @@ int xfrm6_transport_finish(struct sk_buff *skb, int async)
 	skb_postpush_rcsum(skb, skb_network_header(skb), nhlen);
 
 	if (xo && (xo->flags & XFRM_GRO)) {
-		skb_mac_header_rebuild(skb);
+		/* The full l2 header needs to be preserved so that re-injecting the packet at l2
+		 * works correctly in the presence of vlan tags.
+		 */
+		skb_mac_header_rebuild_full(skb, xo->orig_mac_len);
+		skb_reset_network_header(skb);
 		skb_reset_transport_header(skb);
 		return 0;
 	}
net/xfrm/xfrm_input.c +8 -0
index 161f535c8b94..3a2982a72a6b 100644
@@ -389,11 +389,15 @@ static int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb)
  */
 static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 {
+	struct xfrm_offload *xo = xfrm_offload(skb);
 	int ihl = skb->data - skb_transport_header(skb);
 
 	if (skb->transport_header != skb->network_header) {
 		memmove(skb_transport_header(skb),
 			skb_network_header(skb), ihl);
+		if (xo)
+			xo->orig_mac_len =
+				skb_mac_header_was_set(skb) ? skb_mac_header_len(skb) : 0;
 		skb->network_header = skb->transport_header;
 	}
 	ip_hdr(skb)->tot_len = htons(skb->len + ihl);
@@ -404,11 +408,15 @@ static int xfrm4_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 static int xfrm6_transport_input(struct xfrm_state *x, struct sk_buff *skb)
 {
 #if IS_ENABLED(CONFIG_IPV6)
+	struct xfrm_offload *xo = xfrm_offload(skb);
 	int ihl = skb->data - skb_transport_header(skb);
 
 	if (skb->transport_header != skb->network_header) {
 		memmove(skb_transport_header(skb),
 			skb_network_header(skb), ihl);
+		if (xo)
+			xo->orig_mac_len =
+				skb_mac_header_was_set(skb) ? skb_mac_header_len(skb) : 0;
 		skb->network_header = skb->transport_header;
 	}
 	ipv6_hdr(skb)->payload_len = htons(skb->len + ihl -
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 3/3 xfrm: Correct spelling mistake in xfrm.h comment

In reply to Steffen Klassert

From: Antony Antony <[email protected]>

A spelling error was found in the comment section of include/uapi/linux/xfrm.h. Since this header file is copied to many userspace programs and undergoes Debian spellcheck, it's preferable to fix it in upstream rather than downstream having exceptions.

This commit fixes the spelling mistake.

Fixes df71837d5024 ("[LSM-IPSec]: Security association restriction.")
---
 include/uapi/linux/xfrm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/xfrm.h +1 -1
index 6a77328be114..594b66e16395 100644
@@ -228,7 +228,7 @@ enum {
 #define XFRM_NR_MSGTYPES (XFRM_MSG_MAX + 1 - XFRM_MSG_BASE)
 
 /*
- * Generic LSM security context for comunicating to user space
+ * Generic LSM security context for communicating to user space
  * NOTE: Same format as sadb_x_sec_ctx
  */
 struct xfrm_user_sec_ctx {
Signature · 1 line
2.34.1
maintainer
#5 lore raw
In reply to Steffen Klassert
Quoted 10 lines · Steffen Klassert

1) Fix an error pointer dereference in xfrm_in_fwd_icmp. From Antony Antony.

2) Preserve vlan tags for ESP transport mode software GRO. From Paul Davey.

3) Fix a spelling mistake in an uapi xfrm.h comment. From Anotny Antony.

Please pull or let me know if there are problems.

This landed in my inbox after I almost finalized today's net PR, so these fixes will not enter it, they will reach Liuns' tree next week.

I hope it's not a big deal.

Cheers,

Paolo

author maintainer
#6 lore raw
Quoted 10 lines · Paolo Abeni
Quoted 9 lines · Steffen Klassert

1) Fix an error pointer dereference in xfrm_in_fwd_icmp. From Antony Antony.

2) Preserve vlan tags for ESP transport mode software GRO. From Paul Davey.

3) Fix a spelling mistake in an uapi xfrm.h comment. From Anotny Antony.

Quoted 6 lines
Quoted 1 line

Please pull or let me know if there are problems.

This landed in my inbox after I almost finalized today's net PR, so these fixes will not enter it, they will reach Liuns' tree next week.

I hope it's not a big deal.

I'm OK with that.

Thanks!