Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1731602 > unrolled thread

[PATCH] brd: fix overflow in __brd_direct_access

Started byMikulas Patocka <mpatocka@redhat.com>
First post2017-09-13 15:20 +0200
Last post2017-09-13 19:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] brd: fix overflow in __brd_direct_access Mikulas Patocka <mpatocka@redhat.com> - 2017-09-13 15:20 +0200
    Re: [PATCH] brd: fix overflow in __brd_direct_access Dan Williams <dan.j.williams@intel.com> - 2017-09-13 18:30 +0200
    Re: [PATCH] brd: fix overflow in __brd_direct_access Jens Axboe <axboe@kernel.dk> - 2017-09-13 19:20 +0200

#1731602 — [PATCH] brd: fix overflow in __brd_direct_access

FromMikulas Patocka <mpatocka@redhat.com>
Date2017-09-13 15:20 +0200
Subject[PATCH] brd: fix overflow in __brd_direct_access
Message-ID<upfKa-7Rm-11@gated-at.bofh.it>
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);

[toc] | [next] | [standalone]


#1731705

FromDan Williams <dan.j.williams@intel.com>
Date2017-09-13 18:30 +0200
Message-ID<upiI1-1gS-9@gated-at.bofh.it>
In reply to#1731602
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>

[toc] | [prev] | [next] | [standalone]


#1731729

FromJens Axboe <axboe@kernel.dk>
Date2017-09-13 19:20 +0200
Message-ID<upjup-1Ow-3@gated-at.bofh.it>
In reply to#1731602
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

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web