From: Yufen Yu <yuyufen@huawei.com>
To: Tejun Heo <tj@kernel.org>
Cc: <axboe@kernel.dk>, <linux-block@vger.kernel.org>, <jack@suse.cz>,
<bvanassche@acm.org>
Subject: Re: [PATCH] bdi: fix use-after-free for bdi device
Date: Fri, 14 Feb 2020 10:50:01 +0800 [thread overview]
Message-ID: <f369a99d-e794-0c1b-85cf-83b577fb0f46@huawei.com> (raw)
In-Reply-To: <20200213135809.GH88887@mtj.thefacebook.com>
On 2020/2/13 21:58, Tejun Heo wrote:
> Hello,
>
> On Thu, Feb 13, 2020 at 03:51:40PM +0800, Yufen Yu wrote:
>> If we destroy the device asynchronously by call_rcu(), we may need to
>> add a new member 'rcu_head' into struct backing_dev_info. Right?
>
> Yes.
>
>> The code may be like:
>>
>> bdi_unregister()
>> {
>> ...
>> if (bdi->dev) {
>> ...
>> device_get(bdi->dev);
>> device_unregister(bdi->dev);
>> bdi->dev = NULL; //XXX
>> bdi_get(bdi); //avoiding bdi to be freed before calling bdi_release_device
>> call_rcu(&bdi->rcu_head, bdi_release_device);
>> }
>> ...
>> }
>>
>> bdi_release_device()
>> {
>> ...
>> put_device(bdi->dev);//XXX
>> bdi_put(bdi);
>> }
>>
>> But, the problem is how do we get 'bdi->dev' in bdi_release_device().
>> If we do not set bdi->dev as 'NULL', re-registration bdi may cannot work well.
>
> So, unregistering can leave ->dev along and re-registering can test
> whether it's NULL and if not put the existing one and put a new one
> there. Wouldn't that work?
Do you mean set bdi->dev as 'NULL' in call_rcu() callback function
(i.e. bdi_release_device()) and test 'bdi->dev' in bdi_register_va()?
I think that may do not work.
We cannot make sure the order of rcu callback function and re-registering.
Then bdi_release_device() may put the new allocated device by re-registering.
Thanks,
Yufen
next prev parent reply other threads:[~2020-02-14 2:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-11 14:00 [PATCH] bdi: fix use-after-free for bdi device Yufen Yu
2020-02-11 13:57 ` Yufen Yu
2020-02-12 21:33 ` Tejun Heo
2020-02-13 2:46 ` Yufen Yu
2020-02-13 3:48 ` Tejun Heo
2020-02-13 7:51 ` Yufen Yu
2020-02-13 13:58 ` Tejun Heo
2020-02-14 2:50 ` Yufen Yu [this message]
2020-02-14 14:05 ` Tejun Heo
2020-02-15 13:54 ` Yufen Yu
2020-02-19 12:55 ` Jan Kara
2020-02-19 15:12 ` Tejun Heo
2020-02-20 11:07 ` Yufen Yu
2020-02-20 12:07 ` Jan Kara
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=f369a99d-e794-0c1b-85cf-83b577fb0f46@huawei.com \
--to=yuyufen@huawei.com \
--cc=axboe@kernel.dk \
--cc=bvanassche@acm.org \
--cc=jack@suse.cz \
--cc=linux-block@vger.kernel.org \
--cc=tj@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.