Skip to contentSkip to conversation

null_blk: fix use-after-free error

PATCH In review Mike Krinkin 3 participants 3 messages Dec 15, 2015 – Dec 22, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 null_blk: fix use-after-free error

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 cf8ecc5a8455266f8d51 ("null_blk: guarantee device restart in all irq modes") and causes general protection fault with slab poisoning enabled.

Fixes cf8ecc5a8455266f8d51 ("null_blk: guarantee device

restart in all irq modes")

---
 drivers/block/null_blk.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/null_blk.c +3 -3
index 36c4651..6a06e3e 100644
@@ -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);
@@ -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;
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Mike Krinkin

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 cf8ecc5a8455266f8d51 ("null_blk: guarantee device restart in all irq modes") and causes general protection fault with slab poisoning enabled.

Quoted 4 lines
Fixes cf8ecc5a8455266f8d51 ("null_blk: guarantee device

restart in all irq modes")

Quoted 36 lines
---
 drivers/block/null_blk.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/block/null_blk.c +3 -4
index 36c4651..6a06e3e 100644
@@ -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);
@@ -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;
--

1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Signature · 1 line
Ming Lei
#2 lore raw
In reply to Mike Krinkin
Quoted 10 lines · Mike Krinkin

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 cf8ecc5a8455266f8d51 ("null_blk: guarantee device restart in all irq modes") and causes general protection fault with slab poisoning enabled.

Fixes cf8ecc5a8455266f8d51 ("null_blk: guarantee device

restart in all irq modes")

Added for 4.4, thanks.

Signature · 1 line
Jens Axboe