Skip to contentSkip to conversation

p9auth: split core function out of some set*{u,g}id functions

PATCH In review Serge E. Hallyn 10 participants 29 messages Apr 21, 2010 – Apr 25, 2010

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

PATCH 1/3 p9auth: split core function out of some set*{u,g}id functions

Break the core functionality of set{fs,res}{u,g}id into cred_setX which performs the access checks based on current_cred(), but performs the requested change on a passed-in cred.

Export the helpers, since p9auth can be compiled as a module. It might be worth not allowing modular p9auth to avoid having to export them.

Really the setfs{u,g}id helper isn't needed, but move it as well to keep the code consistent.

This patch also changes set_user() to use new->user->user_ns. While technically not needed as all callers should have new->user->user_ns equal to current_userns(), it is more correct and may prevent surprises in the future.

---
 include/linux/cred.h |   12 +++++
 kernel/cred.c        |  119 +++++++++++++++++++++++++++++++++++++++++++++
 kernel/sys.c         |  131 ++++++++------------------------------------------
 3 files changed, 151 insertions(+), 111 deletions(-)
include/linux/cred.h +12 -0
index 52507c3..0ce7a50 100644
@@ -22,6 +22,9 @@ struct user_struct;
 struct cred;
 struct inode;
 
+/* defined in sys.c, used in cred_setresuid */
+extern int set_user(struct cred *new);
+
 /*
  * COW Supplementary groups list
  */
@@ -396,4 +399,13 @@ do {						\
 	*(_fsgid) = __cred->fsgid;		\
 } while(0)
 
+#define CRED_SETID_NOFORCE 0
+#define CRED_SETID_FORCE 1
+int cred_setresuid(struct cred *new, uid_t ruid, uid_t euid, uid_t suid,
+		   int force);
+int cred_setresgid(struct cred *new, gid_t rgid, gid_t egid, gid_t sgid,
+		   int force);
+int cred_setfsuid(struct cred *new, uid_t uid, uid_t *old_fsuid);
+int cred_setfsgid(struct cred *new, gid_t gid, gid_t *old_fsgid);
+
 #endif /* _LINUX_CRED_H */
kernel/cred.c +119 -0

125 lines not on this page · raw message

kernel/sys.c +20 -111

195 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/3 p9auth: add CAP_GRANT_ID to authorize use of /dev/caphash

Granting userid capabilities to another task is a dangerous privilege. Don't just let file permissions authorize it. Define CAP_GRANT_ID as a new capability needed to write to /dev/caphash.

For one thing this lets us start a factotum server early on in init, then have init drop CAP_GRANT_ID from its bounding set so the rest of the system cannot regain it.

---
 include/linux/capability.h          |    6 +++++-
 security/selinux/include/classmap.h |    2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/capability.h +5 -1
index 39e5ff5..ba2cbfe 100644
@@ -355,7 +355,11 @@ struct cpu_vfs_cap_data {
 
 #define CAP_MAC_ADMIN        33
 
-#define CAP_LAST_CAP         CAP_MAC_ADMIN
+/* Allow granting setuid capabilities through p9auth /dev/caphash */
+
+#define CAP_GRANT_ID         34
+
+#define CAP_LAST_CAP         CAP_GRANT_ID
 
 #define cap_valid(x) ((x) >= 0 && (x) <= CAP_LAST_CAP)
 
security/selinux/include/classmap.h +1 -1
index 8b32e95..f0ec53a 100644
@@ -142,7 +142,7 @@ struct security_class_mapping secclass_map[] = {
 	    "node_bind", "name_connect", NULL } },
 	{ "memprotect", { "mmap_zero", NULL } },
 	{ "peer", { "recv", NULL } },
-	{ "capability2", { "mac_override", "mac_admin", NULL } },
+	{ "capability2", { "mac_override", "mac_admin", "grant_id", NULL } },
 	{ "kernel_service", { "use_as_override", "create_files_as", NULL } },
 	{ "tun_socket",
 	  { COMMON_SOCK_PERMS, NULL } },
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH 3/3 p9auth: add p9auth driver

In reply to Serge E. Hallyn

This is a driver that adds Plan 9 style capability device implementation. See Documentation/p9auth.txt for a description of how to use this.

This driver allows the implementation of completely unprivileged login daemons. However, doing so requires a fundamental change regarding linux userids: a server privileged with the new CAP_GRANT_ID capability can create a one-time setuid capability allowing another process to change to one specific new userid. This is a change which must be discussed. The use of this privilege can be completely prevented by having init remove CAP_GRANT_ID from its capability bounding set before forking any processes.

---
 Documentation/p9auth.txt     |   47 ++++
 drivers/char/Kconfig         |    2 +
 drivers/char/Makefile        |    2 +
 drivers/char/p9auth/Kconfig  |    9 +
 drivers/char/p9auth/Makefile |    1 +
 drivers/char/p9auth/p9auth.c |  517 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 578 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/p9auth.txt
 create mode 100644 drivers/char/p9auth/Kconfig
 create mode 100644 drivers/char/p9auth/Makefile
 create mode 100644 drivers/char/p9auth/p9auth.c
Documentation/p9auth.txt new file +47 -0
new file mode 100644
index 0000000..14a69d8
@@ -0,0 +1,47 @@
+The p9auth device driver implements a plan-9 factotum-like
+capability API.  Tasks which are privileged (authorized by
+possession of the CAP_GRANT_ID privilege (POSIX capability))
+can write new capabilities to /dev/caphash.  The kernel then
+stores these until a task uses them by writing to the
+/dev/capuse device.  Each capability represents the ability
+for a task running as userid X to switch to userid Y and
+some set of groups.  Each capability may be used only once,
+and unused capabilities are cleared after two minutes.
+
+The following examples shows how to use the API.  Shell 1
+contains a privileged root shell.  Shell 2 contains an
+unprivileged shell as user 501 in the same user namespace.  If
+not already done, the privileged shell should create the p9auth
+devices:
+
+	majfile=/sys/module/p9auth/parameters/cap_major
+	minfile=/sys/module/p9auth/parameters/cap_minor
+	maj=`cat $majfile`
+	mknod /dev/caphash c $maj 0
+	min=`cat $minfile`
+	mknod /dev/capuse c $maj 1
+	chmod ugo+w /dev/capuse
+
+Now shell 2 somehow communicates to shell 1 that it possesses
+valid login credentials to switch to userid 502.  Shell 2 then
+looks up the groups which uid 502 is a member of, and builds
+a capability string to pass to the kernel.  It does this by
+concatenating the old userid, new userid, new primary group,
+number of auxiliary groups, and each auxiliary group, all
+as integers separated by '@'.  The resulting string is hashed
+with a random string.  In our example, userid 501 may transition
+to userid 502, with primary group 502 and auxiliary group 29.
+
+	capstr="501@502@502@1@29"
+	echo -n "$capstr" > /tmp/txtfile
+	randstr=`dd if=/dev/urandom count=1 2>/dev/null | \
+			uuencode -m - | head -n 2 | tail -n 1 | cut -c -8 `
+	openssl sha1 -hmac "$randstr" /tmp/txtfile | awk '{ print $2 '} \
+		> /tmp/hex
+	./unhex < /tmp/hex > /dev/caphash
+
+The source for unhex.c can be found in the ltp testsuite under
+ltp-dev/testcases/kernel/security/p9auth.  To shell 2 it passes $capstr
+and $randstr.  Shell 2 can then transition to the new userid by doing
+
+	echo -n "$capstr@$randstr" > /dev/capuse
drivers/char/Kconfig +2 -0
index 3141dd3..e7ff2a9 100644
@@ -1113,5 +1113,7 @@ config DEVPORT
 
 source "drivers/s390/char/Kconfig"
 
