public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] Make it easier to harden /proc/
@ 2011-03-16 19:31 Richard Weinberger
  2011-03-16 19:55 ` Kees Cook
  0 siblings, 1 reply; 19+ messages in thread
From: Richard Weinberger @ 2011-03-16 19:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: akpm, serge, eparis, kees.cook, jmorris, eugeneteo, drosenberg,
	Richard Weinberger

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.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 fs/proc/proc_sysctl.c  |    3 +++
 include/linux/sysctl.h |    1 +
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
index 8eb2522..cf7f27d 100644
--- a/fs/proc/proc_sysctl.c
+++ b/fs/proc/proc_sysctl.c
@@ -149,6 +149,9 @@ 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 && table->restricted && !capable(CAP_SYS_ADMIN))
+		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..67d6129 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;
+	bool restricted; /* CAP_SYS_ADMIN is needed for write access */
 	struct ctl_table *child;
 	struct ctl_table *parent;	/* Automatically set */
 	proc_handler *proc_handler;	/* Callback for text formatting */
-- 
1.6.6.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-03-19 10:43 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox