From: Leon Romanovsky <leon@kernel.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Doug Ledford <dledford@redhat.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Avihai Horon <avihaih@nvidia.com>,
linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next 3/3] RDMA/uverbs: Fix incorrect variable type
Date: Tue, 8 Dec 2020 10:54:05 +0200 [thread overview]
Message-ID: <20201208085405.GH4430@unreal> (raw)
In-Reply-To: <20201208075539.GA2789@kadam>
On Tue, Dec 08, 2020 at 10:55:39AM +0300, Dan Carpenter wrote:
> On Tue, Dec 08, 2020 at 09:35:45AM +0200, Leon Romanovsky wrote:
> > @@ -336,19 +335,16 @@ static int UVERBS_HANDLER(UVERBS_METHOD_QUERY_GID_TABLE)(
> > attrs, UVERBS_ATTR_QUERY_GID_TABLE_RESP_ENTRIES,
> > user_entry_size);
> > if (max_entries <= 0)
> > - return -EINVAL;
> > + return max_entries ?: -EINVAL;
> >
> > ucontext = ib_uverbs_get_ucontext(attrs);
> > if (IS_ERR(ucontext))
> > return PTR_ERR(ucontext);
> > ib_dev = ucontext->device;
> >
> > - if (check_mul_overflow(max_entries, sizeof(*entries), &num_bytes))
> > - return -EINVAL;
> > -
> > - entries = uverbs_zalloc(attrs, num_bytes);
> > - if (!entries)
> > - return -ENOMEM;
> > + entries = uverbs_kcalloc(attrs, max_entries, sizeof(*entries));
> > + if (IS_ERR(entries))
> > + return PTR_ERR(entries);
>
> This isn't right. The uverbs_kcalloc() should match every other
> kcalloc() function and return NULL on error. This actually buggy
> because it returns both is error pointers and NULL so it will lead to
> a NULL dereference.
The actual bug was before, when an error result from uverbs_zalloc()
was treated as NULL. The uverbs_kcalloc/uverbs_zalloc will call to
_uverbs_alloc() that doesn't return NULL.
>
> Btw, when a function returns both error pointers and NULL the NULL
> return means that the feature has been deliberately disabled. It's not
> an error pointer because it's deliberate.
>
> regards,
> dan carpenter
>
> >
> > num_entries = rdma_query_gid_table(ib_dev, entries, max_entries);
> > if (num_entries < 0)
> > diff --git a/include/rdma/uverbs_ioctl.h b/include/rdma/uverbs_ioctl.h
> > index bf167ef6c688..39ef204753ec 100644
> > --- a/include/rdma/uverbs_ioctl.h
> > +++ b/include/rdma/uverbs_ioctl.h
> > @@ -865,6 +865,16 @@ static inline __malloc void *uverbs_zalloc(struct uverbs_attr_bundle *bundle,
> > {
> > return _uverbs_alloc(bundle, size, GFP_KERNEL | __GFP_ZERO);
> > }
> > +
> > +static inline __malloc void *uverbs_kcalloc(struct uverbs_attr_bundle *bundle,
> > + size_t n, size_t size)
> > +{
> > + size_t bytes;
> > +
> > + if (unlikely(check_mul_overflow(n, size, &bytes)))
> > + return ERR_PTR(-EOVERFLOW);
> > + return uverbs_zalloc(bundle, bytes);
> > +}
> > int _uverbs_get_const(s64 *to, const struct uverbs_attr_bundle *attrs_bundle,
> > size_t idx, s64 lower_bound, u64 upper_bound,
> > s64 *def_val);
> > --
> > 2.28.0
next prev parent reply other threads:[~2020-12-08 8:54 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-08 7:35 [PATCH rdma-next 0/3] Various fixes collected over time Leon Romanovsky
2020-12-08 7:35 ` [PATCH rdma-next 1/3] RDMA/core: Clean up cq pool mechanism Leon Romanovsky
2020-12-08 7:35 ` [PATCH rdma-next 2/3] RDMA/core: Do not indicate device ready when device enablement fails Leon Romanovsky
2020-12-08 7:35 ` [PATCH rdma-next 3/3] RDMA/uverbs: Fix incorrect variable type Leon Romanovsky
2020-12-08 7:55 ` Dan Carpenter
2020-12-08 8:54 ` Leon Romanovsky [this message]
2020-12-08 9:26 ` Dan Carpenter
2020-12-08 14:00 ` Jason Gunthorpe
2020-12-10 20:26 ` [PATCH rdma-next 0/3] Various fixes collected over time 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=20201208085405.GH4430@unreal \
--to=leon@kernel.org \
--cc=avihaih@nvidia.com \
--cc=dan.carpenter@oracle.com \
--cc=dledford@redhat.com \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.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).