+source "drivers/char/p9auth/Kconfig"
+
 endmenu
 
drivers/char/Makefile +2 -0
index f957edf..3c27905 100644
@@ -111,6 +111,8 @@ obj-$(CONFIG_PS3_FLASH)		+= ps3flash.o
 obj-$(CONFIG_JS_RTC)		+= js-rtc.o
 js-rtc-y = rtc.o
 
+obj-$(CONFIG_PLAN9AUTH)		+= p9auth/
+
 # Files generated that shall be removed upon make clean
 clean-files := consolemap_deftbl.c defkeymap.c
 
drivers/char/p9auth/Kconfig new file +9 -0
new file mode 100644
index 0000000..d1c66d2
@@ -0,0 +1,9 @@
+config PLAN9AUTH
+	tristate "Plan 9 style capability device implementation"
+	default n
+	depends on CRYPTO
+	help
+	  This module implements the Plan 9 style capability device.
+
+	  To compile this driver as a module, choose
+	  M here: the module will be called p9auth.
drivers/char/p9auth/Makefile new file +1 -0
new file mode 100644
index 0000000..3ebf6ff
@@ -0,0 +1 @@
+obj-$(CONFIG_PLAN9AUTH)	+= p9auth.o
drivers/char/p9auth/p9auth.c new file +517 -0

517 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#4 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 3 lines · Serge E. Hallyn

This is a driver that adds Plan 9 style capability device implementation. See Documentation/p9auth.txt for a description of how to use this.

Hm, you didn't originally write this driver, so it would be good to get some original authorship information in here to keep everything correct, right?

Quoted 6 lines
 Documentation/p9auth.txt     |   47 ++++
 drivers/char/Kconfig         |    2 +
 drivers/char/Makefile        |    2 +
 drivers/char/p9auth/Kconfig  |    9 +
 drivers/char/p9auth/Makefile |    1 +
 drivers/char/p9auth/p9auth.c |  517 ++++++++++++++++++++++++++++++++++++++++++

Is this code really ready for drivers/char/? What has changed in it that makes it ok to move out of the staging tree?

And who is going to maintain it? You? Or someone else?

Quoted 25 lines
 6 files changed, 578 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/p9auth.txt
 create mode 100644 drivers/char/p9auth/Kconfig
 create mode 100644 drivers/char/p9auth/Makefile
 create mode 100644 drivers/char/p9auth/p9auth.c
Documentation/p9auth.txt new file +13 -0
new file mode 100644
index 0000000..14a69d8
@@ -0,0 +1,47 @@
+The p9auth device driver implements a plan-9 factotum-like
+capability API.  Tasks which are privileged (authorized by
+possession of the CAP_GRANT_ID privilege (POSIX capability))
+can write new capabilities to /dev/caphash.  The kernel then
+stores these until a task uses them by writing to the
+/dev/capuse device.  Each capability represents the ability
+for a task running as userid X to switch to userid Y and
+some set of groups.  Each capability may be used only once,
+and unused capabilities are cleared after two minutes.
+
+The following examples shows how to use the API.  Shell 1
+contains a privileged root shell.  Shell 2 contains an
+unprivileged shell as user 501 in the same user namespace.  If

Documentation/p9auth.txt line 23

Quoted 10 lines
Documentation/p9auth.txt new file +10 -0
+not already done, the privileged shell should create the p9auth
+devices:
+
+	majfile=/sys/module/p9auth/parameters/cap_major
+	minfile=/sys/module/p9auth/parameters/cap_minor
+	maj=`cat $majfile`
+	mknod /dev/caphash c $maj 0
+	min=`cat $minfile`
+	mknod /dev/capuse c $maj 1
+	chmod ugo+w /dev/capuse

That is incorrect, you don't need the cap_major/minor files at all, the device node should be automatically created for you, right?

And do you really want to do all of this control through a device node? Why?

Documentation/p9auth.txt line 24

Quoted 1 line
Documentation/p9auth.txt new file +1 -0
+DEFINE_MUTEX(cap_mutex); /* TODO fix up the locking one day */

One might hope that today would be that day...

Also, please run this through sparse. This is a variable that doesn't need to be global.

Documentation/p9auth.txt line 27

Quoted 3 lines
Documentation/p9auth.txt new file +3 -0
+struct cap_dev {
+	struct cdev cdev;
+};

Do you really need to do it this way? A cdev for a single device node? That's major overkill.

Documentation/p9auth.txt line 29

Quoted 2 lines
Documentation/p9auth.txt new file +2 -0
+static int cap_major = CAP_MAJOR;
+static int cap_minor;

Just always use a dynamic misc device, you never need a whole major for this.

Documentation/p9auth.txt line 31

Quoted 2 lines
Documentation/p9auth.txt new file +2 -0
+module_param(cap_major, int, S_IRUGO);
+module_param(cap_minor, int, S_IRUGO);

Can be removed.

Documentation/p9auth.txt line 32

Quoted 1 line
Documentation/p9auth.txt new file +1 -0
+MODULE_AUTHOR("Ashwin Ganti");

Hm, who is going to maintain this, you, or Ashwin?

Documentation/p9auth.txt line 38

Quoted 6 lines
Documentation/p9auth.txt new file +6 -0
+static void hexdump(unsigned char *buf, unsigned int len)
+{
+	while (len--)
+		printk(KERN_DEBUG "%02x", *buf++);
+	printk(KERN_DEBUG "\n");
+}

We have a built-in function for this already.

Oh, this function is also incorrect, which is a good reason to use the built-in ones.

I'm going to stop now, this doesn't belong in drivers/char/ yet, it needs work...

thanks,

greg k-h

Documentation/p9auth.txt line 44

Quoted 6 lines
Documentation/p9auth.txt new file +6 -0
+/*
+ * read an entry.  For now it is
+ * source_user@target_user@rand
+ * Next it will become
+ * source_user@target_user@target_group@numgroups@grp1..@grpn@rand
+ */

Hm, wait, one more.... The kernel/user api is going to change some time in the future? Please fix this now before it gets merged.

#2 lore raw

Re: [PATCH 2/3] p9auth: add CAP_GRANT_ID to authorize use of /dev/caphash

In reply to Serge E. Hallyn
Quoted 5 lines · Serge E. Hallyn

Granting userid capabilities to another task is a dangerous privilege. Don't just let file permissions authorize it. Define CAP_GRANT_ID as a new capability needed to write to /dev/caphash.

