From: Lin Jiapeng <jiap…@tencent.com> Commit 6785011f8b16 ("ipv4: validate checksum_start before completing checksum") added a checksum-start check before skb_checksum_help(), but did not validate the IPv4 header it reads. TencentOS Corvus AI found an OVS fragmentation BUG with a PUSH_MPLS/TRUNC reproducer, and review of the first fix identified related checksum-order and network-offset cases. That fix was incomplete. ip_do_fragment() completes CHECKSUM_PARTIAL before validating the fixed header or IHL, while its fragment helpers require skb->data to point to a complete linear IPv4 header. OVS prepare_frag() can also copy and pull more L2 bytes than remain after TRUNC. The resulting state->left underflow makes ip_frag_next() copy beyond the logical linear header and then hit BUG(). The enabled detector configuration records the failing path: kernel BUG at net/ipv4/ip_output.c:725 Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:ip_frag_next+0xa70/0xb10 Call Trace: ip_do_fragment+0xdf0/0x1a30 do_output+0x33c/0x5c0 do_execute_actions+0x5d8e/0x76d0 ovs_packet_cmd_execute+0xd57/0x14b0 Kernel panic - not syncing: Fatal exception in interrupt Validate the network offset, fixed header and IHL before checksum completion, retain the validated header length, and reload iph after the checksum helper. In OVS, reject negative or unpullable L2 offsets before prepare_frag() copies or pulls them. Valid packets continue through the existing checksum and fragmentation paths. Reproduce with CONFIG_USER_NS, CONFIG_NET_NS, CONFIG_OPENVSWITCH and CONFIG_MPLS enabled. An unprivileged process creates a user+network namespace, gains CAP_NET_ADMIN only there, creates an OVS datapath, and executes a 60-byte IPv4 frame with PUSH_MPLS x4, TRUNC(45), OUTPUT and MRU=28. Boot with oops=panic panic=1 panic_on_warn=1; no race is required. The unfixed kernel panics in ip_frag_next(), while the fixed kernel drops the malformed packet and still fragments plain IPv4 with TRUNC(45) and MRU=28. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Suggested-by: Paulos Yibelo <habt…@gmail.com> Reported-by: TencentOS Corvus AI <corv…@tencent.com> Signed-off-by: Lin Jiapeng <jiap…@tencent.com> --- v1 -> v2: - validate the fixed IPv4 header and IHL before CHECKSUM_PARTIAL - require skb->data == skb_network_header() for the fragment helpers - reload iph after skb_checksum_help() - reject invalid OVS L2 geometry before prepare_frag() - describe the pre-BUG read and remove the incorrect KASAN dependency - include the panic/oops call trace for localization - credit Paulos Yibelo with Suggested-by v1: https://lore.kernel.org/netdev/2026…@gmail.com/ base-commit: 0d39bf81267861742b80d5f1c52e8a63e9ca0ca1 net/ipv4/ip_output.c | 27 +++++++++++++++++++-------- net/openvswitch/actions.c | 7 +++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index d42d776af273..365b9c8b9c9b 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -770,21 +770,33 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, struct ip_frag_state state; int err = 0; - /* for offloaded checksums cleanup checksum before fragmentation */ + /* + * Point into the IP datagram header. The fragmentation helpers use + * skb->data as the header base, so reject any other network offset. + */ + if (unlikely(skb_network_offset(skb) != 0 || + skb_headlen(skb) < sizeof(struct iphdr))) { + err = -EINVAL; + goto fail; + } + + iph = ip_hdr(skb); + hlen = iph->ihl * 4; + if (unlikely(hlen < sizeof(*iph) || hlen > skb_headlen(skb))) { + err = -EINVAL; + goto fail; + } + + /* Complete offloaded checksums only after validating the IP header. */ if (skb->ip_summed == CHECKSUM_PARTIAL) { err = ip_check_csum_start(skb); if (!err) err = skb_checksum_help(skb); if (err) goto fail; + iph = ip_hdr(skb); } - /* - * Point into the IP datagram header. - */ - - iph = ip_hdr(skb); - mtu = ip_skb_dst_mtu(sk, skb); if (IPCB(skb)->frag_max_size && IPCB(skb)->frag_max_size < mtu) mtu = IPCB(skb)->frag_max_size; @@ -793,7 +805,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; diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 7691f262294d..b65304bb5ab8 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -818,6 +818,13 @@ static void ovs_fragment(struct net *net, struct vport *vport, goto err; } + if (skb_network_offset(skb) < 0 || + skb_network_offset(skb) > skb_headlen(skb)) { + OVS_NLERR(1, "Invalid L2 header length for fragmentation"); + kfree_skb_reason(skb, SKB_DROP_REASON_PKT_TOO_SMALL); + return; + } + if (key->eth.type == htons(ETH_P_IP)) { struct rtable ovs_rt = { 0 }; unsigned long orig_dst;