mm/page_owner: clamp read count to PAGE_SIZE
authorMiles Chen <[email protected]>
Fri, 28 Dec 2018 08:33:21 +0000 (00:33 -0800)
committerLinus Torvalds <[email protected]>
Fri, 28 Dec 2018 20:11:46 +0000 (12:11 -0800)
The (root-only) page owner read might allocate a large size of memory with
a large read count.  Allocation fails can easily occur when doing high
order allocations.

Clamp buffer size to PAGE_SIZE to avoid arbitrary size allocation
and avoid allocation fails due to high order allocation.

[[email protected]: use min_t()]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Miles Chen <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Joe Perches <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
mm/page_owner.c

index 87bc0dfdb52b679c19856d19878f2a5838ac3b55..28b06524939fa853307307469c76ac76d7955304 100644 (file)
@@ -351,6 +351,7 @@ print_page_owner(char __user *buf, size_t count, unsigned long pfn,
                .skip = 0
        };
 
+       count = min_t(size_t, count, PAGE_SIZE);
        kbuf = kmalloc(count, GFP_KERNEL);
        if (!kbuf)
                return -ENOMEM;