* [PATCH] RDMA/rtrs: Fix some signedness bugs in error handling
@ 2020-05-19 12:02 Dan Carpenter
2020-05-19 12:40 ` Jinpu Wang
0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2020-05-19 12:02 UTC (permalink / raw)
To: Danil Kipnis, Jack Wang
Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
negative, it gets type promoted to a high positive value and the
condition is false. This patch fixes it by handling negatives separately.
Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 468fdd0d8713..17f99f0962d0 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1047,11 +1047,10 @@ static int rtrs_map_sg_fr(struct rtrs_clt_io_req *req, size_t count)
/* Align the MR to a 4K page size to match the block virt boundary */
nr = ib_map_mr_sg(req->mr, req->sglist, count, NULL, SZ_4K);
- if (unlikely(nr < req->sg_cnt)) {
- if (nr < 0)
- return nr;
+ if (nr < 0)
+ return -EINVAL;
+ if (unlikely(nr < req->sg_cnt))
return -EINVAL;
- }
ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey));
return nr;
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index ba8ab33b94a2..eefd149ce7a4 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -649,7 +649,7 @@ static int map_cont_bufs(struct rtrs_srv_sess *sess)
}
nr = ib_map_mr_sg(mr, sgt->sgl, sgt->nents,
NULL, max_chunk_size);
- if (nr < sgt->nents) {
+ if (nr < 0 || nr < sgt->nents) {
err = nr < 0 ? nr : -EINVAL;
goto dereg_mr;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: Fix some signedness bugs in error handling
2020-05-19 12:02 [PATCH] RDMA/rtrs: Fix some signedness bugs in error handling Dan Carpenter
@ 2020-05-19 12:40 ` Jinpu Wang
2020-05-19 13:25 ` Dan Carpenter
2020-05-19 13:32 ` [PATCH v2] " Dan Carpenter
0 siblings, 2 replies; 6+ messages in thread
From: Jinpu Wang @ 2020-05-19 12:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: Danil Kipnis, Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
On Tue, May 19, 2020 at 2:05 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
> negative, it gets type promoted to a high positive value and the
> condition is false. This patch fixes it by handling negatives separately.
>
> Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Thanks Dan, fix looks correct, just one comment inline.
> ---
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
> drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 468fdd0d8713..17f99f0962d0 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -1047,11 +1047,10 @@ static int rtrs_map_sg_fr(struct rtrs_clt_io_req *req, size_t count)
>
> /* Align the MR to a 4K page size to match the block virt boundary */
> nr = ib_map_mr_sg(req->mr, req->sglist, count, NULL, SZ_4K);
> - if (unlikely(nr < req->sg_cnt)) {
> - if (nr < 0)
> - return nr;
> + if (nr < 0)
> + return -EINVAL;
Why not just return nr here?
> + if (unlikely(nr < req->sg_cnt))
> return -EINVAL;
> - }
> ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey));
>
> return nr;
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> index ba8ab33b94a2..eefd149ce7a4 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> @@ -649,7 +649,7 @@ static int map_cont_bufs(struct rtrs_srv_sess *sess)
> }
> nr = ib_map_mr_sg(mr, sgt->sgl, sgt->nents,
> NULL, max_chunk_size);
> - if (nr < sgt->nents) {
> + if (nr < 0 || nr < sgt->nents) {
> err = nr < 0 ? nr : -EINVAL;
> goto dereg_mr;
> }
> --
> 2.26.2
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] RDMA/rtrs: Fix some signedness bugs in error handling
2020-05-19 12:40 ` Jinpu Wang
@ 2020-05-19 13:25 ` Dan Carpenter
2020-05-19 13:32 ` [PATCH v2] " Dan Carpenter
1 sibling, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2020-05-19 13:25 UTC (permalink / raw)
To: Jinpu Wang
Cc: Danil Kipnis, Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
On Tue, May 19, 2020 at 02:40:41PM +0200, Jinpu Wang wrote:
> On Tue, May 19, 2020 at 2:05 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
> > negative, it gets type promoted to a high positive value and the
> > condition is false. This patch fixes it by handling negatives separately.
> >
> > Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Thanks Dan, fix looks correct, just one comment inline.
> > ---
> > drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
> > drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
> > 2 files changed, 4 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> > index 468fdd0d8713..17f99f0962d0 100644
> > --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> > +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> > @@ -1047,11 +1047,10 @@ static int rtrs_map_sg_fr(struct rtrs_clt_io_req *req, size_t count)
> >
> > /* Align the MR to a 4K page size to match the block virt boundary */
> > nr = ib_map_mr_sg(req->mr, req->sglist, count, NULL, SZ_4K);
> > - if (unlikely(nr < req->sg_cnt)) {
> > - if (nr < 0)
> > - return nr;
> > + if (nr < 0)
> > + return -EINVAL;
> Why not just return nr here?
Sorry. I thought I did but I made a typo. Let me resend.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] RDMA/rtrs: Fix some signedness bugs in error handling
2020-05-19 12:40 ` Jinpu Wang
2020-05-19 13:25 ` Dan Carpenter
@ 2020-05-19 13:32 ` Dan Carpenter
2020-05-19 13:35 ` Jinpu Wang
2020-05-19 23:46 ` Jason Gunthorpe
1 sibling, 2 replies; 6+ messages in thread
From: Dan Carpenter @ 2020-05-19 13:32 UTC (permalink / raw)
To: Danil Kipnis, Jack Wang
Cc: Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
negative, it gets type promoted to a high positive value and the
condition is false. This patch fixes it by handling negatives separately.
Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
v2: propagate the correct error code instead of returning -EINVAL
drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 468fdd0d8713..17f99f0962d0 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1047,11 +1047,10 @@ static int rtrs_map_sg_fr(struct rtrs_clt_io_req *req, size_t count)
/* Align the MR to a 4K page size to match the block virt boundary */
nr = ib_map_mr_sg(req->mr, req->sglist, count, NULL, SZ_4K);
- if (unlikely(nr < req->sg_cnt)) {
- if (nr < 0)
- return nr;
+ if (nr < 0)
+ return nr;
+ if (unlikely(nr < req->sg_cnt))
return -EINVAL;
- }
ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey));
return nr;
diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index ba8ab33b94a2..eefd149ce7a4 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -649,7 +649,7 @@ static int map_cont_bufs(struct rtrs_srv_sess *sess)
}
nr = ib_map_mr_sg(mr, sgt->sgl, sgt->nents,
NULL, max_chunk_size);
- if (nr < sgt->nents) {
+ if (nr < 0 || nr < sgt->nents) {
err = nr < 0 ? nr : -EINVAL;
goto dereg_mr;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] RDMA/rtrs: Fix some signedness bugs in error handling
2020-05-19 13:32 ` [PATCH v2] " Dan Carpenter
@ 2020-05-19 13:35 ` Jinpu Wang
2020-05-19 23:46 ` Jason Gunthorpe
1 sibling, 0 replies; 6+ messages in thread
From: Jinpu Wang @ 2020-05-19 13:35 UTC (permalink / raw)
To: Dan Carpenter
Cc: Danil Kipnis, Doug Ledford, Jason Gunthorpe, linux-rdma, kernel-janitors
On Tue, May 19, 2020 at 3:32 PM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
> negative, it gets type promoted to a high positive value and the
> condition is false. This patch fixes it by handling negatives separately.
>
> Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Thanks Dan,
Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> ---
> v2: propagate the correct error code instead of returning -EINVAL
>
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
> drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
> 2 files changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 468fdd0d8713..17f99f0962d0 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -1047,11 +1047,10 @@ static int rtrs_map_sg_fr(struct rtrs_clt_io_req *req, size_t count)
>
> /* Align the MR to a 4K page size to match the block virt boundary */
> nr = ib_map_mr_sg(req->mr, req->sglist, count, NULL, SZ_4K);
> - if (unlikely(nr < req->sg_cnt)) {
> - if (nr < 0)
> - return nr;
> + if (nr < 0)
> + return nr;
> + if (unlikely(nr < req->sg_cnt))
> return -EINVAL;
> - }
> ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey));
>
> return nr;
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> index ba8ab33b94a2..eefd149ce7a4 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
> @@ -649,7 +649,7 @@ static int map_cont_bufs(struct rtrs_srv_sess *sess)
> }
> nr = ib_map_mr_sg(mr, sgt->sgl, sgt->nents,
> NULL, max_chunk_size);
> - if (nr < sgt->nents) {
> + if (nr < 0 || nr < sgt->nents) {
> err = nr < 0 ? nr : -EINVAL;
> goto dereg_mr;
> }
> --
> 2.26.2
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v2] RDMA/rtrs: Fix some signedness bugs in error handling
2020-05-19 13:32 ` [PATCH v2] " Dan Carpenter
2020-05-19 13:35 ` Jinpu Wang
@ 2020-05-19 23:46 ` Jason Gunthorpe
1 sibling, 0 replies; 6+ messages in thread
From: Jason Gunthorpe @ 2020-05-19 23:46 UTC (permalink / raw)
To: Dan Carpenter
Cc: Danil Kipnis, Jack Wang, Doug Ledford, linux-rdma, kernel-janitors
On Tue, May 19, 2020 at 04:32:23PM +0300, Dan Carpenter wrote:
> The problem is that "req->sg_cnt" is an unsigned int so if "nr" is
> negative, it gets type promoted to a high positive value and the
> condition is false. This patch fixes it by handling negatives separately.
>
> Fixes: 6a98d71daea1 ("RDMA/rtrs: client: main functionality")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> Reviewed-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> ---
> v2: propagate the correct error code instead of returning -EINVAL
>
> drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
> drivers/infiniband/ulp/rtrs/rtrs-srv.c | 2 +-
> 2 files changed, 4 insertions(+), 5 deletions(-)
Applied to for-next, thanks
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-05-19 23:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-19 12:02 [PATCH] RDMA/rtrs: Fix some signedness bugs in error handling Dan Carpenter
2020-05-19 12:40 ` Jinpu Wang
2020-05-19 13:25 ` Dan Carpenter
2020-05-19 13:32 ` [PATCH v2] " Dan Carpenter
2020-05-19 13:35 ` Jinpu Wang
2020-05-19 23:46 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).