Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2] net: mpls: clear stale inner state on pop
@ 2026-12-04  7:06 Lin Jiapeng
  2026-12-05  7:25 ` netdev-bot+sashiko
  0 siblings, 1 reply; 2+ messages in thread
From: Lin Jiapeng @ 2026-12-04  7:06 UTC (permalink / raw)
  To: aconole, almasrymina, davem, dev, echaudro, edumazet, horms,
	i.maximets, jbenc, jiayuan.chen, josef, kuba, littleddfu, netdev,
	pabeni, willemb
  Cc: Lin Jiapeng, stable, TencentOS Corvus AI

From: Lin Jiapeng <jiapenglin@tencent.com>

Commit 78a86d75a70e ("net: mpls: clear inner_protocol when the last
label is popped") made skb_mpls_pop() clear the saved inner protocol when
the next protocol is not MPLS, so a later push records fresh inner state.
TencentOS Corvus AI audited the remaining Open vSwitch MPLS fragmentation
paths and got a KASAN slab-out-of-bounds report in prepare_frag().

That fix was incomplete. When every POP declares an MPLS next protocol,
an excessive pop can advance the current network header beyond the saved
inner_network_header without satisfying the clearing condition.
ovs_fragment() copies that stale offset into network_header; on an L3 port
it becomes -4, passes the signed MAX_L2_LEN check and is widened to an
unsigned memcpy length. Ethernet ports can also retain positive stale
offsets, so a negative-only downstream check is insufficient. The L3 case
produces this report and panic:
  [   44.274264] BUG: KASAN: slab-out-of-bounds in prepare_frag+0x3c2/0x4c0
  [   44.274757] Read of size 4294967292 at addr ff110001069fc044 by task ovs_frag_trigge/131
  [   44.275681] CPU: 0 UID: 1000 PID: 131 Comm: ovs_frag_trigge Not tainted 7.4.0-rc5 #1 PREEMPT(lazy)
  [   44.276170] Call Trace:
  [   44.277460]  __asan_memcpy+0x23/0x60
  [   44.277531]  prepare_frag+0x3c2/0x4c0
  [   44.277606]  ovs_fragment+0x578/0x860
  [   44.279078]  do_output+0x33e/0x5c0
  [   44.279210]  do_execute_actions+0x5eb8/0x7800
  [   44.279748]  ovs_execute_actions+0xdd/0x420
  [   44.280105]  ovs_dp_process_packet+0x23b/0x570
  [   44.280405]  clone_execute+0xe9/0x670
  [   44.280495]  do_execute_actions+0x16af/0x7800
  [   44.280987]  ovs_execute_actions+0xdd/0x420
  [   44.281155]  ovs_packet_cmd_execute+0xd69/0x14a0
  [   44.285198] Allocated by task 131:
  [   44.285393]  kasan_save_stack+0x30/0x50
  [   44.285738]  __kasan_kmalloc+0x7f/0x90
  [   44.285830]  __kmalloc_node_track_caller_noprof+0x27e/0x6d0
  [   44.285906]  kmalloc_reserve+0xc4/0x2f0
  [   44.285982]  __alloc_skb+0x143/0x650
  [   44.286062]  __netdev_alloc_skb+0x5f/0x6d0
  [   44.286157]  ovs_packet_cmd_execute+0x21a/0x14a0
  [   44.287020] The buggy address belongs to the object at ff110001069fc000
  [   44.287020]  which belongs to the cache kmalloc-2k of size 2048
  [   44.287125] The buggy address is located 68 bytes inside of
  [   44.287125]  allocated 2048-byte region [ff110001069fc000, ff110001069fc800)
  [   44.290904] Kernel panic - not syncing: KASAN: panic_on_warn set ...

Extend the existing invalidation in skb_mpls_pop(): after setting the
current network header, also clear the inner state when
skb_inner_network_offset(skb) is smaller than mac_len. Set
inner_network_header to the current network_header together with clearing
inner_protocol, because OVS can fragment immediately after the POP without
re-extracting its flow key. Packets whose inner header remains at or after
the current network header keep the old behavior.

Reproducing this needs CONFIG_OPENVSWITCH, CONFIG_USER_NS and
CONFIG_NET_NS. From uid 1000, create a user and network namespace, use
the OVS netlink interface to create a datapath and an L3 flow, install
MPLS push/pop actions and an output action with MRU=100, then execute
IPv4 and IPv6 packets through that flow with OVS_PACKET_CMD_EXECUTE. No
race or special hardware is required. The unfixed kernel emits the report
above and panics, while the patched kernel completes both runs without a
detector report.

Fixes: 78a86d75a70e ("net: mpls: clear inner_protocol when the last label is popped")
Cc: stable@vger.kernel.org
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
v2:
 - Move the fix from ovs_fragment() to skb_mpls_pop(), extending
   78a86d75a70e as requested by Jiri Benc.
 - Cover positive stale offsets on Ethernet ports and invalidate the saved
   inner_network_header for immediate consumers.
 - Rebuild and rerun the IPv4/IPv6 A/B reproducers and functional tests.

v1: https://lore.kernel.org/all/20261126083218.55429-1-ljp1205831794@gmail.com/

 net/core/skbuff.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 85d5caa08887..df700fb9f409 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -6834,12 +6834,15 @@ int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
 	}
 	skb->protocol = next_proto;
 
-	/* The last label is gone, so the inner header recorded by
-	 * skb_mpls_push() no longer describes this packet. Drop it, or a
-	 * later push keeps the stale offset.
+	/* Clear the inner state when the last label is gone or the recorded
+	 * inner header precedes the current network header. Point it at the
+	 * current network header so consumers cannot reuse a stale offset.
 	 */
-	if (!eth_p_mpls(next_proto))
+	if (!eth_p_mpls(next_proto) ||
+	    skb_inner_network_offset(skb) < mac_len) {
 		skb->inner_protocol = 0;
+		skb->inner_network_header = skb->network_header;
+	}
 
 	return 0;
 }

-- 
2.55.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net v2] net: mpls: clear stale inner state on pop
  2026-12-04  7:06 [PATCH net v2] net: mpls: clear stale inner state on pop Lin Jiapeng
@ 2026-12-05  7:25 ` netdev-bot+sashiko
  0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05  7:25 UTC (permalink / raw)
  To: ljp1205831794
  Cc: aconole, almasrymina, davem, dev, echaudro, edumazet, horms,
	i.maximets, jbenc, jiayuan.chen, josef, kuba, littleddfu, netdev,
	pabeni, willemb, jiapenglin, stable, corvus

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

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).

