path: root/fs/proc/proc_sysctl.c
diff options
authorChristoph Hellwig <>2020-06-09 19:08:19 +0200
committerAl Viro <>2020-06-10 14:11:33 -0400
commitef9d965bc8b6fce5bcc0ae76a4a5b3ed91ee81eb (patch)
treeb8c9350abed0e245cbda54b026158f78a977cbe0 /fs/proc/proc_sysctl.c
parent8c46fa96822c28ca81036e26c2d963f1fac9a961 (diff)
sysctl: reject gigantic reads/write to sysctl files
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: 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler") Reported-by: Vegard Nossum <> Signed-off-by: Christoph Hellwig <> Signed-off-by: Al Viro <>
Diffstat (limited to 'fs/proc/proc_sysctl.c')
1 files changed, 4 insertions, 0 deletions
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index df2143e05c57..08c33bd1642d 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -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)) {