Skip to contentSkip to conversation

block: null_blk: fix use after free

PATCH In review Ming Lei 2 participants 2 messages May 1, 2014 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 block: null_blk: fix use after free

entry(cmd->ll_list) may belong to new request once end_cmd() returns, so fix the bug with the patch.

Without the change, it is easy to observe oops when doing null_blk(timer) test.

---
 drivers/block/null_blk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/null_blk.c +1 -1
index 8e7e3a0..e932398 100644
@@ -203,8 +203,8 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
 		entry = llist_reverse_order(entry);
 		do {
 			cmd = container_of(entry, struct nullb_cmd, ll_list);
-			end_cmd(cmd);
 			entry = entry->next;
+			end_cmd(cmd);
 		} while (entry);
 	}
 
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 16 lines · Ming Lei

entry(cmd->ll_list) may belong to new request once end_cmd() returns, so fix the bug with the patch.

Without the change, it is easy to observe oops when doing null_blk(timer) test.

---
 drivers/block/null_blk.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/null_blk.c +0 -0
index 8e7e3a0..e932398 100644

drivers/block/null_blk.c static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer) · line 209

Quoted 8 lines
drivers/block/null_blk.c +1 -1
@@ -203,8 +203,8 @@ static enum hrtimer_restart null_cmd_timer_expired(struct hrtimer *timer)
 		entry = llist_reverse_order(entry);
 		do {
 			cmd = container_of(entry, struct nullb_cmd, ll_list);
-			end_cmd(cmd);
 			entry = entry->next;
+			end_cmd(cmd);
 		} while (entry);
 	}

Good catch, applied.

Signature · 1 line
Jens Axboe