From: Dan Carpenter <dan.carpenter@oracle.com>
To: Leon Romanovsky <leon@kernel.org>
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 12:26:19 +0300 [thread overview]
Message-ID: <20201208092619.GB2789@kadam> (raw)
In-Reply-To: <20201208085405.GH4430@unreal>
On Tue, Dec 08, 2020 at 10:54:05AM +0200, Leon Romanovsky wrote:
> 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.
>
Ah.... Thanks.
regards,
dan carpenter
next prev parent reply other threads:[~2020-12-08 9:29 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
2020-12-08 9:26 ` Dan Carpenter [this message]
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=20201208092619.GB2789@kadam \
--to=dan.carpenter@oracle.com \
--cc=avihaih@nvidia.com \
--cc=dledford@redhat.com \
--cc=jgg@nvidia.com \
--cc=leon@kernel.org \
--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