Skip to content

Commit 481097d

Browse files
Ming Leigregkh
Ming Lei
authored andcommitted
block: fix use-after-free in disk_part_iter_next
commit aebf5db upstream. Make sure that bdgrab() is done on the 'block_device' instance before referring to it for avoiding use-after-free. Cc: <[email protected]> Reported-by: [email protected] Signed-off-by: Ming Lei <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 61e8c02 commit 481097d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

block/genhd.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,17 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
256256
part = rcu_dereference(ptbl->part[piter->idx]);
257257
if (!part)
258258
continue;
259+
get_device(part_to_dev(part));
260+
piter->part = part;
259261
if (!part_nr_sects_read(part) &&
260262
!(piter->flags & DISK_PITER_INCL_EMPTY) &&
261263
!(piter->flags & DISK_PITER_INCL_EMPTY_PART0 &&
262-
piter->idx == 0))
264+
piter->idx == 0)) {
265+
put_device(part_to_dev(part));
266+
piter->part = NULL;
263267
continue;
268+
}
264269

265-
get_device(part_to_dev(part));
266-
piter->part = part;
267270
piter->idx += inc;
268271
break;
269272
}

0 commit comments

Comments
 (0)