linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lukasz Pawelczyk <l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
To: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
Cc: linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Eric Dumazet <edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	Ingo Molnar <mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Jonathan Corbet <corbet-T1hC0tSOHrs@public.gmane.org>,
	Ionut Alexa
	<ionut.m.alexa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Lukasz Pawelczyk <havner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Christoph Hellwig <hch-jcswGhMUV9g@public.gmane.org>,
	Jeff Layton <jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org>,
	Stephen Smalley <sds-+05T5uksL2qpZYMLLGbcSA@public.gmane.org>,
	Alexey Dobriyan
	<adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Rik van Riel <riel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
	Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Mauro Carvalho Chehab
	<mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>,
	Fabian Frederick <fabf-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org>,
	Casey Schaufler <casey-iSGtlc1asvQWG2LlvL+J4A@public.gmane.org>,
	Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>,
	James Morris
	<james.l.morris-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>,
	"Kirill A. Shutemov"
	<kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org>,
	Michal Hocko <mhocko-AlSwsSmVLrQ@public.gmane.org>,
	Peter Hurley
	<peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>,
	Rafal Krypa <r.krypa-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Greg KH
	<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>co
Subject: Re: [PATCH 1/8] kernel/exit.c: make sure current's nsproxy != NULL while checking caps
Date: Mon, 25 May 2015 13:33:18 +0200	[thread overview]
Message-ID: <1432553598.1781.4.camel@samsung.com> (raw)
In-Reply-To: <878ucf2nh4.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>

On sob, 2015-05-23 at 12:49 -0500, Eric W. Biederman wrote:
> Lukasz Pawelczyk <l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org> writes:
> 
> > There is a rare case where current's nsproxy might be NULL but we are
> > required to check for credentials and capabilities. It sometimes happens
> > during an exit_group() syscall while destroying user's session (logging
> > out).
> >
> > My understanding is that while we have to lock the task to get task's
> > nsproxy and check whether it's NULL, for the 'current' we don't have to
> > and it's expected not to be NULL. There is a code in the kernel
> > currently that does current->nsproxy->user_ns without any checks.
> > And include/linux/nsproxy.h confirms that:
> >
> > 2. when accessing (i.e. reading) current task's namespaces - no
> >    precautions should be taken - just dereference the pointers
> >
> > There seem to be no crash currently because of this, but with accessing
> > nsproxy from LSM hooks there is. This is the backtrace:
> >
> > 0  smk_tskacc (task=0xffff88003b0b92e0, obj_known=0x2 <irq_stack_union+2>, mode=2, a=0xffff88003be53dd8) at security/smack/smack_access.c:261
> > 1  0xffffffff8130e2aa in smk_curacc (obj_known=<optimized out>, mode=<optimized out>, a=<optimized out>) at security/smack/smack_access.c:318
> > 2  0xffffffff8130a50d in smack_task_kill (p=0xffff88003b0b92e0, info=<optimized out>, sig=<optimized out>, secid=<optimized out>) at security/smack/smack_lsm.c:2071
> > 3  0xffffffff812ea4f6 in security_task_kill (p=<optimized out>, info=<optimized out>, sig=<optimized out>, secid=<optimized out>) at security/security.c:952
> > 4  0xffffffff8109ac80 in check_kill_permission (sig=15, info=0x0 <irq_stack_union>, t=0xffff88003b0b8000) at kernel/signal.c:796
> > 5  0xffffffff8109d3ab in group_send_sig_info (sig=15, info=0x0 <irq_stack_union>, p=0xffff88003b0b8000) at kernel/signal.c:1296
> > 6  0xffffffff8108e527 in forget_original_parent (father=<optimized out>) at kernel/exit.c:575
> > 7  exit_notify (group_dead=<optimized out>, tsk=<optimized out>) at kernel/exit.c:606
> > 8  do_exit (code=<optimized out>) at kernel/exit.c:775
> > 9  0xffffffff8108ec0f in do_group_exit (exit_code=0) at kernel/exit.c:891
> > 10 0xffffffff8108ec84 in SYSC_exit_group (error_code=<optimized out>) at kernel/exit.c:902
> > 11 SyS_exit_group (error_code=<optimized out>) at kernel/exit.c:900
> >
> > This backtrace clearly shows that there is an LSM hook task_kill() that
> > happens during an exit_group() syscall and that this happens after
> > exit_task_namespaces(). LSM hooks with namespaces might need nsproxy to
> > be able to check for capabilities. At this point this is impossible. The
> > current's nsproxy is already NULL/destroyed.
> >
> > This is the case because exit_task_namespaces() is called before the
> > exit_notify() where all of the above happens. This patch changes their
> > order.
> 
> Nacked-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
> 
> current->nsproxy->user_ns does not exist,
> and changing where exit_task_namespaces is fragile and I am really not
> interested in messing with it right now, to solve a problem that does
> not exist.

I must have missed the moment where current->nsproxy->user_ns was
removed. I obviously even don't use it in my patches anymore (replaced
with cred->user_ns).

Back when I started to write my patches and wanted to use
current->nsproxy->user_ns in LSM hooks the problem was real.

Fortunately current->cred->user_ns does not exhibit the same issue. I'll
drop this patch.

Sorry for the confusion.


