Skip to contentSkip to conversation

RDMA/uverbs: Zero the QP attrs in ib_uverbs_query_qp

PATCH Applied Selvin Xavier 3 participants 3 messages Nov 4 – Nov 5 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/uverbs: Zero the QP attrs in ib_uverbs_query_qp

ib_uverbs_query_qp() allocates qp_attr and qp_init_attr without zeroing and copies fields such as alt_ah_attr, path_mig_state and sq_draining to userspace. Drivers are not required to set every field in their query_qp() callback, so uninitialized kernel heap memory can leak.

Allocate both structures zeroed.

Fixes 7ccc9a24e012 ("IB/uverbs: Support for query QP from userspace")
---
 drivers/infiniband/core/uverbs_cmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/core/uverbs_cmd.c +2 -2
index aca7c6ab55cd..54da98431f40 100644
@@ -1668,8 +1668,8 @@ static int ib_uverbs_query_qp(struct uverbs_attr_bundle *attrs)
 	if (ret)
 		return ret;
 
-	attr = kmalloc_obj(*attr);
-	init_attr = kmalloc_obj(*init_attr);
+	attr = kzalloc_obj(*attr);
+	init_attr = kzalloc_obj(*init_attr);
 	if (!attr || !init_attr) {
 		ret = -ENOMEM;
 		goto out;
Signature · 1 line
2.39.3
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

ib_uverbs_query_qp() allocates qp_attr and qp_init_attr without zeroing and copies fields such as alt_ah_attr, path_mig_state and sq_draining to userspace. Drivers are not required to set every field in their query_qp() callback, so uninitialized kernel heap memory can leak.

Allocate both structures zeroed.

Fixes 7ccc9a24e012 ("IB/uverbs: Support for query QP from userspace")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Selvin Xavier
Quoted 8 lines · Selvin Xavier

ib_uverbs_query_qp() allocates qp_attr and qp_init_attr without zeroing and copies fields such as alt_ah_attr, path_mig_state and sq_draining to userspace. Drivers are not required to set every field in their query_qp() callback, so uninitialized kernel heap memory can leak.

Allocate both structures zeroed.

[...]

Applied, thanks!

[1/1] RDMA/uverbs: Zero the QP attrs in ib_uverbs_query_qp

      https://git.kernel.org/rdma/rdma/c/997ca6555b9fc3

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>