From patchwork Wed Feb 9 13:40:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuyuntao X-Patchwork-Id: 12740297 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 EF4D3C433F5 for ; Wed, 9 Feb 2022 13:40:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 590496B0073; Wed, 9 Feb 2022 08:40:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 53E776B0074; Wed, 9 Feb 2022 08:40:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42DD96B0075; Wed, 9 Feb 2022 08:40:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 2FCF56B0073 for ; Wed, 9 Feb 2022 08:40:42 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id D51C68249980 for ; Wed, 9 Feb 2022 13:40:41 +0000 (UTC) X-FDA: 79123351482.29.DBEA81C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf14.hostedemail.com (Postfix) with ESMTP id 9A37C100007 for ; Wed, 9 Feb 2022 13:40:39 +0000 (UTC) Received: from kwepemi100010.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Jv19w2MpbzZfFs; Wed, 9 Feb 2022 21:36:20 +0800 (CST) Received: from kwepemm600012.china.huawei.com (7.193.23.74) by kwepemi100010.china.huawei.com (7.221.188.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 9 Feb 2022 21:40:33 +0800 Received: from huawei.com (10.174.177.28) by kwepemm600012.china.huawei.com (7.193.23.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 9 Feb 2022 21:40:32 +0800 From: liuyuntao To: , , CC: , , , , Subject: [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter Date: Wed, 9 Feb 2022 21:40:18 +0800 Message-ID: <20220209134018.8242-1-liuyuntao10@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.174.177.28] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600012.china.huawei.com (7.193.23.74) X-CFilter-Loop: Reflected X-Stat-Signature: n5jbqhcwhkdhhhfbqwetjb6tujdbphap Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of liuyuntao10@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liuyuntao10@huawei.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9A37C100007 X-HE-Tag: 1644414039-38675 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: From: Liu Yuntao When we specify a large number for node in hugepages parameter, it may be parsed to another number due to truncation in this statement: node = tmp; For example, add following parameter in command line: hugepagesz=1G hugepages=4294967297:5 and kernel will allocate 5 hugepages for node 1 instead of ignoring it. I move the validation check earlier to fix this issue, and slightly simplifies the condition here. Fixes: b5389086ad7be0 ("hugetlbfs: extend the definition of hugepages parameter to support node allocation") Signed-off-by: Liu Yuntao Reviewed-by: Mike Kravetz --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 61895cc01d09..0929547f6ad6 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4159,10 +4159,10 @@ static int __init hugepages_setup(char *s) pr_warn("HugeTLB: architecture can't support node specific alloc, ignoring!\n"); return 0; } + if (tmp >= nr_online_nodes) + goto invalid; node = tmp; p += count + 1; - if (node < 0 || node >= nr_online_nodes) - goto invalid; /* Parse hugepages */ if (sscanf(p, "%lu%n", &tmp, &count) != 1) goto invalid;