> 
> >
> > Signed-off-by: Lukasz Pawelczyk <l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> > ---
> >  kernel/exit.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/exit.c b/kernel/exit.c
> > index 22fcc05..da1bb18 100644
> > --- a/kernel/exit.c
> > +++ b/kernel/exit.c
> > @@ -742,7 +742,6 @@ void do_exit(long code)
> >  	exit_fs(tsk);
> >  	if (group_dead)
> >  		disassociate_ctty(1);
> > -	exit_task_namespaces(tsk);
> >  	exit_task_work(tsk);
> >  	exit_thread();
> >  
> > @@ -763,6 +762,13 @@ void do_exit(long code)
> >  
> >  	TASKS_RCU(tasks_rcu_i = __srcu_read_lock(&tasks_rcu_exit_srcu));
> >  	exit_notify(tsk, group_dead);
> > +
> > +	/*
> > +	 * This should be after all things that potentially require
> > +	 * process's namespaces (e.g. capability checks).
> > +	 */
> > +	exit_task_namespaces(tsk);
> > +
> >  	proc_exit_connector(tsk);
> >  #ifdef CONFIG_NUMA
> >  	task_lock(tsk);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Lukasz Pawelczyk
Samsung R&D Institute Poland
Samsung Electronics

  parent reply	other threads:[~2015-05-25 11:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1432209222-8479-1-git-send-email-l.pawelczyk@samsung.com>
     [not found] ` <1432209222-8479-1-git-send-email-l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-21 11:53   ` [PATCH 1/8] kernel/exit.c: make sure current's nsproxy != NULL while checking caps Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 2/8] user_ns: 3 new hooks for LSM namespace operations Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 3/8] smack: extend capability functions and fix 2 checks Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 4/8] smack: abstraction layer for 2 common Smack operations Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 5/8] smack: misc cleanups in preparation for a namespace patch Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 6/8] smack: namespace groundwork Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 7/8] smack: namespace implementation Lukasz Pawelczyk
2015-05-21 11:53   ` [PATCH 8/8] smack: documentation for the Smack namespace Lukasz Pawelczyk
2015-05-25 12:32   ` [PATCH v2 0/7] " Lukasz Pawelczyk
     [not found] ` <1432209222-8479-2-git-send-email-l.pawelczyk@samsung.com>
     [not found]   ` <1432209222-8479-2-git-send-email-l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-23 17:49     ` [PATCH 1/8] kernel/exit.c: make sure current's nsproxy != NULL while checking caps Eric W. Biederman
     [not found]       ` <878ucf2nh4.fsf-JOvCrm2gF+uungPnsOpG7nhyD016LWXt@public.gmane.org>
2015-05-25 11:33         ` Lukasz Pawelczyk [this message]
     [not found] ` <1432557162-19123-1-git-send-email-l.pawelczyk@samsung.com>
     [not found]   ` <1432557162-19123-1-git-send-email-l.pawelczyk-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2015-05-25 12:32     ` [PATCH v2 1/7] user_ns: 3 new hooks for user namespace operations Lukasz Pawelczyk
2015-05-25 12:32     ` [PATCH v2 2/7] smack: extend capability functions and fix 2 checks Lukasz Pawelczyk
2015-05-25 12:32     ` [PATCH v2 3/7] smack: abstraction layer for 2 common Smack operations Lukasz Pawelczyk
2015-05-25 12:32     ` [PATCH v2 4/7] smack: misc cleanups in preparation for a namespace patch Lukasz Pawelczyk
2015-05-25 12:32     ` [PATCH v2 5/7] smack: namespace groundwork Lukasz Pawelczyk
2015-05-25 12:32     ` [PATCH v2 6/7] smack: namespace implementation Lukasz Pawelczyk
2015-05-25 12:32     ` [PATCH v2 7/7] smack: documentation for the Smack namespace Lukasz Pawelczyk
2015-05-26 14:35     ` [PATCH v2 0/7] " Stephen Smalley
2015-05-27  1:04     ` Casey Schaufler
2015-05-27  3:13     ` Eric W. Biederman
2015-05-27 10:13       ` Lukasz Pawelczyk
2015-05-27 15:12         ` Eric W. Biederman
2015-05-27 17:15           ` Lukasz Pawelczyk
     [not found]   ` <55651823.10304@schaufler-ca.com>
2015-05-27  9:29     ` Lukasz Pawelczyk
2015-05-27 13:05       ` Casey Schaufler
     [not found]   ` <556484BD.2060004@tycho.nsa.gov>
     [not found]     ` <556484BD.2060004-+05T5uksL2qpZYMLLGbcSA@public.gmane.org>
2015-05-26 16:27       ` Lukasz Pawelczyk
2015-05-26 16:34         ` Stephen Smalley
     [not found]           ` <5564A088.4040507-+05T5uksL2qpZYMLLGbcSA@public.gmane.org>
2015-05-26 16:42             ` Lukasz Pawelczyk
2015-05-27  9:36     ` Lukasz Pawelczyk
2015-05-27 13:33       ` Stephen Smalley

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=1432553598.1781.4.camel@samsung.com \
    --to=l.pawelczyk-sze3o3uu22jbdgjk7y7tuq@public.gmane.org \
    --cc=adobriyan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=casey-iSGtlc1asvQWG2LlvL+J4A@public.gmane.org \
    --cc=corbet-T1hC0tSOHrs@public.gmane.org \
    --cc=dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
    --cc=edumazet-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
    --cc=fabf-AgBVmzD5pcezQB+pC5nmwQ@public.gmane.org \
    --cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
    --cc=havner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=hch-jcswGhMUV9g@public.gmane.org \
    --cc=ionut.m.alexa-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=james.l.morris-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
    --cc=jlayton-7I+n7zu2hftEKMMhf/gKZA@public.gmane.org \
    --cc=keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=kirill-oKw7cIdHH8eLwutG50LtGA@public.gmane.org \
    --cc=linux-doc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mchehab-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org \
    --cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
    --cc=mingo-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org \
    --cc=r.krypa-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=riel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=sds-+05T5uksL2qpZYMLLGbcSA@public.gmane.org \
    --cc=viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.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).