2021-05-09 11:41:11

by Leon Romanovsky

[permalink] [raw]
Subject: [PATCH rdma-rc] RDMA/siw: Properly check send and receive CQ pointers

From: Leon Romanovsky <[email protected]>

The check for the NULL of pointer received from container_of is
incorrect by definition as it points to some random memory.

Change such check with proper NULL check of SIW QP attributes.

Fixes: 303ae1cdfdf7 ("rdma/siw: application interface")
Signed-off-by: Leon Romanovsky <[email protected]>
---
drivers/infiniband/sw/siw/siw_verbs.c | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c
index d2313efb26db..917c8a919f38 100644
--- a/drivers/infiniband/sw/siw/siw_verbs.c
+++ b/drivers/infiniband/sw/siw/siw_verbs.c
@@ -300,7 +300,6 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
struct siw_ucontext *uctx =
rdma_udata_to_drv_context(udata, struct siw_ucontext,
base_ucontext);
- struct siw_cq *scq = NULL, *rcq = NULL;
unsigned long flags;
int num_sqe, num_rqe, rv = 0;
size_t length;
@@ -343,10 +342,8 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
rv = -EINVAL;
goto err_out;
}
- scq = to_siw_cq(attrs->send_cq);
- rcq = to_siw_cq(attrs->recv_cq);

- if (!scq || (!rcq && !attrs->srq)) {
+ if (!attrs->send_cq || (!attrs->recv_cq && !attrs->srq)) {
siw_dbg(base_dev, "send CQ or receive CQ invalid\n");
rv = -EINVAL;
goto err_out;
@@ -401,8 +398,8 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
}
}
qp->pd = pd;
- qp->scq = scq;
- qp->rcq = rcq;
+ qp->scq = to_siw_cq(attrs->send_cq);
+ qp->rcq = to_siw_cq(attrs->recv_cq);

