RDMA/irdma: Fix possible null-pointer dereference in irdma_create_user_ah()
Subsystems (2)
PATCH 1/1 RDMA/irdma: Fix possible null-pointer dereference in irdma_create_user_ah()
The variable udata is checked at the beginning of irdma_create_user_as(), indicating that it can be NULL:
if (udata && udata->outlen < IRDMA_CREATE_AH_MIN_RESP_LEN)
return -EINVAL;However, if udata is NULL, a null-pointer dereference may occur when calling ib_copy_to_udata():
err = ib_copy_to_udata(udata, &uresp, min(sizeof(uresp), udata->outlen));
To prevent this possible null-pointer dereference, add a NULL check for udata before calling ib_copy_to_udata().
Signed-off-by Tuo Li <[email protected]>
--- drivers/infiniband/hw/irdma/verbs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/infiniband/hw/irdma/verbs.c +2 -1
@@ -5233,7 +5233,8 @@ static int irdma_create_user_ah(struct ib_ah *ibah,mutex_unlock (&iwdev->rf->ah_tbl_lock); uresp.ah_id = ah->sc_ah.ah_info.ah_idx; - err =ib_copy_to_udata (udata, &uresp,min (sizeof (uresp), udata->outlen)); +if (udata) + err =ib_copy_to_udata (udata, &uresp,min (sizeof (uresp), udata->outlen));if (err)irdma_destroy_ah (ibah, attr->flags);
Signature · 1 line
2.43.0
Quoted 5 lines · Tuo Li
The variable udata is checked at the beginning of
irdma_create_user_as(), indicating that it can be NULL:if (udata && udata->outlen < IRDMA_CREATE_AH_MIN_RESP_LEN) return -EINVAL;
Just delete "udata" check from this if(). irdma_create_user_ah() always receives udate.
Thanks