Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1448686
| From | Josh Poimboeuf <jpoimboe@redhat.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v3 02/11] mm: Hardened usercopy |
| Date | 2016-07-22 19:50 +0200 |
| Message-ID | <rXMKe-r1-13@gated-at.bofh.it> (permalink) |
| References | <rVj9E-3EM-7@gated-at.bofh.it> <rVj9E-3EM-15@gated-at.bofh.it> <rXr34-2Nx-45@gated-at.bofh.it> <rXr34-2Nx-43@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Thu, Jul 21, 2016 at 11:34:25AM -0700, Kees Cook wrote:
> On Wed, Jul 20, 2016 at 11:52 PM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> > Kees Cook <keescook@chromium.org> writes:
> >
> >> diff --git a/mm/usercopy.c b/mm/usercopy.c
> >> new file mode 100644
> >> index 000000000000..e4bf4e7ccdf6
> >> --- /dev/null
> >> +++ b/mm/usercopy.c
> >> @@ -0,0 +1,234 @@
> > ...
> >> +
> >> +/*
> >> + * Checks if a given pointer and length is contained by the current
> >> + * stack frame (if possible).
> >> + *
> >> + * 0: not at all on the stack
> >> + * 1: fully within a valid stack frame
> >> + * 2: fully on the stack (when can't do frame-checking)
> >> + * -1: error condition (invalid stack position or bad stack frame)
> >> + */
> >> +static noinline int check_stack_object(const void *obj, unsigned long len)
> >> +{
> >> + const void * const stack = task_stack_page(current);
> >> + const void * const stackend = stack + THREAD_SIZE;
> >
> > That allows access to the entire stack, including the struct thread_info,
> > is that what we want - it seems dangerous? Or did I miss a check
> > somewhere else?
>
> That seems like a nice improvement to make, yeah.
>
> > We have end_of_stack() which computes the end of the stack taking
> > thread_info into account (end being the opposite of your end above).
>
> Amusingly, the object_is_on_stack() check in sched.h doesn't take
> thread_info into account either. :P Regardless, I think using
> end_of_stack() may not be best. To tighten the check, I think we could
> add this after checking that the object is on the stack:
>
> #ifdef CONFIG_STACK_GROWSUP
> stackend -= sizeof(struct thread_info);
> #else
> stack += sizeof(struct thread_info);
> #endif
>
> e.g. then if the pointer was in the thread_info, the second test would
> fail, triggering the protection.
FWIW, this won't work right on x86 after Andy's
CONFIG_THREAD_INFO_IN_TASK patches get merged.
--
Josh
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-15 23:50 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Laura Abbott <labbott@redhat.com> - 2016-07-19 03:10 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-19 20:50 +0200
[PATCH] mm: Add is_migrate_cma_page Laura Abbott <labbott@redhat.com> - 2016-07-20 00:10 +0200
Re: [PATCH] mm: Add is_migrate_cma_page Kees Cook <keescook@chromium.org> - 2016-07-20 00:50 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Balbir Singh <bsingharora@gmail.com> - 2016-07-20 12:30 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Laura Abbott <labbott@redhat.com> - 2016-07-20 17:40 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Laura Abbott <labbott@redhat.com> - 2016-07-19 04:00 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-19 21:20 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-20 01:00 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Christian Borntraeger <borntraeger@de.ibm.com> - 2016-07-19 11:30 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-19 21:40 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Christian Borntraeger <borntraeger@de.ibm.com> - 2016-07-19 22:20 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-19 22:40 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Christian Borntraeger <borntraeger@de.ibm.com> - 2016-07-19 22:50 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Kees Cook <keescook@chromium.org> - 2016-07-21 20:40 +0200
Re: [PATCH v3 02/11] mm: Hardened usercopy Josh Poimboeuf <jpoimboe@redhat.com> - 2016-07-22 19:50 +0200
RE: [PATCH v3 02/11] mm: Hardened usercopy David Laight <David.Laight@ACULAB.COM> - 2016-07-25 11:30 +0200
csiph-web