Skip to content

Commit 321f95c

Browse files
Ming Leimehmetb0
Ming Lei
authored andcommitted
block: avoid to reuse hctx not removed from cpuhp callback list
BugLink: https://bugs.launchpad.net/bugs/2097332 [ Upstream commit 85672ca ] If the 'hctx' isn't removed from cpuhp callback list, we can't reuse it, otherwise use-after-free may be triggered. Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Tested-by: kernel test robot <[email protected]> Fixes: 22465bb ("blk-mq: move cpuhp callback registering out of q->sysfs_lock") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit b5792c162dcf6197bf3d2de2be6c8169435b73d0 linux-6.12.y) [koichiroden: pulled in follow-up fix from v6.12.7] Signed-off-by: Koichiro Den <[email protected]>
1 parent e946b4f commit 321f95c

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

block/blk-mq.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -4417,6 +4417,15 @@ struct gendisk *blk_mq_alloc_disk_for_queue(struct request_queue *q,
44174417
}
44184418
EXPORT_SYMBOL(blk_mq_alloc_disk_for_queue);
44194419

4420+
/*
4421+
* Only hctx removed from cpuhp list can be reused
4422+
*/
4423+
static bool blk_mq_hctx_is_reusable(struct blk_mq_hw_ctx *hctx)
4424+
{
4425+
return hlist_unhashed(&hctx->cpuhp_online) &&
4426+
hlist_unhashed(&hctx->cpuhp_dead);
4427+
}
4428+
44204429
static struct blk_mq_hw_ctx *blk_mq_alloc_and_init_hctx(
44214430
struct blk_mq_tag_set *set, struct request_queue *q,
44224431
int hctx_idx, int node)
@@ -4426,7 +4435,7 @@ static struct blk_mq_hw_ctx *blk_mq_alloc_and_init_hctx(
44264435
/* reuse dead hctx first */
44274436
spin_lock(&q->unused_hctx_lock);
44284437
list_for_each_entry(tmp, &q->unused_hctx_list, hctx_list) {
4429-
if (tmp->numa_node == node) {
4438+
if (tmp->numa_node == node && blk_mq_hctx_is_reusable(tmp)) {
44304439
hctx = tmp;
44314440
break;
44324441
}

0 commit comments

Comments
 (0)