* [PATCH net] openvswitch: reject negative L2 length in ovs_fragment()
@ 2026-11-26 8:31 Lin Jiapeng
2026-11-26 9:14 ` Jiri Benc
2026-11-27 9:13 ` netdev-bot+sashiko
0 siblings, 2 replies; 5+ messages in thread
From: Lin Jiapeng @ 2026-11-26 8:31 UTC (permalink / raw)
To: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, jbenc, netdev, dev
Cc: Lin Jiapeng, stable, TencentOS Corvus AI
From: Lin Jiapeng <jiapenglin@tencent.com>
ovs_fragment() refragments MPLS packets from their inner network header
and saves the L2 header in a MAX_L2_LEN-byte buffer before fragmenting.
POP_MPLS can leave inner_network_header behind skb->data. The signed
offset is then negative and passes the "> MAX_L2_LEN" check, so
prepare_frag() widens it to 0xfffffffc for memcpy() into l2_data. An
unprivileged user can trigger this on both IPv4 and IPv6 paths. KASAN
reports:
BUG: KASAN: slab-out-of-bounds in prepare_frag+0x3c2/0x4c0
Read of size 4294967292 at addr ff110001059cf044 by task
ovs_frag_trigge/132
__asan_memcpy+0x23/0x60
prepare_frag+0x3c2/0x4c0
ovs_fragment+0x578/0x860
Reject a negative offset together with an oversized one and drop the
packet through OVS_DROP_FRAG_L2_TOO_LONG. Valid offsets are unchanged.
Fixes: c66549ffd666 ("openvswitch: correctly fragment packet with mpls headers")
Cc: stable@vger.kernel.org
Reported-by: TencentOS Corvus AI <corvus@tencent.com>
Signed-off-by: Lin Jiapeng <jiapenglin@tencent.com>
---
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 12e339cbf791..9c19fe8676a7 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -788,7 +788,8 @@ static void ovs_fragment(struct net *net, struct vport *vport,
skb->network_header = skb->inner_network_header;
}
- if (skb_network_offset(skb) > MAX_L2_LEN) {
+ if (skb_network_offset(skb) > MAX_L2_LEN ||
+ skb_network_offset(skb) < 0) {
OVS_NLERR(1, "L2 header too long to fragment");
reason = OVS_DROP_FRAG_L2_TOO_LONG;
goto err;
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: reject negative L2 length in ovs_fragment()
2026-11-26 8:31 [PATCH net] openvswitch: reject negative L2 length in ovs_fragment() Lin Jiapeng
@ 2026-11-26 9:14 ` Jiri Benc
2026-11-26 9:34 ` Lin Jiapeng
2026-11-27 9:13 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: Jiri Benc @ 2026-11-26 9:14 UTC (permalink / raw)
To: Lin Jiapeng
Cc: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, netdev, dev, Lin Jiapeng, stable, TencentOS Corvus AI
On Thu, 26 Nov 2026 16:31:41 +0800, Lin Jiapeng wrote:
> From: Lin Jiapeng <jiapenglin@tencent.com>
>
> ovs_fragment() refragments MPLS packets from their inner network header
> and saves the L2 header in a MAX_L2_LEN-byte buffer before fragmenting.
>
> POP_MPLS can leave inner_network_header behind skb->data. The signed
> offset is then negative and passes the "> MAX_L2_LEN" check, so
> prepare_frag() widens it to 0xfffffffc for memcpy() into l2_data. An
> unprivileged user can trigger this on both IPv4 and IPv6 paths. KASAN
> reports:
> BUG: KASAN: slab-out-of-bounds in prepare_frag+0x3c2/0x4c0
> Read of size 4294967292 at addr ff110001059cf044 by task
> ovs_frag_trigge/132
> __asan_memcpy+0x23/0x60
> prepare_frag+0x3c2/0x4c0
> ovs_fragment+0x578/0x860
>
> Reject a negative offset together with an oversized one and drop the
> packet through OVS_DROP_FRAG_L2_TOO_LONG. Valid offsets are unchanged.
This was supposed to be fixed by
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=78a86d75a70e1e227711c72865c59b1422d0a5ae
What kernel did you reproduce this on?
Jiri
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: reject negative L2 length in ovs_fragment()
2026-11-26 9:14 ` Jiri Benc
@ 2026-11-26 9:34 ` Lin Jiapeng
2026-11-26 10:08 ` Jiri Benc
0 siblings, 1 reply; 5+ messages in thread
From: Lin Jiapeng @ 2026-11-26 9:34 UTC (permalink / raw)
To: Jiri Benc
Cc: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, netdev, dev, Lin Jiapeng, stable, TencentOS Corvus AI
On 2026-11-26 5:14 p.m., Jiri Benc wrote:
> On Thu, 26 Nov 2026 16:31:41 +0800, Lin Jiapeng wrote:
>> From: Lin Jiapeng <jiapenglin@tencent.com>
>> ...
>> Reject a negative offset together with an oversized one and drop the
>> packet through OVS_DROP_FRAG_L2_TOO_LONG. Valid offsets are unchanged.
>
> This was supposed to be fixed by
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=78a86d75a70e1e227711c72865c59b1422d0a5ae
>
> What kernel did you reproduce this on?
>
> Jiri
Thank you for pointing me to that fix. I reproduced the issue on the
then-current mainline, commit
4dce97c6c265544342e716e62fd24bbb232590c5, fetched on 2026-11-25.
I also verified that 78a86d75a70e1e227711c72865c59b1422d0a5ae is
already an ancestor of this commit.
You are right that 78a86d75 addresses the original issue. However, it
does not cover this particular variant.
The existing fix is reached through the following POP path:
do_execute_actions()
-> pop_mpls()
-> skb_mpls_pop()
-> if (!eth_p_mpls(next_proto))
skb->inner_protocol = 0;
Thus, when the last POP specifies a non-MPLS next_proto, the stale
inner_protocol state is cleared as intended.
My reproducer instead installs the following action list:
PUSH_MPLS,
POP_MPLS(ETH_P_MPLS_UC),
POP_MPLS(ETH_P_MPLS_UC),
OUTPUT
This takes a different path:
PUSH_MPLS
-> skb_mpls_push()
-> record inner_network_header and inner_protocol
POP_MPLS(0x8847) x 2
-> pop_mpls()
-> skb_mpls_pop()
-> advance skb->data by four bytes per POP
-> !eth_p_mpls(next_proto) is false for both POPs
-> inner_protocol is not cleared
OUTPUT
-> do_output()
-> ovs_fragment()
-> skb->network_header = skb->inner_network_header
-> skb_network_offset(skb) becomes -4
-> the signed "> MAX_L2_LEN" check does not reject it
-> prepare_frag()
-> unsigned int hlen = skb_network_offset(skb)
-> hlen becomes 0xfffffffc
-> memcpy(&data->l2_data, skb->data, hlen)
After PUSH_MPLS followed by the two POP_MPLS actions, skb->data is four
bytes past the saved inner_network_header. Because both POP actions
still declare next_proto as MPLS, the clearing condition added by
78a86d75 is never satisfied, even though the label stack has already
been emptied.
This produces the reported KASAN signature:
BUG: KASAN: slab-out-of-bounds in prepare_frag
Read of size 4294967292
So this is not a case of the fix being absent from the tested kernel;
rather, the all-MPLS POP sequence described above is not covered by its
clearing condition.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: reject negative L2 length in ovs_fragment()
2026-11-26 9:34 ` Lin Jiapeng
@ 2026-11-26 10:08 ` Jiri Benc
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Benc @ 2026-11-26 10:08 UTC (permalink / raw)
To: Lin Jiapeng
Cc: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, netdev, dev, Lin Jiapeng, stable, TencentOS Corvus AI
On Thu, 26 Nov 2026 17:34:19 +0800, Lin Jiapeng wrote:
> After PUSH_MPLS followed by the two POP_MPLS actions, skb->data is four
> bytes past the saved inner_network_header. Because both POP actions
> still declare next_proto as MPLS, the clearing condition added by
> 78a86d75 is never satisfied, even though the label stack has already
> been emptied.
In other words, the fix in 78a86d75a70e was incomplete. In addition to
checking whether the caller is claiming to pop the last header, we also
need to check whether the inner_network_header is still inside the
packet and reset the inner_protocol if it's not.
Please adjust, test and send v2.
Note the severity of this bug is close to zero (as also evidenced by
no previous reports of such panic). Your action list is not going to
appear anywhere in practice.
Also, permanently add to your prompt that your AI must check the git
log for similar bugs in the past, analyze the past fixes and verify the
proposed fix is in alignment with them.
Jiri
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] openvswitch: reject negative L2 length in ovs_fragment()
2026-11-26 8:31 [PATCH net] openvswitch: reject negative L2 length in ovs_fragment() Lin Jiapeng
2026-11-26 9:14 ` Jiri Benc
@ 2026-11-27 9:13 ` netdev-bot+sashiko
1 sibling, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-27 9:13 UTC (permalink / raw)
To: ljp1205831794
Cc: aconole, echaudro, i.maximets, davem, edumazet, kuba, pabeni,
horms, jbenc, netdev, dev, jiapenglin, stable, corvus
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · 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).
- [Medium] The patch makes ovs_fragment()
(net/openvswitch/actions.c:791-792) reject only…
- [Low] The new `skb_network_offset(skb) < 0` case in ovs_fragment()
(actions.c:791-795) reuses OVS_DROP_FRAG_L2_TOO_LONG and the log text…
--
openvswitch: reject negative L2 length in ovs_fragment()
This patch makes ovs_fragment() drop MPLS packets whose inner network
header sits before skb->data. Before the patch, a negative offset passed
the MAX_L2_LEN check and reached a huge memcpy() in prepare_frag(). Such
packets are now dropped with OVS_DROP_FRAG_L2_TOO_LONG.
> diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
> index 12e339cbf7912..9c19fe8676a7a 100644
> --- a/net/openvswitch/actions.c
> +++ b/net/openvswitch/actions.c
> @@ -788,7 +788,8 @@ static void ovs_fragment(struct net *net, struct vport *vport,
> skb->network_header = skb->inner_network_header;
> }
>
> - if (skb_network_offset(skb) > MAX_L2_LEN) {
> + if (skb_network_offset(skb) > MAX_L2_LEN ||
> + skb_network_offset(skb) < 0) {
[Severity: Medium]
Is a lower bound of 0 strong enough here?
In the eth_p_mpls() branch, orig_network_offset is where the label stack
starts. A real inner network header is always at least
orig_network_offset + MPLS_HLEN past skb->data. So any offset in
[0, orig_network_offset) would come from the same stale
inner_network_header that the commit message blames on POP_MPLS.
Each excess skb_mpls_pop() moves skb->data forward but does not touch
inner_network_header:
net/core/skbuff.c:skb_mpls_pop() {
...
__skb_pull(skb, MPLS_HLEN);
skb_reset_mac_header(skb);
skb_set_network_header(skb, mac_len);
...
}
On an L3 port (mac_len 0), one excess pop gives -4. That matches the
0xfffffffc in the KASAN report, and the new check catches it.
On an Ethernet port (mac_len 14), the same pops would give 10, then 6,
then 2. The offset only goes negative after the fourth pop. Offsets 10,
6 and 2 all pass the new check.
With an offset of 10, prepare_frag() saves a short L2 header and pulls
10 bytes:
data->network_offset = orig_network_offset;
...
data->l2_len = hlen;
memcpy(&data->l2_data, skb->data, hlen);
ip_do_fragment() or ip6_fragment() would then parse a fake L3 header
from the bytes that the memmove() in skb_mpls_pop() left behind. For
IPv4 those bytes are the last two bytes of the source MAC followed by
the 0x8847 ethertype, so iph->ihl would come from the source MAC.
ip_frag_next() then copies iph->ihl * 4 bytes with
skb_copy_from_linear_data() and does not check skb_headlen(). Stale
buffer bytes might leak if the fake ihl is larger than the linear area.
That part is speculative.
On output, ovs_vport_output() pushes back only data->l2_len (10) bytes
but sets the network header at data->network_offset (14):
skb_push(skb, data->l2_len);
memcpy(skb->data, &data->l2_data, data->l2_len);
...
if (eth_p_mpls(skb->protocol)) {
skb->inner_network_header = skb->network_header;
skb_set_network_header(skb, data->network_offset);
skb_reset_mac_len(skb);
}
It isn't clear whether this over-pop vector can actually be reached in
this tree. The commit message does not describe it.
__ovs_nla_copy_actions() resets eth_type when mpls_label_count reaches
0, which rejects a simple push_mpls followed by two pop_mpls(0x8847)
under an IPv4 flow key.
An MPLS flow key with a masked label count can over-pop through the
u32 underflow. However, key->eth.type is then MPLS at runtime, so
ovs_fragment() takes the WARN branch instead of reaching
prepare_frag().
A path that carries the stale state across recirculation looks blocked
by the skb_mpls_pop() change that clears inner_protocol when popping to
a non-MPLS ethertype (commit 78a86d75a70e1e).
If the vector the commit relies on does exist for Ethernet ports, would
it be safer to check this inside the eth_p_mpls() branch instead:
skb_network_offset(skb) < orig_network_offset + MPLS_HLEN
using signed offsets? Valid traffic would not be affected.
> OVS_NLERR(1, "L2 header too long to fragment");
> reason = OVS_DROP_FRAG_L2_TOO_LONG;
[Severity: Low]
This isn't a bug, but the new negative offset case reuses the "L2 header
too long to fragment" message and OVS_DROP_FRAG_L2_TOO_LONG. A negative
offset means the L2 length is invalid, not too long.
Drop monitor and the kfree_skb tracepoint will show the
OVS_DROP_FRAG_L2_TOO_LONG name from net/openvswitch/drop.h for this
case. Reusing the reason makes sense for a stable fix. Could the log
text say something like "invalid L2 header length" instead?
> goto err;
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126083218.55429-1-ljp1205831794%40gmail.com
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-27 9:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26 8:31 [PATCH net] openvswitch: reject negative L2 length in ovs_fragment() Lin Jiapeng
2026-11-26 9:14 ` Jiri Benc
2026-11-26 9:34 ` Lin Jiapeng
2026-11-26 10:08 ` Jiri Benc
2026-11-27 9:13 ` 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