net/mlx5: fs, fix invalid pointer dereference in mlx5_fs_add_rule tracepoint
Subsystems (5)
PATCH 1/1 net/mlx5: fs, fix invalid pointer dereference in mlx5_fs_add_rule tracepoint
From: Kenneth Klette Jonassen <[email protected]>
The mlx5_fs_add_rule tracepoint has used the flow destination type in a bitwise test since its introduction. However, that's not a valid way to treat it anymore (if it ever was), and after commit d639af621600dc ("net/mlx5: fs, split software and IFC flow destination definitions"), this mismatch caused nearly any destination type to be mistaken as a flow counter, and thus stashing 32 bits of the mlx5_flow_destination union into the counter_id field of the tracepoint.
Later commit 95f68e06b41b9e ("net/mlx5: fs, add counter object to flow destination") exacerbates this issue by converting the counter union member from an integer to a pointer. Now the tracepoint dereferences whichever value is in the union, and in cases where that's not a valid pointer, it can lead to a kernel oops.
Fix the check. Reported by GitHub user whi71800.
--- drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/diag/fs_tracepoint.h +1 -1
@@ -289,7 +289,7 @@ TRACE_EVENT(mlx5_fs_add_rule,memcpy (__entry->destination, &rule->dest_attr,sizeof (__entry->destination)); -if (rule->dest_attr.type & +if (rule->dest_attr.type ==MLX5_FLOW_DESTINATION_TYPE_COUNTER ) __entry->counter_id =mlx5_fc_id (rule->dest_attr.counter);
Signature · 1 line
2.43.0
Quoted 15 lines · On 3/28/2026 10:20 PM, [email protected] wrote:
The
mlx5_fs_add_ruletracepoint has used the flow destination type in a bitwise test since its introduction. However, that's not a valid way to treat it anymore (if it ever was), and after commitd639af621600dc("net/mlx5: fs, split software and IFC flow destination definitions"), this mismatch caused nearly any destination type to be mistaken as a flow counter, and thus stashing 32 bits of themlx5_flow_destinationunion into thecounter_idfield of the tracepoint.Later commit
95f68e06b41b9e("net/mlx5: fs, add counter object to flow destination") exacerbates this issue by converting the counter union member from an integer to a pointer. Now the tracepoint dereferences whichever value is in the union, and in cases where that's not a valid pointer, it can lead to a kernel oops.
Quoted 6 lines
Fix the check. Reported by GitHub user whi71800.
Fixes 95f68e06b41b9e ("net/mlx5: fs, add counter object to flow destination")Signed-off-by Kenneth Klette Jonassen<[email protected]>
Thanks.