* [PATCH 1/2] ataflop: potential out of bounds in do_format()
@ 2021-04-21 10:18 Dan Carpenter
2021-04-21 10:19 ` [PATCH 2/2] ataflop: fix off by one in ataflop_probe() Dan Carpenter
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Dan Carpenter @ 2021-04-21 10:18 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig; +Cc: linux-block, linux-kernel, kernel-janitors
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: bf9c0538e485 ("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>
---
drivers/block/ataflop.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 104b713f4055..aed2c2a4f4ea 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -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);
@@ -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];
}
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] ataflop: fix off by one in ataflop_probe()
2021-04-21 10:18 [PATCH 1/2] ataflop: potential out of bounds in do_format() Dan Carpenter
@ 2021-04-21 10:19 ` Dan Carpenter
2021-04-21 14:23 ` Christoph Hellwig
2021-04-21 14:22 ` [PATCH 1/2] ataflop: potential out of bounds in do_format() Christoph Hellwig
2021-04-21 15:15 ` Jens Axboe
2 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2021-04-21 10:19 UTC (permalink / raw)
To: Jens Axboe, Christoph Hellwig; +Cc: linux-block, linux-kernel, kernel-janitors
Smatch complains that the "type > NUM_DISK_MINORS" should be >=
instead of >. We also need to subtract one from "type" at the start.
Fixes: bf9c0538e485 ("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>
---
drivers/block/ataflop.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index aed2c2a4f4ea..d601e49f80e0 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -2001,7 +2001,10 @@ static void ataflop_probe(dev_t dev)
int drive = MINOR(dev) & 3;
int type = MINOR(dev) >> 2;
- if (drive >= FD_MAX_UNITS || type > NUM_DISK_MINORS)
+ if (type)
+ type--;
+
+ if (drive >= FD_MAX_UNITS || type >= NUM_DISK_MINORS)
return;
mutex_lock(&ataflop_probe_lock);
if (!unit[drive].disk[type]) {
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] ataflop: fix off by one in ataflop_probe()
2021-04-21 10:19 ` [PATCH 2/2] ataflop: fix off by one in ataflop_probe() Dan Carpenter
@ 2021-04-21 14:23 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-04-21 14:23 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jens Axboe, Christoph Hellwig, linux-block, linux-kernel,
kernel-janitors
On Wed, Apr 21, 2021 at 01:19:45PM +0300, Dan Carpenter wrote:
> Smatch complains that the "type > NUM_DISK_MINORS" should be >=
> instead of >. We also need to subtract one from "type" at the start.
>
> Fixes: bf9c0538e485 ("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>
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] ataflop: potential out of bounds in do_format()
2021-04-21 10:18 [PATCH 1/2] ataflop: potential out of bounds in do_format() Dan Carpenter
2021-04-21 10:19 ` [PATCH 2/2] ataflop: fix off by one in ataflop_probe() Dan Carpenter
@ 2021-04-21 14:22 ` Christoph Hellwig
2021-04-21 15:15 ` Jens Axboe
2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2021-04-21 14:22 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jens Axboe, Christoph Hellwig, linux-block, linux-kernel,
kernel-janitors
Looks good,
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] ataflop: potential out of bounds in do_format()
2021-04-21 10:18 [PATCH 1/2] ataflop: potential out of bounds in do_format() Dan Carpenter
2021-04-21 10:19 ` [PATCH 2/2] ataflop: fix off by one in ataflop_probe() Dan Carpenter
2021-04-21 14:22 ` [PATCH 1/2] ataflop: potential out of bounds in do_format() Christoph Hellwig
@ 2021-04-21 15:15 ` Jens Axboe
2 siblings, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2021-04-21 15:15 UTC (permalink / raw)
To: Dan Carpenter, Christoph Hellwig
Cc: linux-block, linux-kernel, kernel-janitors
On 4/21/21 4:18 AM, Dan Carpenter wrote:
> 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.
Applied this and 2/2, thanks Dan.
--
Jens Axboe
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-04-21 15:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-21 10:18 [PATCH 1/2] ataflop: potential out of bounds in do_format() Dan Carpenter
2021-04-21 10:19 ` [PATCH 2/2] ataflop: fix off by one in ataflop_probe() Dan Carpenter
2021-04-21 14:23 ` Christoph Hellwig
2021-04-21 14:22 ` [PATCH 1/2] ataflop: potential out of bounds in do_format() Christoph Hellwig
2021-04-21 15:15 ` Jens Axboe
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.