Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by Henry Martin
Fri, 27 Nov 2026 06:30
[PATCH net] net: ife: reject headers that would overflow the network header offset
Author: Henry Martin
Date: Fri, 27 Nov 2026 06:30
Date: Fri, 27 Nov 2026 06:30
56 lines
12462 bytes
12462 bytes
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
Re: [PATCH net] net: ife: reject headers that would overflow the network header offset
Author: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 07:16
Date: Sat, 28 Nov 2026 07:16
104 lines
11984 bytes
11984 bytes
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider. Critical: 1 ยท High: 0 ยท Medium: 0 ยท Low: 0 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Critical] The patch does not fully close the bug class it claims to fix. -- net: ife: reject headers that would overflow the network header offset This patch adds a bound check to ife_decode(). It rejects IFE frames when the total pull plus the extra ETH_HLEN stripped by eth_type_trans() would push the network header offset past U16_MAX. The aim is to stop the u16 network_header from being truncated, which later lets skb->data be moved to a wild address on the forwarding path. > 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; [Severity: Critical] Is this bound tight enough? It still lets the final network header offset be anything up to exactly U16_MAX. That leaves no room for the u16 offsets the stack computes from network_header afterwards. After ife_decode() returns, tcf_ife_decode() in net/sched/act_ife.c does: skb->protocol = eth_type_trans(skb, skb->dev); skb_reset_network_header(skb); So network_header can end up anywhere in the range up to 65535. Then ip_rcv_core() in net/ipv4/ip_input.c stores into the __u16 field: skb->transport_header = skb->network_header + iph->ihl*4; With network_header in [65516, 65535] and ihl=5, or a wider window when IP options are present, this sum wraps. The result is transport_header smaller than network_header. On local delivery, ip_local_deliver_finish() then does: __skb_pull(skb, skb_network_header_len(skb)); skb_network_header_len() returns the u32 value transport_header - network_header, which here is about 0xFFFF0014. In __skb_pull(), skb->len wraps upward, so this check never fires: if (unlikely(skb->len < skb->data_len)) After that, skb->data has moved about 4 GiB forward. Isn't this the same "negative offset pulled as an unsigned length" primitive the commit message describes? The difference is that it shows up on the local delivery path (ip_rcv -> ip_rcv_core -> ip_local_deliver -> ip_local_deliver_finish) instead of neigh_resolve_output(). The L4 handlers (icmp_rcv(), udp_rcv(), tcp_v4_rcv()) would then read through the wild skb->data with an inflated skb->len. The sender seems to control the offset precisely. metalen is a u16 taken from the packet. The TLV walk in tcf_ife_decode() accepts any run of 4-byte aligned unknown TLVs and only bumps the overlimit counter. That means ifehdrln can be stepped in 4-byte increments to land inside the 20-byte IPv4 wrap window. IPv6 has the same u16 wrap in ip6_rcv_core() in net/ipv6/ip6_input.c: skb->transport_header = skb->network_header + sizeof(*hdr); This happens when network_header is above 65495. On local delivery the pskb_pull() length check in ip6_protocol_deliver_rcu() appears to catch it, but the stored transport offset is still bogus. Would it be better to leave real slack below U16_MAX for the headers derived later, or to cap the IFE metadata length / total offset at a sane value, instead of only checking that the network header offset fits? > + > if (unlikely(!pskb_may_pull(skb, total_pull + ETH_HLEN))) > return NULL; > -- Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261127063006.2908187-1-bsdhenrymartin%40gmail.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads