block: fix use-after-free bug in blk throttle code
authorJens Axboe <jaxboe@fusionio.com>
Sat, 23 Oct 2010 18:40:26 +0000 (20:40 +0200)
committerJens Axboe <jaxboe@fusionio.com>
Sat, 23 Oct 2010 18:40:26 +0000 (20:40 +0200)
blk_throtl_exit() frees the throttle data hanging off the queue
in blk_cleanup_queue(), but blk_put_queue() will indirectly
dereference this data when calling blk_sync_queue() which in
turns calls throtl_shutdown_timer_wq().

Fix this by moving the freeing of the throttle data to when
the queue is truly being released, and post the call to
blk_sync_queue().

Reported-by: Ingo Molnar <mingo@elte.hu>
Tested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
block/blk-core.c
block/blk-sysfs.c

index 45141469e89eba5f24c9594afdfa5218e5688f46..51efd835d4cffa3d1fc1dc80b4aad87b41820498 100644 (file)
@@ -462,8 +462,6 @@ void blk_cleanup_queue(struct request_queue *q)
        if (q->elevator)
                elevator_exit(q->elevator);
 
-       blk_throtl_exit(q);
-
        blk_put_queue(q);
 }
 EXPORT_SYMBOL(blk_cleanup_queue);
index da8a8a40cd4c3596762590da48a6c823f62f9fb4..013457f47fdc8b12eded858c852f588884b962c5 100644 (file)
@@ -471,6 +471,8 @@ static void blk_release_queue(struct kobject *kobj)
 
        blk_sync_queue(q);
 
+       blk_throtl_exit(q);
+
        if (rl->rq_pool)
                mempool_destroy(rl->rq_pool);