drivers/infiniband: copy userspace arrays safely
Subsystems (2)
PATCH 1/1 drivers/infiniband: copy userspace arrays safely
Currently, memdup_user() is utilized at two positions to copy userspace arrays. This is done without overflow checks.
Use the new wrapper memdup_array_user() to copy the arrays more safely.
--- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 4 ++-- drivers/infiniband/hw/hfi1/user_sdma.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/infiniband/hw/hfi1/user_exp_rcv.c +2 -2
@@ -491,8 +491,8 @@ int hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd,if (unlikely (tinfo->tidcnt > fd->tid_used))return -EINVAL ; - tidinfo =memdup_user (u64_to_user_ptr (tinfo->tidlist), -sizeof (tidinfo[0 ]) * tinfo->tidcnt); + tidinfo =memdup_array_user (u64_to_user_ptr (tinfo->tidlist), + tinfo->tidcnt,sizeof (tidinfo[0 ]));if (IS_ERR (tidinfo))return PTR_ERR (tidinfo);
drivers/infiniband/hw/hfi1/user_sdma.c +2 -2
@@ -494,8 +494,8 @@ int hfi1_user_sdma_process_request(struct hfi1_filedata *fd,* equal to the pkt count. However, there is no way to * tell at this point. */ - tmp =memdup_user (iovec[idx].iov_base, - ntids *sizeof (*req->tids)); + tmp =memdup_array_user (iovec[idx].iov_base, + ntids,sizeof (*req->tids));if (IS_ERR (tmp)) { ret =PTR_ERR (tmp); SDMA_DBG(req, "Failed to copy %d TIDs (%d)",
Signature · 1 line
2.41.0
Quoted 32 lines · Philipp Stanner
Currently,
memdup_user()is utilized at two positions to copy userspace arrays. This is done without overflow checks.Use the new wrapper
memdup_array_user()to copy the arrays more safely.Suggested-by Dave Airlie <[email protected]>Signed-off-by Philipp Stanner <[email protected]>--- drivers/infiniband/hw/hfi1/user_exp_rcv.c | 4 ++-- drivers/infiniband/hw/hfi1/user_sdma.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)drivers/infiniband/hw/hfi1/user_exp_rcv.c +2
-2@@ -491,8 +491,8 @@ int hfi1_user_exp_rcv_clear(struct hfi1_filedata *fd,if (unlikely (tinfo->tidcnt > fd->tid_used))return -EINVAL ; - tidinfo =memdup_user (u64_to_user_ptr (tinfo->tidlist), -sizeof (tidinfo[0 ]) * tinfo->tidcnt); + tidinfo =memdup_array_user (u64_to_user_ptr (tinfo->tidlist), + tinfo->tidcnt,sizeof (tidinfo[0 ]));if (IS_ERR (tidinfo))return PTR_ERR (tidinfo);drivers/infiniband/hw/hfi1/user_sdma.c +0
-0
drivers/infiniband/hw/hfi1/user_sdma.c int hfi1_user_sdma_process_request(struct hfi1_filedata *fd, · line 501
Quoted 10 lines
drivers/infiniband/hw/hfi1/user_sdma.c +2
-2@@ -494,8 +494,8 @@ int hfi1_user_sdma_process_request(struct hfi1_filedata *fd,* equal to the pkt count. However, there is no way to * tell at this point. */ - tmp =memdup_user (iovec[idx].iov_base, - ntids *sizeof (*req->tids)); + tmp =memdup_array_user (iovec[idx].iov_base, + ntids,sizeof (*req->tids));if (IS_ERR (tmp)) { ret =PTR_ERR (tmp); SDMA_DBG(req, "Failed to copy %d TIDs (%d)",
Leon Romanovsky
AppliedQuoted 6 lines · Philipp Stanner
Currently,
memdup_user()is utilized at two positions to copy userspace arrays. This is done without overflow checks.Use the new wrapper
memdup_array_user()to copy the arrays more safely.
Applied, thanks!
[1/1] drivers/infiniband: copy userspace arrays safely
https://git.kernel.org/rdma/rdma/c/c170d4ff21a8a5
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>