Isn't there some man page that also needs to be updated when you add something like this to the user/kernel api?

thanks,

greg k-h

#5 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Greg KH
Quoted 8 lines · Greg KH
Quoted 3 lines · Serge E. Hallyn

This is a driver that adds Plan 9 style capability device implementation. See Documentation/p9auth.txt for a description of how to use this.

Hm, you didn't originally write this driver, so it would be good to get some original authorship information in here to keep everything correct, right?

That's why I left the MODULE_AUTHOR line in there - not sure what else to do for that. I'll add a comment in p9auth.txt, especially pointing back to Ashwin's original paper.

Quoted 9 lines
Quoted 6 lines
 Documentation/p9auth.txt     |   47 ++++
 drivers/char/Kconfig         |    2 +
 drivers/char/Makefile        |    2 +
 drivers/char/p9auth/Kconfig  |    9 +
 drivers/char/p9auth/Makefile |    1 +
 drivers/char/p9auth/p9auth.c |  517 ++++++++++++++++++++++++++++++++++++++++++

Is this code really ready for drivers/char/? What has changed in it that makes it ok to move out of the staging tree?

It was dropped from staging :) I don't particularly care to see it go back into staging, as opposed to working out issues out of tree (assuming they are solvable). For one thing, as you note below, there is the question of whether it should be a device driver at all.

Quoted 1 line

And who is going to maintain it? You? Or someone else?

If Ashwin doesn't want to maintain it, I'll do it. Either way.

Quoted 30 lines
Quoted 30 lines
 6 files changed, 578 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/p9auth.txt
 create mode 100644 drivers/char/p9auth/Kconfig
 create mode 100644 drivers/char/p9auth/Makefile
 create mode 100644 drivers/char/p9auth/p9auth.c
Documentation/p9auth.txt new file +18 -0
new file mode 100644
index 0000000..14a69d8
@@ -0,0 +1,47 @@
+The p9auth device driver implements a plan-9 factotum-like
+capability API.  Tasks which are privileged (authorized by
+possession of the CAP_GRANT_ID privilege (POSIX capability))
+can write new capabilities to /dev/caphash.  The kernel then
+stores these until a task uses them by writing to the
+/dev/capuse device.  Each capability represents the ability
+for a task running as userid X to switch to userid Y and
+some set of groups.  Each capability may be used only once,
+and unused capabilities are cleared after two minutes.
+
+The following examples shows how to use the API.  Shell 1
+contains a privileged root shell.  Shell 2 contains an
+unprivileged shell as user 501 in the same user namespace.  If
+not already done, the privileged shell should create the p9auth
+devices:
+
+	majfile=/sys/module/p9auth/parameters/cap_major
+	minfile=/sys/module/p9auth/parameters/cap_minor
Quoted 8 lines

Documentation/p9auth.txt line 23

Quoted 5 lines
Documentation/p9auth.txt new file +5 -0
+	maj=`cat $majfile`
+	mknod /dev/caphash c $maj 0
+	min=`cat $minfile`
+	mknod /dev/capuse c $maj 1
+	chmod ugo+w /dev/capuse

That is incorrect, you don't need the cap_major/minor files at all, the device node should be automatically created for you, right?

Hmm, where? Not in /dev on my SLES11 partition...

Quoted 2 lines

And do you really want to do all of this control through a device node? Why?

Well...

At first I was thinking same as you were. So I was going to switch to a pure syscall-based approach. But it just turned out more complicated. The factotum server would call sys_grantid(), and the target task would end up doing some huge sys_setresugid() or else multiple syscalls using the granted id. It just was uglier. I think there's an experimental patchset sitting somewhere I could point to (if I weren't embarassed :).

Another possibility would be to use netlink, but that doesn't appear as amenable to segragation by user namespaces. The pid (presumably/hopefully global pid, as __u32) is available, so it shouldn't be impossible, but a simple device with simple synchronous read/write certainly has its appeal. Firing off a message hoping that at some point our credentials will be changes, less so.

Quoted 3 lines

Documentation/p9auth.txt line 24

Quoted 1 line
Documentation/p9auth.txt new file +1 -0
+DEFINE_MUTEX(cap_mutex); /* TODO fix up the locking one day */

One might hope that today would be that day...

Well there's nothing actually wrong with the cap_mutex. I put in this comment thinking I'd switch to rcu at some point, but it doesn't seem worthwhile at the moment, by a long shot.

Quoted 10 lines

Also, please run this through sparse. This is a variable that doesn't need to be global.

Documentation/p9auth.txt line 27

Quoted 3 lines
Documentation/p9auth.txt new file +3 -0
+struct cap_dev {
+	struct cdev cdev;
+};

Do you really need to do it this way? A cdev for a single device node? That's major overkill.

Quoted 5 lines

Documentation/p9auth.txt line 29

Quoted 2 lines
Documentation/p9auth.txt new file +2 -0
+static int cap_major = CAP_MAJOR;
+static int cap_minor;

Just always use a dynamic misc device, you never need a whole major for this.

Right - will switch that over, assuming we don't nix the whole idea first.

Quoted 8 lines

Documentation/p9auth.txt line 31

Quoted 2 lines
Documentation/p9auth.txt new file +2 -0
+module_param(cap_major, int, S_IRUGO);
+module_param(cap_minor, int, S_IRUGO);

Can be removed.

Documentation/p9auth.txt line 32

Quoted 1 line
Documentation/p9auth.txt new file +1 -0
+MODULE_AUTHOR("Ashwin Ganti");

Hm, who is going to maintain this, you, or Ashwin?

I haven't asked Ashwin, and will be happy either way. Ashwin, did you want to maintain it?

Quoted 11 lines

Documentation/p9auth.txt line 38

Quoted 6 lines
Documentation/p9auth.txt new file +6 -0
+static void hexdump(unsigned char *buf, unsigned int len)
+{
+	while (len--)
+		printk(KERN_DEBUG "%02x", *buf++);
+	printk(KERN_DEBUG "\n");
+}

We have a built-in function for this already.

Oh, this function is also incorrect, which is a good reason to use the built-in ones.

Really I prefer to get rid of that altogether. Anyone who wants to see that can use a kprobe hooked to the exit of cap_hash().

Quoted 2 lines

I'm going to stop now, this doesn't belong in drivers/char/ yet, it needs work...

/me rolls up his sleeves.

Quoted 11 lines

thanks,

greg k-h

Documentation/p9auth.txt line 44

Quoted 6 lines
Documentation/p9auth.txt new file +6 -0
+/*
+ * read an entry.  For now it is
+ * source_user@target_user@rand
+ * Next it will become
+ * source_user@target_user@target_group@numgroups@grp1..@grpn@rand
+ */
Quoted 2 lines

Hm, wait, one more.... The kernel/user api is going to change some time in the future? Please fix this now before it gets merged.

Huh, no that change already happened.

thanks,
-serge

#6 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 5 lines · Serge E. Hallyn
Quoted 1 line · Greg KH

Hm, who is going to maintain this, you, or Ashwin?

