Skip to content

Commit fdcbddc

Browse files
jgunthorperleon
authored andcommitted
RDMA/hns: Remove the duplicate calls to ib_copy_validate_udata_in()
A udata should be read only once per ioctl, not multiple times. Multiple reads make it unclear what the content is since userspace can change it between the reads. Lift the ib_copy_validate_udata_in() out of alloc_srq_buf()/alloc_srq_db() and into hns_roce_create_srq(). Found by AI. Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
1 parent 8e3e07c commit fdcbddc

1 file changed

Lines changed: 16 additions & 19 deletions

File tree

drivers/infiniband/hw/hns/hns_roce_srq.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -340,22 +340,16 @@ static int set_srq_param(struct hns_roce_srq *srq,
340340
}
341341

342342
static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
343-
struct ib_udata *udata)
343+
struct ib_udata *udata,
344+
struct hns_roce_ib_create_srq *ucmd)
344345
{
345-
struct hns_roce_ib_create_srq ucmd = {};
346346
int ret;
347347

348-
if (udata) {
349-
ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
350-
if (ret)
351-
return ret;
352-
}
353-
354-
ret = alloc_srq_idx(hr_dev, srq, udata, ucmd.que_addr);
348+
ret = alloc_srq_idx(hr_dev, srq, udata, ucmd->que_addr);
355349
if (ret)
356350
return ret;
357351

358-
ret = alloc_srq_wqe_buf(hr_dev, srq, udata, ucmd.buf_addr);
352+
ret = alloc_srq_wqe_buf(hr_dev, srq, udata, ucmd->buf_addr);
359353
if (ret)
360354
goto err_idx;
361355

@@ -404,22 +398,18 @@ static void free_srq_db(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
404398

405399
static int alloc_srq_db(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
406400
struct ib_udata *udata,
401+
struct hns_roce_ib_create_srq *ucmd,
407402
struct hns_roce_ib_create_srq_resp *resp)
408403
{
409-
struct hns_roce_ib_create_srq ucmd;
410404
struct hns_roce_ucontext *uctx;
411405
int ret;
412406

413407
if (udata) {
414-
ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
415-
if (ret)
416-
return ret;
417-
418408
if ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SRQ_RECORD_DB) &&
419-
(ucmd.req_cap_flags & HNS_ROCE_SRQ_CAP_RECORD_DB)) {
409+
(ucmd->req_cap_flags & HNS_ROCE_SRQ_CAP_RECORD_DB)) {
420410
uctx = rdma_udata_to_drv_context(udata,
421411
struct hns_roce_ucontext, ibucontext);
422-
ret = hns_roce_db_map_user(uctx, ucmd.db_addr,
412+
ret = hns_roce_db_map_user(uctx, ucmd->db_addr,
423413
&srq->rdb);
424414
if (ret)
425415
return ret;
@@ -448,6 +438,7 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
448438
struct hns_roce_dev *hr_dev = to_hr_dev(ib_srq->device);
449439
struct hns_roce_ib_create_srq_resp resp = {};
450440
struct hns_roce_srq *srq = to_hr_srq(ib_srq);
441+
struct hns_roce_ib_create_srq ucmd = {};
451442
int ret;
452443

453444
mutex_init(&srq->mutex);
@@ -457,11 +448,17 @@ int hns_roce_create_srq(struct ib_srq *ib_srq,
457448
if (ret)
458449
goto err_out;
459450

460-
ret = alloc_srq_buf(hr_dev, srq, udata);
451+
if (udata) {
452+
ret = ib_copy_validate_udata_in(udata, ucmd, que_addr);
453+
if (ret)
454+
goto err_out;
455+
}
456+
457+
ret = alloc_srq_buf(hr_dev, srq, udata, &ucmd);
461458
if (ret)
462459
goto err_out;
463460

464-
ret = alloc_srq_db(hr_dev, srq, udata, &resp);
461+
ret = alloc_srq_db(hr_dev, srq, udata, &ucmd, &resp);
465462
if (ret)
466463
goto err_srq_buf;
467464

0 commit comments

Comments
 (0)