• M
    blk-mq: always free hctx after request queue is freed · d1642ed3
    Ming Lei 提交于
    mainline inclusion
    from mainline-5.2-rc1
    commit 2f8f1336
    category: bugfix
    bugzilla: 14836
    CVE: NA
    ---------------------------
    
    In normal queue cleanup path, hctx is released after request queue
    is freed, see blk_mq_release().
    
    However, in __blk_mq_update_nr_hw_queues(), hctx may be freed because
    of hw queues shrinking. This way is easy to cause use-after-free,
    because: one implicit rule is that it is safe to call almost all block
    layer APIs if the request queue is alive; and one hctx may be retrieved
    by one API, then the hctx can be freed by blk_mq_update_nr_hw_queues();
    finally use-after-free is triggered.
    
    Fixes this issue by always freeing hctx after releasing request queue.
    If some hctxs are removed in blk_mq_update_nr_hw_queues(), introduce
    a per-queue list to hold them, then try to resuse these hctxs if numa
    node is matched.
    
    Cc: Dongli Zhang <dongli.zhang@oracle.com>
    Cc: James Smart <james.smart@broadcom.com>
    Cc: Bart Van Assche <bart.vanassche@wdc.com>
    Cc: linux-scsi@vger.kernel.org,
    Cc: Martin K . Petersen <martin.petersen@oracle.com>,
    Cc: Christoph Hellwig <hch@lst.de>,
    Cc: James E . J . Bottomley <jejb@linux.vnet.ibm.com>,
    Reviewed-by: NHannes Reinecke <hare@suse.com>
    Tested-by: NJames Smart <james.smart@broadcom.com>
    Signed-off-by: NMing Lei <ming.lei@redhat.com>
    Signed-off-by: NJens Axboe <axboe@kernel.dk>
    
    Conflict:
    	block/blk-mq.c
    	include/linux/blk-mq.h
    	include/linux/blkdev.h
    Signed-off-by: Nyangerkun <yangerkun@huawei.com>
    Reviewed-by: Nzhangyi (F) <yi.zhang@huawei.com>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    d1642ed3
blk-mq.h 10.0 KB