I haven't asked Ashwin, and will be happy either way.  Ashwin, did you want to maintain it?

Well, since you have been driving a lot of implementation changes recently, I feel it makes sense for you to be a maintainer. Honestly I don't think I will be able to find time maintaining this in the future although I can do the code reviews for you. I will be more than happy if this feature continues to get traction.

- Ashwin
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Serge E. Hallyn
Quoted 88 lines · Serge E. Hallyn
Quoted 8 lines · Greg KH
Quoted 3 lines · Serge E. Hallyn

This is a driver that adds Plan 9 style capability device implementation. See Documentation/p9auth.txt for a description of how to use this.

Hm, you didn't originally write this driver, so it would be good to get some original authorship information in here to keep everything correct, right?

That's why I left the MODULE_AUTHOR line in there - not sure what else to do for that. I'll add a comment in p9auth.txt, especially pointing back to Ashwin's original paper.

Quoted 9 lines
Quoted 6 lines
 Documentation/p9auth.txt     |   47 ++++
 drivers/char/Kconfig         |    2 +
 drivers/char/Makefile        |    2 +
 drivers/char/p9auth/Kconfig  |    9 +
 drivers/char/p9auth/Makefile |    1 +
 drivers/char/p9auth/p9auth.c |  517 ++++++++++++++++++++++++++++++++++++++++++

Is this code really ready for drivers/char/? What has changed in it that makes it ok to move out of the staging tree?

It was dropped from staging :) I don't particularly care to see it go back into staging, as opposed to working out issues out of tree (assuming they are solvable). For one thing, as you note below, there is the question of whether it should be a device driver at all.

Quoted 1 line

And who is going to maintain it? You? Or someone else?

If Ashwin doesn't want to maintain it, I'll do it. Either way.

Quoted 30 lines
Quoted 30 lines
 6 files changed, 578 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/p9auth.txt
 create mode 100644 drivers/char/p9auth/Kconfig
 create mode 100644 drivers/char/p9auth/Makefile
 create mode 100644 drivers/char/p9auth/p9auth.c
Documentation/p9auth.txt new file +18 -0
new file mode 100644
index 0000000..14a69d8
@@ -0,0 +1,47 @@
+The p9auth device driver implements a plan-9 factotum-like
+capability API.  Tasks which are privileged (authorized by
+possession of the CAP_GRANT_ID privilege (POSIX capability))
+can write new capabilities to /dev/caphash.  The kernel then
+stores these until a task uses them by writing to the
+/dev/capuse device.  Each capability represents the ability
+for a task running as userid X to switch to userid Y and
+some set of groups.  Each capability may be used only once,
+and unused capabilities are cleared after two minutes.
+
+The following examples shows how to use the API.  Shell 1
+contains a privileged root shell.  Shell 2 contains an
+unprivileged shell as user 501 in the same user namespace.  If
+not already done, the privileged shell should create the p9auth
+devices:
+
+	majfile=/sys/module/p9auth/parameters/cap_major
+	minfile=/sys/module/p9auth/parameters/cap_minor
Quoted 8 lines

Documentation/p9auth.txt line 23

Quoted 5 lines
Documentation/p9auth.txt new file +5 -0
+	maj=`cat $majfile`
+	mknod /dev/caphash c $maj 0
+	min=`cat $minfile`
+	mknod /dev/capuse c $maj 1
+	chmod ugo+w /dev/capuse

That is incorrect, you don't need the cap_major/minor files at all, the device node should be automatically created for you, right?

Hmm, where? Not in /dev on my SLES11 partition...

Quoted 2 lines

And do you really want to do all of this control through a device node? Why?

Well...

At first I was thinking same as you were. So I was going to switch to a pure syscall-based approach. But it just turned out more complicated. The factotum server would call sys_grantid(), and the target task would end up doing some huge sys_setresugid() or else multiple syscalls using the granted id. It just was uglier. I think there's an experimental patchset sitting somewhere I could point to (if I weren't embarassed :).

Quoted 6 lines

Another possibility would be to use netlink, but that doesn't appear as amenable to segragation by user namespaces. The pid (presumably/hopefully global pid, as __u32) is available, so it shouldn't be impossible, but a simple device with simple synchronous read/write certainly has its appeal. Firing off a message hoping that at some point our credentials will be changes, less so.

pid in the netlink context is the netlink port-id. It is a very different concept from struct pid. These days netlink calls to the kernel are synchronous, not that I would encourage netlink for anything except networking code.

Can we make this a trivial filesystem? I expect that would match up better with whatever plan9 userspace apps already exist, remove the inode double translation, and would make it much more reasonable to do a user namespace aware version if and when that becomes necessary.

Eric

#15 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Serge E. Hallyn
Quoted 4 lines

This is a change which must be discussed. The use of this privilege can be completely prevented by having init remove CAP_GRANT_ID from its capability bounding set before forking any processes.

Which is a minor back compat issue - but you could start without it and allow init to add it.

It seems a very complex interface to do a simple thing. A long time ago there was discussion around extending the AF_UNIX fd passing to permit 'pass handle and auth' so you could send someone a handle with a "become me" token attached.

Alan

#27 lore raw
In reply to Serge E. Hallyn

