* [PATCH net] net: mpls: clear inner_protocol when mpls_forward() pops the last label
@ 2026-12-01 8:04 Kyuwon Cho
2026-12-04 11:04 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Kyuwon Cho @ 2026-12-01 8:04 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Willem de Bruijn, Simon Horman, David Ahern, Fourie Zhang,
Aaron Conole, Eelco Chaudron, Ilya Maximets, Jiri Benc,
Lin Jiapeng, netdev
Commit 78a86d75a70e ("net: mpls: clear inner_protocol when the last
label is popped") made skb_mpls_pop() drop the inner header that
skb_mpls_push() records once the packet is no longer MPLS. MPLS
forwarding pops labels without skb_mpls_pop(): mpls_forward() pulls
each label itself, and on the last one mpls_egress() switches
skb->protocol to IPv4 or IPv6 but leaves skb->inner_protocol and
skb->inner_network_header in place.
A packet that had MPLS pushed by an Open vSwitch datapath, was then
forwarded by MPLS routes, and reaches an OVS datapath again keeps the
old record. A second push_mpls does not record a new inner header,
because inner_protocol is still set, and ovs_fragment() trusts the old
one. After the forwarding hops have moved skb->data past it,
skb_network_offset() is negative and prepare_frag() copies
(unsigned int)-2 bytes:
BUG: KASAN: slab-out-of-bounds in prepare_frag+0x3ab/0x510
Read of size 4294967294 at addr ff11000013f16050 by task test/106
Call Trace:
<IRQ>
__asan_memcpy+0x23/0x60
prepare_frag+0x3ab/0x510
ovs_fragment+0x517/0x840
do_execute_actions+0x580e/0x7380
ovs_execute_actions+0xd3/0x3e0
ovs_dp_process_packet+0x21c/0x500
ovs_vport_receive+0x22e/0x380
netdev_frame_hook+0x396/0x6b0
An unprivileged user can set this up in its own user and network
namespace.
Clear inner_protocol in mpls_egress() once the packet is IP again, as
skb_mpls_pop() does.
Fixes: 48d2ab609b6b ("net: mpls: Fixups for GSO")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kyuwon Cho <kyuwoncho18@gmail.com>
---
The issue was found by an LLM-guided test generator that we are
developing as a research prototype. I sent it privately on 2026-11-18;
it comes to the list now because security-bugs.rst asks for bugs found
with AI assistance to be handled in public. The reproducer is available
on request.
Lin Jiapeng has posted a fix for the same prepare_frag() overflow
reached through OVS PUSH_MPLS/POP_MPLS actions:
https://lore.kernel.org/all/20261126083218.55429-1-ljp1205831794@gmail.com/
That path pops labels with skb_mpls_pop(). This one is MPLS routing:
mpls_forward() pops the last label itself and never calls
skb_mpls_pop(), so a check there would not cover it.
Reproduced on mainline v7.4-rc5 (fe6ff8d5d675, with KASAN); the patch
is against net (76fca30e8d34), and with it the reproducer runs clean.
net/mpls/af_mpls.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
index ad4ad6f2001a..e2e5da8d757b 100644
--- a/net/mpls/af_mpls.c
+++ b/net/mpls/af_mpls.c
@@ -361,6 +361,9 @@ static bool mpls_egress(struct net *net, struct mpls_route *rt,
break;
}
+ if (success)
+ skb->inner_protocol = 0;
+
return success;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net] net: mpls: clear inner_protocol when mpls_forward() pops the last label
2026-12-01 8:04 [PATCH net] net: mpls: clear inner_protocol when mpls_forward() pops the last label Kyuwon Cho
@ 2026-12-04 11:04 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-04 11:04 UTC (permalink / raw)
To: kyuwoncho18
Cc: davem, edumazet, kuba, pabeni, willemb, horms, dsahern,
littleddfu, aconole, echaudro, i.maximets, jbenc, jiapenglin,
netdev
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · 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).
- [High] The patch fixes only one source of the stale state, not the
place where it is trusted, so the prepare_frag() overflow described in…
--
net: mpls: clear inner_protocol when mpls_forward() pops the last label
This patch clears skb->inner_protocol in mpls_egress() once the last MPLS
label has been popped by mpls_forward() and the packet is IPv4 or IPv6
again. skb_mpls_pop() already does the same. The goal is to stop a later
OVS push_mpls from reusing a stale inner_network_header, which leads to a
huge memcpy() in prepare_frag().
> diff --git a/net/mpls/af_mpls.c b/net/mpls/af_mpls.c
> index ad4ad6f2001ab..e2e5da8d757b8 100644
> --- a/net/mpls/af_mpls.c
> +++ b/net/mpls/af_mpls.c
> @@ -361,6 +361,9 @@ static bool mpls_egress(struct net *net, struct mpls_route *rt,
> break;
> }
>
> + if (success)
> + skb->inner_protocol = 0;
> +
[Severity: High]
This closes the mpls_forward() source. Can the prepare_frag() overflow
still be reached from other paths that leave a stale inner_protocol and
inner_network_header behind?
skb_mpls_push() trusts the recorded state. It does not check that the
packet is MPLS or that the recorded offset is still valid:
net/core/skbuff.c:skb_mpls_push() {
...
if (!skb->inner_protocol) {
skb_set_inner_network_header(skb, skb_network_offset(skb));
skb_set_inner_protocol(skb, skb->protocol);
}
...
}
ovs_fragment() then installs that offset, and its only check is a signed
upper bound:
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) {
...
}
A negative offset passes that check and becomes the memcpy() length in
prepare_frag():
unsigned int hlen = skb_network_offset(skb);
...
memcpy(&data->l2_data, skb->data, hlen);
IP tunnels such as ipip seem to leave the same stale state without any
MPLS forwarding. Take two nested ipip tunnels and a packet that is neither
GSO nor CHECKSUM_PARTIAL (for example ICMP fragments):
ipip_tunnel_xmit()
iptunnel_handle_offloads()
skb_reset_inner_headers() <- encapsulation was 0
skb->encapsulation = 0; <- not GSO, not CHECKSUM_PARTIAL
skb_set_inner_ipproto() <- shares a union with inner_protocol
The second ipip xmit also sees encapsulation == 0. It resets
inner_network_header to the middle IP header.
On receive, ipip_tunnel_rcv() runs twice, through
__iptunnel_pull_header() and ip_tunnel_rcv(). skb_scrub_packet(),
iptunnel_pull_offloads() and ip_tunnel_rcv() never clear inner_protocol
or inner_network_header. The recorded inner header now points at the
stripped middle header, 20 bytes before the real IP header.
Suppose the packet is then forwarded out a veth into an OVS port.
__dev_forward_skb2() does not clear these fields. OVS ct() reassembles
the fragments, and skb_morph() copies the fields over.
A push_mpls action then calls skb_mpls_push() with encapsulation == 0 and
a non-zero inner_protocol, so the stale offset is kept. On output,
skb_network_offset() in ovs_fragment() would be -6, and prepare_frag()
would copy 0xFFFFFFFA bytes.
This path comes from reading the code and has not been reproduced. Every
step needs only CAP_NET_ADMIN in a user namespace, the same setup the
commit message describes.
This would be the third point fix for the same sink. The first was
78a86d75a70e for skb_mpls_pop(), and the second is Lin Jiapeng's patch for
the OVS PUSH_MPLS/POP_MPLS path.
Would a check at the point of use be more robust? For example,
skb_mpls_push() could reuse the recorded inner header only when
eth_p_mpls(skb->protocol) is already true. ovs_fragment() could also
reject skb_network_offset(skb) < 0.
> return success;
> }
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/179607412883.627473.3063198838105400446%40gmail.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 11:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 8:04 [PATCH net] net: mpls: clear inner_protocol when mpls_forward() pops the last label Kyuwon Cho
2026-12-04 11:04 ` 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