Skip to contentSkip to conversation

pull request (net): ipsec 2022-04-14

PATCH Applied Steffen Klassert 2 participants 4 messages Apr 14, 2022 – Apr 15, 2022

Subsystems (3)
lore
Share & tools
lore

Steffen Klassert

author maintainer
#0 lore raw

cover pull request (net): ipsec 2022-04-14

1) Fix the output interface for VRF cases in xfrm_dst_lookup. From David Ahern.

2) Fix write out of bounds by doing COW on esp output when the packet size is larger than a page.
From Sabrina Dubroca.

Please pull or let me know if there are problems.

Thanks!

The following changes since commit 692930cc435099580a4b9e32fa781b0688c18439:

selftests: net: fix nexthop warning cleanup double ip typo (2022-04-03 13:09:05 +0100)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec.git master

for you to fetch changes up to 5bd8baab087dff657e05387aee802e70304cc813:

esp: limit skb_page_frag_refill use to a single page (2022-04-13 10:16:11 +0200)

----------------------------------------------------------------
David Ahern (1):
xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup

Sabrina Dubroca (1):
esp: limit skb_page_frag_refill use to a single page

 include/net/esp.h      | 2 --
 net/ipv4/esp4.c        | 5 ++---
 net/ipv6/esp6.c        | 5 ++---
 net/xfrm/xfrm_policy.c | 4 +++-
 4 files changed, 7 insertions(+), 9 deletions(-)
author maintainer
#1 lore raw

PATCH 1/2 xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup

From: David Ahern <[email protected]>

The commit referenced in the Fixes tag no longer changes the flow oif to the l3mdev ifindex. A xfrm use case was expecting the flowi_oif to be the VRF if relevant and the change broke that test. Update xfrm_bundle_create to pass oif if set and any potential flowi_l3mdev if oif is not set.

Fixes 40867d74c374 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices")
---
 net/xfrm/xfrm_policy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/xfrm/xfrm_policy.c +3 -1
index 19aa994f5d2c..00bd0ecff5a1 100644
@@ -2593,12 +2593,14 @@ static struct dst_entry *xfrm_bundle_create(struct xfrm_policy *policy,
 
 		if (xfrm[i]->props.mode != XFRM_MODE_TRANSPORT) {
 			__u32 mark = 0;
+			int oif;
 
 			if (xfrm[i]->props.smark.v || xfrm[i]->props.smark.m)
 				mark = xfrm_smark_get(fl->flowi_mark, xfrm[i]);
 
 			family = xfrm[i]->props.family;
-			dst = xfrm_dst_lookup(xfrm[i], tos, fl->flowi_oif,
+			oif = fl->flowi_oif ? : fl->flowi_l3mdev;
+			dst = xfrm_dst_lookup(xfrm[i], tos, oif,
 					      &saddr, &daddr, family, mark);
 			err = PTR_ERR(dst);
 			if (IS_ERR(dst))
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup

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

Hello:

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

Quoted 9 lines · On Thu, 14 Apr 2022 11:19:42 +0200 you wrote:

From: David Ahern <[email protected]>

The commit referenced in the Fixes tag no longer changes the flow oif to the l3mdev ifindex. A xfrm use case was expecting the flowi_oif to be the VRF if relevant and the change broke that test. Update xfrm_bundle_create to pass oif if set and any potential flowi_l3mdev if oif is not set.

[...]

Here is the summary with links:
- [1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup

    https://git.kernel.org/netdev/net/c/748b82c23e25
  - [2/2] esp: limit skb_page_frag_refill use to a single page
    https://git.kernel.org/netdev/net/c/5bd8baab087d

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 esp: limit skb_page_frag_refill use to a single page

In reply to Steffen Klassert

From: Sabrina Dubroca <[email protected]>

Commit ebe48d368e97 ("esp: Fix possible buffer overflow in ESP transformation") tried to fix skb_page_frag_refill usage in ESP by capping allocsize to 32k, but that doesn't completely solve the issue, as skb_page_frag_refill may return a single page. If that happens, we will write out of bounds, despite the check introduced in the previous patch.

This patch forces COW in cases where we would end up calling skb_page_frag_refill with a size larger than a page (first in esp_output_head with tailen, then in esp_output_tail with skb->data_len).

Fixes cac2661c53f3 ("esp4: Avoid skb_cow_data whenever possible")
Fixes 03e2a30f6a27 ("esp6: Avoid skb_cow_data whenever possible")
---
 include/net/esp.h | 2 --
 net/ipv4/esp4.c   | 5 ++---
 net/ipv6/esp6.c   | 5 ++---
 3 files changed, 4 insertions(+), 8 deletions(-)
include/net/esp.h +0 -2
index 90cd02ff77ef..9c5637d41d95 100644
@@ -4,8 +4,6 @@
 
 #include <linux/skbuff.h>
 
-#define ESP_SKB_FRAG_MAXSIZE (PAGE_SIZE << SKB_FRAG_PAGE_ORDER)
-
 struct ip_esp_hdr;
 
 static inline struct ip_esp_hdr *ip_esp_hdr(const struct sk_buff *skb)
net/ipv4/esp4.c +2 -3
index 70e6c87fbe3d..d747166bb291 100644
@@ -446,7 +446,6 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 	struct page *page;
 	struct sk_buff *trailer;
 	int tailen = esp->tailen;
-	unsigned int allocsz;
 
 	/* this is non-NULL only with TCP/UDP Encapsulation */
 	if (x->encap) {
@@ -456,8 +455,8 @@ int esp_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *
 			return err;
 	}
 
-	allocsz = ALIGN(skb->data_len + tailen, L1_CACHE_BYTES);
-	if (allocsz > ESP_SKB_FRAG_MAXSIZE)
+	if (ALIGN(tailen, L1_CACHE_BYTES) > PAGE_SIZE ||
+	    ALIGN(skb->data_len, L1_CACHE_BYTES) > PAGE_SIZE)
 		goto cow;
 
 	if (!skb_cloned(skb)) {
net/ipv6/esp6.c +2 -3
index 55d604c9b3b3..f2120e92caf1 100644
@@ -482,7 +482,6 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
 	struct page *page;
 	struct sk_buff *trailer;
 	int tailen = esp->tailen;
-	unsigned int allocsz;
 
 	if (x->encap) {
 		int err = esp6_output_encap(x, skb, esp);
@@ -491,8 +490,8 @@ int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info
 			return err;
 	}
 
-	allocsz = ALIGN(skb->data_len + tailen, L1_CACHE_BYTES);
-	if (allocsz > ESP_SKB_FRAG_MAXSIZE)
+	if (ALIGN(tailen, L1_CACHE_BYTES) > PAGE_SIZE ||
+	    ALIGN(skb->data_len, L1_CACHE_BYTES) > PAGE_SIZE)
 		goto cow;
 
 	if (!skb_cloned(skb)) {
Signature · 1 line
2.25.1