Skip to contentSkip to conversation

file capabilities: add no_file_caps switch (v2)

PATCH In review Serge E. Hallyn 6 participants 13 messages Sep 22, 2008 – Sep 23, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 file capabilities: add no_file_caps switch (v2)

(Resend of two patches from late August. If noone objects, would it be possible to see this pair take a turn in security-testing?)

Add a no_file_caps boot option when file capabilities are compiled into the kernel (CONFIG_SECURITY_FILE_CAPABILITIES=y).

This allows distributions to ship a kernel with file capabilities compiled in, without forcing users to use (and understand and trust) them.

When no_file_caps is specified at boot, then when a process executes a file, any file capabilities stored with that file will not be used in the calculation of the process' new capability sets.

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.

---
 kernel/capability.c  |   13 +++++++++++++
 security/commoncap.c |   11 +++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
kernel/capability.c +13 -0
index 33e51e7..5d034ec 100644
@@ -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:
  *
security/commoncap.c +11 -0
index e4c4b3f..8c66d34 100644
@@ -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;
Signature · 1 line
1.5.4.3
#1 lore raw

PATCH 2/2 file capabilities: turn on by default

Now that file capabilities can be turned off at boot, go ahead and compile them into the kernel by default by making CONFIG_SECURITY_FILE_CAPABILITIES=y the default.

Note that the boot flag no_file_caps must be specified to turn file capabilities off, as by default they are on. So the default behavior is in fact changed.

---
 security/Kconfig |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
security/Kconfig +5 -2
index 5592939..6fbb233 100644
@@ -75,12 +75,15 @@ config SECURITY_NETWORK_XFRM
 
 config SECURITY_FILE_CAPABILITIES
 	bool "File POSIX Capabilities"
-	default n
+	default y
 	help
 	  This enables filesystem capabilities, allowing you to give
 	  binaries a subset of root's powers without using setuid 0.
 
-	  If in doubt, answer N.
+	  You can still boot with the no_file_caps option to disable
+	  file capabilities.
+
+	  If in doubt, answer Y.
 
 config SECURITY_ROOTPLUG
 	bool "Root Plug Support"
Signature · 1 line
1.5.4.3
#2 lore raw

Re: [PATCH 2/2] file capabilities: turn on by default

Quoted 4 lines · On Mon, 22 Sep 2008 13:49:01 -0500 Serge E. Hallyn wrote:

Now that file capabilities can be turned off at boot, go ahead and compile them into the kernel by default by making CONFIG_SECURITY_FILE_CAPABILITIES=y the default.

Hi,

How much code does this add to everyone's kernel?

Quoted 3 lines

Note that the boot flag no_file_caps must be specified to turn file capabilities off, as by default they are on. So the default behavior is in fact changed.

If most people want this enable, using 'no_file_caps' makes some sense. OTOH, if most people don't want/use it, then having a 'file_caps_on' option would make more sense.

Do you have any (unbiased :) ideas about this?

Thanks.

Quoted 18 lines
---
 security/Kconfig |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
security/Kconfig +1 -1
index 5592939..6fbb233 100644
@@ -75,12 +75,15 @@ config SECURITY_NETWORK_XFRM
 
 config SECURITY_FILE_CAPABILITIES
 	bool "File POSIX Capabilities"
-	default n
+	default y
 	help
 	  This enables filesystem capabilities, allowing you to give

security/Kconfig config SECURITY_NETWORK_XFRM · line 89

Quoted 10 lines
security/Kconfig +4 -1
 	  binaries a subset of root's powers without using setuid 0.
 
-	  If in doubt, answer N.
+	  You can still boot with the no_file_caps option to disable
+	  file capabilities.
+
+	  If in doubt, answer Y.
 
 config SECURITY_ROOTPLUG
 	bool "Root Plug Support"

---
~Randy

#3 lore raw

Re: [PATCH 2/2] file capabilities: turn on by default

Quoted 10 lines · Randy Dunlap
Quoted 4 lines · On Mon, 22 Sep 2008 13:49:01 -0500 Serge E. Hallyn wrote:

Now that file capabilities can be turned off at boot, go ahead and compile them into the kernel by default by making CONFIG_SECURITY_FILE_CAPABILITIES=y the default.

Hi,

How much code does this add to everyone's kernel?

Here are the sizes I get with Linus' plain tree and patched with both of these patches:

master with file capabilities: 6241626
master w/o file capabilities: 6241595

patched with file capabilities: 6241782
patched w/o file capabilities: 6241595

So actually I don't like the added size.

Quoted 9 lines
Quoted 3 lines

Note that the boot flag no_file_caps must be specified to turn file capabilities off, as by default they are on. So the default behavior is in fact changed.

If most people want this enable, using 'no_file_caps' makes some sense. OTOH, if most people don't want/use it, then having a 'file_caps_on' option would make more sense.

Do you have any (unbiased :) ideas about this?

I'll sit this one out I guess :)

Quoted 34 lines

Thanks.

Quoted 18 lines
---
 security/Kconfig |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
