From: Dan Carpenter <dan.carpenter@oracle.com>
To: Lijun Ou <oulijun@huawei.com>
Cc: "Wei Hu(Xavier)" <xavier.huwei@huawei.com>,
Doug Ledford <dledford@redhat.com>,
Jason Gunthorpe <jgg@ziepe.ca>,
linux-rdma@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] RDMA/hns: prevent undefined behavior in hns_roce_set_user_sq_size()
Date: Mon, 7 Oct 2019 15:18:22 +0300 [thread overview]
Message-ID: <20191007121821.GI21515@kadam> (raw)
In-Reply-To: <20190608092514.GC28890@mwanda>
This one still needs to be applied.
regards,
dan carpenter
On Sat, Jun 08, 2019 at 12:25:14PM +0300, Dan Carpenter wrote:
> The "ucmd->log_sq_bb_count" variable is a user controlled variable in
> the 0-255 range. If we shift more than then number of bits in an int
> then it's undefined behavior (it shift wraps). It turns out this
> doesn't cause any real issues at runtime, but it's good to check anyway.
>
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/infiniband/hw/hns/hns_roce_qp.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c
> index 8db2817a249e..006b3e7f4ed5 100644
> --- a/drivers/infiniband/hw/hns/hns_roce_qp.c
> +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c
> @@ -342,7 +342,8 @@ static int hns_roce_set_user_sq_size(struct hns_roce_dev *hr_dev,
> u32 max_cnt;
>
> /* Sanity check SQ size before proceeding */
> - if ((u32)(1 << ucmd->log_sq_bb_count) > hr_dev->caps.max_wqes ||
> + if (ucmd->log_sq_bb_count > 31 ||
> + (u32)(1 << ucmd->log_sq_bb_count) > hr_dev->caps.max_wqes ||
> ucmd->log_sq_stride > max_sq_stride ||
> ucmd->log_sq_stride < HNS_ROCE_IB_MIN_SQ_STRIDE) {
> dev_err(hr_dev->dev, "check SQ size error!\n");
> --
> 2.20.1
next parent reply other threads:[~2019-10-07 12:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190608092514.GC28890@mwanda>
2019-10-07 12:18 ` Dan Carpenter [this message]
2019-10-24 16:37 ` [PATCH] RDMA/hns: prevent undefined behavior in hns_roce_set_user_sq_size() Jason Gunthorpe
2019-10-24 18:20 ` Dan Carpenter
2019-10-28 14:23 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191007121821.GI21515@kadam \
--to=dan.carpenter@oracle.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=oulijun@huawei.com \
--cc=xavier.huwei@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).