]> git.baikalelectronics.ru Git - kernel.git/commitdiff
sysctl: reject gigantic reads/write to sysctl files
authorChristoph Hellwig <hch@lst.de>
Tue, 9 Jun 2020 17:08:19 +0000 (19:08 +0200)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 10 Jun 2020 18:11:33 +0000 (14:11 -0400)
Instead of triggering a WARN_ON deep down in the page allocator just
give up early on allocations that are way larger than the usual sysctl
values.

Fixes: ecad013df758 ("sysctl: pass kernel pointers to ->proc_handler")
Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/proc/proc_sysctl.c

index df2143e05c571e830f71640961a21b1e455fe311..08c33bd1642dcdc069ce35a668a119cd77228ca6 100644 (file)
@@ -564,6 +564,10 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *ubuf,
        if (!table->proc_handler)
                goto out;
 
+       /* don't even try if the size is too large */
+       if (count > KMALLOC_MAX_SIZE)
+               return -ENOMEM;
+
        if (write) {
                kbuf = memdup_user_nul(ubuf, count);
                if (IS_ERR(kbuf)) {