From: Mike Kravetz <mike.kravetz@oracle.com>
To: liuyuntao <liuyuntao10@huawei.com>,
akpm@linux-foundation.org, yaozhenguo1@gmail.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
wuxu.wu@huawei.com, fangchuangchuang@huawei.com,
windspectator@gmail.com
Subject: Re: [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter
Date: Wed, 9 Feb 2022 16:43:29 -0800 [thread overview]
Message-ID: <95d1dc4e-fc3b-fe3c-5d85-218a7410e966@oracle.com> (raw)
In-Reply-To: <20220209134018.8242-1-liuyuntao10@huawei.com>
On 2/9/22 05:40, liuyuntao wrote:
> From: Liu Yuntao <liuyuntao10@huawei.com>
>
> 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 <liuyuntao10@huawei.com>
> ---
> 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;
I am surprised none of the automated checking complained about that
assignment.
> p += count + 1;
> - if (node < 0 || node >= 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?
> - goto invalid;
> /* Parse hugepages */
> if (sscanf(p, "%lu%n", &tmp, &count) != 1)
> goto invalid;
Thanks,
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
--
Mike Kravetz
next prev parent reply other threads:[~2022-02-10 0:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 13:40 [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter liuyuntao
2022-02-10 0:43 ` Mike Kravetz [this message]
2022-02-10 3:22 ` liuyuntao
2022-02-28 2:59 ` Zhenguo Yao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=95d1dc4e-fc3b-fe3c-5d85-218a7410e966@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=fangchuangchuang@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=liuyuntao10@huawei.com \
--cc=windspectator@gmail.com \
--cc=wuxu.wu@huawei.com \
--cc=yaozhenguo1@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).