security/Kconfig +1 -1
index 5592939..6fbb233 100644
@@ -75,12 +75,15 @@ config SECURITY_NETWORK_XFRM
 
 config SECURITY_FILE_CAPABILITIES
 	bool "File POSIX Capabilities"
-	default n
+	default y
 	help
 	  This enables filesystem capabilities, allowing you to give

security/Kconfig config SECURITY_NETWORK_XFRM · line 89

Quoted 10 lines
security/Kconfig +4 -1
 	  binaries a subset of root's powers without using setuid 0.
 
-	  If in doubt, answer N.
+	  You can still boot with the no_file_caps option to disable
+	  file capabilities.
+
+	  If in doubt, answer Y.
 
 config SECURITY_ROOTPLUG
 	bool "Root Plug Support"

---
~Randy

#4 lore raw

Re: [PATCH 2/2] file capabilities: turn on by default

Quoted 24 lines · Serge E. Hallyn
Quoted 8 lines · Randy Dunlap
Quoted 3 lines · On Mon, 22 Sep 2008 13:49:01 -0500 Serge E. Hallyn wrote:

Now that file capabilities can be turned off at boot, go ahead and compile them into the kernel by default by making CONFIG_SECURITY_FILE_CAPABILITIES=y the default.

Hi,

How much code does this add to everyone's kernel?

Here are the sizes I get with Linus' plain tree and patched with both of these patches:

master with file capabilities: 6241626
master w/o file capabilities: 6241595

patched with file capabilities: 6241782
patched w/o file capabilities: 6241595

So actually I don't like the added size.

Quoted 3 lines
Quoted 3 lines

Note that the boot flag no_file_caps must be specified to turn file capabilities off, as by default they are on. So the default behavior is in fact changed.

Quoted 7 lines
Quoted 5 lines

If most people want this enable, using 'no_file_caps' makes some sense. OTOH, if most people don't want/use it, then having a 'file_caps_on' option would make more sense.

Do you have any (unbiased :) ideas about this?

I'll sit this one out I guess :)

BTW, I like Stephen's suggestion of using file_caps=0/1 instead of no_file_caps.

Signature · 1 line
~Randy
#5 lore raw

Re: [PATCH 2/2] file capabilities: turn on by default

In reply to Serge E. Hallyn
Quoted 10 lines · * Serge E. Hallyn ([email protected]) wrote:

Here are the sizes I get with Linus' plain tree and patched with both of these patches:

master with file capabilities: 6241626
master w/o file capabilities: 6241595

patched with file capabilities: 6241782
patched w/o file capabilities: 6241595

So actually I don't like the added size.

Different than I'm seeing here (note: defconfig has file capabilities):

text data bss dec hex filename
6804621 1017960 671900 8494481 819d91 obj64-defconfig/vmlinux
6804642 1017984 671900 8494526 819dbe obj64-defconfig-patch/vmlinux
6804069 1017960 671900 8493929 819b69 obj64-nofcap/vmlinux
6804068 1017960 671900 8493928 819b68 obj64-nofcap-patch/vmlinux

thanks,
-chris

#6 lore raw
In reply to Serge E. Hallyn
Quoted 5 lines · Serge E. Hallyn

(Resend of two patches from late August. If noone objects, would it be possible to see this pair take a turn in security-testing?)

Add a no_file_caps boot option when file capabilities are compiled into the kernel (CONFIG_SECURITY_FILE_CAPABILITIES=y).

Is there a reason you didn't just use a filecaps=0/1 approach ala the selinux= boot parameter? And let the default value be selectable as well?

Quoted 18 lines

This allows distributions to ship a kernel with file capabilities compiled in, without forcing users to use (and understand and trust) them.

When no_file_caps is specified at boot, then when a process executes a file, any file capabilities stored with that file will not be used in the calculation of the process' new capability sets.

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.

Quoted 8 lines

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.

Seems a bit confusing to offer a no_file_caps option with different behavior than disabling it at build time.

BTW, I think Fedora kernel have had CONFIG_SECURITY_FILE_CAPABILITIES=y for quite some time. Not that they are using it AFAIK, but the kernel support has seemingly been enabled.

Quoted 60 lines
---
 kernel/capability.c  |   13 +++++++++++++
 security/commoncap.c |   11 +++++++++++
 2 files changed, 24 insertions(+), 0 deletions(-)
kernel/capability.c +13 -0
index 33e51e7..5d034ec 100644
@@ -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:
  *
security/commoncap.c +11 -0
index e4c4b3f..8c66d34 100644
@@ -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;
Signature · 2 lines
Stephen Smalley
National Security Agency
#7 lore raw
Quoted 10 lines · On Monday 22 September 2008 21:16:04 Stephen Smalley wrote:
Quoted 5 lines · Serge E. Hallyn

(Resend of two patches from late August. If noone objects, would it be possible to see this pair take a turn in security-testing?)

Add a no_file_caps boot option when file capabilities are compiled into the kernel (CONFIG_SECURITY_FILE_CAPABILITIES=y).

