mlx5: Fix dbrec alloc returning garbage pointer on failure
[ Upstream commit d73d3288c5e5aa65b7a8ca5b1593745aedeb5723 ]
When mlx5_alloc_dbrec() falls back from the custom allocator to the
default one, db is not cleared before jumping to default_alloc. If the
default allocator also fails, the function returns db still holding a
non-NULL garbage value instead of NULL.
create_qp() checks the return value for NULL to detect failure. Since it
is not NULL, create_qp() proceeds and crashes dereferencing
qp->db[MLX5_RCV_DBR].
Clear db before entering the default_alloc path so any failure there
returns NULL.
Fixes: acee8f6e64b3 ("mlx5: Add custom allocation support for DBR")
Signed-off-by: Maher Sanalla <msanalla@nvidia.com>
Signed-off-by: Yishai Hadas <yishaih@nvidia.com>
Signed-off-by: Nicolas Morey <nmorey@suse.com>
diff --git a/providers/mlx5/dbrec.c b/providers/mlx5/dbrec.c
index e35183f..d176413 100644
--- a/providers/mlx5/dbrec.c
+++ b/providers/mlx5/dbrec.c
@@ -98,8 +98,10 @@
mparent_domain->pd_context, 8, 8,
MLX5DV_RES_TYPE_DBR);
- if (db == IBV_ALLOCATOR_USE_DEFAULT)
+ if (db == IBV_ALLOCATOR_USE_DEFAULT) {
+ db = NULL;
goto default_alloc;
+ }
if (!db)
return NULL;