Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3113605pxm; Mon, 28 Feb 2022 12:17:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXCRfU/eznu9UVCCYKwnWClrg/mKPVtPq++8wOIVp1CBqs6FQDa6MrrY9KP4lr2LqqEoEK X-Received: by 2002:a17:902:ab5b:b0:14f:ba0b:9359 with SMTP id ij27-20020a170902ab5b00b0014fba0b9359mr21704304plb.133.1646079465089; Mon, 28 Feb 2022 12:17:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079465; cv=none; d=google.com; s=arc-20160816; b=RyOHjIhzEC+F72BIJKzhRL8sTnFXXAsyx51uFVJEauDAnhLFu++XPVOgWVHohnfXaq jM43EVru7meZDqnFDjia4Z5ebEIKfzEdG+gR4mZ56GoRqv74nuPCSW3aYI2dxT/ZmppO 5pKycAUQXhw3eDPORgHQtETQxGGCbdOm0EflFjmzQiVXQfvTjvNnKuNMHzlZyiGYQYfx EckJZvDDpyNDnsJiBXdMPcOtVqw/h82GT98NjUY2w0dfp1ymWR3RrBtF2oj3FVmk8z/W MnFgDCT+HQgY36mNGzllKITWmc8t66Lt2DIB4/bCII8NH8hX3TisJvS8XH7Ssfy8Csf3 6lrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oFI0sROYeQFCAb2l9mW36DXKIffjreRQNC3+DYqkfu0=; b=k9qgJzMJBWYXMVQ/oV4xKGX6vbDtTe4MwpcuxmRIJH7m6/sDa3zsOa53DMIAbhQAy6 r5wwU25EQ1x1ua7u8axBX79zsX00wD/YoUab2mn+ReM+ImVq4KVMb3XZ2ybc9JDTjWeC y2ppAldIvzHYivmvfAsequjo6FMrfd1ogDC+icAw8y52bAJc8tHLqRw/P0VOHCcXHZl2 o7S61qXdWvfebAql3CmqKPH+ypWhirThmD/0xzXljLboiRrj4YMFdSQ+La3YNvoAUNUY 19b8NXEjfkXqu4eXZcy66zxCDr0TXggGkH9SkhvCVQNMhkNDO73SPz83/nDklLfPEYwH ru8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bX5aC1yV; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h91-20020a17090a29e400b001bcc6150588si382139pjd.159.2022.02.28.12.17.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:17:45 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=bX5aC1yV; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 44DD8186B87; Mon, 28 Feb 2022 11:38:25 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236811AbiB1SP1 (ORCPT + 99 others); Mon, 28 Feb 2022 13:15:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240952AbiB1SJS (ORCPT ); Mon, 28 Feb 2022 13:09:18 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DCA55E768; Mon, 28 Feb 2022 09:49:18 -0800 (PST) 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 1ABB860748; Mon, 28 Feb 2022 17:49:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37D5FC340E7; Mon, 28 Feb 2022 17:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646070557; bh=HFf6HB8g39HJQPZk8Gzm1m7F9fQJjHJtEmp1AGuZ/+4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bX5aC1yVHv+z83n/cNppfaWuCq4qsNqKFUKU4upOpguvLhmXDhmTV88At0oPpX7ji FHTKP6z1Mf7XgGTZUGucsCJnjSHAYPle/TRoFbdpgf+Xqp9BgS35cz1lLmaJdpjSNb BsH+b2k+t74F+LZfCTvJfJJAWIBG6uo/1BQuGL3w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Yuntao , Mike Kravetz , Andrew Morton , Linus Torvalds Subject: [PATCH 5.16 153/164] hugetlbfs: fix a truncation issue in hugepages parameter Date: Mon, 28 Feb 2022 18:25:15 +0100 Message-Id: <20220228172413.643077553@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172359.567256961@linuxfoundation.org> References: <20220228172359.567256961@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Liu Yuntao commit e79ce9832316e09529b212a21278d68240ccbf1f upstream. 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 Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index e57650a9404f..f294db835f4b 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; -- 2.35.1