From mboxrd@z Thu Jan 1 00:00:00 1970 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 BA7A2C433EF for ; Sat, 26 Feb 2022 03:11:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 505A38D0006; Fri, 25 Feb 2022 22:11:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B4BD8D0001; Fri, 25 Feb 2022 22:11:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A4118D0006; Fri, 25 Feb 2022 22:11:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 2DE378D0001 for ; Fri, 25 Feb 2022 22:11:05 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 054FC80709 for ; Sat, 26 Feb 2022 03:11:05 +0000 (UTC) X-FDA: 79183454490.14.67DA6BF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf15.hostedemail.com (Postfix) with ESMTP id 0CC1BA0002 for ; Sat, 26 Feb 2022 03:11:03 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 75E1961E49; Sat, 26 Feb 2022 03:11:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37D84C340E7; Sat, 26 Feb 2022 03:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1645845063; bh=NwpuICpm0V8qEMhlsHOVt+1UzXIwqQEEcQj42gz4J88=; h=Date:To:From:In-Reply-To:Subject:From; b=PTb3Pke/oRR+dKf07zJhVHtdD+aLBFWBwReJUQUG4ZcNlaZ9spdEMo2j2asgO1P31 BNAUH4HnQUQ12CL+ur5x/4VhXTnbORDsOzpCdxPd7DJo/mknRrRsSyRj/XKtnLFE52 jdF3DR8uLyAGBYB14okzqazSU0iCibet+SaHladw= Date: Fri, 25 Feb 2022 19:11:02 -0800 To: stable@vger.kernel.org,mike.kravetz@oracle.com,liuyuntao10@huawei.com,akpm@linux-foundation.org,patches@lists.linux.dev,linux-mm@kvack.org,mm-commits@vger.kernel.org,torvalds@linux-foundation.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20220225191021.f71538a3f43dc448110e88b6@linux-foundation.org> Subject: [patch 04/12] hugetlbfs: fix a truncation issue in hugepages parameter Message-Id: <20220226031103.37D84C340E7@smtp.kernel.org> X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0CC1BA0002 X-Stat-Signature: jdz6wkjt9omkgxo9ko53m15kosu7z4wn Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b="PTb3Pke/"; spf=pass (imf15.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1645845063-538827 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 Subject: hugetlbfs: fix a truncation issue in hugepages parameter 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. Link: https://lkml.kernel.org/r/20220209134018.8242-1-liuyuntao10@huawei.com Fixes: b5389086ad7be0 ("hugetlbfs: extend the definition of hugepages parameter to support node allocation") Signed-off-by: Liu Yuntao Reviewed-by: Mike Kravetz Cc: Signed-off-by: Andrew Morton --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/mm/hugetlb.c~hugetlbfs-fix-a-truncation-issue-in-hugepages-parameter +++ a/mm/hugetlb.c @@ -4159,10 +4159,10 @@ static int __init hugepages_setup(char * 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; _