* [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs
@ 2026-11-18 17:32 Tariq Toukan
2026-11-18 17:32 ` [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation Tariq Toukan
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Tariq Toukan @ 2026-11-18 17:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Alexandre Cassen, Alex Vesker, Erez Shitrit, Gal Pressman,
Kees Cook, Leon Romanovsky, open list, linux-rdma, Mark Bloch,
Moshe Shemesh, Prathamesh Deshpande, Saeed Mahameed, Simon Horman,
Tariq Toukan, William Theesfeld, Yevgeny Kliteynik
Hi,
This series by Yevgeny fixes two memory safety bugs in the mlx5 software
and hardware steering code paths.
Both are missing-check or wrong-handling problems that lead to a NULL
pointer being inserted into an xarray, or an out-of-bounds write that
corrupts the kernel heap.
Regards,
Tariq
V2:
Took patch #2 out of the series.
Patch #1: Remove empty line. Updated commit message.
Patch #3 (now #2): Update commit message.
Not allocating chunks in error state.
Print error once when putting pool into error state
V1:
https://lore.kernel.org/all/20261021074949.3471704-1-tariqt@nvidia.com/
Yevgeny Kliteynik (2):
net/mlx5: HWS, Handle NULL in vport destination action creation
net/mlx5: DR, Fix out-of-bounds write when sync to HW fails
.../mellanox/mlx5/core/steering/hws/fs_hws.c | 2 ++
.../mlx5/core/steering/sws/dr_icm_pool.c | 32 +++++++++++++++++--
2 files changed, 31 insertions(+), 3 deletions(-)
base-commit: aa40afa831ebfe45e40a23721711059f2ac584d4
--
2.44.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation
2026-11-18 17:32 [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs Tariq Toukan
@ 2026-11-18 17:32 ` Tariq Toukan
2026-11-18 17:41 ` sashiko-bot
2026-11-18 17:32 ` [PATCH net V2 2/2] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails Tariq Toukan
2026-11-18 17:37 ` [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs netdev-bot+sinfo
2 siblings, 1 reply; 6+ messages in thread
From: Tariq Toukan @ 2026-11-18 17:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Alexandre Cassen, Alex Vesker, Erez Shitrit, Gal Pressman,
Kees Cook, Leon Romanovsky, open list, linux-rdma, Mark Bloch,
Moshe Shemesh, Prathamesh Deshpande, Saeed Mahameed, Simon Horman,
Tariq Toukan, William Theesfeld, Yevgeny Kliteynik
From: Yevgeny Kliteynik <kliteyn@nvidia.com>
mlx5hws_action_create_dest_vport() can return NULL. If this
happens, xa_insert() will insert a NULL entry into the xarray.
The next mlx5hws_action_create_dest_vport() failure will try to
insert NULL again, but xa_insert() will return -EBUSY, because
we already have NULL entry. In such case the code will go into
error flow of action creation, and eventually will cause NULL
dereference at hws_action_destroy_hws().
The issue was discovered by code inspection.
Fixes: 8e2e08a6d1e0 ("net/mlx5: fs, add support for dest vport HWS action")
Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Signed-off-by: Alex Vesker <valex@nvidia.com>
Reviewed-by: Erez Shitrit <erezsh@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
index cbcbc2b62809..de22e7279a31 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
@@ -441,6 +441,8 @@ mlx5_fs_get_dest_action_vport(struct mlx5_fs_hws_context *fs_ctx,
dest = mlx5hws_action_create_dest_vport(ctx, vport_num, vhca_id_valid,
dest_attr->vport.vhca_id, flags);
+ if (!dest)
+ return NULL;
err = xa_insert(dests_xa, idx, dest, GFP_KERNEL);
if (err) {
--
2.44.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net V2 2/2] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails
2026-11-18 17:32 [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs Tariq Toukan
2026-11-18 17:32 ` [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation Tariq Toukan
@ 2026-11-18 17:32 ` Tariq Toukan
2026-11-18 17:41 ` sashiko-bot
2026-11-18 17:37 ` [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs netdev-bot+sinfo
2 siblings, 1 reply; 6+ messages in thread
From: Tariq Toukan @ 2026-11-18 17:32 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Alexandre Cassen, Alex Vesker, Erez Shitrit, Gal Pressman,
Kees Cook, Leon Romanovsky, open list, linux-rdma, Mark Bloch,
Moshe Shemesh, Prathamesh Deshpande, Saeed Mahameed, Simon Horman,
Tariq Toukan, William Theesfeld, Yevgeny Kliteynik
From: Yevgeny Kliteynik <kliteyn@nvidia.com>
mlx5dr_icm_free_chunk() moves a freed chunk to the "hot" chunks array by
writing it to hot_chunks_arr and, once the accumulated hot memory
crosses a threshold, triggers a sync to HW that flushes the array. The
array is large enough to hold the chunks of a single accumulation cycle,
and relies on the sync path to flush it.
However, if sync to HW fails, hot chunks array is not cleared, and every
subsequent mlx5dr_icm_free_chunk will write past the end of
hot_chunks_arr, resulting in an out-of-bounds write and kernel heap
corruption.
A failed sync to HW also means it is no longer safe to recycle ICM: a
chunk's memory may only be returned to the buddy allocator (and thus be
reused) after a sync has confirmed that HW no longer references it.
The issue was discovered by a fuzzer that repeatedly triggered sync
failure, at which point the out-of-bounds write was reported by KASAN:
KASAN log excerpt: BUG:
slab-out-of-bounds in mlx5dr_icm_free_chunk+0x4cd at call 2
(hot_chunks_num=3 > cap=2).
Fix this by putting the pool into an error state on the first failed
sync to HW, reporting the failure once. The sync is not retried, and
while the pool is in this state:
- mlx5dr_icm_free_chunk() doesn't queue freed chunks; the segment is
left reserved and is reclaimed when the pool is destroyed.
- mlx5dr_icm_alloc_chunk() doesn't serve new chunks.
Fixes: 4519fc45beeb ("net/mlx5: DR, Keep track of hot ICM chunks in an array instead of list")
Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Alex Vesker <valex@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mlx5/core/steering/sws/dr_icm_pool.c | 32 +++++++++++++++++--
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c
index 1b928b40686e..a906a72601c4 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/steering/sws/dr_icm_pool.c
@@ -33,6 +33,11 @@ struct mlx5dr_icm_pool {
u64 hot_memory_size;
/* hot memory size threshold for triggering sync */
u64 th;
+ /* Set when a sync to HW fails - no new chunks are served, freed
+ * chunks are no longer queued, and their ICM is not returned to
+ * the buddy allocator.
+ */
+ bool error_state;
};
struct mlx5dr_icm_dm {
@@ -368,7 +373,15 @@ static int dr_icm_pool_sync_all_buddy_pools(struct mlx5dr_icm_pool *pool)
err = mlx5dr_cmd_sync_steering(pool->dmn->mdev);
if (err) {
- mlx5dr_err(pool->dmn, "Failed to sync to HW (err: %d)\n", err);
+ /* The hot chunks could not be flushed. Put the pool in an
+ * error state so that no further chunks are queued (which
+ * would overflow hot_chunks_arr), and no new chunks are
+ * served. The sync is not retried.
+ */
+ mlx5dr_err(pool->dmn,
+ "Failed to sync to HW (err: %d), disabling ICM pool\n",
+ err);
+ pool->error_state = true;
return err;
}
@@ -443,6 +456,10 @@ mlx5dr_icm_alloc_chunk(struct mlx5dr_icm_pool *pool,
return NULL;
mutex_lock(&pool->mutex);
+
+ if (pool->error_state)
+ goto out;
+
/* find mem, get back the relevant buddy pool and seg in that mem */
ret = dr_icm_handle_buddies_get_mem(pool, chunk_size, &buddy, &seg);
if (ret)
@@ -475,6 +492,14 @@ void mlx5dr_icm_free_chunk(struct mlx5dr_icm_chunk *chunk)
/* move the chunk to the waiting chunks array, AKA "hot" memory */
mutex_lock(&pool->mutex);
+ /* If the pool is in an error state, the chunk must not be queued.
+ * ICM memory is not returned to the buddy allocator - it is
+ * reclaimed only when the pool is destroyed.
+ * Just free the chunk's bookkeeping struct.
+ */
+ if (pool->error_state)
+ goto out;
+
pool->hot_memory_size += mlx5dr_icm_pool_get_chunk_byte_size(chunk);
hot_chunk = &pool->hot_chunks_arr[pool->hot_chunks_num++];
@@ -482,12 +507,13 @@ void mlx5dr_icm_free_chunk(struct mlx5dr_icm_chunk *chunk)
hot_chunk->seg = chunk->seg;
hot_chunk->size = chunk->size;
- kmem_cache_free(chunks_cache, chunk);
-
/* Check if we have chunks that are waiting for sync-ste */
if (dr_icm_pool_is_sync_required(pool))
dr_icm_pool_sync_all_buddy_pools(pool);
+out:
+ kmem_cache_free(chunks_cache, chunk);
+
mutex_unlock(&pool->mutex);
}
--
2.44.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs
2026-11-18 17:32 [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs Tariq Toukan
2026-11-18 17:32 ` [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation Tariq Toukan
2026-11-18 17:32 ` [PATCH net V2 2/2] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails Tariq Toukan
@ 2026-11-18 17:37 ` netdev-bot+sinfo
2 siblings, 0 replies; 6+ messages in thread
From: netdev-bot+sinfo @ 2026-11-18 17:37 UTC (permalink / raw)
To: Tariq Toukan
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni, Alexandre Cassen, Alex Vesker, Erez Shitrit,
Gal Pressman, Kees Cook, Leon Romanovsky, open list, linux-rdma,
Mark Bloch, Moshe Shemesh, Prathamesh Deshpande, Saeed Mahameed,
Simon Horman, William Theesfeld, Yevgeny Kliteynik
Hi!
This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:
- What hardware the change was tested on. For driver fixes please
mention the device (and if relevant firmware version) used for
testing, or say that the change was not tested on real hardware.
Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.
*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
--
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation
2026-11-18 17:32 ` [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation Tariq Toukan
@ 2026-11-18 17:41 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-18 17:41 UTC (permalink / raw)
To: Tariq Toukan; +Cc: linux-rdma
> From: Yevgeny Kliteynik <kliteyn@nvidia.com>
>
> mlx5hws_action_create_dest_vport() can return NULL. If this
> happens, xa_insert() will insert a NULL entry into the xarray.
> The next mlx5hws_action_create_dest_vport() failure will try to
> insert NULL again, but xa_insert() will return -EBUSY, because
> we already have NULL entry. In such case the code will go into
> error flow of action creation, and eventually will cause NULL
> dereference at hws_action_destroy_hws().
>
> The issue was discovered by code inspection.
>
> Fixes: 8e2e08a6d1e0 ("net/mlx5: fs, add support for dest vport HWS action")
> Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
> Signed-off-by: Alex Vesker <valex@nvidia.com>
> Reviewed-by: Erez Shitrit <erezsh@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118173227.1957670-1-tariqt@nvidia.com?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH net V2 2/2] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails
2026-11-18 17:32 ` [PATCH net V2 2/2] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails Tariq Toukan
@ 2026-11-18 17:41 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-18 17:41 UTC (permalink / raw)
To: Tariq Toukan; +Cc: linux-rdma
> From: Yevgeny Kliteynik <kliteyn@nvidia.com>
>
> mlx5dr_icm_free_chunk() moves a freed chunk to the "hot" chunks array by
> writing it to hot_chunks_arr and, once the accumulated hot memory
> crosses a threshold, triggers a sync to HW that flushes the array. The
> array is large enough to hold the chunks of a single accumulation cycle,
> and relies on the sync path to flush it.
>
> However, if sync to HW fails, hot chunks array is not cleared, and every
> subsequent mlx5dr_icm_free_chunk will write past the end of
> hot_chunks_arr, resulting in an out-of-bounds write and kernel heap
> corruption.
>
> A failed sync to HW also means it is no longer safe to recycle ICM: a
> chunk's memory may only be returned to the buddy allocator (and thus be
> [ ... ]
>
> Fixes: 4519fc45beeb ("net/mlx5: DR, Keep track of hot ICM chunks in an array instead of list")
> Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
> Reviewed-by: Alex Vesker <valex@nvidia.com>
> Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118173227.1957670-1-tariqt@nvidia.com?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-18 17:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 17:32 [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs Tariq Toukan
2026-11-18 17:32 ` [PATCH net V2 1/2] net/mlx5: HWS, Handle NULL in vport destination action creation Tariq Toukan
2026-11-18 17:41 ` sashiko-bot
2026-11-18 17:32 ` [PATCH net V2 2/2] net/mlx5: DR, Fix out-of-bounds write when sync to HW fails Tariq Toukan
2026-11-18 17:41 ` sashiko-bot
2026-11-18 17:37 ` [PATCH net V2 0/2] net/mlx5: Fix HWS and DR steering memory safety bugs netdev-bot+sinfo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox