From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Smalley Subject: Re: [kernel-hardening] Re: [PATCH] move RLIMIT_NPROC check from set_user() to do_execve_common() Date: Fri, 15 Jul 2011 09:58:33 -0400 Message-ID: <1310738313.30257.27.camel@moss-pluto> References: <20110713091408.0d456352@notabene.brown> <20110713063142.GA19976@openwall.com> <20110713170657.59dae548@notabene.brown> <20110714112751.1bfd998f@notabene.brown> <20110714150602.GA30019@openwall.com> <20110715133013.4fa38d19@notabene.brown> <20110715063113.GA3166@albatros> <20110715170650.585f1dad@notabene.brown> <20110715073823.GA3821@albatros> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: NeilBrown , kernel-hardening@lists.openwall.com, Solar Designer , James Morris , Linus Torvalds , linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Andrew Morton , "David S. Miller" , Jiri Slaby , Alexander Viro , linux-fsdevel@vger.kernel.org, KOSAKI Motohiro , Eric Paris , Willy Tarreau , Sebastian Krahmer To: Vasiliy Kulikov Return-path: In-Reply-To: <20110715073823.GA3821@albatros> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org On Fri, 2011-07-15 at 11:38 +0400, Vasiliy Kulikov wrote: > Neil, > > On Fri, Jul 15, 2011 at 17:06 +1000, NeilBrown wrote: > > How about this then? > > AFAIU, with this patch: > > 1) setuid() doesn't fail in NPROC exceed case. > 2) NPROC is forced on execve() after setuid(). > 3) execve() fails only if NPROC was exceeded during setuid() execution. > 4) Other processes of the same user doesn't suffer from "occasional" > execve() failures. > > If it is correct, then I like the patch :) It does RLIMIT_NPROC > enforcement without mixing other execve() calls like -ow patch did. Does this have implications for Android's zygote model? There you have a long running uid 0 / all caps process (the zygote), which forks itself upon receiving a request to spawn an app and then calls setgroups(); setrlimit(); setgid(); setuid(); assuming the limits and credentials of the app but never does an exec at all, as it is just loading the app's class and executing it from memory. Also, can't setuid() fail under other conditions, e.g. ENOMEM upon prepare_creds() allocation failure? Is it ever reasonable for a program to not check setuid() for failure? Certainly there are plenty of examples of programs not doing that, but it isn't clear that this is a bug in the kernel. -- Stephen Smalley National Security Agency