* [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array
@ 2026-09-06 8:21 Norbert Szetei
2026-09-07 19:43 ` Ilya Maximets
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Norbert Szetei @ 2026-09-06 8:21 UTC (permalink / raw)
To: netdev
Cc: Aaron Conole, Eelco Chaudron, Ilya Maximets, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, dev,
linux-kernel
tbl_mask_array_realloc() retires the old mask_array before it stops being
reachable:
old = ovsl_dereference(tbl->mask_array);
if (old) {
...
call_rcu(&old->rcu, mask_array_rcu_cb);
}
rcu_assign_pointer(tbl->mask_array, new);
call_rcu() only waits for read-side critical sections already in flight.
tbl->mask_array still points at old between the call_rcu() and the
rcu_assign_pointer(), so a reader entering ovs_flow_tbl_lookup_stats() in
that window picks up old in a fresh critical section that the pending
grace period does not cover.
tbl_mask_array_realloc() runs in process context under ovs_mutex, so the
window is preemptible and can outlast the grace period. Then
mask_array_rcu_cb() frees old before the swap runs:
BUG: KASAN: slab-use-after-free in flow_lookup.constprop.0+0x2bf/0x2f0
Read of size 8 at addr ffff888020b3e018 by task poc/741
flow_lookup.constprop.0+0x2bf/0x2f0
ovs_flow_tbl_lookup_stats+0x4a3/0x5c0
ovs_dp_process_packet+0x19c/0x710
ovs_vport_receive+0x243/0x390
internal_dev_xmit+0x81/0x170
Freed by task 728:
kfree+0x16a/0x4e0
rcu_core+0x853/0x1030
Publish the new array before retiring the old one. The kfree_rcu() that
call_rcu() replaced ran after the swap.
Fixes: eac87c413bf9 ("net: openvswitch: reorder masks array based on usage")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5
Signed-off-by: Norbert Szetei <norbert@doyensec.com>
---
Reproducer available if needed. The issue was confirmed on a KASAN
build, where the crash reproduces in about a minute on a 2 vCPU guest.
net/openvswitch/flow_table.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/openvswitch/flow_table.c b/net/openvswitch/flow_table.c
index 67d5b8c0fe79..1e0f9d193eb0 100644
--- a/net/openvswitch/flow_table.c
+++ b/net/openvswitch/flow_table.c
@@ -257,11 +257,13 @@ static int tbl_mask_array_realloc(struct flow_table *tbl, int size)
if (ovsl_dereference(old->masks[i]))
new->masks[new->count++] = old->masks[i];
}
- call_rcu(&old->rcu, mask_array_rcu_cb);
}
rcu_assign_pointer(tbl->mask_array, new);
+ if (old)
+ call_rcu(&old->rcu, mask_array_rcu_cb);
+
return 0;
}
--
2.55.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array
2026-09-06 8:21 [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array Norbert Szetei
@ 2026-09-07 19:43 ` Ilya Maximets
2026-09-08 7:19 ` Eelco Chaudron
2026-09-09 0:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Ilya Maximets @ 2026-09-07 19:43 UTC (permalink / raw)
To: Norbert Szetei, netdev
Cc: Aaron Conole, Eelco Chaudron, Ilya Maximets, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, dev,
linux-kernel
On 9/6/26 10:21 AM, Norbert Szetei wrote:
> tbl_mask_array_realloc() retires the old mask_array before it stops being
> reachable:
>
> old = ovsl_dereference(tbl->mask_array);
> if (old) {
> ...
> call_rcu(&old->rcu, mask_array_rcu_cb);
> }
>
> rcu_assign_pointer(tbl->mask_array, new);
>
> call_rcu() only waits for read-side critical sections already in flight.
> tbl->mask_array still points at old between the call_rcu() and the
> rcu_assign_pointer(), so a reader entering ovs_flow_tbl_lookup_stats() in
> that window picks up old in a fresh critical section that the pending
> grace period does not cover.
>
> tbl_mask_array_realloc() runs in process context under ovs_mutex, so the
> window is preemptible and can outlast the grace period. Then
> mask_array_rcu_cb() frees old before the swap runs:
>
> BUG: KASAN: slab-use-after-free in flow_lookup.constprop.0+0x2bf/0x2f0
> Read of size 8 at addr ffff888020b3e018 by task poc/741
> flow_lookup.constprop.0+0x2bf/0x2f0
> ovs_flow_tbl_lookup_stats+0x4a3/0x5c0
> ovs_dp_process_packet+0x19c/0x710
> ovs_vport_receive+0x243/0x390
> internal_dev_xmit+0x81/0x170
> Freed by task 728:
> kfree+0x16a/0x4e0
> rcu_core+0x853/0x1030
>
> Publish the new array before retiring the old one. The kfree_rcu() that
> call_rcu() replaced ran after the swap.
>
> Fixes: eac87c413bf9 ("net: openvswitch: reorder masks array based on usage")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Norbert Szetei <norbert@doyensec.com>
> ---
Reviewed-by: Ilya Maximets <i.maximets@ovn.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array
2026-09-06 8:21 [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array Norbert Szetei
2026-09-07 19:43 ` Ilya Maximets
@ 2026-09-08 7:19 ` Eelco Chaudron
2026-09-09 0:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Eelco Chaudron @ 2026-09-08 7:19 UTC (permalink / raw)
To: Norbert Szetei
Cc: netdev, Aaron Conole, Ilya Maximets, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman, dev,
linux-kernel
On 6 Sep 2026, at 10:21, Norbert Szetei wrote:
> tbl_mask_array_realloc() retires the old mask_array before it stops being
> reachable:
>
> old = ovsl_dereference(tbl->mask_array);
> if (old) {
> ...
> call_rcu(&old->rcu, mask_array_rcu_cb);
> }
>
> rcu_assign_pointer(tbl->mask_array, new);
>
> call_rcu() only waits for read-side critical sections already in flight.
> tbl->mask_array still points at old between the call_rcu() and the
> rcu_assign_pointer(), so a reader entering ovs_flow_tbl_lookup_stats() in
> that window picks up old in a fresh critical section that the pending
> grace period does not cover.
>
> tbl_mask_array_realloc() runs in process context under ovs_mutex, so the
> window is preemptible and can outlast the grace period. Then
> mask_array_rcu_cb() frees old before the swap runs:
>
> BUG: KASAN: slab-use-after-free in flow_lookup.constprop.0+0x2bf/0x2f0
> Read of size 8 at addr ffff888020b3e018 by task poc/741
> flow_lookup.constprop.0+0x2bf/0x2f0
> ovs_flow_tbl_lookup_stats+0x4a3/0x5c0
> ovs_dp_process_packet+0x19c/0x710
> ovs_vport_receive+0x243/0x390
> internal_dev_xmit+0x81/0x170
> Freed by task 728:
> kfree+0x16a/0x4e0
> rcu_core+0x853/0x1030
>
> Publish the new array before retiring the old one. The kfree_rcu() that
> call_rcu() replaced ran after the swap.
>
> Fixes: eac87c413bf9 ("net: openvswitch: reorder masks array based on usage")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Norbert Szetei <norbert@doyensec.com>
> ---
Changes look good to me. Although not really necessary, I did run all the kernel userspace tests, and they pass.
Acked-by: Eelco Chaudron echaudro@redhat.com
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array
2026-09-06 8:21 [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array Norbert Szetei
2026-09-07 19:43 ` Ilya Maximets
2026-09-08 7:19 ` Eelco Chaudron
@ 2026-09-09 0:30 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-09 0:30 UTC (permalink / raw)
To: Norbert Szetei
Cc: netdev, aconole, echaudro, i.maximets, davem, edumazet, kuba,
pabeni, horms, dev, linux-kernel
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sun, 6 Sep 2026 10:21:09 +0200 you wrote:
> tbl_mask_array_realloc() retires the old mask_array before it stops being
> reachable:
>
> old = ovsl_dereference(tbl->mask_array);
> if (old) {
> ...
> call_rcu(&old->rcu, mask_array_rcu_cb);
> }
>
> [...]
Here is the summary with links:
- [net] net: openvswitch: fix use-after-free of the flow table mask array
https://git.kernel.org/netdev/net/c/ba4ba11ed6eb
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-09 0:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-06 8:21 [PATCH net] net: openvswitch: fix use-after-free of the flow table mask array Norbert Szetei
2026-09-07 19:43 ` Ilya Maximets
2026-09-08 7:19 ` Eelco Chaudron
2026-09-09 0:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®