From: Bart Van Assche <bvanassche@acm.org>
To: Hillf Danton <hdanton@sina.com>
Cc: Mike Christie <michael.christie@oracle.com>,
"lizhijian@fujitsu.com" <lizhijian@fujitsu.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>,
"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>,
"target-devel@vger.kernel.org" <target-devel@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: Re: use-after-free in srpt_enable_tpg()
Date: Sun, 3 Jul 2022 07:55:05 -0700 [thread overview]
Message-ID: <19f203e5-e965-23bd-401b-0ae8d9a73a5d@acm.org> (raw)
In-Reply-To: <20220703021119.1109-1-hdanton@sina.com>
On 7/2/22 19:11, Hillf Danton wrote:
> On Sat, 2 Jul 2022 15:26:33 -0700 Bart Van Assche wrote:
>> As long as a session is live the ch->qp pointer may be
>> dereferenced. The sdev->pd pointer is stored in the pd member of struct
>> ib_qp and hence may be dereferenced by any function that uses ch->qp.
>
> If it is still an issue after ib_dealloc_pd(sdev->pd) then it goes beyond the
> aperture of my proposal and needs another fix.
>
> Hillf
>
> +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
> @@ -3235,6 +3235,8 @@ static void srpt_remove_one(struct ib_de
>
> ib_set_client_data(device, &srpt_client, NULL);
>
> + /* make sdev survive ib_dealloc_pd(sdev->pd); */
> + atomic_inc(&sdev->port_refcount);
> /*
> * Unregistering a target must happen after destroying sdev->cm_id
> * such that no new SRP_LOGIN_REQ information units can arrive while
> @@ -3250,6 +3252,9 @@ static void srpt_remove_one(struct ib_de
> srpt_free_srq(sdev);
>
> ib_dealloc_pd(sdev->pd);
> +
> + if (0 == atomic_dec_return(&sdev->port_refcount))
> + kfree(sdev);
> }
>
> static struct ib_client srpt_client = {
Do you perhaps want to combine the above patch with the previous patch?
I don't think that any reference counting scheme can fix all
use-after-free issues related to srpt_remove_one(). Immediately after
srpt_remove_one() returns the caller of this function calls
ib_device_put() and ib_client_put(). These functions free data
structures that can be reached from the pointers that are stored in
struct ib_qp. Holding a reference on struct ib_device as long as any
session is live would allow to remove the while-loop from
srpt_release_sport(). However, I'm not sure that would make a
significant difference since there is a similar while-loop in one of the
callers of srpt_remove_one() (disable_device() in the RDMA core).
Bart.
next prev parent reply other threads:[~2022-07-03 14:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-27 7:09 lizhijian
2022-06-27 16:37 ` Bart Van Assche
2022-06-30 16:40 ` Mike Christie
2022-06-30 18:42 ` Bart Van Assche
[not found] ` <20220701015934.1105-1-hdanton@sina.com>
2022-07-02 22:26 ` Bart Van Assche
[not found] ` <20220703021119.1109-1-hdanton@sina.com>
2022-07-03 14:55 ` Bart Van Assche [this message]
[not found] ` <20220704001157.1644-1-hdanton@sina.com>
2022-07-05 4:34 ` Bart Van Assche
2022-07-05 12:39 ` Jason Gunthorpe
2022-07-27 3:24 ` lizhijian
[not found] ` <20220705114050.1979-1-hdanton@sina.com>
2022-07-05 16:10 ` Bart Van Assche
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=19f203e5-e965-23bd-401b-0ae8d9a73a5d@acm.org \
--to=bvanassche@acm.org \
--cc=hdanton@sina.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=lizhijian@fujitsu.com \
--cc=michael.christie@oracle.com \
--cc=target-devel@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
all inboxes | Powered by JetHome®