Skip to contentSkip to conversation

proc_do_large_bitmap - return error on writes to non-existant bitmap

PATCH In review Maciej Żenczykowski 2 participants 3 messages Nov 27, 2019 – Dec 2, 2019 1 message not in the archive

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

PATCH 1/1 proc_do_large_bitmap - return error on writes to non-existant bitmap

From: Maciej Żenczykowski <[email protected]>

Writing to an unallocated bitmap (with echo) results in an infinite loop - although I'm not clear if this is in kernel or in userspace.

We return ENOMEDIUM 'No medium found', because it's the best error I could come up with to describe the situation.

(Note: I'm not aware of any actual way to hit this with current kernel code, I hit this while testing new code, but it still seems like it should be fixed, especially since it prevented my machine from booting, and didn't even have the dignity to crash...)

Cc Luis Chamberlain <[email protected]>
Cc Kees Cook <[email protected]>
Cc Iurii Zaikin <[email protected]>
Cc Linux Kernel Mailing List <[email protected]>
Cc Linus FS Devel Mailing List <[email protected]>
---
 kernel/sysctl.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/sysctl.c +5 -0
index 2c3958d2f463..431966967c99 100644
@@ -3174,6 +3174,11 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
 	unsigned long *tmp_bitmap = NULL;
 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
 
+	if (write && (!bitmap || !bitmap_len))
+		/* returning 0 could cause an infinite loop */
+		return -ENOMEDIUM;
+	}
+
 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
 		*lenp = 0;
 		return 0;
Signature · 1 line
2.24.0.432.g9d3f5f5b63-goog
#2 lore raw
In reply to a message not in the archive
Quoted 2 lines · Luis Chamberlain

Can you also extend the tools/testing/selftests/sysctl and respectful lib/test_sysctl.c if needed with a test to cover this case or other cases you can think of to trigger this issue?

+1

#3 lore raw
In reply to Maciej Żenczykowski
Quoted 2 lines · Maciej Żenczykowski

We return ENOMEDIUM 'No medium found', because it's the best error I could come up with to describe the situation.

EFAULT for bitmap == NULL and
EINVAL for bitmap_len == 0?