Linux-RDMA Archive on lore.kernel.org
 help / color / Atom feed
From: Shay Drory <shayd@nvidia.com>
To: Jason Gunthorpe <jgg@nvidia.com>, Leon Romanovsky <leon@kernel.org>
Cc: Doug Ledford <dledford@redhat.com>,
	Krishna Kumar <krkumar2@in.ibm.com>, <linux-rdma@vger.kernel.org>,
	Sean Hefty <sean.hefty@intel.com>
Subject: Re: [PATCH rdma-next 2/3] RDMA/core: Fix check of device in rdma_listen()
Date: Thu, 22 Apr 2021 15:44:55 +0300
Message-ID: <1fca1133-8cdd-8b21-42cf-69d610b4f8f4@nvidia.com> (raw)
In-Reply-To: <20210422112802.GA2320845@nvidia.com>

On 4/22/2021 14:28, Jason Gunthorpe wrote:

> On Sun, Apr 18, 2021 at 04:55:53PM +0300, Leon Romanovsky wrote:
>> From: Shay Drory <shayd@nvidia.com>
>>
>> rdma_listen() checks if device already attached to rdma_id_priv,
>> based on the response the its decide to what to listen, however
>> this is different when the listeners are canceled.
>>
>> This leads to a mismatch between rdma_listen() and cma_cancel_operation(),
>> and causes to bellow wild-memory-access. Fix it by aligning rdma_listen()
>> according to the cma_cancel_operation().
> So this is happening because the error unwind in rdma_bind_addr() is
> taking the exit path and calling cma_release_dev()?
>
> This allows rdma_listen() to be called with a bogus device pointer
> which precipitates this UAF during destroy.
>
> However, I think rdma_bind_addr() should not allow the bogus device
> pointer to leak out at all, since the ULP could see it. It really is
> invalid to have it present no matter what.
>
> This would make cma_release_dev() and _cma_attach_to_dev()
> symmetrical - what do you think?
>
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index 2dc302a83014ae..91f6d968b46f65 100644
> --- a/drivers/infiniband/core/cma.c
> +++ b/drivers/infiniband/core/cma.c
> @@ -474,6 +474,7 @@ static void cma_release_dev(struct rdma_id_private *id_priv)
>   	list_del(&id_priv->list);
>   	cma_dev_put(id_priv->cma_dev);
>   	id_priv->cma_dev = NULL;
> +	id_priv->id.device = NULL;
>   	if (id_priv->id.route.addr.dev_addr.sgid_attr) {
>   		rdma_put_gid_attr(id_priv->id.route.addr.dev_addr.sgid_attr);
>   		id_priv->id.route.addr.dev_addr.sgid_attr = NULL;

I try that. this will break restrack_del() since restrack_del() is using id_priv->id.device
and is being called before restrack_del():
_destroy_id <https://elixir.bootlin.com/linux/v5.11/C/ident/_destroy_id>() {
if (id_priv 
<https://elixir.bootlin.com/linux/v5.11/C/ident/id_priv>->cma_dev 
<https://elixir.bootlin.com/linux/v5.11/C/ident/cma_dev>) 
cma_release_dev 
<https://elixir.bootlin.com/linux/v5.11/C/ident/cma_release_dev>(id_priv 
<https://elixir.bootlin.com/linux/v5.11/C/ident/id_priv>); ... 
rdma_restrack_del 
<https://elixir.bootlin.com/linux/v5.11/C/ident/rdma_restrack_del>(&id_priv 
<https://elixir.bootlin.com/linux/v5.11/C/ident/id_priv>->res); }  


  reply index

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-18 13:55 [PATCH rdma-next 0/3] CMA fixes Leon Romanovsky
2021-04-18 13:55 ` [PATCH rdma-next 1/3] RDMA/cma: Skip device which doesn't support CM Leon Romanovsky
2021-04-18 13:55 ` [PATCH rdma-next 2/3] RDMA/core: Fix check of device in rdma_listen() Leon Romanovsky
2021-04-22 11:28   ` Jason Gunthorpe
2021-04-22 12:44     ` Shay Drory [this message]
2021-04-22 12:51       ` Jason Gunthorpe
2021-04-22 13:01         ` Leon Romanovsky
2021-04-22 13:02           ` Jason Gunthorpe
2021-04-22 14:58             ` Leon Romanovsky
2021-04-22 16:18               ` Jason Gunthorpe
2021-04-25 13:17                 ` Leon Romanovsky
2021-04-18 13:55 ` [PATCH rdma-next 3/3] RDMA/core: Add CM to restrack after successful attachment to a device Leon Romanovsky
2021-04-21 23:59 ` [PATCH rdma-next 0/3] CMA fixes Jason Gunthorpe
2021-04-22  6:46   ` Leon Romanovsky

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=1fca1133-8cdd-8b21-42cf-69d610b4f8f4@nvidia.com \
    --to=shayd@nvidia.com \
    --cc=dledford@redhat.com \
    --cc=jgg@nvidia.com \
    --cc=krkumar2@in.ibm.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sean.hefty@intel.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

Linux-RDMA Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rdma/0 linux-rdma/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rdma linux-rdma/ https://lore.kernel.org/linux-rdma \
		linux-rdma@vger.kernel.org
	public-inbox-index linux-rdma

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rdma


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git