Re: [patch] file capabilities: Add no_file_caps switch

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Serge E. Hallyn
Date: Wednesday, August 27, 2008 - 11:58 am

Quoting Andreas Gruenbacher (agruen@suse.de):

The below patch seems to be working for me.  Please take a look.


Ok, cool.  In that case - David I was a little surprised to find that
patch not applied in Linus' tree.  You sent it quite some time ago,
didn't you?  Were you planning on trying again to push it soon?

In any case, how about the following patch?

If it is ok with everyone, then I'll rewrite the intro and send it
out separately.

thanks,
-serge

From 0b69a9e882b07e33814aa15a2f5cdf90b92c7ec8 Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serue@us.ibm.com>
Date: Wed, 27 Aug 2008 13:33:37 -0500
Subject: [PATCH 1/1] file capabilities: add no_file_caps switch (v2)

Hi,

here is a simplification of Andreas' patch from yesterday.  We
appear to be agreed that it suffices to prevent file capabilities
from being actually read from disk, so this version only does that.
This means that booting with the no_file_caps boot option will
not be the same as booting a kernel with file capabilities
compiled out - in particular a task with  CAP_SETPCAP will not
have any chance of passing capabilities to another task (which
isn't "really" possible anyway, and which may soon by killed
altogether by David Howells in any case), and it will instead
be able to put new capabilities in its pI.  However since fI
will always be empty and pI is masked with fI, it gains the
task nothing.

We also support the extra prctl options, setting securebits and
dropping capabilities from the per-process bounding set.

The other remaining difference is that killpriv, task_setscheduler,
setioprio, and setnice will continue to be hooked.  That will
be noticable in the case where a root task changed its uid
while keeping some caps, and another task owned by the new uid
tries to change settings for the more privileged task.

Signed-off-by: Serge Hallyn <serue@us.ibm.com>
---
 kernel/capability.c  |   13 +++++++++++++
 security/commoncap.c |   11 +++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/kernel/capability.c b/kernel/capability.c
index 33e51e7..5d034ec 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -33,6 +33,19 @@ EXPORT_SYMBOL(__cap_empty_set);
 EXPORT_SYMBOL(__cap_full_set);
 EXPORT_SYMBOL(__cap_init_eff_set);
 
+#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
+int file_caps_enabled = 1;
+
+static int __init file_caps_disable(char *str)
+{
+	file_caps_enabled = 0;
+	return 1;
+}
+__setup("no_file_caps", file_caps_disable);
+#else
+static const int file_caps_enabled = 0;
+#endif
+
 /*
  * More recent versions of libcap are available from:
  *
diff --git a/security/commoncap.c b/security/commoncap.c
index e4c4b3f..8c66d34 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -27,6 +27,12 @@
 #include <linux/prctl.h>
 #include <linux/securebits.h>
 
+#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
+extern int file_caps_enabled;
+#else
+static const int file_caps_enabled = 0;
+#endif
+
 int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
 {
 	NETLINK_CB(skb).eff_cap = current->cap_effective;
@@ -279,6 +285,11 @@ static int get_file_caps(struct linux_binprm *bprm)
 	struct vfs_cap_data vcaps;
 	struct inode *inode;
 
+	if (!file_caps_enabled) {
+		bprm_clear_caps(bprm);
+		return 0;
+	}
+
 	if (bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID) {
 		bprm_clear_caps(bprm);
 		return 0;
-- 
1.5.4.3

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[patch] file capabilities: Add no_file_caps switch, Andreas Gruenbacher, (Tue Aug 26, 11:57 am)
Re: [patch] file capabilities: Add no_file_caps switch, Ingo Molnar, (Tue Aug 26, 1:28 pm)
Re: [patch] file capabilities: Add no_file_caps switch, Serge E. Hallyn, (Wed Aug 27, 6:52 am)
Re: [patch] file capabilities: Add no_file_caps switch, Andreas Gruenbacher, (Wed Aug 27, 8:29 am)
Re: [patch] file capabilities: Add no_file_caps switch, Serge E. Hallyn, (Wed Aug 27, 9:04 am)
Re: [patch] file capabilities: Add no_file_caps switch, David Howells, (Wed Aug 27, 9:13 am)
Re: [patch] file capabilities: Add no_file_caps switch, Andreas Gruenbacher, (Wed Aug 27, 9:57 am)
Re: [patch] file capabilities: Add no_file_caps switch, David Howells, (Wed Aug 27, 10:00 am)
Re: [patch] file capabilities: Add no_file_caps switch, David Howells, (Wed Aug 27, 10:04 am)
Re: [patch] file capabilities: Add no_file_caps switch, Serge E. Hallyn, (Wed Aug 27, 11:58 am)
Re: [patch] file capabilities: Add no_file_caps switch, David Howells, (Wed Aug 27, 2:14 pm)
Re: [patch] file capabilities: Add no_file_caps switch, James Morris, (Wed Aug 27, 5:05 pm)
Re: [patch] file capabilities: Add no_file_caps switch, Serge E. Hallyn, (Wed Aug 27, 5:48 pm)
Re: [patch] file capabilities: Add no_file_caps switch, James Morris, (Wed Aug 27, 6:57 pm)
Re: [patch] file capabilities: Add no_file_caps switch, Andrew G. Morgan, (Thu Aug 28, 8:35 am)
Re: [patch] file capabilities: Add no_file_caps switch, Andreas Gruenbacher, (Thu Aug 28, 9:27 am)
Re: [patch] file capabilities: Add no_file_caps switch, Serge E. Hallyn, (Thu Aug 28, 10:09 am)