linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] mm/hugetlb: Fix unsigned overflow in  __nr_hugepages_store_common()
@ 2019-02-23  1:32 Jing Xiangfeng
  2019-02-25  0:45 ` Mike Kravetz
  0 siblings, 1 reply; 20+ messages in thread
From: Jing Xiangfeng @ 2019-02-23  1:32 UTC (permalink / raw)
  To: mike.kravetz, mhocko
  Cc: akpm, hughd, linux-mm, n-horiguchi, aarcange, kirill.shutemov,
	linux-kernel, Jing Xiangfeng

User can change a node specific hugetlb count. i.e.
/sys/devices/system/node/node1/hugepages/hugepages-2048kB/nr_hugepages
the calculated value of count is a total number of huge pages. It could
be overflow when a user entering a crazy high value. If so, the total
number of huge pages could be a small value which is not user expect.
We can simply fix it by setting count to ULONG_MAX, then it goes on. This
may be more in line with user's intention of allocating as many huge pages
as possible.

Signed-off-by: Jing Xiangfeng <jingxiangfeng@huawei.com>
---
 mm/hugetlb.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index afef616..6688894 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2423,7 +2423,14 @@ static ssize_t __nr_hugepages_store_common(bool obey_mempolicy,
 		 * per node hstate attribute: adjust count to global,
 		 * but restrict alloc/free to the specified node.
 		 */
+		unsigned long old_count = count;
 		count += h->nr_huge_pages - h->nr_huge_pages_node[nid];
+		/*
+		 * If user specified count causes overflow, set to
+		 * largest possible value.
+		 */
+		if (count < old_count)
+			count = ULONG_MAX;
 		init_nodemask_of_node(nodes_allowed, nid);
 	} else
 		nodes_allowed = &node_states[N_MEMORY];
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2019-03-07  0:18 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-23  1:32 [PATCH v4] mm/hugetlb: Fix unsigned overflow in __nr_hugepages_store_common() Jing Xiangfeng
2019-02-25  0:45 ` Mike Kravetz
2019-02-25  3:17   ` David Rientjes
2019-02-25 16:49     ` Mike Kravetz
2019-02-25 18:19       ` Mike Kravetz
2019-02-25 19:17         ` David Rientjes
2019-02-26  2:22           ` Jing Xiangfeng
2019-02-26  6:21             ` David Rientjes
2019-02-26 19:32               ` Mike Kravetz
2019-02-26 22:36                 ` Andrew Morton
2019-02-27  0:03                   ` Mike Kravetz
2019-03-04 13:48                     ` Oscar Salvador
2019-03-05  0:03                     ` Naoya Horiguchi
2019-03-05  4:15                       ` Mike Kravetz
2019-03-05 21:16                         ` Andrew Morton
2019-03-05 21:35                           ` Mike Kravetz
2019-03-05 21:41                             ` Alex Ghiti
2019-03-06  9:41                         ` Oscar Salvador
2019-03-07  0:17                           ` Mike Kravetz
2019-03-04  6:00                 ` Naoya Horiguchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).