linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] block, zoned: fix integer overflow with BLKRESETZONE et al
@ 2020-02-12 17:40 Alexey Dobriyan
  2020-02-19 16:34 ` Christoph Hellwig
  2020-03-12 15:11 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2020-02-12 17:40 UTC (permalink / raw)
  To: axboe; +Cc: linux-block, hare

Check for overflow in addition before checking for end-of-block-device.

Steps to reproduce:

	#define _GNU_SOURCE 1
	#include <sys/ioctl.h>
	#include <sys/types.h>
	#include <sys/stat.h>
	#include <fcntl.h>

	typedef unsigned long long __u64;

	struct blk_zone_range {
	        __u64 sector;
	        __u64 nr_sectors;
	};

	#define BLKRESETZONE    _IOW(0x12, 131, struct blk_zone_range)

	int main(void)
	{
	        int fd = open("/dev/nullb0", O_RDWR|O_DIRECT);
	        struct blk_zone_range zr = {4096, 0xfffffffffffff000ULL};
	        ioctl(fd, BLKRESETZONE, &zr);
	        return 0;
	}

BUG: KASAN: null-ptr-deref in submit_bio_wait+0x74/0xe0
Write of size 8 at addr 0000000000000040 by task a.out/1590

CPU: 8 PID: 1590 Comm: a.out Not tainted 5.6.0-rc1-00019-g359c92c02bfa #2
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190711_202441-buildvm-armv7-10.arm.fedoraproject.org-2.fc31 04/01/2014
Call Trace:
 dump_stack+0x76/0xa0
 __kasan_report.cold+0x5/0x3e
 kasan_report+0xe/0x20
 submit_bio_wait+0x74/0xe0
 blkdev_zone_mgmt+0x26f/0x2a0
 blkdev_zone_mgmt_ioctl+0x14b/0x1b0
 blkdev_ioctl+0xb28/0xe60
 block_ioctl+0x69/0x80
 ksys_ioctl+0x3af/0xa50

Signed-off-by: Alexey Dobriyan (SK hynix) <adobriyan@gmail.com>
---

 block/blk-zoned.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -173,7 +173,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
 	if (!op_is_zone_mgmt(op))
 		return -EOPNOTSUPP;
 
-	if (!nr_sectors || end_sector > capacity)
+	if (end_sector <= sector || end_sector > capacity)
 		/* Out of range */
 		return -EINVAL;
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] block, zoned: fix integer overflow with BLKRESETZONE et al
  2020-02-12 17:40 [PATCH] block, zoned: fix integer overflow with BLKRESETZONE et al Alexey Dobriyan
@ 2020-02-19 16:34 ` Christoph Hellwig
  2020-03-12 15:11 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2020-02-19 16:34 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: axboe, linux-block, hare

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

Can you wire up your test for blktests?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] block, zoned: fix integer overflow with BLKRESETZONE et al
  2020-02-12 17:40 [PATCH] block, zoned: fix integer overflow with BLKRESETZONE et al Alexey Dobriyan
  2020-02-19 16:34 ` Christoph Hellwig
@ 2020-03-12 15:11 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2020-03-12 15:11 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-block, hare

On 2/12/20 10:40 AM, Alexey Dobriyan wrote:
> Check for overflow in addition before checking for end-of-block-device.
> 
> Steps to reproduce:
> 
> 	#define _GNU_SOURCE 1
> 	#include <sys/ioctl.h>
> 	#include <sys/types.h>
> 	#include <sys/stat.h>
> 	#include <fcntl.h>
> 
> 	typedef unsigned long long __u64;
> 
> 	struct blk_zone_range {
> 	        __u64 sector;
> 	        __u64 nr_sectors;
> 	};
> 
> 	#define BLKRESETZONE    _IOW(0x12, 131, struct blk_zone_range)
> 
> 	int main(void)
> 	{
> 	        int fd = open("/dev/nullb0", O_RDWR|O_DIRECT);
> 	        struct blk_zone_range zr = {4096, 0xfffffffffffff000ULL};
> 	        ioctl(fd, BLKRESETZONE, &zr);
> 	        return 0;
> 	}
> 
> BUG: KASAN: null-ptr-deref in submit_bio_wait+0x74/0xe0
> Write of size 8 at addr 0000000000000040 by task a.out/1590
> 
> CPU: 8 PID: 1590 Comm: a.out Not tainted 5.6.0-rc1-00019-g359c92c02bfa #2
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190711_202441-buildvm-armv7-10.arm.fedoraproject.org-2.fc31 04/01/2014
> Call Trace:
>  dump_stack+0x76/0xa0
>  __kasan_report.cold+0x5/0x3e
>  kasan_report+0xe/0x20
>  submit_bio_wait+0x74/0xe0
>  blkdev_zone_mgmt+0x26f/0x2a0
>  blkdev_zone_mgmt_ioctl+0x14b/0x1b0
>  blkdev_ioctl+0xb28/0xe60
>  block_ioctl+0x69/0x80
>  ksys_ioctl+0x3af/0xa50

Applied, thanks.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-12 15:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-12 17:40 [PATCH] block, zoned: fix integer overflow with BLKRESETZONE et al Alexey Dobriyan
2020-02-19 16:34 ` Christoph Hellwig
2020-03-12 15:11 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).