Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751936AbdIMNSB (ORCPT ); Wed, 13 Sep 2017 09:18:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46004 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751019AbdIMNSA (ORCPT ); Wed, 13 Sep 2017 09:18:00 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E346B4A6E1 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=mpatocka@redhat.com Date: Wed, 13 Sep 2017 09:17:57 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Jens Axboe , Dan Williams cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] brd: fix overflow in __brd_direct_access Message-ID: User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 13 Sep 2017 13:18:00 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1028 Lines: 29 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 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);