Skip to contentSkip to conversation

security: introduce file posix caps

PATCH In review Serge E. Hallyn 5 participants 11 messages Nov 7, 2006 – Nov 8, 2006

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

PATCH 1/1 security: introduce file posix caps

Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/pub/fscaps-1.0-kg.src.rpm under
http://www.kaigai.gr.jp/index.php?FrontPage#b556e50d.

(For more information on how to use, Chris Friedhoff has posted a nice page on his use of file caps at http://www.friedhoff.org/fscaps.html.

This has been boot tested with selinux on a FC6 image (qemu-i386), and tested for basic regressions with LTP without selinux enabled.

Changelog:
Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and task_setscheduler so that selinux and capabilities with file cap support can be stacked.

Sep 05:
As Seth Arnold points out, uid checks are out of place for capability code.

Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and task_setnice to make sure a user cannot affect a process in which they called a program with some fscaps.

One remaining question is the note under task_setscheduler: are we ok with CAP_SYS_NICE being sufficient to confine a process to a cpuset?

It is a semantic change, as without fsccaps, attach_task doesn't allow CAP_SYS_NICE to override the uid equivalence check. But since it uses security_task_setscheduler, which elsewhere is used where CAP_SYS_NICE can be used to override the uid equivalence check, fixing it might be tough.

task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another process. Need same checks as setrlimit

Aug 21:
Updated secureexec implementation to reflect the fact that euid and uid might be the same and nonzero, but the process might still have elevated caps.

Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk. Enforce that no bits beyond the known max capability are set, else return -EPERM.
With this extra processing, it may be worth reconsidering doing all the work at bprm_set_security rather than d_instantiate.

Aug 10:
Always call getxattr at bprm_set_security, rather than caching it at d_instantiate.

---
 include/linux/capability.h |    2 +
 include/linux/security.h   |   10 ++-
 security/Kconfig           |   10 +++
 security/capability.c      |    4 +
 security/commoncap.c       |  159 ++++++++++++++++++++++++++++++++++++++++++--
 security/selinux/hooks.c   |   12 +++
 6 files changed, 188 insertions(+), 9 deletions(-)
include/linux/capability.h +2 -0
index 6548b35..76a6e87 100644
@@ -288,6 +288,8 @@ typedef __u32 kernel_cap_t;
 
 #define CAP_AUDIT_CONTROL    30
 
+#define CAP_NUMCAPS	     31
+
 #ifdef __KERNEL__
 /* 
  * Bounding set
include/linux/security.h +7 -3
index b200b98..ea631ee 100644
@@ -53,6 +53,10 @@ extern int cap_inode_setxattr(struct den
 extern int cap_inode_removexattr(struct dentry *dentry, char *name);
 extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
 extern void cap_task_reparent_to_init (struct task_struct *p);
+extern int cap_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid);
+extern int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setioprio (struct task_struct *p, int ioprio);
+extern int cap_task_setnice (struct task_struct *p, int nice);
 extern int cap_syslog (int type);
 extern int cap_vm_enough_memory (long pages);
 
@@ -2594,12 +2598,12 @@ static inline int security_task_setgroup
 
 static inline int security_task_setnice (struct task_struct *p, int nice)
 {
-	return 0;
+	return cap_task_setnice(p, nice);
 }
 
 static inline int security_task_setioprio (struct task_struct *p, int ioprio)
 {
-	return 0;
+	return cap_task_setioprio(p, ioprio);
 }
 
 static inline int security_task_getioprio (struct task_struct *p)
@@ -2634,7 +2638,7 @@ static inline int security_task_kill (st
 				      struct siginfo *info, int sig,
 				      u32 secid)
 {
-	return 0;
+	return cap_task_kill(p, info, sig, secid);
 }
 
 static inline int security_task_wait (struct task_struct *p)
security/Kconfig +10 -0
index 460e5c9..9c798a5 100644
@@ -80,6 +80,16 @@ config SECURITY_CAPABILITIES
 	  This enables the "default" Linux capabilities functionality.
 	  If you are unsure how to answer this question, answer Y.
 
+config SECURITY_FS_CAPABILITIES
+	bool "Filesystem Capabilities"
+	depends on SECURITY_CAPABILITIES
+	default n
+	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.
+
 config SECURITY_ROOTPLUG
 	tristate "Root Plug Support"
 	depends on USB && SECURITY
security/capability.c +4 -0
index b868e7e..14cb592 100644
@@ -40,6 +40,10 @@ static struct security_operations capabi
 	.inode_setxattr =		cap_inode_setxattr,
 	.inode_removexattr =		cap_inode_removexattr,
 
+	.task_kill =			cap_task_kill,
+	.task_setscheduler =		cap_task_setscheduler,
+	.task_setioprio =		cap_task_setioprio,
+	.task_setnice =			cap_task_setnice,
 	.task_post_setuid =		cap_task_post_setuid,
 	.task_reparent_to_init =	cap_task_reparent_to_init,
 
security/commoncap.c +153 -6

193 lines not on this page · raw message

security/selinux/hooks.c +12 -0
index 8ab5679..2fcc60f 100644
@@ -2775,6 +2775,12 @@ static int selinux_task_setnice(struct t
 
 static int selinux_task_setioprio(struct task_struct *p, int ioprio)
 {
+	int rc;
+
+	rc = secondary_ops->task_setioprio(p, ioprio);
+	if (rc)
+		return rc;
+
 	return task_has_perm(current, p, PROCESS__SETSCHED);
 }
 
@@ -2804,6 +2810,12 @@ static int selinux_task_setrlimit(unsign
 
 static int selinux_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp)
 {
+	int rc;
+
+	rc = secondary_ops->task_setscheduler(p, policy, lp);
+	if (rc)
+		return rc;
+
 	return task_has_perm(current, p, PROCESS__SETSCHED);
 }
 
Signature · 1 line
1.4.3.3
#1 lore raw

Hi, Serge.

I packaged the xattr extension of libcap, get/setfcaps command and manual pages with original libcap-1.10-25.
See, http://www.kaigai.gr.jp/index.php?FrontPage#b556e50d

You can download RPM and SRPM package for the latest FC6 system. There are no difference at its functionality, but the part of xattr extension is moved into /lib/libcap.so.1.

Thanks,

Quoted 10 lines · Serge E. Hallyn

Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/pub/fscaps-1.0-kg.src.rpm under
http://www.kaigai.gr.jp/index.php?FrontPage#b556e50d.

(For more information on how to use, Chris Friedhoff has posted a nice page on his use of file caps at http://www.friedhoff.org/fscaps.html.

Signature · 1 line
KaiGai Kohei <[email protected]>
#2 lore raw
In reply to Serge E. Hallyn
Quoted 24 lines · Serge E. Hallyn

Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

include/linux/security.h +4 -1
index b200b98..ea631ee 100644
@@ -53,6 +53,10 @@ extern int cap_inode_setxattr(struct den
 extern int cap_inode_removexattr(struct dentry *dentry, char *name);
 extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
 extern void cap_task_reparent_to_init (struct task_struct *p);
+extern int cap_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid);
+extern int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setioprio (struct task_struct *p, int ioprio);
+extern int cap_task_setnice (struct task_struct *p, int nice);
 extern int cap_syslog (int type);
 extern int cap_vm_enough_memory (long pages);
 
@@ -2594,12 +2598,12 @@ static inline int security_task_setgroup
 
 static inline int security_task_setnice (struct task_struct *p, int nice)
 {
-	return 0;

include/linux/security.h static inline int security_task_setgroup · line 2609

Quoted 10 lines
include/linux/security.h +2 -1
+	return cap_task_setnice(p, nice);
 }
 
 static inline int security_task_setioprio (struct task_struct *p, int ioprio)
 {
-	return 0;
+	return cap_task_setioprio(p, ioprio);
 }
 
 static inline int security_task_getioprio (struct task_struct *p)

setscheduler change seems to be missing here.

Quoted 20 lines
include/linux/security.h +1 -1
@@ -2634,7 +2638,7 @@ static inline int security_task_kill (st
 				      struct siginfo *info, int sig,
 				      u32 secid)
 {
-	return 0;
+	return cap_task_kill(p, info, sig, secid);
 }
 
 static inline int security_task_wait (struct task_struct *p)
security/commoncap.c +6 -0
index 5a5ef5c..0eae004 100644
+int cap_task_kill(struct task_struct *p, struct siginfo *info,
+				int sig, u32 secid)
+{
+	if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
+		return 0;
+

security/commoncap.c int cap_task_post_setuid (uid_t old_ruid · line 439

Quoted 10 lines
security/commoncap.c +10 -0
+	if (secid)
+		/*
+		 * Signal sent as a particular user.
+		 * Capabilities are ignored.  May be wrong, but it's the
+		 * only thing we can do at the moment.
+		 * Used only by usb drivers?
+		 */
+		return 0;
+	if (capable(CAP_KILL))
+		return 0;

This will trigger spurious audit messages; should only be checked if next test fails.

Quoted 9 lines
security/commoncap.c +6 -0
+	if (cap_issubset(p->cap_permitted, current->cap_permitted))
+		return 0;
+
+	return -EPERM;
+}
+
 void cap_task_reparent_to_init (struct task_struct *p)
 {
 	p->cap_effective = CAP_INIT_EFF_SET;
Signature · 2 lines
Stephen Smalley
National Security Agency
#3 lore raw
Quoted 34 lines · Stephen Smalley
Quoted 33 lines · Serge E. Hallyn

Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

include/linux/security.h +6 -2
index b200b98..ea631ee 100644
@@ -53,6 +53,10 @@ extern int cap_inode_setxattr(struct den
 extern int cap_inode_removexattr(struct dentry *dentry, char *name);
 extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
 extern void cap_task_reparent_to_init (struct task_struct *p);
+extern int cap_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid);
+extern int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setioprio (struct task_struct *p, int ioprio);
+extern int cap_task_setnice (struct task_struct *p, int nice);
 extern int cap_syslog (int type);
 extern int cap_vm_enough_memory (long pages);
 
@@ -2594,12 +2598,12 @@ static inline int security_task_setgroup
 
 static inline int security_task_setnice (struct task_struct *p, int nice)
 {
-	return 0;
+	return cap_task_setnice(p, nice);
 }
 
 static inline int security_task_setioprio (struct task_struct *p, int ioprio)
 {
-	return 0;
+	return cap_task_setioprio(p, ioprio);
 }
 
Quoted 3 lines

include/linux/security.h static inline int security_task_setgroup · line 2609

Quoted 1 line
include/linux/security.h +0 -0
 static inline int security_task_getioprio (struct task_struct *p)

setscheduler change seems to be missing here.

I'm confused - my kernel version already had selinux_task_setscheduler() calling a secondary_ops->task_setscheduler().

I don't know where that came from then.

Quoted 25 lines
Quoted 25 lines
include/linux/security.h +1 -1
@@ -2634,7 +2638,7 @@ static inline int security_task_kill (st
 				      struct siginfo *info, int sig,
 				      u32 secid)
 {
-	return 0;
+	return cap_task_kill(p, info, sig, secid);
 }
 
 static inline int security_task_wait (struct task_struct *p)
security/commoncap.c +11 -0
index 5a5ef5c..0eae004 100644
+int cap_task_kill(struct task_struct *p, struct siginfo *info,
+				int sig, u32 secid)
+{
+	if (info != SEND_SIG_NOINFO && (is_si_special(info) || SI_FROMKERNEL(info)))
+		return 0;
+
+	if (secid)
+		/*
+		 * Signal sent as a particular user.
+		 * Capabilities are ignored.  May be wrong, but it's the
+		 * only thing we can do at the moment.
Quoted 9 lines

security/commoncap.c int cap_task_post_setuid (uid_t old_ruid · line 439

Quoted 5 lines
security/commoncap.c +5 -0
+		 * Used only by usb drivers?
+		 */
+		return 0;
+	if (capable(CAP_KILL))
+		return 0;

This will trigger spurious audit messages; should only be checked if next test fails.

I see, will swap, thanks.

Quoted 13 lines
Quoted 9 lines
security/commoncap.c +6 -0
+	if (cap_issubset(p->cap_permitted, current->cap_permitted))
+		return 0;
+
+	return -EPERM;
+}
+
 void cap_task_reparent_to_init (struct task_struct *p)
 {
 	p->cap_effective = CAP_INIT_EFF_SET;
Signature · 2 lines
Stephen Smalley
National Security Agency
#4 lore raw
Quoted 35 lines · Serge E. Hallyn
Quoted 34 lines · Stephen Smalley
Quoted 33 lines · Serge E. Hallyn

Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

include/linux/security.h +6 -2
index b200b98..ea631ee 100644
@@ -53,6 +53,10 @@ extern int cap_inode_setxattr(struct den
 extern int cap_inode_removexattr(struct dentry *dentry, char *name);
 extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
 extern void cap_task_reparent_to_init (struct task_struct *p);
+extern int cap_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid);
+extern int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setioprio (struct task_struct *p, int ioprio);
+extern int cap_task_setnice (struct task_struct *p, int nice);
 extern int cap_syslog (int type);
 extern int cap_vm_enough_memory (long pages);
 
@@ -2594,12 +2598,12 @@ static inline int security_task_setgroup
 
 static inline int security_task_setnice (struct task_struct *p, int nice)
 {
-	return 0;
+	return cap_task_setnice(p, nice);
 }
 
 static inline int security_task_setioprio (struct task_struct *p, int ioprio)
 {
-	return 0;
+	return cap_task_setioprio(p, ioprio);
 }
 
Quoted 6 lines
Quoted 3 lines

include/linux/security.h static inline int security_task_setgroup · line 2609

Quoted 1 line
include/linux/security.h +0 -0
 static inline int security_task_getioprio (struct task_struct *p)

setscheduler change seems to be missing here.

I'm confused - my kernel version already had selinux_task_setscheduler() calling a secondary_ops->task_setscheduler().

I meant you didn't change the default implementation of security_task_setscheduler() to call cap_task_setscheduler() in security.h. For the case where CONFIG_SECURITY is not defined.

Signature · 2 lines
Stephen Smalley
National Security Agency
#5 lore raw
Quoted 40 lines · Stephen Smalley
Quoted 39 lines · Serge E. Hallyn
Quoted 37 lines · Stephen Smalley
Quoted 24 lines · Serge E. Hallyn

Implement file posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

include/linux/security.h +4 -1
index b200b98..ea631ee 100644
@@ -53,6 +53,10 @@ extern int cap_inode_setxattr(struct den
 extern int cap_inode_removexattr(struct dentry *dentry, char *name);
 extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
 extern void cap_task_reparent_to_init (struct task_struct *p);
+extern int cap_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid);
+extern int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setioprio (struct task_struct *p, int ioprio);
+extern int cap_task_setnice (struct task_struct *p, int nice);
 extern int cap_syslog (int type);
 extern int cap_vm_enough_memory (long pages);
 
@@ -2594,12 +2598,12 @@ static inline int security_task_setgroup
 
 static inline int security_task_setnice (struct task_struct *p, int nice)
 {
-	return 0;

include/linux/security.h static inline int security_task_setgroup · line 2609

Quoted 10 lines
include/linux/security.h +2 -1
+	return cap_task_setnice(p, nice);
 }
 
 static inline int security_task_setioprio (struct task_struct *p, int ioprio)
 {
-	return 0;
+	return cap_task_setioprio(p, ioprio);
 }
 
 static inline int security_task_getioprio (struct task_struct *p)

setscheduler change seems to be missing here.

Quoted 6 lines
Quoted 2 lines

I'm confused - my kernel version already had selinux_task_setscheduler() calling a secondary_ops->task_setscheduler().

I meant you didn't change the default implementation of security_task_setscheduler() to call cap_task_setscheduler() in security.h. For the case where CONFIG_SECURITY is not defined.

Oh, I thought my git tree had gotten messed up.

So I guess that CONFIG_SECURITY_FS_CAPABILITIES should not be dependent on CONFIG_SECURITY_CAPABILITIES, since the !CONFIG_SECURITY case actually enables capabilities?

-serge

#6 lore raw
In reply to Stephen Smalley

Thanks, Stephen. Following is a new patch addressing your comments.

thanks,
-serge

Quoted 1 line

From 377dc4be01818296490ab4246ce96c25f6cfdbd4 Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Tue, 7 Nov 2006 11:35:07 -0600
Subject: [PATCH 1/1] security: introduce fs caps

Implement filesystem posix capabilities. This allows programs to be given a subset of root's powers regardless of who runs them, without having to use setuid and giving the binary all of root's powers.

This version works with Kaigai Kohei's userspace tools, found at
http://www.kaigai.gr.jp/pub/fscaps-1.0-kg.src.rpm under
http://www.kaigai.gr.jp/index.php?FrontPage#b556e50d.

Changelog:
Nov 07:
Allow file caps to be enabled without CONFIG_SECURITY, since capabilities are the default.
Hook cap_task_setscheduler when !CONFIG_SECURITY. Move capable(TASK_KILL) to end of cap_task_kill to reduce audit messages.

Nov 05:
Add secondary calls in selinux/hooks.c to task_setioprio and task_setscheduler so that selinux and capabilities with file cap support can be stacked.

Sep 05:
As Seth Arnold points out, uid checks are out of place for capability code.

Sep 01:
Define task_setscheduler, task_setioprio, cap_task_kill, and task_setnice to make sure a user cannot affect a process in which they called a program with some fscaps.

One remaining question is the note under task_setscheduler: are we ok with CAP_SYS_NICE being sufficient to confine a process to a cpuset?

It is a semantic change, as without fsccaps, attach_task doesn't allow CAP_SYS_NICE to override the uid equivalence check. But since it uses security_task_setscheduler, which elsewhere is used where CAP_SYS_NICE can be used to override the uid equivalence check, fixing it might be tough.

task_setscheduler
note: this also controls cpuset:attach_task. Are we ok with
CAP_SYS_NICE being used to confine to a cpuset?
task_setioprio
task_setnice
sys_setpriority uses this (through set_one_prio) for another process. Need same checks as setrlimit

Aug 21:
Updated secureexec implementation to reflect the fact that euid and uid might be the same and nonzero, but the process might still have elevated caps.

Aug 15:
Handle endianness of xattrs.
Enforce capability version match between kernel and disk. Enforce that no bits beyond the known max capability are set, else return -EPERM.
With this extra processing, it may be worth reconsidering doing all the work at bprm_set_security rather than d_instantiate.

Aug 10:
Always call getxattr at bprm_set_security, rather than caching it at d_instantiate.

---
 include/linux/capability.h |    2 +
 include/linux/security.h   |   12 ++-
 security/Kconfig           |    9 +++
 security/capability.c      |    4 +
 security/commoncap.c       |  159 ++++++++++++++++++++++++++++++++++++++++++--
 security/selinux/hooks.c   |   12 +++
 6 files changed, 188 insertions(+), 10 deletions(-)
include/linux/capability.h +2 -0
index 6548b35..76a6e87 100644
@@ -288,6 +288,8 @@ typedef __u32 kernel_cap_t;
 
 #define CAP_AUDIT_CONTROL    30
 
+#define CAP_NUMCAPS	     31
+
 #ifdef __KERNEL__
 /* 
  * Bounding set
include/linux/security.h +8 -4
index b200b98..2718aeb 100644
@@ -53,6 +53,10 @@ extern int cap_inode_setxattr(struct den
 extern int cap_inode_removexattr(struct dentry *dentry, char *name);
 extern int cap_task_post_setuid (uid_t old_ruid, uid_t old_euid, uid_t old_suid, int flags);
 extern void cap_task_reparent_to_init (struct task_struct *p);
+extern int cap_task_kill(struct task_struct *p, struct siginfo *info, int sig, u32 secid);
+extern int cap_task_setscheduler (struct task_struct *p, int policy, struct sched_param *lp);
+extern int cap_task_setioprio (struct task_struct *p, int ioprio);
+extern int cap_task_setnice (struct task_struct *p, int nice);
 extern int cap_syslog (int type);
 extern int cap_vm_enough_memory (long pages);
 
@@ -2594,12 +2598,12 @@ static inline int security_task_setgroup
 
 static inline int security_task_setnice (struct task_struct *p, int nice)
 {
-	return 0;
+	return cap_task_setnice(p, nice);
 }
 
 static inline int security_task_setioprio (struct task_struct *p, int ioprio)
 {
-	return 0;
+	return cap_task_setioprio(p, ioprio);
 }
 
 static inline int security_task_getioprio (struct task_struct *p)
@@ -2617,7 +2621,7 @@ static inline int security_task_setsched
 					      int policy,
 					      struct sched_param *lp)
 {
-	return 0;
+	return cap_task_setscheduler(p, policy, lp);
 }
 
 static inline int security_task_getscheduler (struct task_struct *p)
@@ -2634,7 +2638,7 @@ static inline int security_task_kill (st
 				      struct siginfo *info, int sig,
 				      u32 secid)
 {
-	return 0;
+	return cap_task_kill(p, info, sig, secid);
 }
 
 static inline int security_task_wait (struct task_struct *p)
security/Kconfig +9 -0
index 460e5c9..6c9d69e 100644
@@ -80,6 +80,15 @@ config SECURITY_CAPABILITIES
 	  This enables the "default" Linux capabilities functionality.
 	  If you are unsure how to answer this question, answer Y.
 
+config SECURITY_FS_CAPABILITIES
+	bool "File POSIX Capabilities"
+	default n
+	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.
+
 config SECURITY_ROOTPLUG
 	tristate "Root Plug Support"
 	depends on USB && SECURITY
security/capability.c +4 -0
index b868e7e..14cb592 100644
@@ -40,6 +40,10 @@ static struct security_operations capabi
 	.inode_setxattr =		cap_inode_setxattr,
 	.inode_removexattr =		cap_inode_removexattr,
 
+	.task_kill =			cap_task_kill,
+	.task_setscheduler =		cap_task_setscheduler,
+	.task_setioprio =		cap_task_setioprio,
+	.task_setnice =			cap_task_setnice,
 	.task_post_setuid =		cap_task_post_setuid,
 	.task_reparent_to_init =	cap_task_reparent_to_init,
 
security/commoncap.c +153 -6

193 lines not on this page · raw message

security/selinux/hooks.c +12 -0
index 8ab5679..2fcc60f 100644
@@ -2775,6 +2775,12 @@ static int selinux_task_setnice(struct t
 
 static int selinux_task_setioprio(struct task_struct *p, int ioprio)
 {
+	int rc;
+
+	rc = secondary_ops->task_setioprio(p, ioprio);
+	if (rc)
+		return rc;
+
 	return task_has_perm(current, p, PROCESS__SETSCHED);
 }
 
@@ -2804,6 +2810,12 @@ static int selinux_task_setrlimit(unsign
 
 static int selinux_task_setscheduler(struct task_struct *p, int policy, struct sched_param *lp)
 {
+	int rc;
+
+	rc = secondary_ops->task_setscheduler(p, policy, lp);
+	if (rc)
+		return rc;
+
 	return task_has_perm(current, p, PROCESS__SETSCHED);
 }
 
Signature · 1 line
1.4.3.3
#7 lore raw
In reply to Serge E. Hallyn
Quoted 3 lines · Serge E. Hallyn

#define CAP_AUDIT_CONTROL 30

+#define CAP_NUMCAPS 31

[...]

Quoted 6 lines
security/commoncap.c +6 -0
+struct vfs_cap_data_struct {
+	__u32 version;
+	__u32 effective;
+	__u32 permitted;
+	__u32 inheritable;
+};

[...]

Quoted 12 lines
security/commoncap.c +12 -0
+static int check_cap_sanity(struct vfs_cap_data_struct *cap)
+{
+	int i;
+
+	if (cap->version != _LINUX_CAPABILITY_VERSION)
+		return -EPERM;
+
+	for (i=CAP_NUMCAPS; i<sizeof(cap->effective); i++) {
+		if (cap->effective & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->permitted); i++) {

security/commoncap.c void cap_capset_set (struct task_struct · line 150

Quoted 10 lines
security/commoncap.c +10 -0
+		if (cap->permitted & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->inheritable); i++) {
+		if (cap->inheritable & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+
+	return 0;
+}

for (i=31; i<4; i++) ...

I'm not sure this checks what you think it checks? :)

Thanks

#8 lore raw
Quoted 41 lines · Seth Arnold
Quoted 3 lines · Serge E. Hallyn

#define CAP_AUDIT_CONTROL 30

+#define CAP_NUMCAPS 31

[...]

Quoted 6 lines
security/commoncap.c +6 -0
+struct vfs_cap_data_struct {
+	__u32 version;
+	__u32 effective;
+	__u32 permitted;
+	__u32 inheritable;
+};

[...]

Quoted 12 lines
security/commoncap.c +12 -0
+static int check_cap_sanity(struct vfs_cap_data_struct *cap)
+{
+	int i;
+
+	if (cap->version != _LINUX_CAPABILITY_VERSION)
+		return -EPERM;
+
+	for (i=CAP_NUMCAPS; i<sizeof(cap->effective); i++) {
+		if (cap->effective & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->permitted); i++) {

security/commoncap.c void cap_capset_set (struct task_struct · line 150

Quoted 10 lines
security/commoncap.c +10 -0
+		if (cap->permitted & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->inheritable); i++) {
+		if (cap->inheritable & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+
+	return 0;
+}

for (i=31; i<4; i++) ...

Quoted 1 line

I'm not sure this checks what you think it checks? :)

Hah! Thanks for catching that.

I will send a fix out tonight.

-serge

#9 lore raw
In reply to Seth Arnold
Quoted 41 lines · Seth Arnold
Quoted 3 lines · Serge E. Hallyn

#define CAP_AUDIT_CONTROL 30

+#define CAP_NUMCAPS 31

[...]

Quoted 6 lines
(quoted diff) +6 -0
+struct vfs_cap_data_struct {
+	__u32 version;
+	__u32 effective;
+	__u32 permitted;
+	__u32 inheritable;
+};

[...]

Quoted 12 lines
(quoted diff) +12 -0
+static int check_cap_sanity(struct vfs_cap_data_struct *cap)
+{
+	int i;
+
+	if (cap->version != _LINUX_CAPABILITY_VERSION)
+		return -EPERM;
+
+	for (i=CAP_NUMCAPS; i<sizeof(cap->effective); i++) {
+		if (cap->effective & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->permitted); i++) {

Review

Quoted 10 lines
(quoted diff) +10 -0
+		if (cap->permitted & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->inheritable); i++) {
+		if (cap->inheritable & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+
+	return 0;
+}

for (i=31; i<4; i++) ...

Quoted 1 line

I'm not sure this checks what you think it checks? :)

Thanks again for catching this. Here is the obvious patch. Hopefully I have it right this time.

Quoted 1 line

From b91c46589b13bab78ddf431245a7ecbd59bcf2fd Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Tue, 7 Nov 2006 23:16:06 -0600
Subject: [PATCH 1/1] fscaps: fix cap sanity check

When checking for valid capabilities on files, we want to make sure that unused bits are not set. Fix the calculation of the highest bit checked.

---
 security/commoncap.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
security/commoncap.c +3 -3
index 6a0d033..6f5e46c 100644
@@ -133,15 +133,15 @@ static int check_cap_sanity(struct vfs_c
 	if (cap->version != _LINUX_CAPABILITY_VERSION)
 		return -EPERM;
 
-	for (i=CAP_NUMCAPS; i<sizeof(cap->effective); i++) {
+	for (i=CAP_NUMCAPS; i<8*sizeof(cap->effective); i++) {
 		if (cap->effective & CAP_TO_MASK(i))
 			return -EPERM;
 	}
-	for (i=CAP_NUMCAPS; i<sizeof(cap->permitted); i++) {
+	for (i=CAP_NUMCAPS; i<8*sizeof(cap->permitted); i++) {
 		if (cap->permitted & CAP_TO_MASK(i))
 			return -EPERM;
 	}
-	for (i=CAP_NUMCAPS; i<sizeof(cap->inheritable); i++) {
+	for (i=CAP_NUMCAPS; i<8*sizeof(cap->inheritable); i++) {
 		if (cap->inheritable & CAP_TO_MASK(i))
 			return -EPERM;
 	}
Signature · 1 line
1.4.3.3
#10 lore raw

The patch from Nov 7 2006 with this fix configures, compiles, installs and runns smotthly on 2.6.18.2.
I updated the page http://www.friedhoff.org/fscaps.html.
I also put the patch and this fix for download on the page and I put a slackware-package with Kaigai Kohei's libcap/userspace tools on the page.
I hope this will increase the interest and so testing of this patch.

Thanks Serge and Kaigai

Chris

Quoted 87 lines · On Tue, 7 Nov 2006 23:32:29 -0600 "Serge E. Hallyn" <[email protected]> wrote:
Quoted 41 lines · Seth Arnold
Quoted 3 lines · Serge E. Hallyn

#define CAP_AUDIT_CONTROL 30

+#define CAP_NUMCAPS 31

[...]

Quoted 6 lines
(quoted diff) +6 -0
+struct vfs_cap_data_struct {
+	__u32 version;
+	__u32 effective;
+	__u32 permitted;
+	__u32 inheritable;
+};

[...]

Quoted 12 lines
(quoted diff) +12 -0
+static int check_cap_sanity(struct vfs_cap_data_struct *cap)
+{
+	int i;
+
+	if (cap->version != _LINUX_CAPABILITY_VERSION)
+		return -EPERM;
+
+	for (i=CAP_NUMCAPS; i<sizeof(cap->effective); i++) {
+		if (cap->effective & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->permitted); i++) {

Review

Quoted 10 lines
(quoted diff) +10 -0
+		if (cap->permitted & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+	for (i=CAP_NUMCAPS; i<sizeof(cap->inheritable); i++) {
+		if (cap->inheritable & CAP_TO_MASK(i))
+			return -EPERM;
+	}
+
+	return 0;
+}

for (i=31; i<4; i++) ...

Quoted 1 line

I'm not sure this checks what you think it checks? :)

Thanks again for catching this. Here is the obvious patch. Hopefully I have it right this time.

Quoted 1 line

From b91c46589b13bab78ddf431245a7ecbd59bcf2fd Mon Sep 17 00:00:00 2001

From: Serge E. Hallyn <[email protected]>
Date: Tue, 7 Nov 2006 23:16:06 -0600
Subject: [PATCH 1/1] fscaps: fix cap sanity check

When checking for valid capabilities on files, we want to make sure that unused bits are not set. Fix the calculation of the highest bit checked.

---
 security/commoncap.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
security/commoncap.c +3 -3
index 6a0d033..6f5e46c 100644
@@ -133,15 +133,15 @@ static int check_cap_sanity(struct vfs_c
 	if (cap->version != _LINUX_CAPABILITY_VERSION)
 		return -EPERM;
 
-	for (i=CAP_NUMCAPS; i<sizeof(cap->effective); i++) {
+	for (i=CAP_NUMCAPS; i<8*sizeof(cap->effective); i++) {
 		if (cap->effective & CAP_TO_MASK(i))
 			return -EPERM;
 	}
-	for (i=CAP_NUMCAPS; i<sizeof(cap->permitted); i++) {
+	for (i=CAP_NUMCAPS; i<8*sizeof(cap->permitted); i++) {
 		if (cap->permitted & CAP_TO_MASK(i))
 			return -EPERM;
 	}
-	for (i=CAP_NUMCAPS; i<sizeof(cap->inheritable); i++) {
+	for (i=CAP_NUMCAPS; i<8*sizeof(cap->inheritable); i++) {
 		if (cap->inheritable & CAP_TO_MASK(i))
 			return -EPERM;
 	}
Signature · 1 line
1.4.3.3

--------------------
Chris Friedhoff
[email protected]