public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfrm6: fix slab-out-of-bounds write in xfrm6_input_addr()
@ 2026-03-28 16:35 nicholas
  2026-03-31  7:50 ` Steffen Klassert
  0 siblings, 1 reply; 4+ messages in thread
From: nicholas @ 2026-03-28 16:35 UTC (permalink / raw)
  To: netdev
  Cc: Steffen Klassert, Herbert Xu, David S . Miller, Milad Nasr,
	Nicholas Carlini

From: Nicholas Carlini <nicholas@carlini.com>

The bounds check guarding sp->xvec[sp->len++] uses == where >= is
required. When sp->len has already reached XFRM_MAX_DEPTH via prior
ESP processing in xfrm_input(), the check (1 + 6 == 6) is false and
the write goes out of bounds into the adjacent skbuff_ext_cache slab
object.

An unprivileged local user can trigger this by entering a
user+network namespace, configuring six transport-mode ESP SAs plus
one MIP6 routing SA, and injecting an IPv6 packet with six ESP
layers followed by multiple Routing Header Type 2 extensions.

The check was correct (>) when the function was introduced, but
was changed to == during a refactor in 2007.

Fixes: 9473e1f631de ("[XFRM] MIPv6: Fix to input RO state correctly.")
Reported-by: Milad Nasr <srxzr@anthropic.com>
Signed-off-by: Nicholas Carlini <nicholas@carlini.com>
---
 net/ipv6/xfrm6_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
index 9005fc156a20..a958c08589d6 100644
--- a/net/ipv6/xfrm6_input.c
+++ b/net/ipv6/xfrm6_input.c
@@ -246,7 +246,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
         goto drop;
     }

-    if (1 + sp->len == XFRM_MAX_DEPTH) {
+    if (1 + sp->len >= XFRM_MAX_DEPTH) {
         XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
         goto drop;
     }
--
2.39.5

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

* Re: [PATCH] xfrm6: fix slab-out-of-bounds write in xfrm6_input_addr()
  2026-03-28 16:35 [PATCH] xfrm6: fix slab-out-of-bounds write in xfrm6_input_addr() nicholas
@ 2026-03-31  7:50 ` Steffen Klassert
  2026-04-01  4:56   ` [PATCH v2] " nicholas
  0 siblings, 1 reply; 4+ messages in thread
From: Steffen Klassert @ 2026-03-31  7:50 UTC (permalink / raw)
  To: nicholas; +Cc: netdev, Herbert Xu, David S . Miller, Milad Nasr

On Sat, Mar 28, 2026 at 04:35:16PM +0000, nicholas@carlini.com wrote:
> From: Nicholas Carlini <nicholas@carlini.com>
> 
> The bounds check guarding sp->xvec[sp->len++] uses == where >= is
> required. When sp->len has already reached XFRM_MAX_DEPTH via prior
> ESP processing in xfrm_input(), the check (1 + 6 == 6) is false and
> the write goes out of bounds into the adjacent skbuff_ext_cache slab
> object.
> 
> An unprivileged local user can trigger this by entering a
> user+network namespace, configuring six transport-mode ESP SAs plus
> one MIP6 routing SA, and injecting an IPv6 packet with six ESP
> layers followed by multiple Routing Header Type 2 extensions.
> 
> The check was correct (>) when the function was introduced, but
> was changed to == during a refactor in 2007.
> 
> Fixes: 9473e1f631de ("[XFRM] MIPv6: Fix to input RO state correctly.")
> Reported-by: Milad Nasr <srxzr@anthropic.com>
> Signed-off-by: Nicholas Carlini <nicholas@carlini.com>
> ---
>  net/ipv6/xfrm6_input.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
> index 9005fc156a20..a958c08589d6 100644
> --- a/net/ipv6/xfrm6_input.c
> +++ b/net/ipv6/xfrm6_input.c
> @@ -246,7 +246,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
>          goto drop;
>      }
> 
> -    if (1 + sp->len == XFRM_MAX_DEPTH) {
> +    if (1 + sp->len >= XFRM_MAX_DEPTH) {
>          XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
>          goto drop;
>      }

Your patch is malformed (whitespaces instead of tabs).
Please fix this and rebase on top of the ipsec tree.

Thanks!

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

* [PATCH v2] xfrm6: fix slab-out-of-bounds write in xfrm6_input_addr()
  2026-03-31  7:50 ` Steffen Klassert
