From: Lin Jiapeng 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 Signed-off-by: Lin Jiapeng --- 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;