Netdev List
 help / color / mirror / Atom feed
* [PATCH 0/3] pull request (net): ipsec 2024-05-02
@ 2024-05-02  8:48 Steffen Klassert
  2024-05-02  8:48 ` [PATCH 1/3] xfrm: fix possible derferencing in error path Steffen Klassert
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Steffen Klassert @ 2024-05-02  8:48 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

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

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

* [PATCH 1/3] xfrm: fix possible derferencing in error path
  2024-05-02  8:48 [PATCH 0/3] pull request (net): ipsec 2024-05-02 Steffen Klassert
@ 2024-05-02  8:48 ` Steffen Klassert
  2024-05-03 23:10   ` patchwork-bot+netdevbpf
  2024-05-02  8:48 ` [PATCH 2/3] xfrm: Preserve vlan tags for transport mode software GRO Steffen Klassert
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Steffen Klassert @ 2024-05-02  8:48 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Antony Antony <antony.antony@secunet.com>

Fix derferencing pointer when xfrm_policy_lookup_bytype returns an
 error.

Fixes: 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages")
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/kernel-janitors/f6ef0d0d-96de-4e01-9dc3-c1b3a6338653@moroto.mountain/
Signed-off-by: Antony Antony <antony.antony@secunet.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_policy.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 6affe5cd85d8..53d8fabfa685 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -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;
-- 
2.34.1


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

* [PATCH 2/3] xfrm: Preserve vlan tags for transport mode software GRO
  2024-05-02  8:48 [PATCH 0/3] pull request (net): ipsec 2024-05-02 Steffen Klassert
  2024-05-02  8:48 ` [PATCH 1/3] xfrm: fix possible derferencing in error path Steffen Klassert
@ 2024-05-02  8:48 ` Steffen Klassert
  2024-05-02  8:48 ` [PATCH 3/3] xfrm: Correct spelling mistake in xfrm.h comment Steffen Klassert
  2024-05-02 10:53 ` [PATCH 0/3] pull request (net): ipsec 2024-05-02 Paolo Abeni
  3 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2024-05-02  8:48 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Paul Davey <paul.davey@alliedtelesis.co.nz>

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")
Signed-off-by: Paul Davey <paul.davey@alliedtelesis.co.nz>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 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(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 9d24aec064e8..4ff48eda3f64 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -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);
diff --git a/include/net/xfrm.h b/include/net/xfrm.h
index 57c743b7e4fe..cb4841a9fffd 100644
--- a/include/net/xfrm.h
+++ b/include/net/xfrm.h
@@ -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;
 };
diff --git a/net/ipv4/xfrm4_input.c b/net/ipv4/xfrm4_input.c
index dae35101d189..86382e08140e 100644
--- a/net/ipv4/xfrm4_input.c
+++ b/net/ipv4/xfrm4_input.c
@@ -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;
 	}
diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
index a17d783dc7c0..c6b8e132e10a 100644
--- a/net/ipv6/xfrm6_input.c
+++ b/net/ipv6/xfrm6_input.c
@@ -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;
 	}
diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 161f535c8b94..3a2982a72a6b 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -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 -
-- 
2.34.1


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

* [PATCH 3/3] xfrm: Correct spelling mistake in xfrm.h comment
  2024-05-02  8:48 [PATCH 0/3] pull request (net): ipsec 2024-05-02 Steffen Klassert
  2024-05-02  8:48 ` [PATCH 1/3] xfrm: fix possible derferencing in error path Steffen Klassert
  2024-05-02  8:48 ` [PATCH 2/3] xfrm: Preserve vlan tags for transport mode software GRO Steffen Klassert
@ 2024-05-02  8:48 ` Steffen Klassert
  2024-05-02 10:53 ` [PATCH 0/3] pull request (net): ipsec 2024-05-02 Paolo Abeni
  3 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2024-05-02  8:48 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Antony Antony <antony.antony@secunet.com>

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.")
Signed-off-by: Antony Antony <antony.antony@secunet.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/uapi/linux/xfrm.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/xfrm.h b/include/uapi/linux/xfrm.h
index 6a77328be114..594b66e16395 100644
--- a/include/uapi/linux/xfrm.h
+++ b/include/uapi/linux/xfrm.h
@@ -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 {
-- 
2.34.1


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

* Re: [PATCH 0/3] pull request (net): ipsec 2024-05-02
  2024-05-02  8:48 [PATCH 0/3] pull request (net): ipsec 2024-05-02 Steffen Klassert
                   ` (2 preceding siblings ...)
  2024-05-02  8:48 ` [PATCH 3/3] xfrm: Correct spelling mistake in xfrm.h comment Steffen Klassert
@ 2024-05-02 10:53 ` Paolo Abeni
  2024-05-02 11:02   ` Steffen Klassert
  3 siblings, 1 reply; 7+ messages in thread
From: Paolo Abeni @ 2024-05-02 10:53 UTC (permalink / raw)
  To: Steffen Klassert, David Miller, Jakub Kicinski; +Cc: Herbert Xu, netdev

On Thu, 2024-05-02 at 10:48 +0200, Steffen Klassert wrote:
> 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


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

* Re: [PATCH 0/3] pull request (net): ipsec 2024-05-02
  2024-05-02 10:53 ` [PATCH 0/3] pull request (net): ipsec 2024-05-02 Paolo Abeni
@ 2024-05-02 11:02   ` Steffen Klassert
  0 siblings, 0 replies; 7+ messages in thread
From: Steffen Klassert @ 2024-05-02 11:02 UTC (permalink / raw)
  To: Paolo Abeni; +Cc: David Miller, Jakub Kicinski, Herbert Xu, netdev

On Thu, May 02, 2024 at 12:53:43PM +0200, Paolo Abeni wrote:
> On Thu, 2024-05-02 at 10:48 +0200, Steffen Klassert wrote:
> > 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.

I'm OK with that.

Thanks!

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

* Re: [PATCH 1/3] xfrm: fix possible derferencing in error path
  2024-05-02  8:48 ` [PATCH 1/3] xfrm: fix possible derferencing in error path Steffen Klassert
@ 2024-05-03 23:10   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-05-03 23:10 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: davem, kuba, herbert, netdev

Hello:

This series was applied to netdev/net.git (main)
by Steffen Klassert <steffen.klassert@secunet.com>:

On Thu, 2 May 2024 10:48:36 +0200 you wrote:
> From: Antony Antony <antony.antony@secunet.com>
> 
> Fix derferencing pointer when xfrm_policy_lookup_bytype returns an
>  error.
> 
> Fixes: 63b21caba17e ("xfrm: introduce forwarding of ICMP Error messages")
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Closes: https://lore.kernel.org/kernel-janitors/f6ef0d0d-96de-4e01-9dc3-c1b3a6338653@moroto.mountain/
> Signed-off-by: Antony Antony <antony.antony@secunet.com>
> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2024-05-03 23:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-02  8:48 [PATCH 0/3] pull request (net): ipsec 2024-05-02 Steffen Klassert
2024-05-02  8:48 ` [PATCH 1/3] xfrm: fix possible derferencing in error path Steffen Klassert
2024-05-03 23:10   ` patchwork-bot+netdevbpf
2024-05-02  8:48 ` [PATCH 2/3] xfrm: Preserve vlan tags for transport mode software GRO Steffen Klassert
2024-05-02  8:48 ` [PATCH 3/3] xfrm: Correct spelling mistake in xfrm.h comment Steffen Klassert
2024-05-02 10:53 ` [PATCH 0/3] pull request (net): ipsec 2024-05-02 Paolo Abeni
2024-05-02 11:02   ` Steffen Klassert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox