Skip to content

Commit 5fd7a84

Browse files
Ming Leiaxboe
Ming Lei
authored andcommitted
blk-mq: protect q->elevator by ->sysfs_lock in blk_mq_elv_switch_none
elevator can be tore down by sysfs switch interface or disk release, so hold ->sysfs_lock before referring to q->elevator, then potential use-after-free can be avoided. Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 14dc7a1 commit 5fd7a84

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

block/blk-mq.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4440,12 +4440,14 @@ static bool blk_mq_elv_switch_none(struct list_head *head,
44404440
if (!qe)
44414441
return false;
44424442

4443+
/* q->elevator needs protection from ->sysfs_lock */
4444+
mutex_lock(&q->sysfs_lock);
4445+
44434446
INIT_LIST_HEAD(&qe->node);
44444447
qe->q = q;
44454448
qe->type = q->elevator->type;
44464449
list_add(&qe->node, head);
44474450

4448-
mutex_lock(&q->sysfs_lock);
44494451
/*
44504452
* After elevator_switch_mq, the previous elevator_queue will be
44514453
* released by elevator_release. The reference of the io scheduler

0 commit comments

Comments
 (0)