netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] pull request (net): ipsec 2022-04-14
@ 2022-04-14  9:19 Steffen Klassert
  2022-04-14  9:19 ` [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup Steffen Klassert
  2022-04-14  9:19 ` [PATCH 2/2] esp: limit skb_page_frag_refill use to a single page Steffen Klassert
  0 siblings, 2 replies; 4+ messages in thread
From: Steffen Klassert @ 2022-04-14  9:19 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

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

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

* [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup
  2022-04-14  9:19 [PATCH 0/2] pull request (net): ipsec 2022-04-14 Steffen Klassert
@ 2022-04-14  9:19 ` Steffen Klassert
  2022-04-15 10:40   ` patchwork-bot+netdevbpf
  2022-04-14  9:19 ` [PATCH 2/2] esp: limit skb_page_frag_refill use to a single page Steffen Klassert
  1 sibling, 1 reply; 4+ messages in thread
From: Steffen Klassert @ 2022-04-14  9:19 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

From: David Ahern <dsahern@kernel.org>

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")
Reported-by: kernel test robot <oliver.sang@intel.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_policy.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
index 19aa994f5d2c..00bd0ecff5a1 100644
--- a/net/xfrm/xfrm_policy.c
+++ b/net/xfrm/xfrm_policy.c
@@ -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))
-- 
2.25.1


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

* [PATCH 2/2] esp: limit skb_page_frag_refill use to a single page
  2022-04-14  9:19 [PATCH 0/2] pull request (net): ipsec 2022-04-14 Steffen Klassert
  2022-04-14  9:19 ` [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup Steffen Klassert
@ 2022-04-14  9:19 ` Steffen Klassert
  1 sibling, 0 replies; 4+ messages in thread
From: Steffen Klassert @ 2022-04-14  9:19 UTC (permalink / raw)
  To: David Miller, Jakub Kicinski; +Cc: Herbert Xu, Steffen Klassert, netdev

From: Sabrina Dubroca <sd@queasysnail.net>

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")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 include/net/esp.h | 2 --
 net/ipv4/esp4.c   | 5 ++---
 net/ipv6/esp6.c   | 5 ++---
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/include/net/esp.h b/include/net/esp.h
index 90cd02ff77ef..9c5637d41d95 100644
--- a/include/net/esp.h
+++ b/include/net/esp.h
@@ -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)
diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
index 70e6c87fbe3d..d747166bb291 100644
--- a/net/ipv4/esp4.c
+++ b/net/ipv4/esp4.c
@@ -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)) {
diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
index 55d604c9b3b3..f2120e92caf1 100644
--- a/net/ipv6/esp6.c
+++ b/net/ipv6/esp6.c
@@ -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)) {
-- 
2.25.1


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

* Re: [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup
  2022-04-14  9:19 ` [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup Steffen Klassert
@ 2022-04-15 10:40   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-04-15 10:40 UTC (permalink / raw)
  To: Steffen Klassert; +Cc: davem, kuba, herbert, netdev

Hello:

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

On Thu, 14 Apr 2022 11:19:42 +0200 you wrote:
> From: David Ahern <dsahern@kernel.org>
> 
> 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-04-15 10:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-14  9:19 [PATCH 0/2] pull request (net): ipsec 2022-04-14 Steffen Klassert
2022-04-14  9:19 ` [PATCH 1/2] xfrm: Pass flowi_oif or l3mdev as oif to xfrm_dst_lookup Steffen Klassert
2022-04-15 10:40   ` patchwork-bot+netdevbpf
2022-04-14  9:19 ` [PATCH 2/2] esp: limit skb_page_frag_refill use to a single page Steffen Klassert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).