From: Jason Gunthorpe <jgg@nvidia.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Doug Ledford <dledford@redhat.com>,
Avihai Horon <avihaih@nvidia.com>,
Amit Matityahu <mitm@nvidia.com>, <linux-rdma@vger.kernel.org>
Subject: Re: [PATCH rdma-next v1] RDMA/ucma: Fix use-after-free bug in ucma_create_uevent
Date: Wed, 3 Feb 2021 16:01:16 -0400 [thread overview]
Message-ID: <20210203200116.GA740542@nvidia.com> (raw)
In-Reply-To: <20210125121556.838290-1-leon@kernel.org>
On Mon, Jan 25, 2021 at 02:15:56PM +0200, Leon Romanovsky wrote:
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index e17ba841e204..7ce4d9dea826 100644
> +++ b/drivers/infiniband/core/cma.c
> @@ -352,7 +352,13 @@ struct ib_device *cma_get_ib_dev(struct cma_device *cma_dev)
>
> struct cma_multicast {
> struct rdma_id_private *id_priv;
> - struct ib_sa_multicast *sa_mc;
> + union {
> + struct ib_sa_multicast *sa_mc;
> + struct {
> + struct work_struct work;
> + struct rdma_cm_event event;
> + } iboe_join;
> + };
> struct list_head list;
> void *context;
> struct sockaddr_storage addr;
> @@ -1839,6 +1845,12 @@ static void destroy_mc(struct rdma_id_private *id_priv,
> cma_igmp_send(ndev, &mgid, false);
> dev_put(ndev);
> }
> +
> + if (cancel_work_sync(&mc->iboe_join.work))
> + /* Compensate for cma_iboe_join_work_handler that
> + * didn't run.
> + */
> + cma_id_put(mc->id_priv);
Just get rid of the cma_id_get in cma_iboe_join_multicast() and don't
have this if
> }
> kfree(mc);
> }
> @@ -2702,6 +2714,32 @@ static int cma_query_ib_route(struct rdma_id_private *id_priv,
> return (id_priv->query_id < 0) ? id_priv->query_id : 0;
> }
>
> +static void cma_iboe_join_work_handler(struct work_struct *work)
> +{
> + struct cma_multicast *mc =
> + container_of(work, struct cma_multicast, iboe_join.work);
> + struct rdma_cm_event *event = &mc->iboe_join.event;
> + struct rdma_id_private *id_priv = mc->id_priv;
> +
> + mutex_lock(&id_priv->handler_mutex);
> + if (READ_ONCE(id_priv->state) == RDMA_CM_DESTROYING ||
> + READ_ONCE(id_priv->state) == RDMA_CM_DEVICE_REMOVAL)
> + goto out_unlock;
> +
> + if (cma_cm_event_handler(id_priv, event)) {
> + cma_id_put(id_priv);
> + destroy_id_handler_unlock(id_priv);
This is a problem, destroy_id_handler_unlock eventually will call
destroy_mc() which will deadlock. The IB side has the same bug. Since
multicast isn't use in-kernel and ucma doesn't return anything but 0,
this is all dead code, lets delete it and just leave a WARN_ON(ret)
In the IB side too
> + goto out;
> + }
> +
> +out_unlock:
> + mutex_unlock(&id_priv->handler_mutex);
> + cma_id_put(id_priv);
and this put too
Jason
next prev parent reply other threads:[~2021-02-03 20:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-25 12:15 [PATCH rdma-next v1] RDMA/ucma: Fix use-after-free bug in ucma_create_uevent Leon Romanovsky
2021-02-03 20:01 ` Jason Gunthorpe [this message]
2021-02-04 16:08 ` Leon Romanovsky
2021-02-04 16:10 ` 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=20210203200116.GA740542@nvidia.com \
--to=jgg@nvidia.com \
--cc=avihaih@nvidia.com \
--cc=dledford@redhat.com \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mitm@nvidia.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
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.