block: reject attempts to allocate more than DISK_MAX_PARTS partitions
authorChristoph Hellwig <hch@lst.de>
Wed, 23 Aug 2017 17:10:29 +0000 (19:10 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 23 Aug 2017 18:49:50 +0000 (12:49 -0600)
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/genhd.c

index 2367087cdb7c47726338345c8539069da3bc0e82..3380a1e73ea0a69cd39d104bd714b8689c575b93 100644 (file)
@@ -1357,6 +1357,13 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
        struct gendisk *disk;
        struct disk_part_tbl *ptbl;
 
+       if (minors > DISK_MAX_PARTS) {
+               printk(KERN_ERR
+                       "block: can't allocated more than %d partitions\n",
+                       DISK_MAX_PARTS);
+               minors = DISK_MAX_PARTS;
+       }
+
        disk = kzalloc_node(sizeof(struct gendisk), GFP_KERNEL, node_id);
        if (disk) {
                if (!init_part_stats(&disk->part0)) {