Skip to content

Commit

Permalink
ataflop: potential out of bounds in do_format()
Browse files Browse the repository at this point in the history
[ Upstream commit 1ffec38 ]

The function uses "type" as an array index:

	q = unit[drive].disk[type]->queue;

Unfortunately the bounds check on "type" isn't done until later in the
function.  Fix this by moving the bounds check to the start.

Fixes: bf9c053 ("ataflop: use a separate gendisk for each media format")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
Dan Carpenter authored and gregkh committed May 14, 2021
1 parent 163dd7f commit 2a3a8bb
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions drivers/block/ataflop.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,12 @@ static int do_format(int drive, int type, struct atari_format_descr *desc)
unsigned long flags;
int ret;

if (type)
if (type) {
type--;
if (type >= NUM_DISK_MINORS ||
minor2disktype[type].drive_types > DriveType)
return -EINVAL;
}

q = unit[drive].disk[type]->queue;
blk_mq_freeze_queue(q);
Expand All @@ -742,11 +746,6 @@ static int do_format(int drive, int type, struct atari_format_descr *desc)
local_irq_restore(flags);

if (type) {
if (type >= NUM_DISK_MINORS ||
minor2disktype[type].drive_types > DriveType) {
ret = -EINVAL;
goto out;
}
type = minor2disktype[type].index;
UDT = &atari_disk_type[type];
}
Expand Down

0 comments on commit 2a3a8bb

Please sign in to comment.