Skip to content

Commit

Permalink
bfq-iosched: ensure to clear bic/bfqq pointers when preparing request
Browse files Browse the repository at this point in the history
commit 72961c4 upstream.

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 <[email protected]>
Reported-by: Kees Cook <[email protected]>
Cc: [email protected]
Fixes: aee69d7 ("block, bfq: introduce the BFQ-v0 I/O scheduler as an extra scheduler")
Signed-off-by: Jens Axboe <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
axboe authored and gregkh committed May 1, 2018
1 parent b23b417 commit be10336
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion block/bfq-iosched.c
Original file line number Diff line number Diff line change
Expand Up @@ -4447,8 +4447,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;
return;
}

bic = icq_to_bic(rq->elv.icq);

spin_lock_irq(&bfqd->lock);
Expand Down

0 comments on commit be10336

Please sign in to comment.