From: Lin Jiapeng <ljp1205831794@gmail.com>
To: dsahern@kernel.org, idosch@nvidia.com, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
horms@kernel.org, netdev@vger.kernel.org
Cc: Lin Jiapeng <jiapenglin@tencent.com>,
TencentOS Corvus AI <corvus@tencent.com>
Subject: [PATCH net] ipv4: reject header length beyond linear data in ip_do_fragment()
Date: Thu, 26 Nov 2026 14:43:21 +0800 [thread overview]
Message-ID: <20261126064445.57665-1-ljp1205831794@gmail.com> (raw)
From: Lin Jiapeng <jiapenglin@tencent.com>
ip_do_fragment() splits an oversized IPv4 datagram into link-MTU-sized
fragments. It reads the header length from iph->ihl and hands the packet
to ip_frag_init()/ip_frag_next(), which assume the whole IPv4 header is
still present in the skb's linear area.
Callers that strip or rebase link-layer headers before fragmenting can
break that assumption. Open vSwitch prepare_frag() pulls the L2 stack
(up to MAX_L2_LEN = 30 bytes) off the skb after a TRUNC action has cut
the frame, so the remaining linear data can be shorter than ihl * 4.
ip_frag_init() then computes state->left = skb->len - hlen as an
unsigned underflow, and ip_frag_next() fails its skb_copy_bits() bounds
check and executes BUG(), turning a single unprivileged OVS execute
request (user+network namespace, PUSH_MPLS x4 + TRUNC + MRU) into a
deterministic kernel panic under a KASAN build:
[ 23.501259] kernel BUG at net/ipv4/ip_output.c:725!
[ 23.503346] CPU: 3 UID: 1000 PID: 110 Comm: poc Not tainted 7.4.0-rc4-ovs-hlen-ab #1 PREEMPT(lazy)
[ 23.504370] RIP: 0010:ip_frag_next+0xa71/0xb10
[ 23.533285] Call Trace:
[ 23.534004] ip_do_fragment+0xdf1/0x1a40
[ 23.534004] ovs_fragment+0x6d0/0x850
[ 23.534004] do_execute_actions+0x14a8/0x1660
[ 23.534004] ovs_execute_actions+0x64/0x1e0
[ 23.534004] ovs_packet_cmd_execute+0x2b8/0x300
[ 23.534004] Kernel panic - not syncing: Fatal exception in interrupt
Validate the IPv4 header length against skb_headlen() before any use of
hlen, rejecting malformed packets with -EINVAL. Well-formed skbs always
satisfy hlen <= skb_headlen(), so normal fragmentation is unaffected;
the existing undersized-MTU check keeps handling mtu < hlen + 8 after
the header itself is known to be present.
Closes: https://lore.kernel.org/netdev/20260922030310.8684-3-habte.yibelo@gmail.com/
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
Note: this overlaps the still-unmerged hlen half of Paulos Yibelo's
[PATCH net v6 2/2] (20260922030310.8684-3-habte.yibelo@gmail.com).
The CHECKSUM_PARTIAL equivalent logic already landed as 6785011f8b16;
the hlen guard did not. Verified with an unprivileged OVS
TRUNC+PUSH_MPLS reproducer (3/3 panic on A, clean on B with -EINVAL
at the guard).
net/ipv4/ip_output.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
index d42d776af273..d5ea596724d7 100644
--- a/net/ipv4/ip_output.c
+++ b/net/ipv4/ip_output.c
@@ -784,6 +784,11 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
*/
iph = ip_hdr(skb);
+ hlen = iph->ihl * 4;
+ if (unlikely(hlen < sizeof(*iph) || hlen > skb_headlen(skb))) {
+ err = -EINVAL;
+ goto fail;
+ }
mtu = ip_skb_dst_mtu(sk, skb);
if (IPCB(skb)->frag_max_size && IPCB(skb)->frag_max_size < mtu)
@@ -793,7 +798,6 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
* Setup starting values.
*/
- hlen = iph->ihl * 4;
if (mtu < hlen + 8) {
err = -EMSGSIZE;
goto fail;
reply other threads:[~2026-11-26 6:45 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=20261126064445.57665-1-ljp1205831794@gmail.com \
--to=ljp1205831794@gmail.com \
--cc=corvus@tencent.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=idosch@nvidia.com \
--cc=jiapenglin@tencent.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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