include/linux/cred.h do { \ · line 409

Quoted 6 lines · Serge E. Hallyn
include/linux/cred.h +6 -0
+int cred_setresuid(struct cred *new, uid_t ruid, uid_t euid, uid_t suid,
+		   int force);
+int cred_setresgid(struct cred *new, gid_t rgid, gid_t egid, gid_t sgid,
+		   int force);
+int cred_setfsuid(struct cred *new, uid_t uid, uid_t *old_fsuid);
+int cred_setfsgid(struct cred *new, gid_t gid, gid_t *old_fsgid);

Can you mark these extern please?

Other than that, these functions should probably be mentioned in Documentation/credentials.txt.

David

#25 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Serge E. Hallyn

drivers/char/p9auth/p9auth.c line 263

Quoted 6 lines · Serge E. Hallyn
drivers/char/p9auth/p9auth.c new file +6 -0
+	if (ret == 0)
+		commit_creds(new);
+	else
+		abort_creds(new);
+
+	return ret;

If you make this:

	if (ret == 0)
		return commit_creds(new);
	abort_creds(new);
	return ret;

then gcc can tail-call commit_creds(), which is guaranteed to return 0.

David

#10 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Eric W. Biederman
Quoted 5 lines · Eric W. Biederman

Can we make this a trivial filesystem? I expect that would match up better with whatever plan9 userspace apps already exist, remove the inode double translation, and would make it much more reasonable to do a user namespace aware version if and when that becomes necessary.

Great idea, and so obvious once you mention it. I think that's the way to go. Thanks, Eric.

-serge

#16 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Alan Cox
Quoted 8 lines · Alan Cox
Quoted 4 lines

This is a change which must be discussed. The use of this privilege can be completely prevented by having init remove CAP_GRANT_ID from its capability bounding set before forking any processes.

Which is a minor back compat issue - but you could start without it and allow init to add it.

Quoted 6 lines

It seems a very complex interface to do a simple thing. A long time ago there was discussion around extending the AF_UNIX fd passing to permit 'pass handle and auth' so you could send someone a handle with a "become me" token attached.

Alan

Hi Alan,

sorry I thought I had cc:d you, bc I was pretty sure you'd have some neat ideas. Like this one.

One could try to argue that this makes every linux process susceptible to a trojan making it grant its userid to other tasks, but of course that's silly since the trojan could just fork. Well, what this would buy the attacker is the ability to sit inconspicuously under his old userid, holding on to the fd until the admin goes out to coffee before switching userids.

The other thing is that offhand I think the server can't easily tell from the socket which user namespace the client is in, as ucred only has .uid. Though (1) we might need to create a 'struct puser' analogous to 'struct pid' for signals anyway, (2) userspace can segragate with fs or net_ns (if abstract sock), and (3) client in a container presumably won't be able to authenticate itself to server on the host anyway.

Ashwin (and Ron), I think this idea will give us the same tools that the p9auth driver does, perhaps in a more unix-y way. Would you have objections, or do you see shortcomings?

Thanks, Alan.

-serge

#26 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to David Howells
Quoted 11 lines · David Howells

drivers/char/p9auth/p9auth.c line 263

Quoted 6 lines · Serge E. Hallyn
drivers/char/p9auth/p9auth.c new file +6 -0
+	if (ret == 0)
+		commit_creds(new);
+	else
+		abort_creds(new);
+
+	return ret;

If you make this:

Quoted 8 lines
	if (ret == 0)
		return commit_creds(new);
	abort_creds(new);
	return ret;

then gcc can tail-call commit_creds(), which is guaranteed to return 0.

David

Ok, will do.

thanks,
-serge

#28 lore raw
In reply to David Howells
Quoted 11 lines · David Howells

include/linux/cred.h do { \ · line 409

Quoted 6 lines · Serge E. Hallyn
include/linux/cred.h +6 -0
+int cred_setresuid(struct cred *new, uid_t ruid, uid_t euid, uid_t suid,
+		   int force);
+int cred_setresgid(struct cred *new, gid_t rgid, gid_t egid, gid_t sgid,
+		   int force);
+int cred_setfsuid(struct cred *new, uid_t uid, uid_t *old_fsuid);
+int cred_setfsgid(struct cred *new, gid_t gid, gid_t *old_fsgid);

Can you mark these extern please?

Quoted 4 lines

Other than that, these functions should probably be mentioned in Documentation/credentials.txt.

David

Will do.

thanks,
-serge

#7 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Ashwin Ganti
Quoted 7 lines · Ashwin Ganti
Quoted 5 lines · Serge E. Hallyn
Quoted 1 line · Greg KH

Hm, who is going to maintain this, you, or Ashwin?

I haven't asked Ashwin, and will be happy either way.  Ashwin, did you want to maintain it?

Quoted 7 lines

Well, since you have been driving a lot of implementation changes recently, I feel it makes sense for you to be a maintainer. Honestly I don't think I will be able to find time maintaining this in the future although I can do the code reviews for you. I will be more than happy if this feature continues to get traction.

- Ashwin

Ok. I'll put myself in MAINTAINERS. If we stick with the p9auth driver or filesystem approach, I'd like to keep you in MODULE_AUTHOR() if that's ok, bc it really is yours, and wouldn't exist without you.

thanks,
-serge
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#23 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Alan Cox
Quoted 5 lines · Alan Cox
Quoted 4 lines

This is a change which must be discussed. The use of this privilege can be completely prevented by having init remove CAP_GRANT_ID from its capability bounding set before forking any processes.

Quoted 7 lines

Which is a minor back compat issue - but you could start without it and allow init to add it.

It seems a very complex interface to do a simple thing. A long time ago there was discussion around extending the AF_UNIX fd passing to permit 'pass handle and auth' so you could send someone a handle with a "become me" token attached.

If you do go down this path there is a separate (and actually completely opposite) but related problem I might be able and willing to work with you on. When looking at how auditing works in this modern day and age of dbus+polkit to get background processes to do work on behalf of a user we were discussing an interface that would pass the information about the user to the background server process. The background server process could do some magic such that it still had all the permissions and rights of itself, but had the audit information of the original user. Thus even though it was a server process with uid=0 that did the work, the audit logs could know it was actually on behalf of uid=500.

It was discussed passing that token of audit information over an AF_UNIX socket.

-Eric

#17 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Serge E. Hallyn
Quoted 9 lines

sorry I thought I had cc:d you, bc I was pretty sure you'd have some neat ideas. Like this one.

One could try to argue that this makes every linux process susceptible to a trojan making it grant its userid to other tasks, but of course that's silly since the trojan could just fork. Well, what this would buy the attacker is the ability to sit inconspicuously under his old userid, holding on to the fd until the admin goes out to coffee before switching userids.

Possibly, could you put a timestamp in the passed object ? (Given the expiry of such a uid offer is kind of policy)

Quoted 7 lines

The other thing is that offhand I think the server can't easily tell from the socket which user namespace the client is in, as ucred only has .uid. Though (1) we might need to create a 'struct puser' analogous to 'struct pid' for signals anyway, (2) userspace can segragate with fs or net_ns (if abstract sock), and (3) client in a container presumably won't be able to authenticate itself to server on the host anyway.

That I think needs fixing anyway and now is a good time as any to do it. If you are going to be able to pass userids then you need to be sure you don't get passed a handle with a uid change on it that you didn't want so adding another object type and option of some kind to accept them has to occur anyway.

That also btw needs fixing for other reasons - more than one daemon has been written that generically uses recvmsg and so can be attacked with FD leaks >-)

Alan

#24 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Eric Paris
Quoted 14 lines · Eric Paris
Quoted 5 lines · Alan Cox
Quoted 4 lines

This is a change which must be discussed. The use of this privilege can be completely prevented by having init remove CAP_GRANT_ID from its capability bounding set before forking any processes.

Quoted 7 lines

Which is a minor back compat issue - but you could start without it and allow init to add it.

It seems a very complex interface to do a simple thing. A long time ago there was discussion around extending the AF_UNIX fd passing to permit 'pass handle and auth' so you could send someone a handle with a "become me" token attached.

Quoted 4 lines

If you do go down this path there is a separate (and actually completely opposite) but related problem I might be able and willing to work with you on. When looking at how auditing works in this modern day and age of dbus+polkit to get background processes to do work on behalf of a

This actually brings up an issue I've been a bit worried about: is credentials passing for dbus adequate? I thought that the last time I looked through some code, there was no way in particular for upstart to pass posix capabilities info along. What that means is that as root I can do

capsh --drop=(list of all capabilities) --
reboot

and, although I don't have cap_sys_boot, I can reboot the system. So the only way I can prevent a container from rebooting the host is to start it in a fresh network namespace to segrate the abstract unix domain sockets. But if I don't want a fresh network namespace, I'm out of luck.

Quoted 11 lines

user we were discussing an interface that would pass the information about the user to the background server process. The background server process could do some magic such that it still had all the permissions and rights of itself, but had the audit information of the original user. Thus even though it was a server process with uid=0 that did the work, the audit logs could know it was actually on behalf of uid=500.

It was discussed passing that token of audit information over an AF_UNIX socket.

-Eric

#8 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Serge E. Hallyn
Quoted 14 lines · Serge E. Hallyn
Quoted 13 lines · Ashwin Ganti
Quoted 5 lines · Serge E. Hallyn
Quoted 1 line · Greg KH

Hm, who is going to maintain this, you, or Ashwin?

I haven't asked Ashwin, and will be happy either way.  Ashwin, did you want to maintain it?

Well, since you have been driving a lot of implementation changes recently, I feel it makes sense for you to be a maintainer. Honestly I don't think I will be able to find time maintaining this in the future although I can do the code reviews for you. I will be more than happy if this feature continues to get traction.

Quoted 5 lines
Quoted 1 line

- Ashwin

Ok.  I'll put myself in MAINTAINERS.  If we stick with the p9auth driver or filesystem approach, I'd like to keep you in MODULE_AUTHOR() if that's ok, bc it really is yours, and wouldn't exist without you.

Yeah, sure.

- Ashwin

#18 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Alan Cox
Quoted 10 lines · Alan Cox
Quoted 9 lines

sorry I thought I had cc:d you, bc I was pretty sure you'd have some neat ideas. Like this one.

One could try to argue that this makes every linux process susceptible to a trojan making it grant its userid to other tasks, but of course that's silly since the trojan could just fork. Well, what this would buy the attacker is the ability to sit inconspicuously under his old userid, holding on to the fd until the admin goes out to coffee before switching userids.

Quoted 2 lines

Possibly, could you put a timestamp in the passed object ? (Given the expiry of such a uid offer is kind of policy)

Yup, in fact I do that for the p9auth device driver anyway, to avoid letting a user take up all kernel memory with unused setuid tokens.

Quoted 8 lines
Quoted 7 lines

The other thing is that offhand I think the server can't easily tell from the socket which user namespace the client is in, as ucred only has .uid. Though (1) we might need to create a 'struct puser' analogous to 'struct pid' for signals anyway, (2) userspace can segragate with fs or net_ns (if abstract sock), and (3) client in a container presumably won't be able to authenticate itself to server on the host anyway.

Quoted 5 lines

That I think needs fixing anyway and now is a good time as any to do it. If you are going to be able to pass userids then you need to be sure you don't get passed a handle with a uid change on it that you didn't want so adding another object type and option of some kind to accept them has to occur anyway.

Ignoring namespaces for a moment, I guess we could do something like

struct credentials_pass {
	pid_t global_pid;
	unsigned long unique_id;
	uid_t new_uid;
	gid_t new_gid;
	int num_aux_gids;
	gid_t aux_gids[];
}

The unique_id is assigned by the kernel; the client reads the whole struct credentials_pass - except global_pid - from the unix sock, verifies the desired credentials, then does sys_acceptid(unique_id) to accept.

Again, how to pass user namespace information is not obvious to me.

And it's probably debatable whether we want to also pass info about posix capabilities and LSM security data.

Still, my main concern with this approach is that it makes the server more complicated. Since I'm passing along my current credentials, that means I have to construct just the right credentials, which if using sock identified by pathname may mean I can no longer write to the socket, right?

And of course one other important consideration is that the overall p9auth API has been heavily discussed and documented, whereas implementing our own entirely new approach is breaking new ground and therefore a lot scarier.

Quoted 3 lines

That also btw needs fixing for other reasons - more than one daemon has been written that generically uses recvmsg and so can be attacked with FD leaks >-)

