Skip to content

Commit

Permalink
hugetlb: fix handling of parse errors in sysfs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reported-by: CAI Qian <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Eric B Munson <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Nishanth Aravamudan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
khers authored and torvalds committed Jan 14, 2011
1 parent adbe872 commit 73ae31e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions mm/hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,10 +1375,8 @@ static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);

err = strict_strtoul(buf, 10, &count);
if (err) {
err = 0; /* This seems wrong */
if (err)
goto out;
}

h = kobj_to_hstate(kobj, &nid);
if (h->order >= MAX_ORDER) {
Expand Down Expand Up @@ -1469,7 +1467,7 @@ static ssize_t nr_overcommit_hugepages_store(struct kobject *kobj,

err = strict_strtoul(buf, 10, &input);
if (err)
return 0;
return err;

spin_lock(&hugetlb_lock);
h->nr_overcommit_huge_pages = input;
Expand Down

0 comments on commit 73ae31e

Please sign in to comment.