Skip to content

Commit 84da87f

Browse files
Tetsuo Handagregkh
authored andcommitted
block: check minor range in device_add_disk()
[ Upstream commit e338924 ] 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>
1 parent 02eda18 commit 84da87f

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎block/genhd.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,8 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
425425
DISK_MAX_PARTS);
426426
disk->minors = DISK_MAX_PARTS;
427427
}
428+
if (disk->first_minor + disk->minors > MINORMASK + 1)
429+
return -EINVAL;
428430
} else {
429431
if (WARN_ON(disk->minors))
430432
return -EINVAL;

0 commit comments

Comments
 (0)