Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-12 Thread Alan Cox
> (a) minimal: just use our existing default stack (and stack _only_) > limit value for suid binaries that actually get extra permissions: { > _STK_LIM, RLIM_INFINITY }. Even that is dangerous because a setuid binary can be transitioning between two users (none privileged) yet be subject to an rl

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Rik van Riel
On Mon, 2017-07-10 at 20:16 +0200, Michal Hocko wrote: > OK, I misread the code. 32b applications on 64b systems do top down > by > default and only if they override this by ADDR_COMPAT_LAYOUT > personality. For some reason I thought that 32b userspace goes a > different path and makes sure that t

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Michal Hocko
On Mon 10-07-17 18:27:51, Michal Hocko wrote: > On Mon 10-07-17 09:12:11, Kees Cook wrote: [...] > > >> do_execveat_common() -> > > >> exec_binprm() -> > > >> search_binary_handler() -> > > >> fmt->load_binary (load_elf_binary()) -> > > >> setup_new_exec() -> > > >> arch_pick_mmap_layout() -> > > >

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Willy Tarreau
On Mon, Jul 10, 2017 at 09:18:09AM -0700, Linus Torvalds wrote: > On Mon, Jul 10, 2017 at 9:12 AM, Kees Cook wrote: > > > > Sounds good to me, but won't large-memory users in 32-bit get annoyed? > > We'll see. > > I suspect that all large-memory users have long since upgraded to > x86-64 (rule o

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Michal Hocko
On Mon 10-07-17 09:12:11, Kees Cook wrote: > On Mon, Jul 10, 2017 at 1:44 AM, Michal Hocko wrote: > > On Thu 06-07-17 12:12:55, Kees Cook wrote: > >> On Thu, Jul 6, 2017 at 10:52 AM, Linus Torvalds > >> wrote: > >> > On Thu, Jul 6, 2017 at 10:29 AM, Kees Cook wrote: > >> >>> > >> >>> (a) minima

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Linus Torvalds
On Mon, Jul 10, 2017 at 9:12 AM, Kees Cook wrote: > > Sounds good to me, but won't large-memory users in 32-bit get annoyed? We'll see. I suspect that all large-memory users have long since upgraded to x86-64 (rule of thumb: if you are upgrading kernels today, you probably upgraded hardware ten

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Kees Cook
On Mon, Jul 10, 2017 at 1:44 AM, Michal Hocko wrote: > On Thu 06-07-17 12:12:55, Kees Cook wrote: >> On Thu, Jul 6, 2017 at 10:52 AM, Linus Torvalds >> wrote: >> > On Thu, Jul 6, 2017 at 10:29 AM, Kees Cook wrote: >> >>> >> >>> (a) minimal: just use our existing default stack (and stack _only_)

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-10 Thread Michal Hocko
On Thu 06-07-17 12:12:55, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:52 AM, Linus Torvalds > wrote: > > On Thu, Jul 6, 2017 at 10:29 AM, Kees Cook wrote: > >>> > >>> (a) minimal: just use our existing default stack (and stack _only_) > >>> limit value for suid binaries that actually get extra

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-07 Thread Kees Cook
On Fri, Jul 7, 2017 at 9:06 AM, Linus Torvalds wrote: > On Thu, Jul 6, 2017 at 11:10 PM, Kees Cook wrote: >> On Thu, Jul 6, 2017 at 11:02 PM, Linus Torvalds >> wrote: >>> So 2+MB is still definitely something people can do (and probably *do* do). >> >> With the default 8MB stack, most people are

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-07 Thread Kees Cook
On Fri, Jul 7, 2017 at 9:22 AM, Linus Torvalds wrote: > On Thu, Jul 6, 2017 at 11:40 PM, Kees Cook wrote: > So I definitely like this approach, as long as we clarify that crazy > security_bprm_secureexec() model. That code really is insane. Yeah, it really seems like security_bprm_secureexec() s

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-07 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 11:40 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:49 PM, Kees Cook wrote: > > At Andy's suggestion I'm using security_bprm_secureexec() to test for > setuid-ness. However, this seems to expect the credentials to have > already been installed. That function actually ta

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-07 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 11:10 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 11:02 PM, Linus Torvalds > wrote: >> So 2+MB is still definitely something people can do (and probably *do* do). > > With the default 8MB stack, most people are already limited to 2MB > here. I guess the question is, do pe

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-07 Thread Andy Lutomirski
On Thu, Jul 6, 2017 at 10:45 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:36 PM, Andy Lutomirski wrote: >> Aren't there real use cases that use many megs of arguments? > > They'd be relatively new since the args were pretty limited before. > I'd be curious to see them. > >> We could probably

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 10:49 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:39 PM, Linus Torvalds >> And I think the credentials switch (which is the point of no return >> anyway) happens before we start mmap'ing the executable etc. We used >> to have some odd code there and do it in the complet

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 11:02 PM, Linus Torvalds wrote: > So 2+MB is still definitely something people can do (and probably *do* do). With the default 8MB stack, most people are already limited to 2MB here. I guess the question is, do people raise their stack rlimit to gain more arguments? Should

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 10:45 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:36 PM, Andy Lutomirski wrote: >> >> Aren't there real use cases that use many megs of arguments? > > They'd be relatively new since the args were pretty limited before. > I'd be curious to see them. "megs" yes. "many m

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 10:39 PM, Linus Torvalds wrote: > On Thu, Jul 6, 2017 at 10:15 PM, Kees Cook wrote: >> >> I always say this backwards. :P Default is top-down (allocate at high >> addresses and work down toward low). With unlimited stack, allocations >> start at low addresses and work up. H

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 10:36 PM, Andy Lutomirski wrote: > On Thu, Jul 6, 2017 at 10:15 PM, Kees Cook wrote: >> On Thu, Jul 6, 2017 at 10:10 PM, Kees Cook wrote: >>> On Thu, Jul 6, 2017 at 9:48 PM, Andy Lutomirski wrote: How about a much simpler solution: don't read rlimit at all in co

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 10:15 PM, Kees Cook wrote: > > I always say this backwards. :P Default is top-down (allocate at high > addresses and work down toward low). With unlimited stack, allocations > start at low addresses and work up. Here's the results (shown with > randomize_va_space sysctl set

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Andy Lutomirski
On Thu, Jul 6, 2017 at 10:15 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:10 PM, Kees Cook wrote: >> On Thu, Jul 6, 2017 at 9:48 PM, Andy Lutomirski wrote: >>> How about a much simpler solution: don't read rlimit at all in >>> copy_strings(), let alone try to enforce it. Instead, just befor

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 10:10 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 9:48 PM, Andy Lutomirski wrote: >> How about a much simpler solution: don't read rlimit at all in >> copy_strings(), let alone try to enforce it. Instead, just before the >> point of no return, check how much stack space

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 9:48 PM, Andy Lutomirski wrote: > How about a much simpler solution: don't read rlimit at all in > copy_strings(), let alone try to enforce it. Instead, just before the > point of no return, check how much stack space is already used and, if > it's more than an appropriate

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 9:48 PM, Andy Lutomirski wrote: > > How about a much simpler solution: don't read rlimit at all in > copy_strings(), let alone try to enforce it. People have historically relied on E2BIG and then splitting things into multiple chunks (ie do the whole 'xargs' thing). But I

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Andy Lutomirski
On Thu, Jul 6, 2017 at 12:12 PM, Kees Cook wrote: > On Thu, Jul 6, 2017 at 10:52 AM, Linus Torvalds > wrote: >> On Thu, Jul 6, 2017 at 10:29 AM, Kees Cook wrote: (a) minimal: just use our existing default stack (and stack _only_) limit value for suid binaries that actually get ex

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 10:52 AM, Linus Torvalds wrote: > On Thu, Jul 6, 2017 at 10:29 AM, Kees Cook wrote: >>> >>> (a) minimal: just use our existing default stack (and stack _only_) >>> limit value for suid binaries that actually get extra permissions: { >>> _STK_LIM, RLIM_INFINITY }. >> >> Thi

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 10:29 AM, Kees Cook wrote: >> >> (a) minimal: just use our existing default stack (and stack _only_) >> limit value for suid binaries that actually get extra permissions: { >> _STK_LIM, RLIM_INFINITY }. > > This would look a lot like the existing patch; it'd just not copy t

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Kees Cook
On Thu, Jul 6, 2017 at 9:34 AM, Linus Torvalds wrote: > On Wed, Jul 5, 2017 at 9:32 PM, Kees Cook wrote: >> In an attempt to provide sensible rlimit defaults for setuid execs, this >> inherits the namespace's init rlimits: > > Yeah, so I have to admit to hating this patch. Yup! Totally fine. I j

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Linus Torvalds
On Thu, Jul 6, 2017 at 9:34 AM, Linus Torvalds wrote: > > (a) minimal: just use our existing default stack (and stack _only_) > limit value for suid binaries that actually get extra permissions: { > _STK_LIM, RLIM_INFINITY }. > > (c) perhaps encourage people to annotate their suid binaries with

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Linus Torvalds
On Wed, Jul 5, 2017 at 9:32 PM, Kees Cook wrote: > In an attempt to provide sensible rlimit defaults for setuid execs, this > inherits the namespace's init rlimits: Yeah, so I have to admit to hating this patch. As already mentioned by others, it's not only not clear that we want to do this on e

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Andy Lutomirski
On Thu, Jul 6, 2017 at 5:38 AM, Eric W. Biederman wrote: > Kees Cook writes: > >> In an attempt to provide sensible rlimit defaults for setuid execs, this >> inherits the namespace's init rlimits: >> >> $ ulimit -s >> 8192 >> $ ulimit -s unlimited >> $ /bin/sh -c 'ulimit -s' >> unlimited >> $ sud

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Andy Lutomirski
On Thu, Jul 6, 2017 at 5:45 AM, Eric W. Biederman wrote: > > How this is handled elsewhere in the code is to put the new values in > bprm. Putting new rlimits in bprm and changing them in flush_old_exec > or or setup_new_exec seems very sensible. It also allows for them to be > accessed before de

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Eric W. Biederman
Andy Lutomirski writes: > On Wed, Jul 5, 2017 at 9:32 PM, Kees Cook wrote: >> In an attempt to provide sensible rlimit defaults for setuid execs, this >> inherits the namespace's init rlimits: >> >> $ ulimit -s >> 8192 >> $ ulimit -s unlimited >> $ /bin/sh -c 'ulimit -s' >> unlimited >> $ sudo /

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-06 Thread Eric W. Biederman
Kees Cook writes: > In an attempt to provide sensible rlimit defaults for setuid execs, this > inherits the namespace's init rlimits: > > $ ulimit -s > 8192 > $ ulimit -s unlimited > $ /bin/sh -c 'ulimit -s' > unlimited > $ sudo /bin/sh -c 'ulimit -s' > 8192 > > This is modified from Brad Spengle

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-05 Thread Willy Tarreau
On Wed, Jul 05, 2017 at 09:32:35PM -0700, Kees Cook wrote: > In an attempt to provide sensible rlimit defaults for setuid execs, this > inherits the namespace's init rlimits: > > $ ulimit -s > 8192 > $ ulimit -s unlimited > $ /bin/sh -c 'ulimit -s' > unlimited > $ sudo /bin/sh -c 'ulimit -s' > 819

Re: [RFC][PATCH] exec: Use init rlimits for setuid exec

2017-07-05 Thread Andy Lutomirski
On Wed, Jul 5, 2017 at 9:32 PM, Kees Cook wrote: > In an attempt to provide sensible rlimit defaults for setuid execs, this > inherits the namespace's init rlimits: > > $ ulimit -s > 8192 > $ ulimit -s unlimited > $ /bin/sh -c 'ulimit -s' > unlimited > $ sudo /bin/sh -c 'ulimit -s' > 8192 > > This