mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hui Peng <benquike@gmail.com>
To: steffen.klassert@secunet.com, herbert@gondor.apana.org.au,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com
Cc: horms@kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] xfrm: input: fix 4-bit iph->ihl overflow and OOB read in xfrm4_remove_beet_encap()
Date: Sat, 19 Sep 2026 21:06:19 +0000	[thread overview]
Message-ID: <20260919210619.3029202-1-benquike@gmail.com> (raw)

In xfrm4_remove_beet_encap(), when the BEET pseudo-header is present
(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH), two validation
flaws exist in option decapsulation:

1. optlen is checked against `optlen > 250` instead of `MAX_IPOPTLEN`
   (40). Later, `iph->ihl += optlen / 4` adds up to 62 to the 4-bit
   `iph->ihl` field (which starts at 5), wrapping the 4-bit unsigned
   bitfield around 16 and producing a bogus IPv4 header length smaller
   than 20 bytes.
2. Only `pskb_may_pull(skb, phlen)` is checked before `__skb_pull(skb,
   phlen)` and `ip_fast_csum(skb_network_header(skb), iph->ihl)`. If the
   trailing `optlen` bytes reside in non-linear skb fragments (or beyond
   the packet), `ip_fast_csum()` reads `optlen` bytes past
   `skb_tail_pointer(skb)`.

Cap `optlen` at `MAX_IPOPTLEN` (40) and ensure `pskb_may_pull(skb, phlen
+ optlen)` succeeds before pulling `phlen`.

Fixes: 0a69452cb45a ("[XFRM]: BEET mode")
Fixes: 227620e29509 ("[IPSEC]: Separate inner/outer mode processing on input")
Assisted-by: LLM
Signed-off-by: Hui Peng <benquike@gmail.com>

---
 net/xfrm/xfrm_input.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c
index 5ed87d51392a..3ed5fb0c755c 100644
--- a/net/xfrm/xfrm_input.c
+++ b/net/xfrm/xfrm_input.c
@@ -197,12 +197,12 @@ static int xfrm4_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
 
 		phlen = sizeof(*ph) + ph->padlen;
 		optlen = ph->hdrlen * 8 + (IPV4_BEET_PHMAXLEN - phlen);
-		if (optlen < 0 || optlen & 3 || optlen > 250)
+		if (optlen < 0 || optlen & 3 || optlen > MAX_IPOPTLEN)
 			goto out;
 
 		XFRM_MODE_SKB_CB(skb)->protocol = ph->nexthdr;
 
-		if (!pskb_may_pull(skb, phlen))
+		if (!pskb_may_pull(skb, phlen + optlen))
 			goto out;
 		__skb_pull(skb, phlen);
 	}
-- 
2.55.0.1082.g2b9226bbc0-goog


                 reply	other threads:[~2026-09-19 21:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260919210619.3029202-1-benquike@gmail.com \
    --to=benquike@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®