From patchwork Tue Dec 5 03:32:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 10092025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BED8760327 for ; Tue, 5 Dec 2017 03:26:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B5A77287A3 for ; Tue, 5 Dec 2017 03:26:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9EFB287B4; Tue, 5 Dec 2017 03:26:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 199D3287A3 for ; Tue, 5 Dec 2017 03:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752050AbdLED0Q (ORCPT ); Mon, 4 Dec 2017 22:26:16 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:2252 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751846AbdLED0Q (ORCPT ); Mon, 4 Dec 2017 22:26:16 -0500 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 49D5B4BBE4E2D; Tue, 5 Dec 2017 11:26:01 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.361.1; Tue, 5 Dec 2017 11:25:53 +0800 From: "zhangyi (F)" To: CC: , , , , Subject: [PATCH] dax: fix potential overflow on 32bit machine Date: Tue, 5 Dec 2017 11:32:10 +0800 Message-ID: <20171205033210.38338-1-yi.zhang@huawei.com> X-Mailer: git-send-email 2.9.5 MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 32bit machine, when mmap2 a large enough file with pgoff more than ULONG_MAX >> PAGE_SHIFT, it will trigger offset overflow and lead to unmap the wrong page in dax_insert_mapping_entry(). This patch cast pgoff to 64bit to prevent the overflow. Signed-off-by: zhangyi (F) --- fs/dax.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 78b72c4..8e12848 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -539,10 +539,11 @@ static void *dax_insert_mapping_entry(struct address_space *mapping, /* we are replacing a zero page with block mapping */ if (dax_is_pmd_entry(entry)) unmap_mapping_range(mapping, - (vmf->pgoff << PAGE_SHIFT) & PMD_MASK, + ((loff_t)vmf->pgoff << PAGE_SHIFT) & PMD_MASK, PMD_SIZE, 0); else /* pte entry */ - unmap_mapping_range(mapping, vmf->pgoff << PAGE_SHIFT, + unmap_mapping_range(mapping, + (loff_t)vmf->pgoff << PAGE_SHIFT, PAGE_SIZE, 0); }