if (attrs->srq) {
/*
--
2.31.1


2021-05-10 09:37:16

by Bernard Metzler

[permalink] [raw]
Subject: Re: [PATCH rdma-rc] RDMA/siw: Properly check send and receive CQ pointers

-----"Leon Romanovsky" <[email protected]> wrote: -----

>To: "Doug Ledford" <[email protected]>, "Jason Gunthorpe"
><[email protected]>
>From: "Leon Romanovsky" <[email protected]>
>Date: 05/09/2021 01:39PM
>Cc: "Leon Romanovsky" <[email protected]>, "Bernard Metzler"
><[email protected]>, [email protected],
>[email protected]
>Subject: [EXTERNAL] [PATCH rdma-rc] RDMA/siw: Properly check send and
>receive CQ pointers
>
>From: Leon Romanovsky <[email protected]>
>
>The check for the NULL of pointer received from container_of is
>incorrect by definition as it points to some random memory.
>
>Change such check with proper NULL check of SIW QP attributes.
>
>Fixes: 303ae1cdfdf7 ("rdma/siw: application interface")
>Signed-off-by: Leon Romanovsky <[email protected]>
>---
> drivers/infiniband/sw/siw/siw_verbs.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/infiniband/sw/siw/siw_verbs.c
>b/drivers/infiniband/sw/siw/siw_verbs.c
>index d2313efb26db..917c8a919f38 100644
>--- a/drivers/infiniband/sw/siw/siw_verbs.c
>+++ b/drivers/infiniband/sw/siw/siw_verbs.c
>@@ -300,7 +300,6 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
> struct siw_ucontext *uctx =
> rdma_udata_to_drv_context(udata, struct siw_ucontext,
> base_ucontext);
>- struct siw_cq *scq = NULL, *rcq = NULL;
> unsigned long flags;
> int num_sqe, num_rqe, rv = 0;
> size_t length;
>@@ -343,10 +342,8 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
> rv = -EINVAL;
> goto err_out;
> }
>- scq = to_siw_cq(attrs->send_cq);
>- rcq = to_siw_cq(attrs->recv_cq);
>
>- if (!scq || (!rcq && !attrs->srq)) {
>+ if (!attrs->send_cq || (!attrs->recv_cq && !attrs->srq)) {
> siw_dbg(base_dev, "send CQ or receive CQ invalid\n");
> rv = -EINVAL;
> goto err_out;
>@@ -401,8 +398,8 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
> }
> }
> qp->pd = pd;
>- qp->scq = scq;
>- qp->rcq = rcq;
>+ qp->scq = to_siw_cq(attrs->send_cq);
>+ qp->rcq = to_siw_cq(attrs->recv_cq);
>
> if (attrs->srq) {
> /*
>--
>2.31.1
>
>
Thanks Leon!

Reviewed-by: Bernard Metzler <[email protected]>

2021-05-10 17:33:11

by Bernard Metzler

[permalink] [raw]
Subject: Re: [PATCH rdma-rc] RDMA/siw: Properly check send and receive CQ pointers

-----"Leon Romanovsky" <[email protected]> wrote: -----

>To: "Doug Ledford" <[email protected]>, "Jason Gunthorpe"
><[email protected]>
>From: "Leon Romanovsky" <[email protected]>
>Date: 05/09/2021 01:39PM
>Cc: "Leon Romanovsky" <[email protected]>, "Bernard Metzler"
><[email protected]>, [email protected],
>[email protected]
>Subject: [EXTERNAL] [PATCH rdma-rc] RDMA/siw: Properly check send and
>receive CQ pointers
>
>From: Leon Romanovsky <[email protected]>
>
>The check for the NULL of pointer received from container_of is
>incorrect by definition as it points to some random memory.
>
>Change such check with proper NULL check of SIW QP attributes.
>
>Fixes: 303ae1cdfdf7 ("rdma/siw: application interface")
>Signed-off-by: Leon Romanovsky <[email protected]>
>---
> drivers/infiniband/sw/siw/siw_verbs.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/infiniband/sw/siw/siw_verbs.c
>b/drivers/infiniband/sw/siw/siw_verbs.c
>index d2313efb26db..917c8a919f38 100644
>--- a/drivers/infiniband/sw/siw/siw_verbs.c
>+++ b/drivers/infiniband/sw/siw/siw_verbs.c
>@@ -300,7 +300,6 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
> struct siw_ucontext *uctx =
> rdma_udata_to_drv_context(udata, struct siw_ucontext,
> base_ucontext);
>- struct siw_cq *scq = NULL, *rcq = NULL;
> unsigned long flags;
> int num_sqe, num_rqe, rv = 0;
> size_t length;
>@@ -343,10 +342,8 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
> rv = -EINVAL;
> goto err_out;
> }
>- scq = to_siw_cq(attrs->send_cq);
>- rcq = to_siw_cq(attrs->recv_cq);
>
>- if (!scq || (!rcq && !attrs->srq)) {
>+ if (!attrs->send_cq || (!attrs->recv_cq && !attrs->srq)) {
> siw_dbg(base_dev, "send CQ or receive CQ invalid\n");
> rv = -EINVAL;
> goto err_out;
>@@ -401,8 +398,8 @@ struct ib_qp *siw_create_qp(struct ib_pd *pd,
> }
> }
> qp->pd = pd;
>- qp->scq = scq;
>- qp->rcq = rcq;
>+ qp->scq = to_siw_cq(attrs->send_cq);
>+ qp->rcq = to_siw_cq(attrs->recv_cq);
>
> if (attrs->srq) {
> /*
>--
>2.31.1
>
>

Many thanks Leon!

Reviewed-by: Bernard Metzler <[email protected]>

2021-05-10 19:23:05

by Jason Gunthorpe

[permalink] [raw]
Subject: Re: [PATCH rdma-rc] RDMA/siw: Properly check send and receive CQ pointers

On Sun, May 09, 2021 at 02:39:21PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <[email protected]>
>
> The check for the NULL of pointer received from container_of is
> incorrect by definition as it points to some random memory.
>
> Change such check with proper NULL check of SIW QP attributes.
>
> Fixes: 303ae1cdfdf7 ("rdma/siw: application interface")
> Signed-off-by: Leon Romanovsky <[email protected]>
> Reviewed-by: Bernard Metzler <[email protected]>
> ---
> drivers/infiniband/sw/siw/siw_verbs.c | 9 +++------
> 1 file changed, 3 insertions(+), 6 deletions(-)

Applied to for-rc, thanks

Jason