* [PATCH net] net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put
@ 2026-09-02 19:35 Tariq Toukan
2026-09-05 20:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Tariq Toukan @ 2026-09-02 19:35 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Dragos Tatulea, Gal Pressman, Leon Romanovsky, linux-kernel,
linux-rdma, Mark Bloch, Saeed Mahameed, Tariq Toukan,
Yael Chemla
From: Yael Chemla <ychemla@nvidia.com>
In mlx5_eswitch_termtbl_put(), the zero-ref cleanup check reads
tt->ref_count after termtbl_mutex has been released. Two concurrent
callers on the same mlx5_termtbl_handle race: one decrements ref_count
to zero, removes the hash entry, and calls kfree(tt) while the other
has already dropped the mutex and is about to evaluate
if (!tt->ref_count), producing a use-after-free.
Fix this by capturing the result of the decrement into a stack-local
last variable before dropping the mutex. The cleanup decision is now
made entirely under termtbl_mutex, and tt is not touched after
kfree.
Fixes: 10caabdaad5a ("net/mlx5e: Use termination table for VLAN push actions")
Signed-off-by: Yael Chemla <ychemla@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
index 19f65d4c4def..d43f07360159 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads_termtbl.c
@@ -163,12 +163,15 @@ void
mlx5_eswitch_termtbl_put(struct mlx5_eswitch *esw,
struct mlx5_termtbl_handle *tt)
{
+ bool last;
+
mutex_lock(&esw->offloads.termtbl_mutex);
- if (--tt->ref_count == 0)
+ last = (--tt->ref_count == 0);
+ if (last)
hash_del(&tt->termtbl_hlist);
mutex_unlock(&esw->offloads.termtbl_mutex);
- if (!tt->ref_count) {
+ if (last) {
mlx5_del_flow_rules(tt->rule);
mlx5_destroy_flow_table(tt->termtbl);
kfree(tt);
--
2.44.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH net] net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put
2026-09-02 19:35 [PATCH net] net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put Tariq Toukan
@ 2026-09-05 20:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-05 20:30 UTC (permalink / raw)
To: Tariq Toukan
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, dtatulea,
gal, leon, linux-kernel, linux-rdma, mbloch, saeedm, ychemla
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 2 Sep 2026 22:35:14 +0300 you wrote:
> From: Yael Chemla <ychemla@nvidia.com>
>
> In mlx5_eswitch_termtbl_put(), the zero-ref cleanup check reads
> tt->ref_count after termtbl_mutex has been released. Two concurrent
> callers on the same mlx5_termtbl_handle race: one decrements ref_count
> to zero, removes the hash entry, and calls kfree(tt) while the other
> has already dropped the mutex and is about to evaluate
> if (!tt->ref_count), producing a use-after-free.
>
> [...]
Here is the summary with links:
- [net] net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put
https://git.kernel.org/netdev/net/c/7ee07f601f8f
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] 2+ messages in thread
end of thread, other threads:[~2026-09-05 20:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-02 19:35 [PATCH net] net/mlx5: E-Switch: fix use-after-free in mlx5_eswitch_termtbl_put Tariq Toukan
2026-09-05 20: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®