• Y
    block: fix use-after-free on cached last_lookup partition · f8096783
    Yufen Yu 提交于
    hulk inclusion
    category: bugfix
    bugzilla: 27962
    CVE: NA
    ---------------------------
    
    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/#tReported-by: NYufen Yu <yuyufen@huawei.com>
    Cc: Christoph Hellwig <hch@infradead.org>
    Cc: Hou Tao <houtao1@huawei.com>
    Signed-off-by: NMing Lei <ming.lei@redhat.com>
    Conflict:
    	include/linux/genhd.h
    	block/blk-core.c
    Signed-off-by: NYufen Yu <yuyufen@huawei.com>
    Reviewed-by: NHou Tao <houtao1@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    f8096783
genhd.h 23.8 KB