* [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter
@ 2022-02-09 13:40 liuyuntao
2022-02-10 0:43 ` Mike Kravetz
0 siblings, 1 reply; 4+ messages in thread
From: liuyuntao @ 2022-02-09 13:40 UTC (permalink / raw)
To: mike.kravetz, akpm, yaozhenguo1
Cc: linux-mm, linux-kernel, wuxu.wu, fangchuangchuang, windspectator
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;
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.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter
2022-02-09 13:40 [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter liuyuntao
@ 2022-02-10 0:43 ` Mike Kravetz
2022-02-10 3:22 ` liuyuntao
2022-02-28 2:59 ` Zhenguo Yao
0 siblings, 2 replies; 4+ messages in thread
From: Mike Kravetz @ 2022-02-10 0:43 UTC (permalink / raw)
To: liuyuntao, akpm, yaozhenguo1
Cc: linux-mm, linux-kernel, wuxu.wu, fangchuangchuang, windspectator
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter
2022-02-10 0:43 ` Mike Kravetz
@ 2022-02-10 3:22 ` liuyuntao
2022-02-28 2:59 ` Zhenguo Yao
1 sibling, 0 replies; 4+ messages in thread
From: liuyuntao @ 2022-02-10 3:22 UTC (permalink / raw)
To: mike.kravetz
Cc: akpm, fangchuangchuang, linux-kernel, linux-mm, liuyuntao10,
windspectator, wuxu.wu, yaozhenguo1
On 2022-02-10 0:43 UTC, Mike Kravetz wrote:
> 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.
I think such assignments may be very common in kernel, and thus automated
checks just ignore them.
>
> > 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?
No, I don't. I took a look and found that the check for node < 0 has been
there since his first version of patch.
>
> > - 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
--
Liu Yuntao
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter
2022-02-10 0:43 ` Mike Kravetz
2022-02-10 3:22 ` liuyuntao
@ 2022-02-28 2:59 ` Zhenguo Yao
1 sibling, 0 replies; 4+ messages in thread
From: Zhenguo Yao @ 2022-02-28 2:59 UTC (permalink / raw)
To: Mike Kravetz
Cc: liuyuntao, Andrew Morton, Linux Memory Management List,
linux-kernel, wuxu.wu, fangchuangchuang, windspectator
Mike Kravetz <mike.kravetz@oracle.com> 于2022年2月10日周四 08:44写道:
>
> 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?
>
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=xx hugepages=xx at this
version. With the changing of the code, this check has lost its effect.
> > - 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-02-28 2:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 13:40 [PATCH] hugetlbfs: fix a truncation issue in hugepages parameter liuyuntao
2022-02-10 0:43 ` Mike Kravetz
2022-02-10 3:22 ` liuyuntao
2022-02-28 2:59 ` Zhenguo Yao
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.