From: Bart Van Assche <bvanassche@acm.org>
To: Ming Lei <ming.lei@redhat.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, Yufen Yu <yuyufen@huawei.com>,
Christoph Hellwig <hch@infradead.org>,
Hou Tao <houtao1@huawei.com>
Subject: Re: [PATCH 1/4] block: fix use-after-free on cached last_lookup partition
Date: Thu, 20 Feb 2020 20:03:52 -0800 [thread overview]
Message-ID: <5eb26a32-d2b2-e2c3-52e2-591cf626a1ff@acm.org> (raw)
In-Reply-To: <20200109062109.2313-2-ming.lei@redhat.com>
On 2020-01-08 22:21, Ming Lei wrote:
> delete_partition() clears the cached last_lookup partition. However
> the .last_lookup cache may be overwritten by one IO path after
> it is cleared from delete_partition(). Then another IO path may
> use the cached deleting partition after __delete_partition() is
> called, then use-after-free is triggered on the cached partition.
>
> Fixes the issue by the following approach:
>
> 1) always get the partition's refcount via hd_struct_try_get() before
> setting .last_lookup
>
> 2) move clearing .last_lookup from delete_partition() to
> __delete_partition() which is release handle of the partition's
> percpu-refcount, so that no IO path can overwrite .last_lookup after it
> is cleared in __delete_partition().
>
> It is one candidate approach of Yufen's patch[1] which adds overhead
> in fast path by indirect lookup which may introduce one extra cacheline
> in IO path. Also this patch relies on percpu-refcount's protection, and
> it is easier to understand and verify.
>
> [1] https://lore.kernel.org/linux-block/20200109013551.GB9655@ming.t460p/T/#t
Hi Ming,
disk_map_sector_rcu() is called from the I/O path only and hence with
q->q_usage_counter > 0. Has it been considered to freeze disk->queue
from delete_partition() before deleting a partition and unfreezing
disk->queue after partition deletion has finished? Would that approach
allow to eliminate partition reference counting and thereby improve the
performance of the hot path?
Thanks,
Bart.
next prev parent reply other threads:[~2020-02-21 4:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-09 6:21 [PATCH 0/4] block: fix partition use-after-free and optimization Ming Lei
2020-01-09 6:21 ` [PATCH 1/4] block: fix use-after-free on cached last_lookup partition Ming Lei
2020-02-21 3:05 ` Yufen Yu
2020-02-21 4:03 ` Bart Van Assche [this message]
2020-02-21 7:47 ` Ming Lei
2020-01-09 6:21 ` [PATCH 2/4] block: only define 'nr_sects_seq' in hd_part for 32bit SMP Ming Lei
2020-01-09 6:21 ` [PATCH 3/4] block: re-organize fields of 'struct hd_part' Ming Lei
2020-01-09 6:21 ` [PATCH 4/4] block: don't hold part0's refcount in IO path Ming Lei
2020-05-07 8:52 [PATCH 0/4] block: fix partition use-after-free and optimization Ming Lei
2020-05-07 8:52 ` [PATCH 1/4] block: fix use-after-free on cached last_lookup partition Ming Lei
2020-05-07 14:16 ` Christoph Hellwig
2020-05-08 1:54 ` Ming Lei
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=5eb26a32-d2b2-e2c3-52e2-591cf626a1ff@acm.org \
--to=bvanassche@acm.org \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=houtao1@huawei.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=yuyufen@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).