* [PATCH net] net/mlx5e: Fix use-after-free race in sample_restore_put()
@ 2026-09-02 19:33 Tariq Toukan
2026-09-05 20:20 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Tariq Toukan @ 2026-09-02 19:33 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Chris Mi, Gal Pressman, Kees Cook,
Leon Romanovsky, linux-kernel, linux-rdma, Mark Bloch, Oz Shlomo,
Saeed Mahameed, Shahar Shitrit, Tariq Toukan
From: Carolina Jubran <cjubran@nvidia.com>
Concurrent teardown of TC sample rules sharing the same restore
context may re-read restore->count after dropping restore_lock.
At that point another thread may already have completed cleanup and
freed the restore object.
Use the result of the refcount decrement while holding restore_lock to
determine whether cleanup is needed.
Fixes: 36a3196256bf ("net/mlx5e: TC, Add sampler restore handle API")
Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
Reviewed-by: Shahar Shitrit <shshitrit@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
index 89490f687a9c..93c62d3f3e5b 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c
@@ -311,12 +311,15 @@ sample_restore_get(struct mlx5e_tc_psample *tc_psample, u32 obj_id,
static void
sample_restore_put(struct mlx5e_tc_psample *tc_psample, struct mlx5e_sample_restore *restore)
{
+ bool last;
+
mutex_lock(&tc_psample->restore_lock);
- if (--restore->count == 0)
+ last = --restore->count == 0;
+ if (last)
hash_del(&restore->hlist);
mutex_unlock(&tc_psample->restore_lock);
- if (!restore->count) {
+ if (last) {
mlx5_del_flow_rules(restore->rule);
mlx5_modify_header_dealloc(tc_psample->esw->dev, restore->modify_hdr);
kfree(restore);
--
2.44.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH net] net/mlx5e: Fix use-after-free race in sample_restore_put()
2026-09-02 19:33 [PATCH net] net/mlx5e: Fix use-after-free race in sample_restore_put() Tariq Toukan
@ 2026-09-05 20:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-05 20:20 UTC (permalink / raw)
To: Tariq Toukan
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cmi, gal, kees, leon, linux-kernel, linux-rdma, mbloch, ozsh,
saeedm, shshitrit
Hello:
This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Wed, 2 Sep 2026 22:33:41 +0300 you wrote:
> From: Carolina Jubran <cjubran@nvidia.com>
>
> Concurrent teardown of TC sample rules sharing the same restore
> context may re-read restore->count after dropping restore_lock.
> At that point another thread may already have completed cleanup and
> freed the restore object.
>
> [...]
Here is the summary with links:
- [net] net/mlx5e: Fix use-after-free race in sample_restore_put()
https://git.kernel.org/netdev/net/c/af3aef0245ab
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:21 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:33 [PATCH net] net/mlx5e: Fix use-after-free race in sample_restore_put() Tariq Toukan
2026-09-05 20:20 ` 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®