Is there a reason you didn't just use a filecaps=0/1 approach ala the selinux= boot parameter? And let the default value be selectable as well?

Sure, that would work as well, except that I think that file capabilities should always default to "on" as they will become a standard security mechanism before long. We just don't have much system management tool support yet, and I would like to give that some more time safely, without putting users at unnecessary risk.

I think we could get rid of the command line option again in a year or two ...

Quoted 2 lines

Seems a bit confusing to offer a no_file_caps option with different behavior than disabling it at build time.

I agree. These other behaviorial changes should not depend on CONFIG_SECURITY_FILE_CAPABILITIES; the old behavior should just be fixed instead.

Thanks,
Andreas

#8 lore raw
Quoted 18 lines · Andreas Gruenbacher
Quoted 10 lines · On Monday 22 September 2008 21:16:04 Stephen Smalley wrote:
Quoted 5 lines · Serge E. Hallyn

(Resend of two patches from late August. If noone objects, would it be possible to see this pair take a turn in security-testing?)

Add a no_file_caps boot option when file capabilities are compiled into the kernel (CONFIG_SECURITY_FILE_CAPABILITIES=y).

Is there a reason you didn't just use a filecaps=0/1 approach ala the selinux= boot parameter? And let the default value be selectable as well?

Sure, that would work as well, except that I think that file capabilities should always default to "on" as they will become a standard security mechanism before long. We just don't have much system management tool support yet, and I would like to give that some more time safely, without putting users at unnecessary risk.

Quoted 8 lines

I think we could get rid of the command line option again in a year or two ...

Quoted 2 lines

Seems a bit confusing to offer a no_file_caps option with different behavior than disabling it at build time.

I agree. These other behaviorial changes should not depend on CONFIG_SECURITY_FILE_CAPABILITIES; the old behavior should just be fixed instead.

That of course would be the point of the patch 3/3, which removes CONFIG_SECURITY_FILE_CAPABILITIES as a config option. Should I do that when I redo the patch as per Stephen's suggestion to use filecaps=0/1?

thanks,
-serge

#9 lore raw
Quoted 8 lines · On Monday, 22 September 2008 23:50:32 Serge E. Hallyn wrote:
Quoted 3 lines · Andreas Gruenbacher

I agree. These other behaviorial changes should not depend on CONFIG_SECURITY_FILE_CAPABILITIES; the old behavior should just be fixed instead.

That of course would be the point of the patch 3/3, which removes CONFIG_SECURITY_FILE_CAPABILITIES as a config option. Should I do that

I think yes.

Quoted 1 line

when I redo the patch as per Stephen's suggestion to use filecaps=0/1?

This will require to adjust our installer, which uses no_file_caps already. I don't think that filecaps=0/1 is really necessary, but it I can life with either.

Thanks,
Andreas

maintainer
#10 lore raw
In reply to Serge E. Hallyn
Quoted 6 lines · Serge E. Hallyn
Quoted 3 lines

I agree. These other behaviorial changes should not depend on CONFIG_SECURITY_FILE_CAPABILITIES; the old behavior should just be fixed instead.

That of course would be the point of the patch 3/3, which removes CONFIG_SECURITY_FILE_CAPABILITIES as a config option.

btw, don't make it Y at all (patch 1/3 ?), as Linus has outlawed making new features default to Y.

Quoted 2 lines

Should I do that when I redo the patch as per Stephen's suggestion to
use filecaps=0/1?

Given that there's existing use of no_file_caps, and that I doubt Fedora will provide an install option to disable it, probably just stick with no_file_caps.

- James

Signature · 2 lines
James Morris
<[email protected]>
#11 lore raw
In reply to Serge E. Hallyn
Quoted 22 lines · * Serge E. Hallyn ([email protected]) wrote:
kernel/capability.c +12 -0
@@ -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
 

security/commoncap.c line 35

Quoted 9 lines
security/commoncap.c +6 -0
@@ -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
+

file_caps_enabled cut 'n paste mistake when !CONFIG_SECURITY_FILE_CAPABILITIES?

Also, plan to update Documentation/kernel-parameters.txt?

thanks,
-chris

#12 lore raw
Quoted 26 lines · Chris Wright
Quoted 25 lines · * Serge E. Hallyn ([email protected]) wrote:
kernel/capability.c +12 -0
@@ -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
 
security/commoncap.c +0 -0
@@ -27,6 +27,12 @@
 #include <linux/prctl.h>
 #include <linux/securebits.h>
 
Quoted 8 lines

security/commoncap.c line 35

Quoted 6 lines
security/commoncap.c +6 -0
+#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
+extern int file_caps_enabled;
+#else
+static const int file_caps_enabled = 0;
+#endif
+

file_caps_enabled cut 'n paste mistake when !CONFIG_SECURITY_FILE_CAPABILITIES?

Oops, yup, thanks.

Quoted 1 line

Also, plan to update Documentation/kernel-parameters.txt?

Will do.

thanks,
-serge