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

Configure Feed

Select the types of activity you want to include in your feed.

blk-throttle: fix throtl_data leak during disk release

Tightening the throttle activation check in blk_throtl_activated() to
require both q->td presence and policy bit set introduced a memory leak
during disk release:

blkg_destroy_all() clears the policy bit first during queue deactivation,
causing subsequent blk_throtl_exit() to skip throtl_data cleanup when
blk_throtl_activated() fails policy check.

Idealy we should avoid modifying blk_throtl_exit() activation check because
it's intuitive that blk-throtl start from blk_throtl_init() and end in
blk_throtl_exit(). However, call blk_throtl_exit() before
blkg_destroy_all() will make a long term deadlock problem easier to
trigger[1], hence fix this problem by checking if q->td is NULL from
blk_throtl_exit(), and remove policy deactivation as well since it's
useless.

[1] https://lore.kernel.org/all/CAHj4cs9p9H5yx+ywsb3CMUdbqGPhM+8tuBvhW=9ADiCjAqza9w@mail.gmail.com/#t

Fixes: bd9fd5be6bc0 ("blk-throttle: fix access race during throttle policy activation")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Closes: https://lore.kernel.org/all/CAHj4cs-p-ZwBEKigBj7T6hQCOo-H68-kVwCrV6ZvRovrr9Z+HA@mail.gmail.com/
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Yu Kuai and committed by
Jens Axboe
336aec7b 0b507305

+5 -2
+5 -2
block/blk-throttle.c
··· 1842 1842 { 1843 1843 struct request_queue *q = disk->queue; 1844 1844 1845 - if (!blk_throtl_activated(q)) 1845 + /* 1846 + * blkg_destroy_all() already deactivate throtl policy, just check and 1847 + * free throtl data. 1848 + */ 1849 + if (!q->td) 1846 1850 return; 1847 1851 1848 1852 timer_delete_sync(&q->td->service_queue.pending_timer); 1849 1853 throtl_shutdown_wq(q); 1850 - blkcg_deactivate_policy(disk, &blkcg_policy_throtl); 1851 1854 kfree(q->td); 1852 1855 } 1853 1856