Netdev List
 help / color / mirror / Atom feed
From: Henry Martin <bsdhenrymartin@gmail.com>
To: Yotam Gigi <yotam.gi@gmail.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Victor Nogueira <victor@mojatatu.com>
Cc: netdev@vger.kernel.org, Henry Martin <bsdhenrymartin@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH net] net: ife: reject headers that would overflow the network header offset
Date: Fri, 27 Nov 2026 14:30:05 +0800	[thread overview]
Message-ID: <20261127063006.2908187-1-bsdhenrymartin@gmail.com> (raw)

ife_decode() lets the packet-supplied metadata length drive __skb_pull()
with no upper bound beyond skb->len.  The caller then strips one more
Ethernet header via eth_type_trans() and resets the network header,
whose offset field is a u16.  With a large metadata length the offset
no longer fits and is silently truncated; the packet then carries a
network header pointing 64 KiB before skb->data.  When such a packet is
forwarded, the neighbour output path pulls the negative network offset
as an unsigned length, moving skb->data roughly 4 GiB ahead, and
dev_hard_header() writes the link-layer header at that wild address:

e.g. on mainline v7.4-rc4 (KASAN build):

 BUG: unable to handle page fault for address: ffffed1040e0c000
 CPU: 2 UID: 1000 PID: 80 Comm: poc Not tainted 7.4.0-rc4 #9
 RIP: 0010:eth_header+0x56/0x180
 Call Trace:
  neigh_resolve_output+0x388/0x840
  ip_finish_output2+0x8fb/0x1b80
  ip_forward+0x1388/0x2030
  ip_rcv+0x228/0x270
 Kernel panic - not syncing: Fatal exception in interrupt

Reject IFE headers whose total pull would push the data pointer past
what the network header offset can represent.

This issue was discovered by Tencent CodeBuddy Security.

Cc: stable@vger.kernel.org
Fixes: 1ce8460496c0 ("net: Introduce ife encapsulation module")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 net/ife/ife.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/ife/ife.c b/net/ife/ife.c
index 2ddf725d3389e..272e457517360 100644
--- a/net/ife/ife.c
+++ b/net/ife/ife.c
@@ -79,6 +79,14 @@ void *ife_decode(struct sk_buff *skb, u16 *metalen)
 	if (unlikely(ifehdrln < 2))
 		return NULL;
 
+	/* The caller strips one more ETH_HLEN via eth_type_trans() and
+	 * then resets the network header, whose offset is a u16.  A
+	 * larger pull would silently truncate the offset and leave the
+	 * stack with a negative network offset.
+	 */
+	if (unlikely(skb->data - skb->head + total_pull + ETH_HLEN > U16_MAX))
+		return NULL;
+
 	if (unlikely(!pskb_may_pull(skb, total_pull + ETH_HLEN)))
 		return NULL;
 
-- 
2.39.5


                 reply	other threads:[~2026-11-27  6:30 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=20261127063006.2908187-1-bsdhenrymartin@gmail.com \
    --to=bsdhenrymartin@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jhs@mojatatu.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stable@vger.kernel.org \
    --cc=victor@mojatatu.com \
    --cc=yotam.gi@gmail.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