path: root/block/bfq-iosched.c
diff options
authorJens Axboe <>2018-04-17 17:08:52 -0600
committerJens Axboe <>2018-04-17 17:08:52 -0600
commit72961c4e6082be79825265d9193272b8a1634dec (patch)
treedb6b683240483097d30a95f1de6abaff2414dd55 /block/bfq-iosched.c
parentf4560231ec42092c6662acccabb28c6cac9f5dfb (diff)
bfq-iosched: ensure to clear bic/bfqq pointers when preparing request
Even if we don't have an IO context attached to a request, we still need to clear the priv[0..1] pointers, as they could be pointing to previously used bic/bfqq structures. If we don't do so, we'll either corrupt memory on dispatching a request, or cause an imbalance in counters. Inspired by a fix from Kees. Reported-by: Oleksandr Natalenko <> Reported-by: Kees Cook <> Cc: Fixes: aee69d78dec0 ("block, bfq: introduce the BFQ-v0 I/O scheduler as an extra scheduler") Signed-off-by: Jens Axboe <>
Diffstat (limited to 'block/bfq-iosched.c')
1 files changed, 9 insertions, 1 deletions
diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c
index f0ecd98509d8..771ae9730ac6 100644
--- a/block/bfq-iosched.c
+++ b/block/bfq-iosched.c
@@ -4934,8 +4934,16 @@ static void bfq_prepare_request(struct request *rq, struct bio *bio)
bool new_queue = false;
bool bfqq_already_existing = false, split = false;
- if (!rq->elv.icq)
+ /*
+ * Even if we don't have an icq attached, we should still clear
+ * the scheduler pointers, as they might point to previously
+ * allocated bic/bfqq structs.
+ */
+ if (!rq->elv.icq) {
+ rq->elv.priv[0] = rq->elv.priv[1] = NULL;
+ }
bic = icq_to_bic(rq->elv.icq);