Skip to contentSkip to conversation

RDMA/rxe: Return -EFAULT if copy_from_user() fails

PATCH In review Dan Carpenter 4 participants 9 messages May 11, 2020 – May 12, 2020

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

PATCH 1/1 RDMA/rxe: Return -EFAULT if copy_from_user() fails

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/sw/rxe/rxe_queue.c +3 -2
index fef2ab5112de5..245040c3a35d0 100644
@@ -50,9 +50,10 @@ int do_mmap_info(struct rxe_dev *rxe, struct mminfo __user *outbuf,
 			goto err1;
 		}
 
-		err = copy_to_user(outbuf, &ip->info, sizeof(ip->info));
-		if (err)
+		if (copy_to_user(outbuf, &ip->info, sizeof(ip->info))) {
+			err = -EFAULT;
 			goto err2;
+		}
 
 		spin_lock_bh(&rxe->pending_lock);
 		list_add(&ip->pending_mmaps, &rxe->pending_mmaps);
Signature · 1 line
2.26.2
#1 lore raw

Does this "err = -EFAULT;" make any sense in your commit?

Zhu Yanjun

-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Tuesday, May 12, 2020 2:38 AM
To: Yanjun Zhu <[email protected]>; Sudip Mukherjee <[email protected]>
Cc: Doug Ledford <[email protected]>; Jason Gunthorpe <[email protected]>; [email protected]; [email protected]
Subject: [PATCH] RDMA/rxe: Return -EFAULT if copy_from_user() fails

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/infiniband/sw/rxe/rxe_queue.c +3 -2
index fef2ab5112de5..245040c3a35d0 100644
@@ -50,9 +50,10 @@ int do_mmap_info(struct rxe_dev *rxe, struct mminfo __user *outbuf,
 			goto err1;
 		}
 
-		err = copy_to_user(outbuf, &ip->info, sizeof(ip->info));
-		if (err)
+		if (copy_to_user(outbuf, &ip->info, sizeof(ip->info))) {
+			err = -EFAULT;
 			goto err2;
+		}
 
 		spin_lock_bh(&rxe->pending_lock);
 		list_add(&ip->pending_mmaps, &rxe->pending_mmaps);

--
2.26.2

#2 lore raw
Quoted 1 line · Yanjun Zhu

Does this "err = -EFAULT;" make any sense in your commit?

Yanjun, please stop top-posting, it is annoying.

Thanks

Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Thanks,

#4 lore raw
Quoted 13 lines · Leon Romanovsky
Quoted 10 lines · Dan Carpenter

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 2 lines

Thanks,

Actually Yanjun is right and "err" can be removed.

Thanks

#5 lore raw
Quoted 14 lines · Leon Romanovsky
Quoted 13 lines · Leon Romanovsky
Quoted 10 lines · Dan Carpenter

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 6 lines
Quoted 2 lines

Thanks,

Actually Yanjun is right and "err" can be removed.

Thanks

I don't know if the code you guys are looking at is older or newer than linux-next... :P

drivers/infiniband/sw/rxe/rxe_queue.c

    39  int do_mmap_info(struct rxe_dev *rxe, struct mminfo __user *outbuf,
    40                   struct ib_udata *udata, struct rxe_queue_buf *buf,
    41                   size_t buf_size, struct rxe_mmap_info **ip_p)
    42  {
    43          int err;
                    ^^^

    44          struct rxe_mmap_info *ip = NULL;
    45  
    46          if (outbuf) {
    47                  ip = rxe_create_mmap_info(rxe, buf_size, udata, buf);
    48                  if (IS_ERR(ip)) {
    49                          err = PTR_ERR(ip);
    50                          goto err1;
                                ^^^^^^^^^
    51                  }
    52  
    53                  err = copy_to_user(outbuf, &ip->info, sizeof(ip->info));
    54                  if (err)
    55                          goto err2;
                                ^^^^^^^^^
    56  
    57                  spin_lock_bh(&rxe->pending_lock);
    58                  list_add(&ip->pending_mmaps, &rxe->pending_mmaps);
    59                  spin_unlock_bh(&rxe->pending_lock);
    60          }
    61  
    62          *ip_p = ip;
    63  
    64          return 0;
    65  
    66  err2:
    67          kfree(ip);
    68  err1:
    69          return err;
                       ^^^
    70  }

regards,
dan carpenter

#6 lore raw
Quoted 18 lines · Dan Carpenter
Quoted 17 lines · Leon Romanovsky
Quoted 15 lines · Leon Romanovsky
Quoted 10 lines · Dan Carpenter

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Thanks,

Quoted 6 lines
Quoted 3 lines

Actually Yanjun is right and "err" can be removed.

Thanks

I don't know if the code you guys are looking at is older or newer than linux-next... :P

We both looked on rdma-next, but the wrong code was added to -rc.

Jason, that patch was marked as stable@.

Thanks

#7 lore raw

-----Original Message-----
From: Leon Romanovsky <[email protected]>
Sent: Tuesday, May 12, 2020 4:31 PM
To: Dan Carpenter <[email protected]>; Jason Gunthorpe <[email protected]>
Cc: Yanjun Zhu <[email protected]>; Sudip Mukherjee <[email protected]>; Doug Ledford <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] RDMA/rxe: Return -EFAULT if copy_from_user() fails

Quoted 19 lines · Dan Carpenter
Quoted 18 lines · Leon Romanovsky
Quoted 16 lines · Leon Romanovsky
Quoted 11 lines · Dan Carpenter

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from

rxe_create_mmap_info()")

---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Thanks,

Quoted 8 lines
Quoted 3 lines

Actually Yanjun is right and "err" can be removed.

Thanks

I don't know if the code you guys are looking at is older or newer than linux-next... :P

We both looked on rdma-next, but the wrong code was added to -rc.

Yes. I agree with you.

Zhu Yanjun

Quoted 1 line

Jason, that patch was marked as stable@.

Thanks

#8 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter

This function used to always return -EINVAL but we updated it to try preserve the error codes. Unfortunately the copy_to_user() is returning the number of bytes remaining to be copied instead of a negative error code.

Fixes a3a974b4654d ("RDMA/rxe: Always return ERR_PTR from rxe_create_mmap_info()")
---
 drivers/infiniband/sw/rxe/rxe_queue.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

I squashed this into to the above patch since it is marked for -stable

This means for-rc gets rebased

Thanks,
Jason