From: Bastian Blank Subject: Re: [PATCH 4/7] allow killing tasks in your own or child userns Date: Mon, 10 Jan 2011 22:52:40 +0100 Message-ID: <20110110215240.GA21351@wavehammer.waldi.eu.org> References: <20110110211135.GA22446@mail.hallyn.com> <20110110211334.GD22564@mail.hallyn.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20110110211334.GD22564-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: "Serge E. Hallyn" Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, kernel list , LSM , "Eric W. Biederman" , Kees Cook , Alexey Dobriyan , Michael Kerrisk List-Id: containers.vger.kernel.org On Mon, Jan 10, 2011 at 09:13:34PM +0000, Serge E. Hallyn wrote: > + const struct cred *cred = current_cred(); > + const struct cred *tcred = __task_cred(t); > + > + if (cred->user->user_ns != tcred->user->user_ns) { > + /* userids are not equivalent - either you have the > + capability to the target user ns or you don't */ > + if (ns_capable(tcred->user->user_ns, CAP_KILL)) > + return 1; > + return 0; > + } > + > + /* same user namespace - usual credentials checks apply */ > + if ((cred->euid ^ tcred->suid) && > + (cred->euid ^ tcred->uid) && > + (cred->uid ^ tcred->suid) && > + (cred->uid ^ tcred->uid) && > + !ns_capable(tcred->user->user_ns, CAP_KILL)) > + return 0; > + > + return 1; Isn't that equal to this? if (ns_capable(tcred->user->user_ns, CAP_KILL)) return 1; if (cred->user->user_ns == tcred->user->user_ns && (cred->euid == tcred->suid || cred->euid == tcred->uid || cred->uid == tcred->suid || cred->uid == tcred->uid)) return 1; return 0; I would consider this much easier to read. Bastian -- I'm a soldier, not a diplomat. I can only tell the truth. -- Kirk, "Errand of Mercy", stardate 3198.9