From: Oleg Nesterov <oleg@redhat.com>
To: Christian Brauner <christian.brauner@ubuntu.com>
Cc: linux-kernel@vger.kernel.org, Florian Weimer <fweimer@redhat.com>,
GNU C Library <libc-alpha@sourceware.org>,
Arnd Bergmann <arnd@arndb.de>, Kees Cook <keescook@chromium.org>,
Jann Horn <jannh@google.com>, David Howells <dhowells@redhat.com>,
Ingo Molnar <mingo@redhat.com>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
linux-api@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] clone3: validate stack arguments
Date: Fri, 1 Nov 2019 13:32:57 +0100 [thread overview]
Message-ID: <20191101123257.GA508@redhat.com> (raw)
In-Reply-To: <20191101110639.icbfihw3fk2nzz4o@wittgenstein>
On 11/01, Christian Brauner wrote:
>
> On Thu, Oct 31, 2019 at 05:46:53PM +0100, Oleg Nesterov wrote:
> > On 10/31, Christian Brauner wrote:
> > >
> > > --- a/include/uapi/linux/sched.h
> > > +++ b/include/uapi/linux/sched.h
> > > @@ -51,6 +51,10 @@
> > > * sent when the child exits.
> > > * @stack: Specify the location of the stack for the
> > > * child process.
> > > + * Note, @stack is expected to point to the
> > > + * lowest address. The stack direction will be
> > > + * determined by the kernel and set up
> > > + * appropriately based on @stack_size.
> >
> > I can't review this patch, I have no idea what does stack_size mean
> > if !arch/x86.
>
> In short: nothing at all if it weren't for ia64 (and maybe parisc).
> But let me provide some (hopefully useful) context.
Thanks...
> (Probably most of
> that is well-know,
Certainly not to me ;) Thanks.
> > > +static inline bool clone3_stack_valid(struct kernel_clone_args *kargs)
> > > +{
> > > + if (kargs->stack == 0) {
> > > + if (kargs->stack_size > 0)
> > > + return false;
> > > + } else {
> > > + if (kargs->stack_size == 0)
> > > + return false;
> >
> > So to implement clone3_wrapper(void *bottom_of_stack) you need to do
> >
> > clone3_wrapper(void *bottom_of_stack)
> > {
> > struct clone_args args = {
> > ...
> > // make clone3_stack_valid() happy
> > .stack = bottom_of_stack - 1,
> > .stack_size = 1,
> > };
> > }
> >
> > looks a bit strange. OK, I agree, this example is very artificial.
> > But why do you think clone3() should nack stack_size == 0 ?
>
> In short, consistency.
And in my opinion this stack_size == 0 check destroys the consistency,
see below.
But just in case, let me say that overall I personally like this change.
> The best thing imho, is to clearly communicate to userspace that stack
> needs to point to the lowest address and stack_size to the initial range
> of the stack pointer
Agreed.
But the kernel can't verify that "stack" actually points to the lowest
address and stack_size is actually the stack size. Consider another
artificial
clone3_wrapper(void *bottom_of_stack, unsigned long offs)
{
struct clone_args args = {
...
// make clone3_stack_valid() happy
.stack = bottom_of_stack - offs,
.stack_size = offs,
};
sys_clone3(args);
}
Now,
clone3_wrapper(bottom_of_stack, offs);
is same thing for _any_ offs except offs == 0 will fail. Why? To me this
is not consistent, I think the "stack_size == 0" check buys nothing and
only adds some confusion.
Say, stack_size == 1 is "obviously wrong" too, this certainly means that
"stack" doesn't point to the lowest address (or the child will corrupt the
memory), but it works.
OK, I won't insist. Perhaps it can help to detect the case when a user
forgets to pass the correct stack size.
> > > + if (!access_ok((void __user *)kargs->stack, kargs->stack_size))
> > > + return false;
> >
> > Why?
>
> It's nice of us to tell userspace _before_ we have created a thread that
> it messed up its parameters instead of starting a thread that then
> immediately crashes.
Heh. Then why this code doesn't verify that at least stack + stack_size is
properly mmaped with PROT_READ|WRITE?
Oleg.
next prev parent reply other threads:[~2019-11-01 12:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-31 11:36 [PATCH] clone3: validate stack arguments Christian Brauner
2019-10-31 11:41 ` David Laight
2019-10-31 13:59 ` Aleksa Sarai
2019-10-31 14:27 ` David Laight
2019-10-31 16:46 ` Oleg Nesterov
2019-11-01 11:06 ` Christian Brauner
2019-11-01 12:32 ` Oleg Nesterov [this message]
2019-11-01 14:40 ` Christian Brauner
2019-11-01 14:57 ` Szabolcs Nagy
2019-11-01 15:10 ` Christian Brauner
2019-11-05 14:23 ` Arnd Bergmann
2019-11-05 20:23 ` Michael Kerrisk (man-pages)
[not found] ` <20191031124037.E26AF20650@mail.kernel.org>
2019-11-06 2:18 ` Christian Brauner
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=20191101123257.GA508@redhat.com \
--to=oleg@redhat.com \
--cc=arnd@arndb.de \
--cc=christian.brauner@ubuntu.com \
--cc=dhowells@redhat.com \
--cc=fweimer@redhat.com \
--cc=jannh@google.com \
--cc=keescook@chromium.org \
--cc=libc-alpha@sourceware.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=stable@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/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;
as well as URLs for NNTP newsgroup(s).