Skip to contentSkip to conversation

two more fixes for sysctl

PATCH New Christoph Hellwig 3 participants 5 messages Jun 9, 2020 – Jun 10, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi Al,

two more fixes for the kernel pointers in the sysctl handlers.

#1 lore raw

PATCH 1/2 cdrom: fix an incorrect __user annotation on cdrom_sysctl_info

No user pointers for sysctls anymore.

Fixes 32927393dc1c ("sysctl: pass kernel pointers to ->proc_handler")
---
 drivers/cdrom/cdrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cdrom/cdrom.c +1 -1
index e3bbe108eb542f..410060812e9dbf 100644
@@ -3518,7 +3518,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
 }
 
 static int cdrom_sysctl_info(struct ctl_table *ctl, int write,
-                           void __user *buffer, size_t *lenp, loff_t *ppos)
+                           void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int pos;
 	char *info = cdrom_sysctl_settings.info;
Signature · 1 line
2.26.2
#2 lore raw

PATCH 2/2 sysctl: reject gigantic reads/write to sysctl files

In reply to Christoph Hellwig

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")
---
 fs/proc/proc_sysctl.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/proc/proc_sysctl.c +4 -0
index df2143e05c571e..08c33bd1642dcd 100644
@@ -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)) {
Signature · 1 line
2.26.2
maintainer
#4 lore raw
In reply to Christoph Hellwig
Quoted 3 lines · Christoph Hellwig

Hi Al,

two more fixes for the kernel pointers in the sysctl handlers.

Applied and pushed. Let me beat it up a bit, if it survives - to Linus it goes...