From: Roland McGrath <roland@redhat.com>
To: Solar Designer <solar@openwall.com>
Cc: Kees Cook <kees.cook@canonical.com>,
linux-kernel@vger.kernel.org, oss-security@lists.openwall.com,
Al Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Neil Horman <nhorman@tuxdriver.com>,
linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] exec argument expansion can inappropriately trigger OOM-killer
Date: Mon, 30 Aug 2010 03:06:16 -0700 (PDT) [thread overview]
Message-ID: <20100830100616.78971400D9@magilla.sf.frob.com> (raw)
In-Reply-To: Solar Designer's message of Monday, 30 August 2010 07:23:31 +0400 <20100830032331.GA22773@openwall.com>
> IIRC, prior to that fix, I was able to cause the kernel to loop for tens
> of minutes in a single execve() call on an Alpha with 128 MB RAM, by
> using repeated mappings of the same pages (almost 200 GB total).
And I say, if your userland process could really allocate another 200GB,
then more power to you, you can do it with an exec too. If you could do
the same with a userland stack allocation, and spend all that time in
strlen calls and then memcpy, you can do it inside execve too. If it
takes days, that's what you asked for, and it's your process. It just
ought to be every bit (or near enough) as preemptible and interruptible
as that normal userland activity ought to be.
So, perhaps we want this (count already has a cond_resched in its loop):
diff --git a/fs/exec.c b/fs/exec.c
index 2d94552..0000000 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -369,6 +369,9 @@ static int count(const char __user * con
for (;;) {
const char __user * p;
+ if (signal_pending(current))
+ return -ERESTARTNOINTR;
+
if (get_user(p, argv))
return -EFAULT;
if (!p)
@@ -400,6 +403,10 @@ static int copy_strings(int argc, const
int len;
unsigned long pos;
+ if (signal_pending(current))
+ return -ERESTARTNOINTR;
+ cond_resched();
+
if (get_user(str, argv+argc) ||
!(len = strnlen_user(str, MAX_ARG_STRLEN))) {
ret = -EFAULT;
> Now it appears that, besides the issue that started this thread, the
> same problem I mentioned above got re-introduced. We still have
> strnlen_user() and the "max" argument to count(), but we no longer have
> hard limits for "max". Someone set MAX_ARG_STRINGS to 0x7FFFFFFF, and
> this is just too much. MAX_ARG_STRLEN is set to 32 pages, and these two
> combined allow a userspace program to make the kernel loop for days.
I really don't think we need that stuff back. I think we can get rid of
it and fix the real problems, and be happier overall.
> > But it sounds like all you really need is to fix the OOM/allocation
> > behavior for huge stack allocations.
>
> No, we need both.
I don't agree. If all of the implicit allocation done inside execve is
accounted and controlled as well as normal userland allocations so that
the execve fails when userland allocation would fail, then there is no
reason for special-case arbitrary limits.
> Additionally, 64bit_dos.c mentions that "it triggers a BUG() as the
> stack tries to expand around the address space when shifted". Perhaps
> limiting the stack size would deal with that, but maybe the "bug" needs
> to be patched elsewhere as well. grsecurity has the following hunk:
That change seems like it might be reasonable, but I haven't really
looked at shift_arg_pages before. Has someone reported this BUG_ON
failure mode with a reproducer?
> Overall, there are multiple issues here (maybe up to four?) and multiple
> things to review the code for.
Agreed. But IMHO the missing arbitrary limits on arg/env size are not
among them. I don't know about shift_arg_pages. The core fix I think
makes sense is making the nascent mm get accounted to the user process
normally. Rather than better enabling OOM killing, I think what really
makes sense is for the nascent mm to be marked such that allocations in
it (they'll be from get_arg_page->get_user_pages->handle_mm_fault) just
fail with ENOMEM before it resorts to the OOM killer (or perhaps even to
very aggressive pageout). That should percolate back to the execve just
failing with ENOMEM, which is nicer than OOM kill even if the OOM killer
actually does pick exactly and only the right target.
Thanks,
Roland
next prev parent reply other threads:[~2010-08-30 10:07 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-27 22:02 Kees Cook
2010-08-30 0:19 ` KOSAKI Motohiro
2010-08-30 0:56 ` Roland McGrath
2010-08-30 3:23 ` Solar Designer
2010-08-30 10:06 ` Roland McGrath [this message]
2010-08-30 19:48 ` Solar Designer
2010-08-31 0:40 ` Roland McGrath
2010-09-08 2:34 ` [PATCH 0/3] execve argument-copying fixes Roland McGrath
2010-09-08 2:35 ` [PATCH 1/3] setup_arg_pages: diagnose excessive argument size Roland McGrath
2010-09-08 8:29 ` pageexec
2010-09-10 8:59 ` Roland McGrath
2010-09-11 13:30 ` pageexec
2010-09-14 19:33 ` Roland McGrath
2010-09-14 22:35 ` pageexec
2010-09-08 11:57 ` Brad Spengler
2010-09-09 5:31 ` KOSAKI Motohiro
2010-09-10 9:25 ` Roland McGrath
2010-09-10 9:43 ` KOSAKI Motohiro
2010-09-11 13:39 ` pageexec
2010-09-14 18:51 ` Roland McGrath
2010-09-14 20:28 ` pageexec
2010-09-14 21:16 ` Roland McGrath
2010-09-14 22:27 ` pageexec
2010-09-14 23:04 ` Roland McGrath
2010-09-15 9:27 ` pageexec
2010-09-10 9:18 ` Roland McGrath
2010-09-08 2:36 ` [PATCH 2/3] execve: improve interactivity with large arguments Roland McGrath
2010-09-08 2:37 ` [PATCH 3/3] execve: make responsive to SIGKILL " Roland McGrath
2010-09-08 3:00 ` [PATCH 0/3] execve argument-copying fixes KOSAKI Motohiro
2010-09-09 5:01 ` [PATCH 0/2] execve memory exhaust of " KOSAKI Motohiro
2010-09-09 5:03 ` [PATCH 1/2] oom: don't ignore rss in nascent mm KOSAKI Motohiro
2010-09-09 22:05 ` Oleg Nesterov
2010-09-10 9:39 ` Roland McGrath
2010-09-10 9:57 ` [PATCH] move cred_guard_mutex from task_struct to signal_struct KOSAKI Motohiro
2010-09-10 17:24 ` Oleg Nesterov
2010-09-16 5:51 ` KOSAKI Motohiro
2010-09-09 5:04 ` [PATCH 2/2] execve: check the VM has enough memory at first KOSAKI Motohiro
2010-09-10 15:06 ` Linus Torvalds
2010-09-14 1:52 ` KOSAKI Motohiro
2010-09-16 5:51 ` KOSAKI Motohiro
2010-09-16 15:01 ` Linus Torvalds
2010-08-30 17:49 ` [PATCH] exec argument expansion can inappropriately trigger OOM-killer Solar Designer
2010-08-30 22:08 ` Brad Spengler
2010-08-31 11:53 ` Solar Designer
2010-08-31 11:56 ` [PATCH] exec argument expansion can inappropriately triggerOOM-killer Tetsuo Handa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100830100616.78971400D9@magilla.sf.frob.com \
--to=roland@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=kees.cook@canonical.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=oleg@redhat.com \
--cc=oss-security@lists.openwall.com \
--cc=solar@openwall.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®