Yup.

(By 'needs fixing' you just mean needs to be done right for this service? Else I think I'm missing something...)

thanks,
-serge

#19 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 10 lines · Serge E. Hallyn

Ignoring namespaces for a moment, I guess we could do something like

struct credentials_pass {
	pid_t global_pid;
	unsigned long unique_id;
	uid_t new_uid;
	gid_t new_gid;
	int num_aux_gids;
	gid_t aux_gids[];
}

This looks surprising like what I am doing in passing uids and pids through unix domain sockets.

So if this looks like a direction we want to go it shouldn't be too difficult.

Quoted 8 lines
Quoted 3 lines

That also btw needs fixing for other reasons - more than one daemon has been written that generically uses recvmsg and so can be attacked with FD leaks >-)

Yup.

(By 'needs fixing' you just mean needs to be done right for this service? Else I think I'm missing something...)

Remember my unix domain socket and the patch for converting struct cred into a new context, from a month or so ago. I think that is what we are talking about.

Eric

#20 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 23 lines · Eric W. Biederman
Quoted 10 lines · Serge E. Hallyn

Ignoring namespaces for a moment, I guess we could do something like

struct credentials_pass {
	pid_t global_pid;
	unsigned long unique_id;
	uid_t new_uid;
	gid_t new_gid;
	int num_aux_gids;
	gid_t aux_gids[];
}

This looks surprising like what I am doing in passing uids and pids through unix domain sockets.

So if this looks like a direction we want to go it shouldn't be too difficult.

Quoted 4 lines
Quoted 3 lines

That also btw needs fixing for other reasons - more than one daemon has been written that generically uses recvmsg and so can be attacked with FD leaks >-)

Quoted 8 lines
Quoted 4 lines

Yup.

