Skip to content

Commit d4fbd68

Browse files
author
CKI KWF Bot
committed
Merge: CVE-2025-39979: net/mlx5: fs, fix UAF in flow counter release
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-10/-/merge_requests/1664 JIRA: https://issues.redhat.com/browse/RHEL-124434 CVE: CVE-2025-39979 ``` commit 6043819 Author: Moshe Shemesh <moshe@nvidia.com> Date: Mon Sep 22 10:11:32 2025 +0300 net/mlx5: fs, fix UAF in flow counter release Fix a kernel trace [1] caused by releasing an HWS action of a local flow counter in mlx5_cmd_hws_delete_fte(), where the HWS action refcount and mutex were not initialized and the counter struct could already be freed when deleting the rule. Fix it by adding the missing initializations and adding refcount for the local flow counter struct. [1] Kernel log: Call Trace: <TASK> dump_stack_lvl+0x34/0x48 mlx5_fs_put_hws_action.part.0.cold+0x21/0x94 [mlx5_core] mlx5_fc_put_hws_action+0x96/0xad [mlx5_core] mlx5_fs_destroy_fs_actions+0x8b/0x152 [mlx5_core] mlx5_cmd_hws_delete_fte+0x5a/0xa0 [mlx5_core] del_hw_fte+0x1ce/0x260 [mlx5_core] mlx5_del_flow_rules+0x12d/0x240 [mlx5_core] ? ttwu_queue_wakelist+0xf4/0x110 mlx5_ib_destroy_flow+0x103/0x1b0 [mlx5_ib] uverbs_free_flow+0x20/0x50 [ib_uverbs] destroy_hw_idr_uobject+0x1b/0x50 [ib_uverbs] uverbs_destroy_uobject+0x34/0x1a0 [ib_uverbs] uobj_destroy+0x3c/0x80 [ib_uverbs] ib_uverbs_run_method+0x23e/0x360 [ib_uverbs] ? uverbs_finalize_object+0x60/0x60 [ib_uverbs] ib_uverbs_cmd_verbs+0x14f/0x2c0 [ib_uverbs] ? do_tty_write+0x1a9/0x270 ? file_tty_write.constprop.0+0x98/0xc0 ? new_sync_write+0xfc/0x190 ib_uverbs_ioctl+0xd7/0x160 [ib_uverbs] __x64_sys_ioctl+0x87/0xc0 do_syscall_64+0x59/0x90 Fixes: b581f42 ("net/mlx5: fs, manage flow counters HWS action sharing by refcount") Signed-off-by: Moshe Shemesh <moshe@nvidia.com> Reviewed-by: Yevgeny Kliteynik <kliteyn@nvidia.com> Reviewed-by: Mark Bloch <mbloch@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/1758525094-816583-2-git-send-email-tariqt@nvidia.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> ``` Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com> --- <small>Created 2025-10-27 15:56 UTC by backporter - [KWF FAQ](https://red.ht/kernel_workflow_doc) - [Slack #team-kernel-workflow](https://redhat-internal.slack.com/archives/C04LRUPMJQ5) - [Source](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/webhook/utils/backporter.py) - [Documentation](https://gitlab.com/cki-project/kernel-workflow/-/blob/main/docs/README.backporter.md) - [Report an issue](https://issues.redhat.com/secure/CreateIssueDetails!init.jspa?pid=12334433&issuetype=1&priority=4&summary=backporter+webhook+issue&components=kernel-workflow+/+backporter)</small> Approved-by: mheib <mheib@redhat.com> Approved-by: José Ignacio Tornos Martínez <jtornosm@redhat.com> Approved-by: CKI KWF Bot <cki-ci-bot+kwf-gitlab-com@redhat.com> Merged-by: CKI GitLab Kmaint Pipeline Bot <26919896-cki-kmaint-pipeline-bot@users.noreply.gitlab.com>
2 parents acfdcd7 + d6066bf commit d4fbd68

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static void del_sw_hw_rule(struct fs_node *node)
658658
BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_ACTION) |
659659
BIT(MLX5_SET_FTE_MODIFY_ENABLE_MASK_FLOW_COUNTERS);
660660
fte->act_dests.action.action &= ~MLX5_FLOW_CONTEXT_ACTION_COUNT;
661-
mlx5_fc_local_destroy(rule->dest_attr.counter);
661+
mlx5_fc_local_put(rule->dest_attr.counter);
662662
goto out;
663663
}
664664

