[RFC PATCH 09/16] mm: Read the nr_pages_allocs value given by user
From: Juan Yescas
Date: Thu Jul 23 2026 - 03:54:59 EST
This change reads the nr_page_allocs value given by the user and
validates that is an unsigned long.
If the input is valid, it will allocate an array of nr_page_allocs
size. This array will store the allocation ids. These allocation ids
will be used to free the allocations.
Signed-off-by: Juan Yescas <jyescas@xxxxxxxxxx>
---
mm/page_alloc_hogger.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c
index 3ffad74a0bdf..60dfddf6b441 100644
--- a/mm/page_alloc_hogger.c
+++ b/mm/page_alloc_hogger.c
@@ -136,6 +136,19 @@ struct kmem_cache *page_alloc_cache;
static ssize_t req_page_alloc_write(struct file *file, const char __user *ubuf,
size_t cnt, loff_t *ppos)
{
+ unsigned long nr_pages_allocs;
+ unsigned long *allocs_ids;
+ int ret;
+
+ ret = kstrtoul_from_user(ubuf, cnt, 10, &nr_pages_allocs);
+ if (ret)
+ return ret;
+
+ allocs_ids = kmalloc_array(nr_pages_allocs, sizeof(unsigned long),
+ GFP_KERNEL);
+ if (!allocs_ids)
+ return -ENOMEM;
+
return cnt;
}
--
2.55.0.229.g6434b31f56-goog