Commit 73ae31e5986a4c0ee84bfd13ccd9b57a98956f6f

Authored by Eric B Munson
Committed by Linus Torvalds
1 parent adbe8726dc

hugetlb: fix handling of parse errors in sysfs

When parsing changes to the huge page pool sizes made from userspace via
the sysfs interface, bogus input values are being covered up by
nr_hugepages_store_common and nr_overcommit_hugepages_store returning 0
when strict_strtoul returns an error.  This can cause an infinite loop in
the nr_hugepages_store code.  This patch changes the return value for
these functions to -EINVAL when strict_strtoul returns an error.

Signed-off-by: Eric B Munson <emunson@mgebm.net>
Reported-by: CAI Qian <caiqian@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Eric B Munson <emunson@mgebm.net>
Cc: Michal Hocko <mhocko@suse.cz>
Cc: Nishanth Aravamudan <nacc@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 1 changed file with 2 additions and 4 deletions Side-by-side Diff

... ... @@ -1375,10 +1375,8 @@
1375 1375 NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
1376 1376  
1377 1377 err = strict_strtoul(buf, 10, &count);
1378   - if (err) {
1379   - err = 0; /* This seems wrong */
  1378 + if (err)
1380 1379 goto out;
1381   - }
1382 1380  
1383 1381 h = kobj_to_hstate(kobj, &nid);
1384 1382 if (h->order >= MAX_ORDER) {
... ... @@ -1469,7 +1467,7 @@
1469 1467  
1470 1468 err = strict_strtoul(buf, 10, &input);
1471 1469 if (err)
1472   - return 0;
  1470 + return err;
1473 1471  
1474 1472 spin_lock(&hugetlb_lock);
1475 1473 h->nr_overcommit_huge_pages = input;