net/mlx5e: Skip hairpin entries not ready in debugfs dump
Subsystems (5)
PATCH 1/1 net/mlx5e: Skip hairpin entries not ready in debugfs dump
Hairpin entries are added to the table before creation completes. Reading hairpin_table_dump can therefore dereference a NULL pointer while creation is in progress, or an error pointer if creation fails.
Skip entries that are still being created or whose creation failed.
---
Found with a static analysis tool we are developing.
Compile-tested only, with x86_64_defconfig plus MLX5_CORE_EN, MLX5_ESWITCH, MLX5_CLS_ACT and W=1.
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +4 -1
@@ -1067,12 +1067,15 @@ static int debugfs_hairpin_table_dump_show(struct seq_file *file, void *priv)u32 bkt;mutex_lock (&tc->hairpin_tbl_lock); -hash_for_each (tc->hairpin_tbl, bkt, hpe, hairpin_hlist) +hash_for_each (tc->hairpin_tbl, bkt, hpe, hairpin_hlist) { +if (!completion_done (&hpe->res_ready) ||IS_ERR (hpe->hp)) +continue ;seq_printf (file,"Hairpin peer_vhca_id %u prio %u refcnt %u num_channels %u num_packets %lu\n" , hpe->peer_vhca_id, hpe->prio,refcount_read (&hpe->refcnt), hpe->hp->num_channels,BIT (hpe->hp->log_num_packets)); + }mutex_unlock (&tc->hairpin_tbl_lock);return 0 ;
base-commit: 342e62fd34c2674e82bffc89cb5c7091924986d9
Signature · 1 line
2.43.0
Quoted 7 lines · Changyul Lee
Hairpin entries are added to the table before creation completes. Reading
hairpin_table_dumpcan therefore dereference a NULL pointer while creation is in progress, or an error pointer if creation fails.Skip entries that are still being created or whose creation failed.
Fixes 0e414518d6d8 ("net/mlx5e: Add hairpin debugfs files")
The dump added by that commit printed only peer_vhca_id, prio and refcnt, it did not touch hpe->hp. The dereference came later, in v6.4, so this should be:
The change itself looks good to me.
With the tag fixed, you can add:
Thanks,
Tariq
Thank you for the review and the corrections :)
I will send a v2 patch with the fix tag.
Best,
Changyul