OSDN Git Service

brd: fix overflow in __brd_direct_access
authorMikulas Patocka <mpatocka@redhat.com>
Wed, 13 Sep 2017 13:17:57 +0000 (09:17 -0400)
committerJens Axboe <axboe@kernel.dk>
Mon, 25 Sep 2017 14:56:05 +0000 (08:56 -0600)
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.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 1647b9b959c7 ("brd: add dax_operations support")
Cc: stable@vger.kernel.org # 4.12+
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/brd.c

index bbd0d18..2d7178f 100644 (file)
@@ -342,7 +342,7 @@ static long __brd_direct_access(struct brd_device *brd, pgoff_t pgoff,
 
        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);