Skip to content

Commit

Permalink
null_blk: fix use-after-free error
Browse files Browse the repository at this point in the history
blk_end_request_all may free request, so we need to save
request_queue pointer before blk_end_request_all call.

The problem was introduced in commit cf8ecc5
("null_blk: guarantee device restart in all irq modes")
and causes general protection fault with slab poisoning
enabled.

Fixes: cf8ecc5 ("null_blk: guarantee device
       restart in all irq modes")

Signed-off-by: Mike Krinkin <krinkin.m.u@gmail.com>
Reviewed-by: Ming Lei <tom.leiming@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Mike Krinkin authored and Jens Axboe committed Dec 22, 2015
1 parent 23688bf commit e827120
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/block/null_blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ static void end_cmd(struct nullb_cmd *cmd)
{
struct request_queue *q = NULL;

if (cmd->rq)
q = cmd->rq->q;

switch (queue_mode) {
case NULL_Q_MQ:
blk_mq_end_request(cmd->rq, 0);
Expand All @@ -232,9 +235,6 @@ static void end_cmd(struct nullb_cmd *cmd)
goto free_cmd;
}

if (cmd->rq)
q = cmd->rq->q;

/* Restart queue if needed, as we are freeing a tag */
if (q && !q->mq_ops && blk_queue_stopped(q)) {
unsigned long flags;
Expand Down

0 comments on commit e827120

Please sign in to comment.