VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
author: Ming Lei <ming.lei@redhat.com> 2021-03-27 15:13:09 +0800 committer: Jens Axboe <axboe@kernel.dk> 2021-03-27 09:22:18 -0600 commit: e82fc7855749aa197740a60ef22c492c41ea5d5f parent: 7de55b7d6f09a2865279d3c41c0fbdbfdb87486a
Commit Summary:
block: don't create too many partitions
Diffstat:
1 file changed, 7 insertions, 0 deletions
diff --git a/block/partitions/core.c b/block/partitions/core.c
index 1a7558917c47..46f055bc7ecb 100644
--- a/block/partitions/core.c
+++ b/block/partitions/core.c
@@ -322,6 +322,13 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,
 	const char *dname;
 	int err;
 
+	/*
+	 * disk_max_parts() won't be zero, either GENHD_FL_EXT_DEVT is set
+	 * or 'minors' is passed to alloc_disk().
+	 */
+	if (partno >= disk_max_parts(disk))
+		return ERR_PTR(-EINVAL);
+
 	/*
 	 * Partitions are not supported on zoned block devices that are used as
 	 * such.