- [High] The fix is incomplete.
- [Low] net: mpls: Fixes trailer cites partial fix instead of originating
  commit

--

net: mpls: clear stale inner state on pop

This patch extends the inner state invalidation in skb_mpls_pop(). It now
also fires when the recorded inner network header sits before the current
network header after an excess pop. In that case inner_protocol is cleared
and inner_network_header is set to the current network header, so
ovs_fragment() no longer picks up a negative or stale positive offset.

> diff --git a/net/core/skbuff.c b/net/core/skbuff.c
> index 8ac7ad1378a12..81d101efb8cec 100644
> --- a/net/core/skbuff.c
> +++ b/net/core/skbuff.c
> @@ -6865,12 +6865,15 @@ int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
>  	}
>  	skb->protocol = next_proto;
>  
> -	/* The last label is gone, so the inner header recorded by
> -	 * skb_mpls_push() no longer describes this packet. Drop it, or a
> -	 * later push keeps the stale offset.
> +	/* Clear the inner state when the last label is gone or the recorded
> +	 * inner header precedes the current network header. Point it at the
> +	 * current network header so consumers cannot reuse a stale offset.
>  	 */
> -	if (!eth_p_mpls(next_proto))
> +	if (!eth_p_mpls(next_proto) ||
> +	    skb_inner_network_offset(skb) < mac_len) {
>  		skb->inner_protocol = 0;
> +		skb->inner_network_header = skb->network_header;
> +	}

[Severity: Low]
The Fixes tag points at 78a86d75a70e, but that commit did not
introduce the stale inner_network_header. It only added the
inner_protocol clear in skb_mpls_pop() for a non-MPLS next_proto. It
also carries its own Fixes: 48d2ab609b6b ("net: mpls: Fixups for GSO").

