Skip to contentSkip to conversation

RDMA/mthca: Check for null udata during reg_user_mr

PATCH In review Jacob Moroni 2 participants 4 messages Jun 30 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RDMA/mthca: Check for null udata during reg_user_mr

The mthca driver was unconditionally checking udata->inlen, but udata could be null if the user intentionally triggers the UVERBS_METHOD_REG_MR ioctl. Prevent the potential null deref by adding a check.

---
 drivers/infiniband/hw/mthca/mthca_provider.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/hw/mthca/mthca_provider.c +3 -0
index f90f67afc8f..6005ed40665 100644
@@ -863,6 +863,9 @@ static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
 	if (dmah)
 		return ERR_PTR(-EOPNOTSUPP);
 
+	if (!udata)
+		return ERR_PTR(-EINVAL);
+
 	if (udata->inlen < sizeof ucmd) {
 		if (!context->reg_mr_warned) {
 			mthca_warn(dev, "Process '%s' did not pass in MR attrs.\n",
Signature · 1 line
2.55.0.rc0.799.gd6f94ed593-goog
#1 lore raw
Quoted 4 lines · Jacob Moroni

The mthca driver was unconditionally checking udata->inlen, but udata could be null if the user intentionally triggers the UVERBS_METHOD_REG_MR ioctl. Prevent the potential null deref by adding a check.

???

reg_user_mr should never have a null udata how does this happen?

Jason

#2 lore raw

For irdma at least, I was able to trigger it with a one-off test binary that directly invokes the UVERBS_METHOD_REG_MR ioctl.

The handler in the kernel then calls ops.reg_user_mr with null as the last argument.

drivers/infiniband/core/uverbs_std_types_mr.c#L366

Thanks,
Jake

#3 lore raw
Quoted 7 lines · Jacob Moroni

For irdma at least, I was able to trigger it with a one-off test binary that directly invokes the UVERBS_METHOD_REG_MR ioctl.

The handler in the kernel then calls ops.reg_user_mr with null as the last argument.

drivers/infiniband/core/uverbs_std_types_mr.c#L366

I think that is a bug, would need to research why it turned out like that.

"user mr" should always have an attrs.

Jason