Skip to contentSkip to conversation

blk-cgroup: fix disk reference leak in blkcg_maybe_throttle_current()

PATCH Applied Jackie Liu 4 participants 4 messages Mar 31

Subsystems (3)
lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/1 blk-cgroup: fix disk reference leak in blkcg_maybe_throttle_current()

From: Jackie Liu <[email protected]>

Add the missing put_disk() on the error path in blkcg_maybe_throttle_current(). When blkcg lookup, blkg lookup, or blkg_tryget() fails, the function jumps to the out label which only calls rcu_read_unlock() but does not release the disk reference acquired by blkcg_schedule_throttle() via get_device(). Since current->throttle_disk is already set to NULL before the lookup, blkcg_exit() cannot release this reference either, causing the disk to never be freed.

Restore the reference release that was present as blk_put_queue() in the original code but was inadvertently dropped during the conversion from request_queue to gendisk.

Fixes f05837ed73d0 ("blk-cgroup: store a gendisk to throttle in struct task_struct")
---
 block/blk-cgroup.c | 1 +
 1 file changed, 1 insertion(+)
block/blk-cgroup.c +1 -0
index b70096497d38..c377241ee13c 100644
@@ -2022,6 +2022,7 @@ void blkcg_maybe_throttle_current(void)
 	return;
 out:
 	rcu_read_unlock();
+	put_disk(disk);
 }
 
 /**
Signature · 1 line
2.51.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jackie Liu

From: Jackie Liu <[email protected]>

Add the missing put_disk() on the error path in blkcg_maybe_throttle_current(). When blkcg lookup, blkg lookup, or blkg_tryget() fails, the function jumps to the out label which only calls rcu_read_unlock() but does not release the disk reference acquired by blkcg_schedule_throttle() via get_device(). Since current->throttle_disk is already set to NULL before the lookup, blkcg_exit() cannot release this reference either, causing the disk to never be freed.

Quoted 3 lines

Restore the reference release that was present as blk_put_queue() in the original code but was inadvertently dropped during the conversion from request_queue to gendisk.

Looks good:

maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Jackie Liu
Quoted 8 lines · Jackie Liu

Add the missing put_disk() on the error path in blkcg_maybe_throttle_current(). When blkcg lookup, blkg lookup, or blkg_tryget() fails, the function jumps to the out label which only calls rcu_read_unlock() but does not release the disk reference acquired by blkcg_schedule_throttle() via get_device(). Since current->throttle_disk is already set to NULL before the lookup, blkcg_exit() cannot release this reference either, causing the disk to never be freed.

Quoted 6 lines

Restore the reference release that was present as blk_put_queue() in the original code but was inadvertently dropped during the conversion from request_queue to gendisk.

Fixes f05837ed73d0 ("blk-cgroup: store a gendisk to throttle in struct task_struct")

Thanks.

Signature · 1 line
tejun
maintainer Applied
#3 lore raw
In reply to Jackie Liu
Quoted 9 lines · Jackie Liu

Add the missing put_disk() on the error path in blkcg_maybe_throttle_current(). When blkcg lookup, blkg lookup, or blkg_tryget() fails, the function jumps to the out label which only calls rcu_read_unlock() but does not release the disk reference acquired by blkcg_schedule_throttle() via get_device(). Since current->throttle_disk is already set to NULL before the lookup, blkcg_exit() cannot release this reference either, causing the disk to never be freed.

[...]

Applied, thanks!

[1/1] blk-cgroup: fix disk reference leak in blkcg_maybe_throttle_current()

      commit: 23308af722fefed00af5f238024c11710938fba3

Best regards,

Signature · 1 line
Jens Axboe