All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>,
	Kees Cook <kees.cook@canonical.com>,
	linux-kernel@vger.kernel.org, akpm@linux-foundation.org,
	serge@hallyn.com, eparis@redhat.com, jmorris@namei.org,
	eugeneteo@kernel.org, drosenberg@vsecurity.com
Subject: Re: [PATCH] [RFC] Make it easier to harden /proc/
Date: Sat, 19 Mar 2011 11:43:28 +0100	[thread overview]
Message-ID: <201103191143.28499.richard@nod.at> (raw)
In-Reply-To: <m1mxktbsgy.fsf@fess.ebiederm.org>

Am Donnerstag 17 März 2011, 17:51:41 schrieb Eric W. Biederman:
> Alexey Dobriyan <adobriyan@gmail.com> writes:
> > On Wed, Mar 16, 2011 at 09:08:16PM +0100, Richard Weinberger wrote:
> >> Kees,
> >> 
> >> Am Mittwoch 16 März 2011, 20:55:49 schrieb Kees Cook:
> >> > Hi Richard,
> >> > 
> >> > On Wed, Mar 16, 2011 at 08:31:47PM +0100, Richard Weinberger wrote:
> >> > > When containers like LXC are used a unprivileged and jailed
> >> > > root user can still write to critical files in /proc/.
> >> > > E.g: /proc/sys/kernel/{sysrq, panic, panic_on_oops, ... }
> >> > > 
> >> > > This new restricted attribute makes it possible to protect such
> >> > > files. When restricted is set to true root needs CAP_SYS_ADMIN
> >> > > to into the file.
> >> > 
> >> > I was thinking about this too. I'd prefer more fine-grained control
> >> > in this area, since some sysctl entries aren't strictly controlled by
> >> > CAP_SYS_ADMIN (e.g. mmap_min_addr is already checking CAP_SYS_RAWIO).
> >> > 
> >> > How about this instead?
> >> 
> >> Good Idea.
> >> May we should also consider a per-directory restriction.
> >> Every file in /proc/sys/{kernel/, vm/, fs/, dev/} needs a protection.
> >> It would be much easier to set the protection on the parent directory
> >> instead of protecting file by file...
> > 
> > Of course, not.
> > 
> > You should _enable_ them one by one, not the other way around.
> > 
> > 	"default deny"
> 
> Right.
> 
> Since the primary problem here is containers we can use the
> user_namespace to add the default deny policy.
> 
> Something like the trivial patch below should make /proc/sys safe,
> and the technique applies in general.
> 
> Richard is that a good enough example to get you started?

Yes. Thanks.

> Eric
> 
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 0f1bd83..a172a9d 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -1674,10 +1674,12 @@ void register_sysctl_root(struct ctl_table_root
> *root)
> 
>  static int test_perm(int mode, int op)
>  {
> -	if (!current_euid())
> -		mode >>= 6;
> -	else if (in_egroup_p(0))
> -		mode >>= 3;
> +	if (current_user_ns() == &init_user_ns) {
> +		if (!current_euid())
> +			mode >>= 6;
> +		else if (in_egroup_p(0))
> +			mode >>= 3;
> +	}
>  	if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
>  		return 0;
>  	return -EACCES;


      reply	other threads:[~2011-03-19 10:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-16 19:31 [PATCH] [RFC] Make it easier to harden /proc/ Richard Weinberger
2011-03-16 19:55 ` Kees Cook
2011-03-16 20:08   ` Richard Weinberger
2011-03-16 20:45     ` Arnd Bergmann
2011-03-16 20:52       ` Richard Weinberger
2011-03-16 21:03         ` Arnd Bergmann
2011-03-16 21:04         ` Alexey Dobriyan
2011-03-16 21:07           ` Richard Weinberger
2011-03-16 21:15             ` Alexey Dobriyan
2011-03-17 10:14               ` Miquel van Smoorenburg
2011-03-17 10:57                 ` Richard Weinberger
2011-03-16 21:17         ` Eric W. Biederman
2011-03-16 21:23           ` Richard Weinberger
2011-03-16 21:27             ` Eric W. Biederman
2011-03-17  6:41           ` Kees Cook
2011-03-17  7:30             ` Richard Weinberger
2011-03-16 21:19     ` Alexey Dobriyan
2011-03-17 16:51       ` Eric W. Biederman
2011-03-19 10:43         ` Richard Weinberger [this message]

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=201103191143.28499.richard@nod.at \
    --to=richard@nod.at \
    --cc=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=drosenberg@vsecurity.com \
    --cc=ebiederm@xmission.com \
    --cc=eparis@redhat.com \
    --cc=eugeneteo@kernel.org \
    --cc=jmorris@namei.org \
    --cc=kees.cook@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=serge@hallyn.com \
    /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.