瀏覽代碼

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>
Eric B Munson 14 年之前
父節點
當前提交
73ae31e598
共有 1 個文件被更改,包括 2 次插入4 次删除
  1. 2 4
      mm/hugetlb.c

+ 2 - 4
mm/hugetlb.c

@@ -1375,10 +1375,8 @@ static ssize_t nr_hugepages_store_common(bool obey_mempolicy,
 	NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
 	NODEMASK_ALLOC(nodemask_t, nodes_allowed, GFP_KERNEL | __GFP_NORETRY);
 
 
 	err = strict_strtoul(buf, 10, &count);
 	err = strict_strtoul(buf, 10, &count);
-	if (err) {
-		err = 0;		/* This seems wrong */
+	if (err)
 		goto out;
 		goto out;
-	}
 
 
 	h = kobj_to_hstate(kobj, &nid);
 	h = kobj_to_hstate(kobj, &nid);
 	if (h->order >= MAX_ORDER) {
 	if (h->order >= MAX_ORDER) {
@@ -1469,7 +1467,7 @@ static ssize_t nr_overcommit_hugepages_store(struct kobject *kobj,
 
 
 	err = strict_strtoul(buf, 10, &input);
 	err = strict_strtoul(buf, 10, &input);
 	if (err)
 	if (err)
-		return 0;
+		return err;
 
 
 	spin_lock(&hugetlb_lock);
 	spin_lock(&hugetlb_lock);
 	h->nr_overcommit_huge_pages = input;
 	h->nr_overcommit_huge_pages = input;