2017-06-05 12:22:15

by Jia-Ju Bai

[permalink] [raw]
Subject: [PATCH V5] rxe: Fix a sleep-in-atomic bug in post_one_send

The driver may sleep under a spin lock, and the function call path is:
post_one_send (acquire the lock by spin_lock_irqsave)
init_send_wqe
copy_from_user --> may sleep

There is no flow that makes "qp->is_user" true, and copy_from_user may
cause bug when a non-user pointer is used. So the lines of copy_from_user
and check of "qp->is_user" are removed.

Signed-off-by: Jia-Ju Bai <[email protected]>
---
V5:
* Remove useless check of "qp->is_user".
Thank Leon for pointing it out.

V4:
* Remove the line of copy_from_user.
Thank Moni for good advice.

V3:
* It corrects the mistakes of remaining legacy code in V2.
Thank Ram for pointing it out.

V2:
* The parameter "flags" is added to restore and save the irq status.
Thank Leon for good advice.
---
drivers/infiniband/sw/rxe/rxe_verbs.c | 9 ++-------
1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c
index 83d709e..073e667 100644
--- a/drivers/infiniband/sw/rxe/rxe_verbs.c
+++ b/drivers/infiniband/sw/rxe/rxe_verbs.c
@@ -740,13 +740,8 @@ static int init_send_wqe(struct rxe_qp *qp, struct ib_send_wr *ibwr,

sge = ibwr->sg_list;
for (i = 0; i < num_sge; i++, sge++) {
- if (qp->is_user && copy_from_user(p, (__user void *)
- (uintptr_t)sge->addr, sge->length))
- return -EFAULT;
-
- else if (!qp->is_user)
- memcpy(p, (void *)(uintptr_t)sge->addr,
- sge->length);
+ memcpy(p, (void *)(uintptr_t)sge->addr,
+ sge->length);

p += sge->length;
}
--
1.7.9.5



2017-06-05 12:49:55

by Leon Romanovsky

[permalink] [raw]
Subject: Re: [PATCH V5] rxe: Fix a sleep-in-atomic bug in post_one_send

On Mon, Jun 05, 2017 at 08:23:40PM +0800, Jia-Ju Bai wrote:
> The driver may sleep under a spin lock, and the function call path is:
> post_one_send (acquire the lock by spin_lock_irqsave)
> init_send_wqe
> copy_from_user --> may sleep
>
> There is no flow that makes "qp->is_user" true, and copy_from_user may
> cause bug when a non-user pointer is used. So the lines of copy_from_user
> and check of "qp->is_user" are removed.
>
> Signed-off-by: Jia-Ju Bai <[email protected]>
> ---

Thanks,
Reviewed-by: Leon Romanovsky <[email protected]>


Attachments:
(No filename) (554.00 B)
signature.asc (833.00 B)
Download all attachments

2017-06-13 21:01:55

by Doug Ledford

[permalink] [raw]
Subject: Re: [PATCH V5] rxe: Fix a sleep-in-atomic bug in post_one_send

On Mon, 2017-06-05 at 20:23 +0800, Jia-Ju Bai wrote:
> The driver may sleep under a spin lock, and the function call path
> is:
> post_one_send (acquire the lock by spin_lock_irqsave)
>   init_send_wqe
>     copy_from_user --> may sleep
>
> There is no flow that makes "qp->is_user" true, and copy_from_user
> may
> cause bug when a non-user pointer is used. So the lines of
> copy_from_user
> and check of "qp->is_user" are removed.
>
> Signed-off-by: Jia-Ju Bai <[email protected]>

Thanks, applied.

--
Doug Ledford <[email protected]>
    GPG KeyID: B826A3330E572FDD
   
Key fingerprint = AE6B 1BDA 122B 23B4 265B  1274 B826 A333 0E57 2FDD