]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/commit - block/blk-mq.c
blk-mq: fix race between updating nr_hw_queues and switching io sched
authorMing Lei <ming.lei@redhat.com>
Sat, 6 Jan 2018 08:27:40 +0000 (16:27 +0800)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 12 Apr 2018 13:04:27 +0000 (10:04 -0300)
commita7e54b6a090ae8a5c203e55cc5aa3f9a91de3bff
tree0ccdc7480ad4c8e96f1338b60fc6f2c3fe1a0a71
parent6a684e3d665957958fd73bcfc927799d8166b39e
blk-mq: fix race between updating nr_hw_queues and switching io sched

BugLink: http://bugs.launchpad.net/bugs/1763366
[ Upstream commit fb350e0ad99359768e1e80b4784692031ec340e4 ]

In both elevator_switch_mq() and blk_mq_update_nr_hw_queues(), sched tags
can be allocated, and q->nr_hw_queue is used, and race is inevitable, for
example: blk_mq_init_sched() may trigger use-after-free on hctx, which is
freed in blk_mq_realloc_hw_ctxs() when nr_hw_queues is decreased.

This patch fixes the race be holding q->sysfs_lock.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Tested-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
block/blk-mq.c