summaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>2021-12-17 23:51:25 +0900
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-01-27 12:02:27 +0100
commit84da87f42daeb08e4dd72b6ca5d50043af02cb72 (patch)
tree73cc1db2cd3e2e960a5d03b122465ca5e2742f94 /block
parent02eda1806faafe2dd9a7ada1062381d9895446cc (diff)
block: check minor range in device_add_disk()
[ Upstream commit e338924bd05d6e71574bc13e310c89e10e49a8a5 ] 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 <wangyangbo@uniontech.com> Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Reviewed-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/b1b19379-23ee-5379-0eb5-94bf5f79f1b4@i-love.sakura.ne.jp Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'block')
-rw-r--r--block/genhd.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/block/genhd.c b/block/genhd.c
index 596e43764846..5308e0920fa6 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -425,6 +425,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;