Skip to content

Commit e79ce98

Browse files
Liu Yuntaotorvalds
authored andcommitted
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: b538908 ("hugetlbfs: extend the definition of hugepages parameter to support node allocation") Signed-off-by: Liu Yuntao <liuyuntao10@huawei.com> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 70effdc commit e79ce98

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

mm/hugetlb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4159,10 +4159,10 @@ static int __init hugepages_setup(char *s)
41594159
pr_warn("HugeTLB: architecture can't support node specific alloc, ignoring!\n");
41604160
return 0;
41614161
}
4162+
if (tmp >= nr_online_nodes)
4163+
goto invalid;
41624164
node = tmp;
41634165
p += count + 1;
4164-
if (node < 0 || node >= nr_online_nodes)
4165-
goto invalid;
41664166
/* Parse hugepages */
41674167
if (sscanf(p, "%lu%n", &tmp, &count) != 1)
41684168
goto invalid;

0 commit comments

Comments
 (0)