mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kees Cook <kees.cook@canonical.com>
To: Richard Weinberger <richard@nod.at>
Cc: 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: Wed, 16 Mar 2011 12:55:49 -0700	[thread overview]
Message-ID: <20110316195549.GZ5466@outflux.net> (raw)
In-Reply-To: <1300303907-22627-1-git-send-email-richard@nod.at>

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?

Signed-off-by: Kees Cook <kees.cook@canonical.com>
---
diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 8eb2522..5c5cfab 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -149,6 +149,10 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
 	if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
 		goto out;
 
+	if (write && !cap_isclear(table->write_caps) &&
+            !cap_issubset(table->write_caps, current_cred()->cap_permitted))
+		goto out;
+
 	/* if that can happen at all, it should be -EINVAL, not -EISDIR */
 	error = -EINVAL;
 	if (!table->proc_handler)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index 11684d9..4e05493 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -1018,6 +1018,7 @@ struct ctl_table
 	void *data;
 	int maxlen;
 	mode_t mode;
+	kernel_cap_t write_caps;	/* Capabilities required to write */
 	struct ctl_table *child;
 	struct ctl_table *parent;	/* Automatically set */
 	proc_handler *proc_handler;	/* Callback for text formatting */


-- 
Kees Cook
Ubuntu Security Team

  reply	other threads:[~2011-03-16 19:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-16 19:31 Richard Weinberger
2011-03-16 19:55 ` Kees Cook [this message]
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

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=20110316195549.GZ5466@outflux.net \
    --to=kees.cook@canonical.com \
    --cc=akpm@linux-foundation.org \
    --cc=drosenberg@vsecurity.com \
    --cc=eparis@redhat.com \
    --cc=eugeneteo@kernel.org \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®