The stale offset that ovs_fragment() copies into network_header comes
from 48d2ab609b6b. That commit started recording inner_network_header
and inner_protocol on push, but never updated them on pop.
c66549ffd666 ("openvswitch: correctly fragment packet with mpls
headers") then made ovs_fragment() consume that value. The excess-pop
case handled here, where every POP declares an MPLS next_proto, was
reachable before 78a86d75a70e existed.

With only 78a86d75a70e cited, the stable and CVE tooling will treat
trees that have 48d2ab609b6b but not 78a86d75a70e as unaffected. This
fix would then not reach them.

Should this be Fixes: 48d2ab609b6b ("net: mpls: Fixups for GSO")
instead, or both tags? The hunk is written on top of the
78a86d75a70e condition. Older trees would need either that commit or
a small adjustment, and a note for the stable maintainers below the
--- line might help.

[Severity: High]
Does this fully close the excess-pop path into ovs_fragment()?

After an excess pop with an MPLS next_proto, skb->protocol stays MPLS. The
bytes at the current network header are no longer an IP header. They start
MPLS_HLEN or more bytes into the original IP header.

invalidate_flow_key() only touches key->mac_proto, so key->eth.type still
says IPv4 or IPv6.

ovs_fragment() then does:

net/openvswitch/actions.c:ovs_fragment() {
    ...
	if (eth_p_mpls(skb->protocol)) {
		orig_network_offset = skb_network_offset(skb);
		skb->network_header = skb->inner_network_header;
	}

	if (skb_network_offset(skb) > MAX_L2_LEN) {
    ...
		prepare_frag(vport, skb, orig_network_offset,
			     ovs_key_mac_proto(key));
    ...
		ip_do_fragment(net, skb->sk, skb, ovs_vport_output);
    ...
}

With the new assignment the offset equals mac_len, so it passes the
MAX_L2_LEN check. ip_do_fragment() or ip6_fragment() is then chosen based
on the stale key->eth.type, and the shifted bytes get parsed as an L3
header.

With one excess pop on an IPv4 flow, iph->ihl comes from the high byte of
the original IP ID, which the sender controls. ip_do_fragment() only checks
hlen against the MTU:

	hlen = iph->ihl * 4;
	if (mtu < hlen + 8) {

Nothing bounds hlen by skb->len or skb_headlen().

Could the following setup crash? It uses an Ethernet-framed flow (mac_len
14) that outputs to an ARPHRD_NONE port with hard_header_len 0. A TUN-mode
tun is one such port, and ovs_netdev_link() accepts it. Set MRU=68, make
the garbage ihl 15 (hlen=60), and use a 70-byte frame after the pops:

do_output()
    70 > mru + vport->dev->hard_header_len (68 + 0), so ovs_fragment()
  prepare_frag()
    pulls 14 bytes, skb->len is now 56
  ip_do_fragment()
    mtu 68 >= hlen + 8 (68), so it continues
    ip_frag_init()
      state->left = skb->len - hlen = 56 - 60, wraps to 0xFFFFFFFC
    ip_frag_next()
      skb_copy_from_linear_data(skb, ..., state->hlen) copies 60 bytes
      out of a 56-byte area
      skb_copy_bits(skb, 60, ..., 8) fails
        BUG()

For non-linear skbs, wouldn't the hlen-byte linear copy in ip_frag_next()
also read past skb->tail into tailroom or skb_shared_info? Those bytes
would then go out on the wire in the fragment headers.

The commit message says:

  Ethernet ports can also retain positive stale offsets, so a
  negative-only downstream check is insufficient.

This path still treats a partly consumed packet as IPv4/IPv6. Would it be
better to refuse to fragment, or to validate the L3 header, once the inner
state has been invalidated? Pointing inner_network_header at the current
network header does not seem to stop this.

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204070712.82311-1-ljp1205831794%40gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-05  7:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  7:06 [PATCH net v2] net: mpls: clear stale inner state on pop Lin Jiapeng
2026-12-05  7:25 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox