Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

proc: use kvzalloc for our kernel buffer

Since

sysctl: pass kernel pointers to ->proc_handler

we have been pre-allocating a buffer to copy the data from the proc
handlers into, and then copying that to userspace. The problem is this
just blindly kzalloc()'s the buffer size passed in from the read, which in
the case of our 'cat' binary was 64kib. Order-4 allocations are not
awesome, and since we can potentially allocate up to our maximum order, so
use kvzalloc for these buffers.

[willy@infradead.org: changelog tweaks]

Link: https://lkml.kernel.org/r/6345270a2c1160b89dd5e6715461f388176899d1.1612972413.git.josef@toxicpanda.com
Fixes: 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
CC: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Josef Bacik and committed by
Linus Torvalds
45089437 152c432b

+2 -2
+2 -2
fs/proc/proc_sysctl.c
··· 571 571 error = -ENOMEM; 572 572 if (count >= KMALLOC_MAX_SIZE) 573 573 goto out; 574 - kbuf = kzalloc(count + 1, GFP_KERNEL); 574 + kbuf = kvzalloc(count + 1, GFP_KERNEL); 575 575 if (!kbuf) 576 576 goto out; 577 577 ··· 600 600 601 601 error = count; 602 602 out_free_buf: 603 - kfree(kbuf); 603 + kvfree(kbuf); 604 604 out: 605 605 sysctl_head_finish(head); 606 606