drivers/net/ethernet/mellanox/mlx5/core/fs_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ struct mlx5_fc {
342342
enum mlx5_fc_type type;
343343
struct mlx5_fc_bulk *bulk;
344344
struct mlx5_fc_cache cache;
345+
refcount_t fc_local_refcount;
345346
/* last{packets,bytes} are used for calculating deltas since last reading. */
346347
u64 lastpackets;
347348
u64 lastbytes;

drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,17 +562,36 @@ mlx5_fc_local_create(u32 counter_id, u32 offset, u32 bulk_size)
562562
counter->id = counter_id;
563563
fc_bulk->base_id = counter_id - offset;
564564
fc_bulk->fs_bulk.bulk_len = bulk_size;
565+
refcount_set(&fc_bulk->hws_data.hws_action_refcount, 0);
566+
mutex_init(&fc_bulk->hws_data.lock);
565567
counter->bulk = fc_bulk;
568+
refcount_set(&counter->fc_local_refcount, 1);
566569
return counter;
567570
}
568571
EXPORT_SYMBOL(mlx5_fc_local_create);
569572

570573
void mlx5_fc_local_destroy(struct mlx5_fc *counter)
571574
{
572-
if (!counter || counter->type != MLX5_FC_TYPE_LOCAL)
573-
return;
574-
575575
kfree(counter->bulk);
576576
kfree(counter);
577577
}
578578
EXPORT_SYMBOL(mlx5_fc_local_destroy);
579+
580+
void mlx5_fc_local_get(struct mlx5_fc *counter)
581+
{
582+
if (!counter || counter->type != MLX5_FC_TYPE_LOCAL)
583+
return;
584+
585+
refcount_inc(&counter->fc_local_refcount);
586+
}
587+
588+
void mlx5_fc_local_put(struct mlx5_fc *counter)
589+
{
590+
if (!counter || counter->type != MLX5_FC_TYPE_LOCAL)
591+
return;
592+
593+
if (!refcount_dec_and_test(&counter->fc_local_refcount))
594+
return;
595+
596+
mlx5_fc_local_destroy(counter);
597+
}

drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws_pools.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,15 +407,21 @@ struct mlx5hws_action *mlx5_fc_get_hws_action(struct mlx5hws_context *ctx,
407407
{
408408
struct mlx5_fs_hws_create_action_ctx create_ctx;
409409
struct mlx5_fc_bulk *fc_bulk = counter->bulk;
410+
struct mlx5hws_action *hws_action;
410411

411412
create_ctx.hws_ctx = ctx;
412413
create_ctx.id = fc_bulk->base_id;
413414
create_ctx.actions_type = MLX5HWS_ACTION_TYP_CTR;
414415

415-
return mlx5_fs_get_hws_action(&fc_bulk->hws_data, &create_ctx);
416+
mlx5_fc_local_get(counter);
417+
hws_action = mlx5_fs_get_hws_action(&fc_bulk->hws_data, &create_ctx);
418+
if (!hws_action)
419+
mlx5_fc_local_put(counter);
420+
return hws_action;
416421
}
417422

418423
void mlx5_fc_put_hws_action(struct mlx5_fc *counter)
419424
{
420425
mlx5_fs_put_hws_action(&counter->bulk->hws_data);
426+
mlx5_fc_local_put(counter);
421427
}

include/linux/mlx5/fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ struct mlx5_fc *mlx5_fc_create(struct mlx5_core_dev *dev, bool aging);
308308
void mlx5_fc_destroy(struct mlx5_core_dev *dev, struct mlx5_fc *counter);
309309
struct mlx5_fc *mlx5_fc_local_create(u32 counter_id, u32 offset, u32 bulk_size);
310310
void mlx5_fc_local_destroy(struct mlx5_fc *counter);
311+
void mlx5_fc_local_get(struct mlx5_fc *counter);
312+
void mlx5_fc_local_put(struct mlx5_fc *counter);
311313
u64 mlx5_fc_query_lastuse(struct mlx5_fc *counter);
312314
void mlx5_fc_query_cached(struct mlx5_fc *counter,
313315
u64 *bytes, u64 *packets, u64 *lastuse);

0 commit comments

Comments
 (0)