Skip to contentSkip to conversation

null_blk: fix use-after-free problem

PATCH Applied Mike Krinkin 2 participants 2 messages Jul 19, 2015 – Jul 22, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

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

end_cmd finishes request associated with nullb_cmd struct, so we should save pointer to request_queue in a local variable before calling end_cmd.

The problem was causes general protection fault with slab poisoning enabled.

Fixes 8b70f45e2eb2 ("null_blk: restart request processing on

completion handler")

---
 drivers/block/null_blk.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/block/null_blk.c +9 -9
index 69de41a..3177b24 100644
@@ -240,19 +240,19 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
 	while ((entry = llist_del_all(&cq->list)) != NULL) {
 		entry = llist_reverse_order(entry);
 		do {
+			struct request_queue *q = NULL;
+
 			cmd = container_of(entry, struct nullb_cmd, ll_list);
 			entry = entry->next;
+			if (cmd->rq)
+				q = cmd->rq->q;
 			end_cmd(cmd);
 
-			if (cmd->rq) {
-				struct request_queue *q = cmd->rq->q;
-
-				if (!q->mq_ops && blk_queue_stopped(q)) {
-					spin_lock(q->queue_lock);
-					if (blk_queue_stopped(q))
-						blk_start_queue(q);
-					spin_unlock(q->queue_lock);
-				}
+			if (q && !q->mq_ops && blk_queue_stopped(q)) {
+				spin_lock(q->queue_lock);
+				if (blk_queue_stopped(q))
+					blk_start_queue(q);
+				spin_unlock(q->queue_lock);
 			}
 		} while (entry);
 	}
Signature · 1 line
1.9.1
Applied
#1 lore raw
Quoted 6 lines · Mike Krinkin

end_cmd finishes request associated with nullb_cmd struct, so we should save pointer to request_queue in a local variable before calling end_cmd.

The problem was causes general protection fault with slab poisoning enabled.

Thanks, applied.

Signature · 1 line
Jens Axboe