Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: fix blktrace debugfs entries leakage

Commit 99d055b4fd4b ("block: remove per-disk debugfs files in
blk_unregister_queue") moves blk_trace_shutdown() from
blk_release_queue() to blk_unregister_queue(), this is safe if blktrace
is created through sysfs, however, there is a regression in corner
case.

blktrace can still be enabled after del_gendisk() through ioctl if
the disk is opened before del_gendisk(), and if blktrace is not shutdown
through ioctl before closing the disk, debugfs entries will be leaked.

Fix this problem by shutdown blktrace in disk_release(), this is safe
because blk_trace_remove() is reentrant.

Fixes: 99d055b4fd4b ("block: remove per-disk debugfs files in blk_unregister_queue")
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230610022003.2557284-4-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Yu Kuai and committed by
Jens Axboe
dd7de370 db59133e

+4 -1
+4 -1
block/genhd.c
··· 25 25 #include <linux/pm_runtime.h> 26 26 #include <linux/badblocks.h> 27 27 #include <linux/part_stat.h> 28 - #include "blk-throttle.h" 28 + #include <linux/blktrace_api.h> 29 29 30 + #include "blk-throttle.h" 30 31 #include "blk.h" 31 32 #include "blk-mq-sched.h" 32 33 #include "blk-rq-qos.h" ··· 1147 1146 1148 1147 might_sleep(); 1149 1148 WARN_ON_ONCE(disk_live(disk)); 1149 + 1150 + blk_trace_remove(disk->queue); 1150 1151 1151 1152 /* 1152 1153 * To undo the all initialization from blk_mq_init_allocated_queue in