diff mbox series

[2/2] sysctl: reject gigantic reads/write to sysctl files

Message ID 20200609170819.52353-3-hch@lst.de (mailing list archive)
State New, archived
Headers show
Series [1/2] cdrom: fix an incorrect __user annotation on cdrom_sysctl_info | expand

Commit Message

Christoph Hellwig June 9, 2020, 5:08 p.m. UTC
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

Fixes: 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")
Reported-by: Vegard Nossum <vegard.nossum@oracle.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
 fs/proc/proc_sysctl.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series


diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index df2143e05c571e..08c33bd1642dcd 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)) {