All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman)
To: Aristeu Rozanski <aris-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
Cc: linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Linux Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
Subject: Re: [PATCH] coredump: run the coredump helper using the same namespace as the dead process
Date: Mon, 05 Nov 2012 11:34:26 -0800	[thread overview]
Message-ID: <87r4o7alod.fsf@xmission.com> (raw)
In-Reply-To: <20121105163810.GJ14789-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> (Aristeu Rozanski's message of "Mon, 5 Nov 2012 11:38:11 -0500")

Aristeu Rozanski <aris-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> writes:

> /proc/sys/kernel/core_pattern can be used to specify a userspace helper
> to handle core files and it currently runs in the root namespace.
> This patch allows the helper to run in the same namespace in a step
> towards letting containers setting their own helpers.

I would argue that you very much need to define what it means to have a
per container core dump at the same time as you argue this.

Nacked-by: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>

Running in a namespace different than whoever set the core dump
pattern/helper makes core dump helpers much more attackable.  With this
patch and a little creativity I expect I can get root to write to
whatever file I would like.  Since I also control the content of what is
going into that file.... This design seems emintely exploitable.

Furthermore not all namespaces are pointed at by nsproxy, so even
for it's original design this patch is buggy.


I do think supporting a per container coredump setting makes a lot of
sense but I do not think this patch is the way to do it.

Eric


> Cc: "Serge E. Hallyn" <serge-A9i7LUbDfNHQT0dZR+AlfA@public.gmane.org>
> Cc: "Eric W. Biederman" <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
> Cc: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
> Signed-off-by: Aristeu Rozanski <aris-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index ce47379..fa14ea1 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -455,6 +455,19 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
>  	/* and disallow core files too */
>  	current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
>  
> +	/*
> +	 * We want to run the helper within the same namespace. Since we
> +	 * already forked, current here is using init_nsproxy and the usage
> +	 * was already accounted. switch_task_namespace() will revert that
> +	 * but we need to bump the dead process' nsproxy before calling the
> +	 * the helper. Once it exits, the dead process' nsproxy usage will be
> +	 * decremented as part of normal process exit.
> +	 */
> +	if (current->nsproxy != cp->nsproxy) {
> +		get_nsproxy(cp->nsproxy);
> +		switch_task_namespaces(current, cp->nsproxy);
> +	}
> +
>  	return err;
>  }
>  
> @@ -482,6 +495,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
>  		 * by any locks.
>  		 */
>  		.mm_flags = mm->flags,
> +		/* we run the helper in the same namespace */
> +		.nsproxy = current->nsproxy,
>  	};
>  
>  	audit_core_dumps(siginfo->si_signo);
> diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
> index cfcc6bf..45113e6 100644
> --- a/include/linux/binfmts.h
> +++ b/include/linux/binfmts.h
> @@ -63,6 +63,7 @@ struct coredump_params {
>  	struct file *file;
>  	unsigned long limit;
>  	unsigned long mm_flags;
> +	struct nsproxy *nsproxy;
>  };
>  
>  /*

WARNING: multiple messages have this Message-ID (diff)
From: ebiederm@xmission.com (Eric W. Biederman)
To: Aristeu Rozanski <aris@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	"Serge E. Hallyn" <serge@hallyn.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Linux Containers <containers@lists.linux-foundation.org>
Subject: Re: [PATCH] coredump: run the coredump helper using the same namespace as the dead process
Date: Mon, 05 Nov 2012 11:34:26 -0800	[thread overview]
Message-ID: <87r4o7alod.fsf@xmission.com> (raw)
In-Reply-To: <20121105163810.GJ14789@redhat.com> (Aristeu Rozanski's message of "Mon, 5 Nov 2012 11:38:11 -0500")

Aristeu Rozanski <aris@redhat.com> writes:

> /proc/sys/kernel/core_pattern can be used to specify a userspace helper
> to handle core files and it currently runs in the root namespace.
> This patch allows the helper to run in the same namespace in a step
> towards letting containers setting their own helpers.

I would argue that you very much need to define what it means to have a
per container core dump at the same time as you argue this.

Nacked-by: "Eric W. Biederman" <ebiederm@xmission.com>

Running in a namespace different than whoever set the core dump
pattern/helper makes core dump helpers much more attackable.  With this
patch and a little creativity I expect I can get root to write to
whatever file I would like.  Since I also control the content of what is
going into that file.... This design seems emintely exploitable.

Furthermore not all namespaces are pointed at by nsproxy, so even
for it's original design this patch is buggy.


I do think supporting a per container coredump setting makes a lot of
sense but I do not think this patch is the way to do it.

Eric


> Cc: "Serge E. Hallyn" <serge@hallyn.com>
> Cc: "Eric W. Biederman" <ebiederm@xmission.com>
> Cc: Al Viro <viro@zeniv.linux.org.uk>
> Signed-off-by: Aristeu Rozanski <aris@redhat.com>
>
> diff --git a/fs/coredump.c b/fs/coredump.c
> index ce47379..fa14ea1 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -455,6 +455,19 @@ static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
>  	/* and disallow core files too */
>  	current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
>  
> +	/*
> +	 * We want to run the helper within the same namespace. Since we
> +	 * already forked, current here is using init_nsproxy and the usage
> +	 * was already accounted. switch_task_namespace() will revert that
> +	 * but we need to bump the dead process' nsproxy before calling the
> +	 * the helper. Once it exits, the dead process' nsproxy usage will be
> +	 * decremented as part of normal process exit.
> +	 */
> +	if (current->nsproxy != cp->nsproxy) {
> +		get_nsproxy(cp->nsproxy);
> +		switch_task_namespaces(current, cp->nsproxy);
> +	}
> +
>  	return err;
>  }
>  
> @@ -482,6 +495,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
>  		 * by any locks.
>  		 */
>  		.mm_flags = mm->flags,
> +		/* we run the helper in the same namespace */
> +		.nsproxy = current->nsproxy,
>  	};
>  
>  	audit_core_dumps(siginfo->si_signo);
> diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
> index cfcc6bf..45113e6 100644
> --- a/include/linux/binfmts.h
> +++ b/include/linux/binfmts.h
> @@ -63,6 +63,7 @@ struct coredump_params {
>  	struct file *file;
>  	unsigned long limit;
>  	unsigned long mm_flags;
> +	struct nsproxy *nsproxy;
>  };
>  
>  /*

  parent reply	other threads:[~2012-11-05 19:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-05 16:38 [PATCH] coredump: run the coredump helper using the same namespace as the dead process Aristeu Rozanski
2012-11-05 16:38 ` Aristeu Rozanski
     [not found] ` <20121105163810.GJ14789-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-05 19:34   ` Eric W. Biederman [this message]
2012-11-05 19:34     ` Eric W. Biederman
     [not found]     ` <87r4o7alod.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2012-11-05 20:18       ` Aristeu Rozanski
2012-11-05 20:18         ` Aristeu Rozanski
     [not found]         ` <20121105201825.GM14789-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-11-05 21:13           ` Eric W. Biederman
2012-11-05 21:13             ` Eric W. Biederman

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=87r4o7alod.fsf@xmission.com \
    --to=ebiederm-as9lmozglivwk0htik3j/w@public.gmane.org \
    --cc=aris-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.