@ 2026-04-01  4:56   ` nicholas
  2026-04-01 16:26     ` I Viswanath
  0 siblings, 1 reply; 4+ messages in thread
From: nicholas @ 2026-04-01  4:56 UTC (permalink / raw)
  To: netdev
  Cc: Steffen Klassert, Herbert Xu, David S . Miller, Milad Nasr,
	Nicholas Carlini

From: Nicholas Carlini <nicholas@carlini.com>

The bounds check guarding sp->xvec[sp->len++] uses == where >= is
required. When sp->len has already reached XFRM_MAX_DEPTH via prior
ESP processing in xfrm_input(), the check (1 + 6 == 6) is false and
the write goes out of bounds into the adjacent skbuff_ext_cache slab
object.

An unprivileged local user can trigger this by entering a
user+network namespace, configuring six transport-mode ESP SAs plus
one MIP6 routing SA, and injecting an IPv6 packet with six ESP
layers followed by multiple Routing Header Type 2 extensions.

The check was correct (>) when the function was introduced, but
was changed to == during a refactor in 2007.

Fixes: 9473e1f631de ("[XFRM] MIPv6: Fix to input RO state correctly.")
Reported-by: Milad Nasr <srxzr@anthropic.com>
Signed-off-by: Nicholas Carlini <nicholas@carlini.com>
---
v1 -> v2: fix whitespace (tabs), rebase on ipsec tree (Steffen Klassert)

v1: https://lore.kernel.org/netdev/20260328163516.2111971-1-nicholas@carlini.com

 net/ipv6/xfrm6_input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv6/xfrm6_input.c b/net/ipv6/xfrm6_input.c
index 9005fc156a2..a958c08589d 100644
--- a/net/ipv6/xfrm6_input.c
+++ b/net/ipv6/xfrm6_input.c
@@ -246,7 +246,7 @@ int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
 		goto drop;
 	}
 
-	if (1 + sp->len == XFRM_MAX_DEPTH) {
+	if (1 + sp->len >= XFRM_MAX_DEPTH) {
 		XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
 		goto drop;
 	}
-- 
2.43.0


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

* Re: [PATCH v2] xfrm6: fix slab-out-of-bounds write in xfrm6_input_addr()
  2026-04-01  4:56   ` [PATCH v2] " nicholas
@ 2026-04-01 16:26     ` I Viswanath
  0 siblings, 0 replies; 4+ messages in thread
From: I Viswanath @ 2026-04-01 16:26 UTC (permalink / raw)
  To: nicholas; +Cc: netdev, Steffen Klassert, Herbert Xu, David S . Miller,
	Milad Nasr

On Wed, 1 Apr 2026 at 10:26, <nicholas@carlini.com> wrote:

> -       if (1 + sp->len == XFRM_MAX_DEPTH) {
> +       if (1 + sp->len >= XFRM_MAX_DEPTH) {
>                 XFRM_INC_STATS(net, LINUX_MIB_XFRMINBUFFERERROR);
>                 goto drop;
>         }

If you look at other places where sp->len is incremented, you will
notice the guard condition is always (sp->len == XFRM_MAX_DEPTH). This
bug exists because in xfrm6_input.c, the greatest valid index is taken
to be XFRM_MAX_DEPTH - 2 when it should be XFRM_MAX_DEPTH - 1.
Therefore, The correct fix should be using the common guard not
changing the guard to use >=

On a tangential note, There is no guard present before the increment
in xfrm_output.c which is probably another OOB bug

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

end of thread, other threads:[~2026-04-01 16:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28 16:35 [PATCH] xfrm6: fix slab-out-of-bounds write in xfrm6_input_addr() nicholas
2026-03-31  7:50 ` Steffen Klassert
2026-04-01  4:56   ` [PATCH v2] " nicholas
2026-04-01 16:26     ` I Viswanath

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