]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
hugetlbfs: fix a truncation issue in hugepages parameter
authorLiu Yuntao <liuyuntao10@huawei.com>
Sat, 26 Feb 2022 03:11:02 +0000 (19:11 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Mar 2022 10:51:20 +0000 (11:51 +0100)
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 <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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
mm/hugetlb.c

index f5eff9749b405647810aefec755b07f1f5726da9..221239db6389a20098052ff8006bcd3e6c7e3212 100644 (file)
@@ -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;