summaryrefslogtreecommitdiffstats
path: root/block/genhd.c
diff options
context:
space:
mode:
authorMing Lei <ming.lei@redhat.com>2020-12-21 12:33:35 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2021-01-17 13:55:14 +0100
commita09652089d496a4ecb925e2cb95a6523f22ae538 (patch)
tree0ca909bfb5aeeadc09c61482146a41777ad7796f /block/genhd.c
parentd5453054e2da78cfaf1ec9d18e906702db852b2c (diff)
downloadlinux-stable-a09652089d496a4ecb925e2cb95a6523f22ae538.tar.gz
linux-stable-a09652089d496a4ecb925e2cb95a6523f22ae538.tar.bz2
linux-stable-a09652089d496a4ecb925e2cb95a6523f22ae538.zip
block: fix use-after-free in disk_part_iter_next
commit aebf5db917055b38f4945ed6d621d9f07a44ff30 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>
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 3032453a89e6..0b8c65e51adf 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -158,14 +158,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;
}