Re: [PATCH] fs/proc/kcore.c: Omit kernel text area for hardened usercopy feature

From: Andi Kleen
Date: Wed Sep 07 2016 - 12:39:00 EST


> ---
> diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
> index a939f5ed7f89..de07c273f725 100644
> --- a/fs/proc/kcore.c
> +++ b/fs/proc/kcore.c
> @@ -515,8 +515,20 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
> } else {
> if (kern_addr_valid(start)) {
> unsigned long n;
> + char *buf;
>
> - n = copy_to_user(buffer, (char *)start, tsz);
> + buf = kzalloc(tsz, GFP_KERNEL);

You have to add some limit and a loop, otherwise a user can eat all kernel memory,
or copies > KMALLOC_MAX wouldn't work. Probably only get a single page.

Also don't need kzalloc, kmalloc is sufficient.

-Andi