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 --- Changes in v2: - Free allocs_ids. mm/page_alloc_hogger.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mm/page_alloc_hogger.c b/mm/page_alloc_hogger.c index ded3f0fc6641..9b1eaf3814e1 100644 --- a/mm/page_alloc_hogger.c +++ b/mm/page_alloc_hogger.c @@ -135,6 +135,21 @@ static 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; + + kfree(allocs_ids); + return cnt; } -- 2.55.0.629.g250fe7f194-goog