(By 'needs fixing' you just mean needs to be done right for this service? Else I think I'm missing something...)

Remember my unix domain socket and the patch for converting struct cred into a new context, from a month or so ago. I think that is what we are talking about.

Zoinks! After some digging I found it in my containers.mbox and at
https://lists.linux-foundation.org/pipermail/containers/2010-March/023405.html
and see you even called me out. Sorry! I see your tree at
http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/ebiederm/linux-2.6.33-nsfd-v5.git;a=summary
and commit "af_unix: Allow SO_PEERCRED to work across namespaces", and it all looks good. Definately useful for a SO_PASSCRED or somesuch implementation.

thanks,
-serge

#21 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Eric W. Biederman
Quoted 13 lines · Eric W. Biederman
Quoted 10 lines · Serge E. Hallyn

Ignoring namespaces for a moment, I guess we could do something like

struct credentials_pass {
      pid_t global_pid;
      unsigned long unique_id;
      uid_t new_uid;
      gid_t new_gid;
      int num_aux_gids;
      gid_t aux_gids[];
}

Quoted 5 lines

This looks surprising like what I am doing in passing uids and pids through unix domain sockets.

So if this looks like a direction we want to go it shouldn't be too difficult.

Hmm... for an alternative idea:

We have this nice "kernel keyring" infrastructure that lets us stuff arbitrary things into "keys" and grant/revoke them between processes. What if we created a relatively generic way for processes to package up privileges (of whatever form) into a "key" that could be granted to another process (via UNIX-domain socket)? Then the other process would use a setuid()-ish syscall which would instead apply a specific key as your credentials, possibly including the audit context and/or namespaces it came from.

By using the keyring system, such tokens could be kept around across multiple processes easily (as opposed to FDs), in the same style as a "sudo" ticket file, for example (even with an expiration time).

Types of credentials you could pass around:
* Capabilities
* Filesystem UID/GID in a particular UID namespace (for FS operations)
* Process UID/GID in a particular UID namespace (for kill(), etc)
* Audit contexts
* SELinux/etc security labels

All of the above could be optionally limited to effectively require a bprm-secure-style exec() with specific args. So for example, instead of making "/usr/sbin/passwd" a setuid program, you could make it be an unprivileged helper. It would connect to a privileged daemon and ask for a password-change cookie for that particular user. The daemon would create what is essentially a "delayed exec" key which grants a specific UID and capabilities when that process performs an execkey().

So as an example, you could rewrite "sudo" as a partially-privileged daemon and an unprivileged helper. The unpriv helper would send across a request (optionally including the command and environment) which would be checked by the daemon. It would then issue a key to allow the unpriv helper to perform a limited exec.

Another option would be to rewrite network login programs (eg OpenSSH) to use this for privilege separation. The listening process would get a non-expiring key to allow it to exec a partially-privileged password-checking program. If the password-checking program likes the password it generates a single-use key to pass back to the forked network process that allows it to exec a program as that user.

Cheers,
Kyle Moffett

#22 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 42 lines · Kyle Moffett
Quoted 13 lines · Eric W. Biederman
Quoted 10 lines · Serge E. Hallyn

Ignoring namespaces for a moment, I guess we could do something like

struct credentials_pass {
      pid_t global_pid;
      unsigned long unique_id;
      uid_t new_uid;
      gid_t new_gid;
      int num_aux_gids;
      gid_t aux_gids[];
}

Quoted 5 lines

This looks surprising like what I am doing in passing uids and pids through unix domain sockets.

So if this looks like a direction we want to go it shouldn't be too difficult.

Hmm... for an alternative idea:

We have this nice "kernel keyring" infrastructure that lets us stuff arbitrary things into "keys" and grant/revoke them between processes. What if we created a relatively generic way for processes to package up privileges (of whatever form) into a "key" that could be granted to another process (via UNIX-domain socket)? Then the other process would use a setuid()-ish syscall which would instead apply a specific key as your credentials, possibly including the audit context and/or namespaces it came from.

By using the keyring system, such tokens could be kept around across multiple processes easily (as opposed to FDs), in the same style as a "sudo" ticket file, for example (even with an expiration time).

Types of credentials you could pass around:
* Capabilities
* Filesystem UID/GID in a particular UID namespace (for FS operations)
* Process UID/GID in a particular UID namespace (for kill(), etc)
* Audit contexts
* SELinux/etc security labels

Quoted 7 lines

All of the above could be optionally limited to effectively require a bprm-secure-style exec() with specific args. So for example, instead of making "/usr/sbin/passwd" a setuid program, you could make it be an unprivileged helper. It would connect to a privileged daemon and ask for a password-change cookie for that particular user. The daemon would create what is essentially a "delayed exec" key which grants a specific UID and capabilities when that process performs an execkey().

Hi Kyle,

it's a neat idea in terms of flexibility - but in this case the flexibility really scares me :)

In particular I don't like the ability to keep these tokens around for later use, and your example of passing around capabilities is something we've specifically rejected in the past.

That doesn't mean that it wouldn't be a good idea to take your general approach, use it very inflexibly, and then slowly, as we gain experience, add flexibility.

I think we are best off starting with two options:

1. pass audit credentials only
2. pass full credentials

credentials meaning uid/gid, though - and let capabilities be sorted out by the setuid rules.

Quoted 6 lines

So as an example, you could rewrite "sudo" as a partially-privileged daemon and an unprivileged helper. The unpriv helper would send across a request (optionally including the command and environment) which would be checked by the daemon. It would then issue a key to allow the unpriv helper to perform a limited exec.

Quoted 6 lines

Another option would be to rewrite network login programs (eg OpenSSH) to use this for privilege separation. The listening process would get a non-expiring key to allow it to exec a partially-privileged password-checking program. If the password-checking program likes the password it generates a single-use key to pass back to the forked network process that allows it to exec a program as that user.

Note that the last two examples are possible with with the simple p9auth driver, and are really their motivation. In fact, we only need a single privileged back-end (factotum) server to server a bunch of unprivileged front-end servers.

So over the next few days I will incorporate a bunch of the feedback on the p9auth driver itself, turn it into a filesystem, and resend it. That's not to say that I don't like the other suggestions - I want to pursue those as well and we can see where we end up and which approach we prefer. For a first step I look forward to Eric pushing the patches to do uid and pid translation for unix sock credentials.

thanks,
-serge

#11 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

In reply to Eric W. Biederman
Quoted 102 lines · Eric W. Biederman
Quoted 88 lines · Serge E. Hallyn
Quoted 8 lines · Greg KH
Quoted 3 lines · Serge E. Hallyn

This is a driver that adds Plan 9 style capability device implementation. See Documentation/p9auth.txt for a description of how to use this.

Hm, you didn't originally write this driver, so it would be good to get some original authorship information in here to keep everything correct, right?

That's why I left the MODULE_AUTHOR line in there - not sure what else to do for that. I'll add a comment in p9auth.txt, especially pointing back to Ashwin's original paper.

Quoted 9 lines
Quoted 6 lines
 Documentation/p9auth.txt     |   47 ++++
 drivers/char/Kconfig         |    2 +
 drivers/char/Makefile        |    2 +
 drivers/char/p9auth/Kconfig  |    9 +
 drivers/char/p9auth/Makefile |    1 +
 drivers/char/p9auth/p9auth.c |  517 ++++++++++++++++++++++++++++++++++++++++++

Is this code really ready for drivers/char/? What has changed in it that makes it ok to move out of the staging tree?

It was dropped from staging :) I don't particularly care to see it go back into staging, as opposed to working out issues out of tree (assuming they are solvable). For one thing, as you note below, there is the question of whether it should be a device driver at all.

Quoted 1 line

And who is going to maintain it? You? Or someone else?

If Ashwin doesn't want to maintain it, I'll do it. Either way.

Quoted 30 lines
Quoted 30 lines
 6 files changed, 578 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/p9auth.txt
 create mode 100644 drivers/char/p9auth/Kconfig
 create mode 100644 drivers/char/p9auth/Makefile
 create mode 100644 drivers/char/p9auth/p9auth.c
Documentation/p9auth.txt new file +18 -0
new file mode 100644
index 0000000..14a69d8
@@ -0,0 +1,47 @@
+The p9auth device driver implements a plan-9 factotum-like
+capability API.  Tasks which are privileged (authorized by
+possession of the CAP_GRANT_ID privilege (POSIX capability))
+can write new capabilities to /dev/caphash.  The kernel then
+stores these until a task uses them by writing to the
+/dev/capuse device.  Each capability represents the ability
+for a task running as userid X to switch to userid Y and
+some set of groups.  Each capability may be used only once,
+and unused capabilities are cleared after two minutes.
+
+The following examples shows how to use the API.  Shell 1
+contains a privileged root shell.  Shell 2 contains an
+unprivileged shell as user 501 in the same user namespace.  If
+not already done, the privileged shell should create the p9auth
+devices:
+
+	majfile=/sys/module/p9auth/parameters/cap_major
+	minfile=/sys/module/p9auth/parameters/cap_minor
Quoted 8 lines

