Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2476341pxm; Sun, 27 Feb 2022 22:57:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhGWh7YyEJSKYXM8Vjii3Wd7gY+OUzdGsYdYceCVM8tZqG4dTuHjRo6Q4kmrJZRgdQPCCc X-Received: by 2002:a17:906:2608:b0:6c9:b248:4dcf with SMTP id h8-20020a170906260800b006c9b2484dcfmr13945365ejc.320.1646031442240; Sun, 27 Feb 2022 22:57:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646031442; cv=none; d=google.com; s=arc-20160816; b=Cr4LETU6EUNQQApCEZOpCcmr7bddLbYISMO4k9MBZoVwt/qkHYXiIsCp2AQS2PmNlj YdAbHj3K+7njphx/IP5zXCmQT4b2nUim4diURJ6eAgLet63b1IItOxJ2REEmqUyzmKLk hss/vilXCzs/QWSZ9nW4kI6JKntTNI6Eu7t9inrgwHct1N+Vfb+3URi3nCxRiVqKLzGW WI6g7vdaiDhWTdTdoSnRfGO88tCPfaCanHP8IqwN5gUmnKsQbksOPtE1ks38yedDa8W+ V1d2uybx5tPsiE8pgbyIxqb+xW9WnXsuPvnd9p6kFD68d4Z1UWgkNghb8ra4xdkI4azO AH9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=34pLy5corG+HXHvvIyE030KIDUh7wwaXX8KPYqoWC0k=; b=eBGjEF0buh8+j3r7Vf5uc5l++a3EpqCILc7Dhd1zziTodWyyiMMPeSVU40Lfo6i3zz GdCERqRGzSYfoOqQ1oKdxd4kabPPRz0vuCA24iT9FsSuzluBNkYF8EtnC1l/cIebFmDo wAuEH1NC+IK1OdSzlkJdqWSGATJrJL2pEMdaXVng0s/4/1nfWpH6Q5u/CCHZjZbN19d6 fyDMY/P9eIlEeuQ8WvYDEI6Y2KcQH+ZB1/TZOGCSnqi2vCvGwU5yDfX2IXL05B3eHaFu eszWySUod9HtcmyXpEh0iFDIgGkjMmf7ZgvqJx2sWl17qtjf2TFtRv7vLatZldxj9IfP g+cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FwVj6ufa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a170906524f00b006b66c483d40si5319687ejm.240.2022.02.27.22.57.00; Sun, 27 Feb 2022 22:57:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FwVj6ufa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232717AbiB1C76 (ORCPT + 99 others); Sun, 27 Feb 2022 21:59:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbiB1C74 (ORCPT ); Sun, 27 Feb 2022 21:59:56 -0500 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A7B139B82 for ; Sun, 27 Feb 2022 18:59:19 -0800 (PST) Received: by mail-yb1-xb2a.google.com with SMTP id d21so17705714yba.11 for ; Sun, 27 Feb 2022 18:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=34pLy5corG+HXHvvIyE030KIDUh7wwaXX8KPYqoWC0k=; b=FwVj6ufawxpi9pivekPtYpQj4eJVmPnKCPuxl4736Po6Y/uSYhIfoMzOaKPvSMRWVQ KZ+Hkhg/J80BJsFx6+KlrdIPggrxm850i3K459gfcxdjFulSiQzFG6bwa3PHlzP0rmUX lT6UtPnBk/aioeF7Se4Xt5/y8ZEJVKwT3//EUdyI0JNF8KOsT6EODS3St71J/OZwri4T 6plDDOHax8EX7NNPy45F0h+dNA3FL5F42ZlzMH2d4e+LI8kNynY5D2JWgpFHGATzYCt4 D6gAxLzpSfWc8SpHWcpQiQ8HH9wtnBmL/V9tiDAQOw5ZCraXzXy9tRSC5Dc+Aizwj40e AjbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=34pLy5corG+HXHvvIyE030KIDUh7wwaXX8KPYqoWC0k=; b=uzplzUJmwk2hOROICKCnaF6R0H4IYTV7+xdTiREYCrMWFMPxn1HmQWSV9WnoL8inDr C31lHUReFiHdgGRqwHrKnEREHUmKXOIzIcEBdlV/2UgMbn2oI3SROI+Etr9ZcC9K4Fjk dZXKB5E3+TvijaE9UBnMgdGokaF3peM1T9qGpNqOwuSjcYkgwxwyoPyMS5H/3WgQuDr+ huhxg/0WAYOJ+enEFH6dbJsAkLnpRoFJb/wwAtaBzIrZjq+5xVvhQRjvK2T3Ee+28LTZ h4o23wdkN07I6ntxQjj+ux/e67mdMt5+eg51axgf9wuhF7ZbLTXIRw3CtQtpnwm7uhrC S44g== X-Gm-Message-State: AOAM533dmoYThXzrXc8JAa59d+3giV8dnsPF8ATXRF2oV9pDoVkLY2La KhwfWorI3JLNUlhWS58czMlZvjsK9l8BGhsaaFg= X-Received: by 2002:a25:c00b:0:b0:624:4382:9d0a with SMTP id c11-20020a25c00b000000b0062443829d0amr16841787ybf.436.1646017158396; Sun, 27 Feb 2022 18:59:18 -0800 (PST) MIME-Version: 1.0 References: <20220209134018.8242-1-liuyuntao10@huawei.com> <95d1dc4e-fc3b-fe3c-5d85-218a7410e966@oracle.com> In-Reply-To: <95d1dc4e-fc3b-fe3c-5d85-218a7410e966@oracle.com> From: Zhenguo Yao Date: Mon, 28 Feb 2022 10:59:07 +0800 Message-ID: Subject: Re: [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter To: Mike Kravetz Cc: liuyuntao , Andrew Morton , Linux Memory Management List , linux-kernel@vger.kernel.org, wuxu.wu@huawei.com, fangchuangchuang@huawei.com, windspectator@gmail.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mike Kravetz =E4=BA=8E2022=E5=B9=B42=E6=9C=8810= =E6=97=A5=E5=91=A8=E5=9B=9B 08:44=E5=86=99=E9=81=93=EF=BC=9A > > On 2/9/22 05:40, liuyuntao wrote: > > 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 =3D tmp; > > > > For example, add following parameter in command line: > > hugepagesz=3D1G hugepages=3D4294967297: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 p= arameter to support node allocation") > > Signed-off-by: Liu Yuntao > > --- > > 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 supp= ort node specific alloc, ignoring!\n"); > > return 0; > > } > > + if (tmp >=3D nr_online_nodes) > > + goto invalid; > > node =3D tmp; > > I am surprised none of the automated checking complained about that > assignment. > > > p +=3D count + 1; > > - if (node < 0 || node >=3D nr_online_nodes) > > I can't remember, but I think that check for node < 0 was added to handle > overflow during the above assignment. Do you remember Zhenguo Yao? > Sorry for my late reply. This check for node < 0 was added to handle node parameter overflow from the earliest version: https://lore.kernel.org/lkml/20210820030536.25737-1-yaozhenguo1@gmail.com/ Parameter of node allocation was: hugepages_node=3Dxx hugepages=3Dxx at th= is version. With the changing of the code, this check has lost its effect. > > - goto invalid; > > /* Parse hugepages */ > > if (sscanf(p, "%lu%n", &tmp, &count) !=3D 1) > > goto invalid; > > Thanks, > > Reviewed-by: Mike Kravetz > > -- > Mike Kravetz