linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] proc_do_large_bitmap - return error on writes to non-existant bitmap
@ 2019-11-27  9:54 Maciej Żenczykowski
       [not found] ` <CAB=NE6Ufwg4mkF8Xu9tjajb=bp74pfPiMFYHRATszMqkS7sR0g@mail.gmail.com>
  2019-12-02 18:44 ` Iurii Zaikin
  0 siblings, 2 replies; 3+ messages in thread
From: Maciej Żenczykowski @ 2019-11-27  9:54 UTC (permalink / raw)
  To: Maciej Żenczykowski
  Cc: Luis Chamberlain, Kees Cook, Iurii Zaikin,
	Linux Kernel Mailing List, Linus FS Devel Mailing List

From: Maciej Żenczykowski <maze@google.com>

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 <mcgrof@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Iurii Zaikin <yzaikin@google.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Linus FS Devel Mailing List <linux-fsdevel@vger.kernel.org>
Signed-off-by: Maciej Żenczykowski <maze@google.com>
---
 kernel/sysctl.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 2c3958d2f463..431966967c99 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -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;
-- 
2.24.0.432.g9d3f5f5b63-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] proc_do_large_bitmap - return error on writes to non-existant bitmap
       [not found] ` <CAB=NE6Ufwg4mkF8Xu9tjajb=bp74pfPiMFYHRATszMqkS7sR0g@mail.gmail.com>
@ 2019-11-27 21:32   ` Iurii Zaikin
  0 siblings, 0 replies; 3+ messages in thread
From: Iurii Zaikin @ 2019-11-27 21:32 UTC (permalink / raw)
  To: Luis Chamberlain
  Cc: Maciej Żenczykowski, Maciej Żenczykowski, Kees Cook,
	Linux Kernel Mailing List, Linus FS Devel Mailing List

On Wed, Nov 27, 2019 at 4:44 AM Luis Chamberlain <mcgrof@kernel.org> wrote:
>
>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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] proc_do_large_bitmap - return error on writes to non-existant bitmap
  2019-11-27  9:54 [PATCH] proc_do_large_bitmap - return error on writes to non-existant bitmap Maciej Żenczykowski
       [not found] ` <CAB=NE6Ufwg4mkF8Xu9tjajb=bp74pfPiMFYHRATszMqkS7sR0g@mail.gmail.com>
@ 2019-12-02 18:44 ` Iurii Zaikin
  1 sibling, 0 replies; 3+ messages in thread
From: Iurii Zaikin @ 2019-12-02 18:44 UTC (permalink / raw)
  To: Maciej Żenczykowski
  Cc: Maciej Żenczykowski, Luis Chamberlain, Kees Cook,
	Linux Kernel Mailing List, Linus FS Devel Mailing List

On Wed, Nov 27, 2019 at 1:55 AM Maciej Żenczykowski
<zenczykowski@gmail.com> wrote:
> 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?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-02 18:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-27  9:54 [PATCH] proc_do_large_bitmap - return error on writes to non-existant bitmap Maciej Żenczykowski
     [not found] ` <CAB=NE6Ufwg4mkF8Xu9tjajb=bp74pfPiMFYHRATszMqkS7sR0g@mail.gmail.com>
2019-11-27 21:32   ` Iurii Zaikin
2019-12-02 18:44 ` Iurii Zaikin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).