Documentation/p9auth.txt line 23

Quoted 5 lines
Documentation/p9auth.txt new file +5 -0
+	maj=`cat $majfile`
+	mknod /dev/caphash c $maj 0
+	min=`cat $minfile`
+	mknod /dev/capuse c $maj 1
+	chmod ugo+w /dev/capuse

That is incorrect, you don't need the cap_major/minor files at all, the device node should be automatically created for you, right?

Hmm, where? Not in /dev on my SLES11 partition...

Quoted 2 lines

And do you really want to do all of this control through a device node? Why?

Well...

At first I was thinking same as you were. So I was going to switch to a pure syscall-based approach. But it just turned out more complicated. The factotum server would call sys_grantid(), and the target task would end up doing some huge sys_setresugid() or else multiple syscalls using the granted id. It just was uglier. I think there's an experimental patchset sitting somewhere I could point to (if I weren't embarassed :).

Quoted 6 lines

Another possibility would be to use netlink, but that doesn't appear as amenable to segragation by user namespaces. The pid (presumably/hopefully global pid, as __u32) is available, so it shouldn't be impossible, but a simple device with simple synchronous read/write certainly has its appeal. Firing off a message hoping that at some point our credentials will be changes, less so.

pid in the netlink context is the netlink port-id. It is a very different concept from struct pid. These days netlink calls to the kernel are synchronous, not that I would encourage netlink for anything except networking code.

Quoted 4 lines

Can we make this a trivial filesystem? I expect that would match up better with whatever plan9 userspace apps already exist, remove the inode double translation, and would make it much more reasonable to do a user namespace aware version if and when

BTW, this current version is user namespace aware.

Quoted 1 line

that becomes necessary.

An fs actually seems overkill for two write-only files for process-related information. Would these actually be candidates for new /proc files?

/proc/grantcred - replaces /dev/caphash, for privileged
tasks to tell the kernel about new setuid capabilities
/proc/self/usecred - replaces /dev/capuse for unprivileged
tasks to make use of a setuid capability

-serge

#12 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 9 lines · Serge E. Hallyn

An fs actually seems overkill for two write-only files for process-related information.  Would these actually be candidates for new /proc files?

       /proc/grantcred - replaces /dev/caphash, for privileged tasks to tell the kernel about new setuid capabilities
       /proc/self/usecred - replaces /dev/capuse for unprivileged tasks to make use of a setuid capability

An fs is fine.

To relate this to Plan 9, where it all began, might be useful. There's no equivalent in Plan 9 to Linux/Unix devices of the major/minor number etc. variety. In-kernel drivers and out-of-kernel servers both end up providing the services (i.e. file name spaces) that we see in a Linux file system. So the Plan 9 driver for the capability device really does match closely in function and interface to a Linux kernel-based file system.

Hence, making devcap a file system is entirely appropriate, because it best fits the way it works in Plan 9: a kernel driver that provides two files.

It's pretty easy to write a Linux VFS anyway, so it makes sense from that point of view.

Eric, that was a great suggestion.

ron
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#13 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 22 lines · ron minnich
Quoted 9 lines · Serge E. Hallyn

An fs actually seems overkill for two write-only files for process-related information.  Would these actually be candidates for new /proc files?

       /proc/grantcred - replaces /dev/caphash, for privileged tasks to tell the kernel about new setuid capabilities
       /proc/self/usecred - replaces /dev/capuse for unprivileged tasks to make use of a setuid capability

An fs is fine.

To relate this to Plan 9, where it all began, might be useful. There's no equivalent in Plan 9 to Linux/Unix devices of the major/minor number etc. variety. In-kernel drivers and out-of-kernel servers both end up providing the services (i.e. file name spaces) that we see in a Linux file system. So the Plan 9 driver for the capability device really does match closely in function and interface to a Linux kernel-based file system.

Quoted 8 lines

Hence, making devcap a file system is entirely appropriate, because it best fits the way it works in Plan 9: a kernel driver that provides two files.

It's pretty easy to write a Linux VFS anyway, so it makes sense from that point of view.

Eric, that was a great suggestion.

A fs provides user space policy control of naming. I.e. where the two files go. That can also be a very big deal. Especially when files are writable.

You have no idea how much I am frustrated by sysfs right now, because it does not provide userspace policy control and instead mandates a sometimes inappropriate naming convention.

Eric

maintainer
#14 lore raw

Re: [PATCH 3/3] p9auth: add p9auth driver

Quoted 33 lines · Eric W. Biederman
Quoted 22 lines · ron minnich
Quoted 9 lines · Serge E. Hallyn

An fs actually seems overkill for two write-only files for process-related information. ??Would these actually be candidates for new /proc files?

?? ?? ?? ??/proc/grantcred - replaces /dev/caphash, for privileged ?? ?? ?? ?? ?? ?? ?? ??tasks to tell the kernel about new setuid ?? ?? ?? ?? ?? ?? ?? ??capabilities
?? ?? ?? ??/proc/self/usecred - replaces /dev/capuse for unprivileged ?? ?? ?? ?? ?? ?? ?? ??tasks to make use of a setuid capability

An fs is fine.

To relate this to Plan 9, where it all began, might be useful. There's no equivalent in Plan 9 to Linux/Unix devices of the major/minor number etc. variety. In-kernel drivers and out-of-kernel servers both end up providing the services (i.e. file name spaces) that we see in a Linux file system. So the Plan 9 driver for the capability device really does match closely in function and interface to a Linux kernel-based file system.

Quoted 8 lines

Hence, making devcap a file system is entirely appropriate, because it best fits the way it works in Plan 9: a kernel driver that provides two files.

It's pretty easy to write a Linux VFS anyway, so it makes sense from that point of view.

Eric, that was a great suggestion.

Quoted 8 lines

A fs provides user space policy control of naming. I.e. where the two files go. That can also be a very big deal. Especially when files are writable.

You have no idea how much I am frustrated by sysfs right now, because it does not provide userspace policy control and instead mandates a sometimes inappropriate naming convention.

Eric

Well I'm not convinced that it's a worthwhile tradeoff for polluting /proc/filesystems and needing yet another fs mounted in each container, but a preliminary working version using an fs is at
http://git.kernel.org/gitweb.cgi?p=linux/kernel/git/sergeh/linux-cr.git;a=shortlog;h=refs/heads/p9auth.apr24.2

I'll do some cleanup before sending it out.

Eric, I'd said that the device-based version was namespace-aware, but that meant that you could on grant and use capabilities in your own user namespace. I suppose now that it's an fs we can do better semantics, where each user ns can mount its own p9auth, and anyone with CAP_GRANT_ID targeted at some user ns (i.e. root in a user_ns or the creator of a user_ns) can grant ids to that user ns. Though I'm not sure that's a feature anyone would ever use, and I do like the simplicity of just having one sb.

-serge