Skip to contentSkip to conversation

driver/infiniband/efa: Fix possible null pointer dereference in `efa_alloc_pd()`

PATCH In review Thomas Fourier 2 participants 2 messages May 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 driver/infiniband/efa: Fix possible null pointer dereference in `efa_alloc_pd()`

efa_alloc_pd() assumes that udata is not null but it seems like __ib_alloc_pd() in drivers/infiniband/core/verbs.c:279 can call it through the ib_device interface. This checks if udata is null before dereferencing it.

Fixes 40909f664d27 ("RDMA/efa: Add EFA verbs implementation")
---
 drivers/infiniband/hw/efa/efa_verbs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/efa/efa_verbs.c +2 -2
index a8645a40730f..fea634b7d825 100644
@@ -427,7 +427,7 @@ int efa_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
 	struct efa_pd *pd = to_epd(ibpd);
 	int err;
 
-	if (udata->inlen &&
+	if (udata && udata->inlen &&
 	    !ib_is_udata_cleared(udata, 0, udata->inlen)) {
 		ibdev_dbg(&dev->ibdev,
 			  "Incompatible ABI params, udata not cleared\n");
@@ -442,7 +442,7 @@ int efa_alloc_pd(struct ib_pd *ibpd, struct ib_udata *udata)
 	pd->pdn = result.pdn;
 	resp.pdn = result.pdn;
 
-	if (udata->outlen) {
+	if (udata && udata->outlen) {
 		err = ib_copy_to_udata(udata, &resp,
 				       min(sizeof(resp), udata->outlen));
 		if (err) {
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 7 lines · Thomas Fourier

efa_alloc_pd() assumes that udata is not null but it seems like __ib_alloc_pd() in drivers/infiniband/core/verbs.c:279 can call it through the ib_device interface. This checks if udata is null before dereferencing it.

Fixes 40909f664d27 ("RDMA/efa: Add EFA verbs implementation")

udata will never be NULL since EFA does not support kverbs, and userspace will always pass udata.

Look at ib_device_check_mandatory().