aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTetsuo Handa <[email protected]>2021-12-17 23:51:25 +0900
committerJens Axboe <[email protected]>2021-12-21 09:34:29 -0700
commite338924bd05d6e71574bc13e310c89e10e49a8a5 (patch)
tree47ef4b851875b480e5de9324d79c78427d4e5274
parent37ae5a0f5287a52cf51242e76ccf198d02ffe495 (diff)
block: check minor range in device_add_disk()
ioctl(fd, LOOP_CTL_ADD, 1048576) causes sysfs: cannot create duplicate filename '/dev/block/7:0' message because such request is treated as if ioctl(fd, LOOP_CTL_ADD, 0) due to MINORMASK == 1048575. Verify that all minor numbers for that device fit in the minor range. Reported-by: wangyangbo <[email protected]> Signed-off-by: Tetsuo Handa <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
-rw-r--r--block/genhd.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 603db5d6f10c..626c8406f21a 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -431,6 +431,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
DISK_MAX_PARTS);
disk->minors = DISK_MAX_PARTS;
}
+ if (disk->first_minor + disk->minors > MINORMASK + 1)
+ return -EINVAL;
} else {
if (WARN_ON(disk->minors))
return -EINVAL;