Skip to content

Commit

Permalink
block: fix use-after-free in disk_part_iter_next
Browse files Browse the repository at this point in the history
commit aebf5db upstream.

Make sure that bdgrab() is done on the 'block_device' instance before
referring to it for avoiding use-after-free.

Cc: <stable@vger.kernel.org>
Reported-by: syzbot+825f0f9657d4e528046e@syzkaller.appspotmail.com
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Ming Lei authored and gregkh committed Jan 17, 2021
1 parent 61e8c02 commit 481097d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions block/genhd.c
Expand Up @@ -256,14 +256,17 @@ struct hd_struct *disk_part_iter_next(struct disk_part_iter *piter)
part = rcu_dereference(ptbl->part[piter->idx]);
if (!part)
continue;
get_device(part_to_dev(part));
piter->part = part;
if (!part_nr_sects_read(part) &&
!(piter->flags & DISK_PITER_INCL_EMPTY) &&
!(piter->flags & DISK_PITER_INCL_EMPTY_PART0 &&
piter->idx == 0))
piter->idx == 0)) {
put_device(part_to_dev(part));
piter->part = NULL;
continue;
}

get_device(part_to_dev(part));
piter->part = part;
piter->idx += inc;
break;
}
Expand Down

0 comments on commit 481097d

Please sign in to comment.