linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] brd: fix overflow in __brd_direct_access
@ 2017-09-13 13:17 Mikulas Patocka
  2017-09-13 16:22 ` Dan Williams
  2017-09-13 17:18 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Mikulas Patocka @ 2017-09-13 13:17 UTC (permalink / raw)
  To: Jens Axboe, Dan Williams; +Cc: linux-block, linux-kernel

The code in __brd_direct_access multiplies the pgoff variable by page size
and divides it by 512. It can cause overflow on 32-bit architectures. The
overflow happens if we create ramdisk larger than 4G and use it as a
sparse device.

This patch replaces multiplication and division with multiplication by the
number of sectors per page.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 1647b9b959c7 ("brd: add dax_operations support")
Cc: stable@vger.kernel.org	# 4.12+

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

Index: linux-4.13/drivers/block/brd.c
===================================================================
--- linux-4.13.orig/drivers/block/brd.c
+++ linux-4.13/drivers/block/brd.c
@@ -339,7 +339,7 @@ static long __brd_direct_access(struct b
 
 	if (!brd)
 		return -ENODEV;
-	page = brd_insert_page(brd, PFN_PHYS(pgoff) / 512);
+	page = brd_insert_page(brd, (sector_t)pgoff << PAGE_SECTORS_SHIFT);
 	if (!page)
 		return -ENOSPC;
 	*kaddr = page_address(page);

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

* Re: [PATCH] brd: fix overflow in __brd_direct_access
  2017-09-13 13:17 [PATCH] brd: fix overflow in __brd_direct_access Mikulas Patocka
@ 2017-09-13 16:22 ` Dan Williams
  2017-09-13 17:18 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Williams @ 2017-09-13 16:22 UTC (permalink / raw)
  To: Mikulas Patocka; +Cc: Jens Axboe, linux-block, linux-kernel

On Wed, Sep 13, 2017 at 6:17 AM, Mikulas Patocka <mpatocka@redhat.com> wrote:
> The code in __brd_direct_access multiplies the pgoff variable by page size
> and divides it by 512. It can cause overflow on 32-bit architectures. The
> overflow happens if we create ramdisk larger than 4G and use it as a
> sparse device.
>
> This patch replaces multiplication and division with multiplication by the
> number of sectors per page.
>
> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
> Fixes: 1647b9b959c7 ("brd: add dax_operations support")
> Cc: stable@vger.kernel.org      # 4.12+
>
> ---
>  drivers/block/brd.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> Index: linux-4.13/drivers/block/brd.c
> ===================================================================
> --- linux-4.13.orig/drivers/block/brd.c
> +++ linux-4.13/drivers/block/brd.c
> @@ -339,7 +339,7 @@ static long __brd_direct_access(struct b
>
>         if (!brd)
>                 return -ENODEV;
> -       page = brd_insert_page(brd, PFN_PHYS(pgoff) / 512);
> +       page = brd_insert_page(brd, (sector_t)pgoff << PAGE_SECTORS_SHIFT);

Looks good to me, you can add:

Reviewed-by: Dan Williams <dan.j.williams@intel.com>

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

* Re: [PATCH] brd: fix overflow in __brd_direct_access
  2017-09-13 13:17 [PATCH] brd: fix overflow in __brd_direct_access Mikulas Patocka
  2017-09-13 16:22 ` Dan Williams
@ 2017-09-13 17:18 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2017-09-13 17:18 UTC (permalink / raw)
  To: Mikulas Patocka, Dan Williams; +Cc: linux-block, linux-kernel

On 09/13/2017 07:17 AM, Mikulas Patocka wrote:
> The code in __brd_direct_access multiplies the pgoff variable by page size
> and divides it by 512. It can cause overflow on 32-bit architectures. The
> overflow happens if we create ramdisk larger than 4G and use it as a
> sparse device.
> 
> This patch replaces multiplication and division with multiplication by the
> number of sectors per page.

Thanks, applied with Dan's ack.

-- 
Jens Axboe

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

end of thread, other threads:[~2017-09-13 17:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-13 13:17 [PATCH] brd: fix overflow in __brd_direct_access Mikulas Patocka
2017-09-13 16:22 ` Dan Williams
2017-09-13 17:18 ` 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).