From: Dan Carpenter <dan.carpenter@oracle.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Doug Ledford <dledford@redhat.com>,
Potnuri Bharat Teja <bharat@chelsio.com>,
Matan Barak <matanb@mellanox.com>,
Leon Romanovsky <leon@kernel.org>,
Shamir Rabinovitch <shamir.rabinovitch@oracle.com>,
Matthew Wilcox <willy@infradead.org>,
Michael Guralnik <michaelgur@mellanox.com>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] uverbs: prevent potential underflow
Date: Wed, 9 Oct 2019 10:35:06 +0300 [thread overview]
Message-ID: <20191009073506.GI25098@kadam> (raw)
In-Reply-To: <20191008194425.GA28067@ziepe.ca>
On Tue, Oct 08, 2019 at 04:44:25PM -0300, Jason Gunthorpe wrote:
> On Sat, Oct 05, 2019 at 08:23:37AM +0300, Dan Carpenter wrote:
> > The issue is in drivers/infiniband/core/uverbs_std_types_cq.c in the
> > UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE) function. We check that:
> >
> > if (attr.comp_vector >= attrs->ufile->device->num_comp_vectors) {
> >
> > But we don't check that "attr.comp_vector" whether negative. It
> > could potentially lead to an array underflow. My concern would be where
> > cq->vector is used in the create_cq() function from the cxgb4 driver.
> >
> > Fixes: 9ee79fce3642 ("IB/core: Add completion queue (cq) object actions")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > drivers/infiniband/core/uverbs.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
>
>
> > diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
> > index 1e5aeb39f774..63f7f7db5902 100644
> > --- a/drivers/infiniband/core/uverbs.h
> > +++ b/drivers/infiniband/core/uverbs.h
> > @@ -98,7 +98,7 @@ ib_uverbs_init_udata_buf_or_null(struct ib_udata *udata,
> >
> > struct ib_uverbs_device {
> > atomic_t refcount;
> > - int num_comp_vectors;
> > + u32 num_comp_vectors;
> > struct completion comp;
> > struct device dev;
> > /* First group for device attributes, NULL terminated array */
>
> I would have expected you to change struct ib_cq_init_attr ? Or at
> least both..
>
> This is actually a bug as the type of
> UVERBS_ATTR_CREATE_CQ_COMP_VECTOR for userspace is u32:
>
> UVERBS_ATTR_PTR_IN(UVERBS_ATTR_CREATE_CQ_COMP_VECTOR,
> UVERBS_ATTR_TYPE(u32),
> UA_MANDATORY),
>
> But we are stuffing it into a int:
>
> ret = uverbs_copy_from(&attr.comp_vector, attrs,
> UVERBS_ATTR_CREATE_CQ_COMP_VECTOR);
>
> So very large values will become negative and switching
> num_comp_vectors to u32 won't help??
Yeah. You're right. I should have changed both. I'm not sure what I
was thinking.
My patch does fix the bug because of type promotion, but we should
change both to u32.
regards,
dan carpenter
next prev parent reply other threads:[~2019-10-09 7:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-05 5:23 [PATCH] uverbs: prevent potential underflow Dan Carpenter
2019-10-08 19:44 ` Jason Gunthorpe
2019-10-09 7:35 ` Dan Carpenter [this message]
2019-10-11 13:34 ` [PATCH v2] " Dan Carpenter
2019-10-22 18:15 ` 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=20191009073506.GI25098@kadam \
--to=dan.carpenter@oracle.com \
--cc=bharat@chelsio.com \
--cc=dledford@redhat.com \
--cc=jgg@ziepe.ca \
--cc=kernel-janitors@vger.kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=matanb@mellanox.com \
--cc=michaelgur@mellanox.com \
--cc=shamir.rabinovitch@oracle.com \
--cc=willy@infradead.org \
/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).