All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: Leon Romanovsky <leon@kernel.org>,
	Doug Ledford <dledford@redhat.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:00:36 -0400	[thread overview]
Message-ID: <20201208140036.GJ552508@nvidia.com> (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.

It is abnormal, but returing the EOVERFLOW to the caller vs ENOMEM
does seem somewhat relevant for debuggability..

If anything on the uverbs_*alloc* path returns NULL it is a bug.

Jason

  parent reply	other threads:[~2020-12-08 14:01 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
2020-12-08 14:00     ` Jason Gunthorpe [this message]
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=20201208140036.GJ552508@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=avihaih@nvidia.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dledford@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.