Re: [PATCH net v3 1/1] net/mlx5e: fix NULL pointer dereference in arfs_create_groups()
From: Daniel Machon
Date: Thu Nov 19 2026 - 06:49:14 EST
> arfs_create_groups() creates up to two flow groups in ft->g[], and
> increments ft->num_groups for each group that was created successfully.
> If creating the second group fails, the error path frees ft->g and sets
> it to NULL, but leaves ft->num_groups at 1.
>
> The only caller, arfs_create_table(), calls mlx5e_destroy_flow_table() on
> the error path, which calls mlx5e_destroy_groups(). The latter walks
> ft->g[] from ft->num_groups - 1 down to 0 and dereferences ft->g[0].
> Since ft->g was freed and set to NULL, this is a NULL pointer
> dereference, and the kernel oopses.
>
> The same error path also leaks the flow group that was created
> successfully before the failure, since ft->g is freed without the group
> being destroyed.
>
> Freeing ft->g here was added by commit 3c6d5189246f ("net/mlx5e: fix a
> double-free in arfs_create_groups"). Before that commit, the group
> failure path did not touch ft->g at all, so the caller destroyed the
> flow groups that had been created and then freed the array. That
> commit fixed a double free in the allocation failure path by freeing
> ft->g here as well, and in doing so changed the group failure path
> too.
>
> Rather than also resetting ft->num_groups, leave the free of ft->g to
> the caller: mlx5e_destroy_flow_table() frees ft->g exactly once, and
> also destroys the flow groups that were created. This fixes the NULL
> pointer dereference and the leak, while keeping the double free fixed.
>
> The bug was hit on a virtual mlx5 device whose firmware answers host
> mailbox commands. The device took longer than the firmware's own
> timeout to answer one CREATE_FLOW_GROUP command, so the firmware
> reported the command as failed even though the device had completed it.
> The host then took the error path and oopsed:
>
> Oops [#1]
> epc : mlx5e_destroy_groups+0x38/0x6c
> ra : mlx5e_destroy_flow_table+0x10/0x30
> status: 0000000200000120 badaddr: 0000000000000000 cause: 000000000000000d
>
> Note that the host oopses on any error returned by CREATE_FLOW_GROUP,
> no matter where the error comes from, so the trigger is not specific to
> that firmware.
>
> The fix has not been tested: the patched kernel was not booted, only the
> original crash was reproduced.
>
> Fixes: 3c6d5189246f ("net/mlx5e: fix a double-free in arfs_create_groups")
> Signed-off-by: Jinvas <jinvas@xxxxxxx>
Reviewed-by: Daniel Machon <daniel.machon@xxxxxxxxxxxxx>