Skip to contentSkip to conversation

Capabilities across execve

PATCH Alexander Nyberg 5 participants 10 messages Mar 12, 2005 – Mar 19, 2005

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

This makes it possible for a root-task to pass capabilities to nonroot-task across execve. The root-task needs to change it's cap_inheritable mask and set prctl(PR_SET_KEEPCAPS, 1) to pass on capabilities.
At execve time the capabilities will be passed on to the new nonroot-task and any non-inheritable effective and permitted capabilities will be masked out.
The effective capability of the new nonroot-task will be set to the maximum permitted.

Quoted 1 line

From here on the inheritable mask will be passed on unchanged to the new

tasks children unless told otherwise (effectively the complete capability state is passed on).

With a small insert of prctl(PR_SET_KEEPCAPS, 1) into pam_cap.c at the correct place this makes pam_cap work as expected. I'm also attaching a test-case that tests capabilities across setuid => execve (makes the new task inherit CAP_CHOWN).

===== security/commoncap.c 1.15 vs edited =====

security/commoncap.c +19 -22
@@ -111,13 +111,19 @@ void cap_capset_set (struct task_struct 
 
 int cap_bprm_set_security (struct linux_binprm *bprm)
 {
-	/* Copied from fs/exec.c:prepare_binprm. */
-
-	/* We don't have VFS support for capabilities yet */
-	cap_clear (bprm->cap_inheritable);
-	cap_clear (bprm->cap_permitted);
-	cap_clear (bprm->cap_effective);
+	struct task_struct *p = current;
 
+	/*
+	 * Mask out the non-inheritable capabilities.
+	 * Note: init has a zero mask of cap_inheritable, so a root-task will not
+	 * pass on any capabilities unless explicitly told to do so. If a non-zero
+	 * inheritable mask is passed to a positive uid task it will then pass on 
+	 * its inheritable mask to all children unless told otherwise.
+	 */
+	bprm->cap_permitted = cap_intersect(p->cap_permitted, p->cap_inheritable);
+	bprm->cap_effective = cap_intersect(p->cap_effective, p->cap_inheritable);
+	bprm->cap_inheritable = p->cap_inheritable;
+	
 	/*  To support inheritance of root-permissions and suid-root
 	 *  executables under compatibility mode, we raise all three
 	 *  capability sets for the file.
@@ -127,7 +133,7 @@ int cap_bprm_set_security (struct linux_
 	 */
 
 	if (!issecure (SECURE_NOROOT)) {
-		if (bprm->e_uid == 0 || current->uid == 0) {
+		if (bprm->e_uid == 0 || p->uid == 0) {
 			cap_set_full (bprm->cap_inheritable);
 			cap_set_full (bprm->cap_permitted);
 		}
@@ -139,13 +145,9 @@ int cap_bprm_set_security (struct linux_
 
 void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
 {
-	/* Derived from fs/exec.c:compute_creds. */
-	kernel_cap_t new_permitted, working;
+	kernel_cap_t new_permitted;
 
 	new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
-	working = cap_intersect (bprm->cap_inheritable,
-				 current->cap_inheritable);
-	new_permitted = cap_combine (new_permitted, working);
 
 	if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
 	    !cap_issubset (new_permitted, current->cap_permitted)) {
@@ -166,14 +168,9 @@ void cap_bprm_apply_creds (struct linux_
 	current->suid = current->euid = current->fsuid = bprm->e_uid;
 	current->sgid = current->egid = current->fsgid = bprm->e_gid;
 
-	/* For init, we want to retain the capabilities set
-	 * in the init_task struct. Thus we skip the usual
-	 * capability rules */
-	if (current->pid != 1) {
-		current->cap_permitted = new_permitted;
-		current->cap_effective =
-		    cap_intersect (new_permitted, bprm->cap_effective);
-	}
+	current->cap_permitted = new_permitted;
+	current->cap_effective =
+			cap_intersect (new_permitted, bprm->cap_effective);
 
 	/* AUD: Audit candidate if current->cap_effective is set */
 
@@ -249,9 +246,9 @@ static inline void cap_emulate_setxuid (
 		cap_clear (current->cap_permitted);
 		cap_clear (current->cap_effective);
 	}
-	if (old_euid == 0 && current->euid != 0) {
+	if (old_euid == 0 && current->euid != 0 && !current->keep_capabilities)
 		cap_clear (current->cap_effective);
-	}
+
 	if (old_euid != 0 && current->euid == 0) {
 		current->cap_effective = current->cap_permitted;
 	}

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/capability.h>
#include <sys/prctl.h>

struct caph {
	int version;
	int pid;
};
struct capd {
	__u32 effective;
	__u32 permitted;
	__u32 inheritable;
};

gid_t gid = 1000;
uid_t uid = 1000;

void printcap(char *str)

{
	int ret;
	struct caph caph;
	struct capd capd;
	
	memset(&capd, 0, sizeof(capd));	
	
	caph.version = 0x19980330;
	caph.pid = getpid();

	ret = capget(&caph, &capd);
	if (ret < 0)
		perror("capget");
	printf("%s: ", str);
	printf("eff:%u perm:%u inh:%u\n", capd.effective, capd.permitted, capd.inheritable);
}

void lower_uid()

{
	int ret;
	gid_t gidlist[1];
	
	gidlist[0] = gid;
	ret = setgroups(1, gidlist);
	if (ret < 0)
		perror("setgroups");
	if (setgid(gid))
		perror("setgid");
	if (setuid(uid))
		perror("setuid");
}

const char *bash[] = { "bash", NULL };

int main(int argc, char **argv)

{
	int ret;
	struct caph caph;
	struct capd capd;

	if (argc == 3) {
		uid = strtoul(argv[1], NULL, 0);
		gid = strtoul(argv[2], NULL, 0);
	} else {
		printf("Usage: \"./program uid gid\" where uid & gid\n");
		printf("are the ids you want to change to (then run bash)\n");
		exit(1);
	}

	printcap("caps when started");

	memset(&capd, 0, sizeof(capd));	

	caph.version = 0x19980330;
	caph.pid = getpid();

	ret = capget(&caph, &capd);
	if (ret < 0)
		perror("capget");
	
	capd.inheritable |= (1 << CAP_CHOWN);
	
	ret = capset(&caph, &capd);
	if (ret < 0)
		perror("capset");

	printf("new inheritable mask: %u\n", capd.inheritable);
	
	ret = prctl(PR_SET_KEEPCAPS, 1);
	if (ret)
		perror("prctl");
	
	lower_uid();

	printcap("after setuid");
        
	ret = execv("/bin/bash", bash);
	if (ret < 0)
		perror("execve");
		
	return 0;
}
#1 lore raw
Quoted 4 lines · * Alexander Nyberg ([email protected]) wrote:

This makes it possible for a root-task to pass capabilities to nonroot-task across execve. The root-task needs to change it's cap_inheritable mask and set prctl(PR_SET_KEEPCAPS, 1) to pass on capabilities.

This overloads keepcaps, which could surprise to existing users.

Quoted 5 lines

At execve time the capabilities will be passed on to the new nonroot-task and any non-inheritable effective and permitted capabilities will be masked out.
The effective capability of the new nonroot-task will be set to the maximum permitted.

What happens to eff on setuid() to non-root or restore to uid 0? What happens if you exec a setuid-root binary, or a setuid-nonroot binary? How about ptrace?

Here's the tests I use.

thanks,
-chris

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
#2 lore raw
Quoted 6 lines
Quoted 4 lines

This makes it possible for a root-task to pass capabilities to nonroot-task across execve. The root-task needs to change it's cap_inheritable mask and set prctl(PR_SET_KEEPCAPS, 1) to pass on capabilities.

This overloads keepcaps, which could surprise to existing users.

current->keep_capabilities is set to 0 at each execve, however the inheritable mask is passed on and therefor also the allowed effective + permitted. I think this is very necessery if there's ever going to be a real use of it. It's not worth anything getting a shell with every capability if every new process you run afterwards will have its capabilities dropped. If we do like this it will only be useful in special circumstances when wanting to run _one_ application with some special capability. The scope can be much more general. How about having users that can run all the way CAP_SYS_NICE, would give every audio man his realtime applications. This is certainly possible with capabilities across execve and pam_cap (using a few caps myself right now).

Quoted 7 lines
Quoted 5 lines

At execve time the capabilities will be passed on to the new nonroot-task and any non-inheritable effective and permitted capabilities will be masked out.
The effective capability of the new nonroot-task will be set to the maximum permitted.

What happens to eff on setuid() to non-root

If KEEPCAPS is set the permitted and inheritable capabilities are still there, the effective capabilities are cleared either way.

Quoted 1 line

or restore to uid 0?

Full capabilities restored.

Quoted 1 line

What happens if you exec a setuid-root binary,

Sets full permitted & effective, inheritable left as is. This means that if the setuid-root binary does an execve to another program cap_inheritable will take effect and the capabilities will be the same as before calling the setuid-root binary. I doubt this is common scenario however.

Quoted 1 line

or a setuid-nonroot binary?

capabilities unchanged

Quoted 1 line

How about ptrace?

I'll look into this part, but I don't see it changing anything here right now.

However I'm sure there are cases I've missed and I'm looking for them right now. This patch is going to need a few good eyes.

Quoted 1 line

Here's the tests I use.

I've looked at some cases in this test suite but as It doesn't say much more than "begin test 37" I have no idea of how to parse the output.

Updated patch.

===== security/commoncap.c 1.15 vs edited =====

security/commoncap.c +23 -20
@@ -111,13 +111,19 @@ void cap_capset_set (struct task_struct 
 
 int cap_bprm_set_security (struct linux_binprm *bprm)
 {
-	/* Copied from fs/exec.c:prepare_binprm. */
-
-	/* We don't have VFS support for capabilities yet */
-	cap_clear (bprm->cap_inheritable);
-	cap_clear (bprm->cap_permitted);
-	cap_clear (bprm->cap_effective);
+	struct task_struct *p = current;
 
+	/*
+	 * Mask out the non-inheritable capabilities.
+	 * Note: init has a zero mask of cap_inheritable, so a root-task will not
+	 * pass on any capabilities unless explicitly told to do so. If a non-zero
+	 * inheritable mask is passed to a positive uid task it will then pass on 
+	 * its inheritable mask to all children unless told otherwise.
+	 */
+	bprm->cap_permitted = cap_intersect(p->cap_permitted, p->cap_inheritable);
+	bprm->cap_effective = cap_intersect(p->cap_effective, p->cap_inheritable);
+	bprm->cap_inheritable = p->cap_inheritable;
+	
 	/*  To support inheritance of root-permissions and suid-root
 	 *  executables under compatibility mode, we raise all three
 	 *  capability sets for the file.
@@ -127,7 +133,7 @@ int cap_bprm_set_security (struct linux_
 	 */
 
 	if (!issecure (SECURE_NOROOT)) {
-		if (bprm->e_uid == 0 || current->uid == 0) {
+		if (bprm->e_uid == 0 || p->uid == 0) {
 			cap_set_full (bprm->cap_inheritable);
 			cap_set_full (bprm->cap_permitted);
 		}
@@ -139,13 +145,9 @@ int cap_bprm_set_security (struct linux_
 
 void cap_bprm_apply_creds (struct linux_binprm *bprm, int unsafe)
 {
-	/* Derived from fs/exec.c:compute_creds. */
-	kernel_cap_t new_permitted, working;
+	kernel_cap_t new_permitted;
 
 	new_permitted = cap_intersect (bprm->cap_permitted, cap_bset);
-	working = cap_intersect (bprm->cap_inheritable,
-				 current->cap_inheritable);
-	new_permitted = cap_combine (new_permitted, working);
 
 	if (bprm->e_uid != current->uid || bprm->e_gid != current->gid ||
 	    !cap_issubset (new_permitted, current->cap_permitted)) {
@@ -166,14 +168,15 @@ void cap_bprm_apply_creds (struct linux_
 	current->suid = current->euid = current->fsuid = bprm->e_uid;
 	current->sgid = current->egid = current->fsgid = bprm->e_gid;
 
-	/* For init, we want to retain the capabilities set
-	 * in the init_task struct. Thus we skip the usual
-	 * capability rules */
-	if (current->pid != 1) {
-		current->cap_permitted = new_permitted;
-		current->cap_effective =
-		    cap_intersect (new_permitted, bprm->cap_effective);
-	}
+	current->cap_permitted = new_permitted;
+	/*
+	 * Is this a root task that did seteuid before execve? if so
+	 * it wanted its effective permissions dropped.
+	 */
+	if (current->euid && current->uid == 0)
+		cap_clear(current->cap_effective);
+	else	
+		current->cap_effective = new_permitted;
 
 	/* AUD: Audit candidate if current->cap_effective is set */
 
#3 lore raw
In reply to Chris Wright
Quoted 7 lines · Chris Wright
Quoted 4 lines · * Alexander Nyberg ([email protected]) wrote:

This makes it possible for a root-task to pass capabilities to nonroot-task across execve. The root-task needs to change it's cap_inheritable mask and set prctl(PR_SET_KEEPCAPS, 1) to pass on capabilities.

This overloads keepcaps, which could surprise to existing users.

Chris,

Since you seem to be knowledgeable about the capability system, I have a question.

As part of the libcap library (found on Fedora and such like), there are several programs supplied with it - execcap and sucap for instance:

usage: execcap <caps> <command-path> [command-args...]

This program is a wrapper that can be used to limit the Inheritable capabilities of a program to be executed. Note, this wrapper is intended to assist in overcoming a lack of support for filesystem capability attributes and should be used to launch other files. This program should _NOT_ be made setuid-0.

usage: sucap <user> <group> <command-path> [command-args...]

This program is a wrapper that change UID but not privileges of a program to be executed.
Note, this wrapper is intended to assist in overcoming a lack of support for filesystem capability attributes and should be used to launch other files. This program should _NOT_ be made setuid-0.

At some point, I decided I'd like to run a certain program non-root with certain capabilities only. I looked at the above two programs and stupidly thought they'd actually allow me to do this.

However, the way the kernel is setup today, this seems impossible to achieve, which tends to make the whole idea of capabilities completely and utterly useless.

How is this stuff supposed to work? Are my ideas of what's supposed to be achievable completely wrong, although they look completely reasonable to me.

Don't get me wrong - the capability system seems great at permanently revoking capabilities via /proc/sys/kernel/cap-bound, and dropping them within an application provided it remains UID0. Apart from that, capabilities seem completely useless.

For example:

bash-2.05a# execcap all-ep /bin/sh -c 'getpcaps $$' Capabilities for `5036': =ep cap_setpcap-ep

Note carefully that the requested capabilities haven't been granted:

capset(0x19980330, 0, {, , }) = 0
execve("/bin/sh", ["/bin/sh", "-c", "getpcaps $$"], [/* 19 vars */]) = 0

The reason this happens is that we're still running UID0, and UID0 on execve appears to re-gain all privileges. This is fine of you're running in compatibility mode. So, in order to do this, we want to drop from UID0 _first_ and then play around with capabilities. Great, we have the sucap program to do that for us. So we can do:

sucap rmk rmk execcap <capabilities> program args

Or can we?

bash-2.05a# sucap rmk rmk /bin/sh -c 'getpcaps $$'
Caps: =ep cap_setpcap-ep
Caps: =
[debug] uid:501, real uid:501
sucaps: capsetp: Operation not permitted
sucap: child did not exit cleanly.

Oh dear, I guess sucap doesn't work after all. (It forks a child process, the parent then switches UID, the child then tries to capsetp() the parent - which of course won't work without the cap_setpcap. Since the kernel never grants this capability in the first place to *anyone*... it seems to be something of a lost cause.

Don't get me wrong - the current behaviour is secure. But it's so secure that it gets in the way of things which should appear to work.

I forget precisely what I wanted to achieve with this, and why I couldn't just make the program do it itself... It may have been a script running from cron periodically which needed just one or two capabilities in order to operate, rather than the whole truck load you get by running it as root. What I do remember is that my goal of running the script with minimal capabilities was completely *impossible* to achieve.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#4 lore raw
Quoted 7 lines · * Russell King ([email protected]) wrote:

At some point, I decided I'd like to run a certain program non-root with certain capabilities only. I looked at the above two programs and stupidly thought they'd actually allow me to do this.

However, the way the kernel is setup today, this seems impossible to achieve, which tends to make the whole idea of capabilities completely and utterly useless.

Yes, the only value of capabilities right now is for a single program that starts off as root with full caps to drop uid and caps.

Quoted 3 lines

How is this stuff supposed to work? Are my ideas of what's supposed to be achievable completely wrong, although they look completely reasonable to me.

It was meant to work with capabilities in the filesystem like setuid bits. So the patches that have floated around from myself, Andy Lutomirski and Alex Nyberg are attempts to make something half-way sane out of the mess. The trouble is then convincing yourself that it's not some way to leak capabilities (esp. since some programs use the interface already, like bind9).

Quoted 4 lines

Don't get me wrong - the capability system seems great at permanently revoking capabilities via /proc/sys/kernel/cap-bound, and dropping them within an application provided it remains UID0. Apart from that, capabilities seem completely useless.

It doesn't have to remain uid0. That's what the prctl PR_SET_KEEPCAPS does. But it's not a nice interface, nor simple to use (for example, it'll drop the effective set, so you have to reinstate them).

Quoted 27 lines

For example:

bash-2.05a# execcap all-ep /bin/sh -c 'getpcaps $$' Capabilities for `5036': =ep cap_setpcap-ep

Note carefully that the requested capabilities haven't been granted:

capset(0x19980330, 0, {, , }) = 0
execve("/bin/sh", ["/bin/sh", "-c", "getpcaps $$"], [/* 19 vars */]) = 0

The reason this happens is that we're still running UID0, and UID0 on execve appears to re-gain all privileges. This is fine of you're running in compatibility mode. So, in order to do this, we want to drop from UID0 _first_ and then play around with capabilities. Great, we have the sucap program to do that for us. So we can do:

sucap rmk rmk execcap <capabilities> program args

Or can we?

bash-2.05a# sucap rmk rmk /bin/sh -c 'getpcaps $$'
Caps: =ep cap_setpcap-ep
Caps: =
[debug] uid:501, real uid:501
sucaps: capsetp: Operation not permitted
sucap: child did not exit cleanly.

Quoted 5 lines

Oh dear, I guess sucap doesn't work after all. (It forks a child process, the parent then switches UID, the child then tries to capsetp() the parent - which of course won't work without the cap_setpcap. Since the kernel never grants this capability in the first place to *anyone*... it seems to be something of a lost cause.

Yes, that's the core of the issue. If you exec a uid0 process you get all caps, otherwise you lose all caps. And cap_setpcap was removed when the sendmail exploit came out, so it's further crippled.

Quoted 10 lines

Don't get me wrong - the current behaviour is secure. But it's so secure that it gets in the way of things which should appear to work.

I forget precisely what I wanted to achieve with this, and why I couldn't just make the program do it itself... It may have been a script running from cron periodically which needed just one or two capabilities in order to operate, rather than the whole truck load you get by running it as root. What I do remember is that my goal of running the script with minimal capabilities was completely *impossible* to achieve.

All I can say is work is underway. There's 3 different patches that will get you to your goal. I understand that it's a real pain right now. One of the authors of the withdrawn draft has told me that the notion of capabilities w/out filesystem support was considered effectively useless. So, we're in uncharted territory. BTW, thanks for reminding me of scripts, I had been testing just C programs.

thanks,
-chris

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
#5 lore raw

tis 2005-03-15 klockan 14:42 -0800 skrev Chris Wright:

Quoted 16 lines · * Russell King ([email protected]) wrote:
Quoted 7 lines

At some point, I decided I'd like to run a certain program non-root with certain capabilities only. I looked at the above two programs and stupidly thought they'd actually allow me to do this.

However, the way the kernel is setup today, this seems impossible to achieve, which tends to make the whole idea of capabilities completely and utterly useless.

Yes, the only value of capabilities right now is for a single program that starts off as root with full caps to drop uid and caps.

Quoted 3 lines

How is this stuff supposed to work? Are my ideas of what's supposed to be achievable completely wrong, although they look completely reasonable to me.

Quoted 6 lines

It was meant to work with capabilities in the filesystem like setuid bits. So the patches that have floated around from myself, Andy Lutomirski and Alex Nyberg are attempts to make something half-way sane out of the mess. The trouble is then convincing yourself that it's not some way to leak capabilities (esp. since some programs use the interface already, like bind9).

Anyone who uses the current interfaces should not play with the inheritable flag, the text I looked at said it was specifically for execve. Thus if the application doesn't modify the inheritable mask things will look like it has always done. And it really should not mess with inheritable mask if it doesn't intend to, that would be a security bug.
We really should be safe doing this.

Quoted 21 lines
Quoted 4 lines

Don't get me wrong - the capability system seems great at permanently revoking capabilities via /proc/sys/kernel/cap-bound, and dropping them within an application provided it remains UID0. Apart from that, capabilities seem completely useless.

It doesn't have to remain uid0. That's what the prctl PR_SET_KEEPCAPS does. But it's not a nice interface, nor simple to use (for example, it'll drop the effective set, so you have to reinstate them).

Quoted 10 lines

Don't get me wrong - the current behaviour is secure. But it's so secure that it gets in the way of things which should appear to work.

I forget precisely what I wanted to achieve with this, and why I couldn't just make the program do it itself... It may have been a script running from cron periodically which needed just one or two capabilities in order to operate, rather than the whole truck load you get by running it as root. What I do remember is that my goal of running the script with minimal capabilities was completely *impossible* to achieve.

Quoted 6 lines

All I can say is work is underway. There's 3 different patches that will get you to your goal. I understand that it's a real pain right now. One of the authors of the withdrawn draft has told me that the notion of capabilities w/out filesystem support was considered effectively useless. So, we're in uncharted territory. BTW, thanks for reminding me of scripts, I had been testing just C programs.

I wouldn't call it useless, retaining capabilities across execve + pam_cap is a very useful thing, on my machine I can give myself a few capabilities that have always annoyed me (iirc the database that wanted mlock as regular user would have been solved aswell).

Regarding fs attributes:
http://www.ussg.iu.edu/hypermail/linux/kernel/0211.0/0171.html

I can see useful scenarios of having the possiblity of capabilities per inode (it appears the xattr way wins somewhat in the previous discussion).

Chris, have you seen any capabilities+xattr patches around?

#6 lore raw
Quoted 8 lines · * Alexander Nyberg ([email protected]) wrote:

tis 2005-03-15 klockan 14:42 -0800 skrev Chris Wright:

Quoted 6 lines

It was meant to work with capabilities in the filesystem like setuid bits. So the patches that have floated around from myself, Andy Lutomirski and Alex Nyberg are attempts to make something half-way sane out of the mess. The trouble is then convincing yourself that it's not some way to leak capabilities (esp. since some programs use the interface already, like bind9).

Quoted 7 lines

Anyone who uses the current interfaces should not play with the inheritable flag, the text I looked at said it was specifically for execve. Thus if the application doesn't modify the inheritable mask things will look like it has always done. And it really should not mess with inheritable mask if it doesn't intend to, that would be a security bug.
We really should be safe doing this.

That's one of the points. Latent bugs getting triggered is what makes the change deserving of being conservative.

Quoted 11 lines
Quoted 6 lines

All I can say is work is underway. There's 3 different patches that will get you to your goal. I understand that it's a real pain right now. One of the authors of the withdrawn draft has told me that the notion of capabilities w/out filesystem support was considered effectively useless. So, we're in uncharted territory. BTW, thanks for reminding me of scripts, I had been testing just C programs.

I wouldn't call it useless, retaining capabilities across execve + pam_cap is a very useful thing, on my machine I can give myself a few capabilities that have always annoyed me (iirc the database that wanted mlock as regular user would have been solved aswell).

Yes, that's useful, but having 3 sets and complicated rules for combining task and file based sets is not really necessary for that.

Quoted 6 lines

Regarding fs attributes:
http://www.ussg.iu.edu/hypermail/linux/kernel/0211.0/0171.html

I can see useful scenarios of having the possiblity of capabilities per inode (it appears the xattr way wins somewhat in the previous discussion).

It's how it should be done.

Quoted 1 line

Chris, have you seen any capabilities+xattr patches around?

http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.4-fcap/

thanks,
-chris

Signature · 1 line
Linux Security Modules     http://lsm.immunix.org     http://lsm.bkbits.net
#7 lore raw
Quoted 15 lines
Quoted 7 lines
Quoted 6 lines

It was meant to work with capabilities in the filesystem like setuid bits. So the patches that have floated around from myself, Andy Lutomirski and Alex Nyberg are attempts to make something half-way sane out of the mess. The trouble is then convincing yourself that it's not some way to leak capabilities (esp. since some programs use the interface already, like bind9).

Quoted 7 lines

Anyone who uses the current interfaces should not play with the inheritable flag, the text I looked at said it was specifically for execve. Thus if the application doesn't modify the inheritable mask things will look like it has always done. And it really should not mess with inheritable mask if it doesn't intend to, that would be a security bug.
We really should be safe doing this.

Quoted 2 lines

That's one of the points. Latent bugs getting triggered is what makes the change deserving of being conservative.

bind9 actually sets inheritable, but I don't see it doing any exec in the whole package, so it should be safe. I'll look for other large common packages using capabilities.
I don't think this necessarily is 2.7 material, but otoh if it has waited this long there doesn't appear to be that kind of rush to get it in.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

All I can say is work is underway. There's 3 different patches that will get you to your goal. I understand that it's a real pain right now. One of the authors of the withdrawn draft has told me that the notion of capabilities w/out filesystem support was considered effectively useless. So, we're in uncharted territory. BTW, thanks for reminding me of scripts, I had been testing just C programs.

Quoted 7 lines
Quoted 4 lines

I wouldn't call it useless, retaining capabilities across execve + pam_cap is a very useful thing, on my machine I can give myself a few capabilities that have always annoyed me (iirc the database that wanted mlock as regular user would have been solved aswell).

Yes, that's useful, but having 3 sets and complicated rules for combining task and file based sets is not really necessary for that.

However I never saw any real clean solution for the problem and I would call this better and more general for this kind of problems.

Quoted 7 lines
Quoted 6 lines

Regarding fs attributes:
http://www.ussg.iu.edu/hypermail/linux/kernel/0211.0/0171.html

I can see useful scenarios of having the possiblity of capabilities per inode (it appears the xattr way wins somewhat in the previous discussion).

Quoted 5 lines

It's how it should be done.

Quoted 1 line

Chris, have you seen any capabilities+xattr patches around?

http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.4-fcap/

Thanks, I'll have a look at this.

#8 lore raw
In reply to Chris Wright
Quoted 6 lines · Chris Wright
Quoted 3 lines · * Alexander Nyberg ([email protected]) wrote:

I can see useful scenarios of having the possiblity of capabilities per inode (it appears the xattr way wins somewhat in the previous discussion).

It's how it should be done.

I agree to disagree :-)

Quoted 3 lines
Quoted 1 line

Chris, have you seen any capabilities+xattr patches around?

http://www.kernel.org/pub/linux/libs/security/linux-privs/kernel-2.4-fcap/

Which is pretty useless, since it doesn't apply to any recent (> 2.4.3) kernel. If you insist on a xattr based approach, take Andy Lutomirski's <http://www.stanford.edu/~luto/linux-fscap/>
patch. It is more recent, a lot smaller and considerably more understandable (at least for me ;-).

Regards, Olaf.

#9 lore raw
In reply to Alexander Nyberg

Hi!

Quoted 10 lines

This makes it possible for a root-task to pass capabilities to nonroot-task across execve. The root-task needs to change it's cap_inheritable mask and set prctl(PR_SET_KEEPCAPS, 1) to pass on capabilities.
At execve time the capabilities will be passed on to the new nonroot-task and any non-inheritable effective and permitted capabilities will be masked out.
The effective capability of the new nonroot-task will be set to the maximum permitted.

Quoted 8 lines
Quoted 1 line

From here on the inheritable mask will be passed on unchanged to the new

tasks children unless told otherwise (effectively the complete capability state is passed on).

With a small insert of prctl(PR_SET_KEEPCAPS, 1) into pam_cap.c at the correct place this makes pam_cap work as expected. I'm also attaching a test-case that tests capabilities across setuid => execve (makes the new task inherit CAP_CHOWN).

FWIV, I think this is good idea; this way capabilities will not only be castle in the sky, but also will be actually usable.
Pavel

Signature · 2 lines
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!