From patchwork Wed Nov 24 04:08:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yangerkun X-Patchwork-Id: 12635923 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE375C433EF for ; Wed, 24 Nov 2021 03:56:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 547DE6B0075; Tue, 23 Nov 2021 22:56:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F6276B0078; Tue, 23 Nov 2021 22:56:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E5836B007B; Tue, 23 Nov 2021 22:56:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0117.hostedemail.com [216.40.44.117]) by kanga.kvack.org (Postfix) with ESMTP id 321646B0075 for ; Tue, 23 Nov 2021 22:56:34 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EFC7C7BE7B for ; Wed, 24 Nov 2021 03:56:23 +0000 (UTC) X-FDA: 78842461446.12.2F41719 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf31.hostedemail.com (Postfix) with ESMTP id B94B3104631F for ; Wed, 24 Nov 2021 03:56:16 +0000 (UTC) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4HzRy83VzbzcZxP; Wed, 24 Nov 2021 11:56:16 +0800 (CST) Received: from kwepemm600019.china.huawei.com (7.193.23.64) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 24 Nov 2021 11:56:17 +0800 Received: from localhost.localdomain (10.175.127.227) by kwepemm600019.china.huawei.com (7.193.23.64) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 24 Nov 2021 11:56:08 +0800 From: yangerkun To: , CC: , , , Subject: [PATCH] hugetlbfs: avoid overflow in hugetlbfs_fallocate Date: Wed, 24 Nov 2021 12:08:18 +0800 Message-ID: <20211124040818.2219374-1-yangerkun@huawei.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600019.china.huawei.com (7.193.23.64) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: B94B3104631F X-Stat-Signature: 383ex1y85ez7uncimz49w3etp5fusf98 Authentication-Results: imf31.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf31.hostedemail.com: domain of yangerkun@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=yangerkun@huawei.com X-HE-Tag: 1637726176-343793 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: luojiajun report a problem[1] two years ago which seems still exists in mainline. vfs_fallocate can avoid 'offset + len' trigger overflow, but 'offset + len + hpage_size - 1' may overflow too and will lead to a wrong 'end'. luojiajun give a solution which can fix the wrong 'end' but leave the overflow still happened. We should fix it by transfer 'offset' to unsigned long long. [1] https://patchwork.kernel.org/project/linux-mm/patch/1554775226-67213-1-git-send-email-luojiajun3@huawei.com/ Signed-off-by: yangerkun --- fs/hugetlbfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c index 49d2e686be74..8012a14901de 100644 --- a/fs/hugetlbfs/inode.c +++ b/fs/hugetlbfs/inode.c @@ -651,7 +651,8 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, * as well as being converted to page offsets. */ start = offset >> hpage_shift; - end = (offset + len + hpage_size - 1) >> hpage_shift; + end = ((unsigned long long)offset + len + hpage_size - 1) + >> hpage_shift; inode_lock(inode);