2.6.15: Filesystem capabilities 0.16
Subsystems (3)
PATCH 1/1 2.6.15: Filesystem capabilities 0.16
This patch implements filesystem capabilities. It allows to run privileged executables without the need for suid root.
Changes:
- updated to 2.6.15
This patch is available at:
<http://www.olafdietsche.de/linux/capability/>
Regards, Olaf.
fs/Kconfig +63 -0
@@ -1209,6 +1209,69 @@ It's currently broken, so for now: answer N. +config FS_CAPABILITIES + bool "Filesystem capabilities (Experimental)" + depends on EXPERIMENTAL + default n + help + This implementation is likely _not_ POSIX compatible. + + If you say Y here, you will be able to grant selective privileges to + executables on a needed basis. This means for some executables, there + is no need anymore to run as root or as a suid root binary. + + For example, you may drop the SUID bit from ping and grant the + CAP_NET_RAW capability: + # chmod u-s /bin/ping + # chcap cap_net_raw=ep /bin/ping + + Another use would be to run system daemons with their own uid: + # chcap cap_net_bind_service=ei /usr/sbin/named + This sets the effective and inheritable capabilities of named. + + In your startup script: + inhcaps cap_net_bind_service=i bind:bind /usr/sbin/named + + This sets the inheritable set to CAP_NET_BIND_SERVICE, which is + needed in order to bind to port 53, and runs named as user bind + with group bind. + + This allows running named with needed restricted privileges, if the + parent process (root) owns them already. When started by regular + users, named runs without any privileges. + + WARNING: + resize2fs(8) might relocate inodes and thus break fs capabilities. + For this to work you must dump the capability db before you resize + and restore the db afterwards. + + For user space tools see: + <http://home.t-online.de/home/olaf.dietsche/linux/capability/> + + For libcap and an alternative implementation, based on extended + attributes, see: + <http://www.kernel.org/pub/linux/libs/security/linux-privs/> + + If you're unsure, say N. + +config LIBC_ENABLE_SECURE_HACK + bool "Disable LD_PRELOAD on privileged executables" + depends on FS_CAPABILITIES + default y + help + LD_PRELOAD is a glibc feature, which allows to override system + library functions. But this means also a security hole, through + which an attacker might gain unauthorized privileges. This is + already prevented for SUID and SGID binaries. + + GNU libc doesn't know about filesystem capabilities yet and doesn't + disable LD_PRELOAD for privileged executables, which are not SUID or + SGID. This hack sets the group id to an invalid value and tricks GNU + libc into thinking, this is a SGID binary (unless it is already SUID + and/or SGID). + However, this may break some programs. + + If you're unsure, say Y. config SYSV_FS
fs/Makefile +2 -1
@@ -48,7 +48,8 @@ obj-y += devpts/ obj-$(CONFIG_PROFILING) += dcookies.o - +obj-$(CONFIG_FS_CAPABILITIES) += fscaps.o + # Do not add any filesystems before this line obj-$(CONFIG_REISERFS_FS) += reiserfs/ obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3
fs/attr.c +6 -1
@@ -15,6 +15,7 @@#include <linux/quotaops.h> #include <linux/security.h> #include <linux/time.h> +#include <linux/fscaps.h> /* Taken over from the old code... */
@@ -171,8 +172,12 @@if (ia_valid &ATTR_SIZE )up_write (&dentry->d_inode->i_alloc_sem); -if (!error) +if (!error) { +if (ia_valid & (ATTR_KILL_SUID |ATTR_KILL_SGID )) +fscap_drop (inode); +fsnotify_change (dentry, ia_valid); + }return error; }
fs/fscaps.c +321 -0
321 lines not on this page · raw message
fs/namespace.c +3 -0
@@ -22,6 +22,7 @@#include <linux/namei.h> #include <linux/security.h> #include <linux/mount.h> +#include <linux/fscaps.h> #include <asm/uaccess.h> #include <asm/unistd.h> #include "pnode.h"
@@ -1066,6 +1067,8 @@ newmnt->mnt_flags = mnt_flags;if ((err =graft_tree (newmnt, nd))) goto unlock; + +fscap_mount (newmnt);if (fslist) {/* add to the specified expiration list */
fs/open.c +4 -0
@@ -19,6 +19,7 @@#include <linux/security.h> #include <linux/mount.h> #include <linux/vfs.h> +#include <linux/fscaps.h> #include <asm/uaccess.h> #include <linux/fs.h> #include <linux/personality.h>
@@ -787,6 +788,9 @@ f =ERR_PTR (-EINVAL ); } } + +if (flags &O_CREAT ) +fscap_drop (inode);return f;
fs/super.c +3 -0
@@ -37,6 +37,7 @@#include <linux/writeback.h> /* for the emergency remount stuff */ #include <linux/idr.h> #include <linux/kobject.h> +#include <linux/fscaps.h> #include <asm/uaccess.h>
@@ -86,6 +87,7 @@ s->s_qcop = sb_quotactl_ops; s->s_op = &default_op; s->s_time_gran =1000000000 ; + s->s_fscaps =NULL ; } out:return s;
@@ -172,6 +174,7 @@ s->s_count -=S_BIAS -1 ;spin_unlock (&sb_lock);DQUOT_OFF (s); +fscap_umount (s);down_write (&s->s_umount); fs->kill_sb (s);put_filesystem (fs);
include/linux/capability.h +4 -0
@@ -287,6 +287,10 @@#define CAP_AUDIT_CONTROL 30 +/* Allow setting capabilities on files */ + +#define CAP_SETFCAP 31 +#ifdef __KERNEL__/* * Bounding set
include/linux/fs.h +1 -0
@@ -807,6 +807,7 @@struct block_device *s_bdev;struct list_head s_instances;struct quota_info s_dquot;/* Diskquota specific options */ +struct fscap_info *s_fscaps;/* Filesystem capability stuff */ int s_frozen;wait_queue_head_t s_wait_unfrozen;
include/linux/fscaps.h +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (c) 2002 Olaf Dietsche +* +* Filesystem capabilities for linux. +*/ + +#ifndef _LINUX_FS_CAPS_H +#define _LINUX_FS_CAPS_H + +#include <linux/config.h> + +struct vfsmount ; +struct super_block ; +struct linux_binprm ; +struct inode ; + +#if defined(CONFIG_FS_CAPABILITIES ) || defined(CONFIG_FS_CAPABILITIES_MODULE ) +extern void fscap_mount (struct vfsmount *mnt); +extern void fscap_umount (struct super_block *sb); +extern void fscap_read (struct linux_binprm *bprm); +extern void fscap_drop (struct inode *inode); +#else +/* !CONFIG_FS_CAPABILITIES */ +static inline void fscap_mount (struct vfsmount *mnt) {} +static inline void fscap_umount (struct super_block *sb) {} +static inline void fscap_read (struct linux_binprm *bprm) {} +static inline void fscap_drop (struct inode *inode) {} +#endif + +#endif
security/commoncap.c +7 -1
@@ -23,6 +23,7 @@#include <linux/ptrace.h> #include <linux/xattr.h> #include <linux/hugetlb.h> +#include <linux/fscaps.h> int cap_netlink_send (struct sock *sk,struct sk_buff *skb) {
@@ -113,11 +114,12 @@ {/* 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); +fscap_read (bprm); +/* To support inheritance of root-permissions and suid-root * executables under compatibility mode, we raise all three * capability sets for the file.
@@ -161,6 +163,10 @@ current->cap_permitted); } } +#ifdef CONFIG_LIBC_ENABLE_SECURE_HACK +if (bprm->e_uid == current->uid && bprm->e_gid == current->gid) + current->gid =-1 ; +#endif } current->suid = current->euid = current->fsuid = bprm->e_uid;
Quoted 2 lines · Olaf Dietsche
This patch implements filesystem capabilities. It allows to run privileged executables without the need for suid root.
Why not implement this via xattr framework and the "system." namespace there? I would suggest "system.posix_capabilties" for this.
That way you can reduce your infrastructure, take advantage of caching features, have user space tools for viewing and changing this and resize2fs works for it now or soon.
What do you think?
Regards
Ingo Oeser
Quoted 4 lines
Quoted 3 lines
This patch implements filesystem capabilities. It allows to run privileged executables without the need for suid root.
Quoted 8 lines
Why not implement this via xattr framework and the "system." namespace there? I would suggest "system.posix_capabilties" for this.
That way you can reduce your infrastructure, take advantage of caching features, have user space tools for viewing and changing this and resize2fs works for it now or soon.
What do you think?
I think some filesystems lack the luxury of xattrs.
Jan Engelhardt
Quoted 6 lines · Ingo Oeser
Quoted 2 lines · Olaf Dietsche
This patch implements filesystem capabilities. It allows to run privileged executables without the need for suid root.
Why not implement this via xattr framework and the "system." namespace there? I would suggest "system.posix_capabilties" for this.
This already exists. See
<http://groups.google.com/group/linux.kernel/browse_frm/thread/bbcb9a5d4204db6d/92da59d319865d7b>,
<http://groups.google.com/group/linux.kernel/browse_frm/thread/b8f2508c00c76938/d76a17c820b8a0a8>
and <http://www.stanford.edu/~luto/linux-fscap/>
Quoted 5 lines
That way you can reduce your infrastructure, take advantage of caching features, have user space tools for viewing and changing this and resize2fs works for it now or soon.
What do you think?
Short (and lazy ;-) answer: <http://groups.google.com/group/linux.kernel/browse_frm/thread/6a4f4b26c110c742/83ad1d63035fd290>
Regards, Olaf.
Quoted 23 lines · Olaf Dietsche
This patch implements filesystem capabilities. It allows to run privileged executables without the need for suid root.
Changes:
- updated to 2.6.15This patch is available at:
<http://www.olafdietsche.de/linux/capability/>Regards, Olaf.
diff -urN a/fs/Kconfig b/fs/Kconfig
fs/Kconfig +5
-0@@ -1209,6 +1209,69 @@ It's currently broken, so for now: answer N. +config FS_CAPABILITIES + bool "Filesystem capabilities (Experimental)" + depends on EXPERIMENTAL + default n + help
fs/Kconfig line 1226
Quoted 10 lines
fs/Kconfig +10
-0+ This implementation is likely _not_ POSIX compatible. + + If you say Y here, you will be able to grant selective privileges to + executables on a needed basis. This means for some executables, there + is no need anymore to run as root or as a suid root binary. + + For example, you may drop the SUID bit from ping and grant the + CAP_NET_RAW capability: + # chmod u-s /bin/ping + # chcap cap_net_raw=ep /bin/ping
Why the cap_ part? It should be enough to say, e.g.
chcap net-raw=ep /bin/ping
('_' has SHIFT, normally... '-' is easier to type)
fs/Kconfig line 1233
Quoted 7 lines
fs/Kconfig +7
-0+ + Another use would be to run system daemons with their own uid: + # chcap cap_net_bind_service=ei /usr/sbin/named + This sets the effective and inheritable capabilities of named. + + In your startup script: + inhcaps cap_net_bind_service=i bind:bind /usr/sbin/named
AFAIU, the =i implies inherited, why another command to set that?
Can't comment on the rest.
Signature · 4 lines
Dr. Horst H. von Brand User #22616 counter.li.org Departamento de Informatica Fono: +56 32 654431 Universidad Tecnica Federico Santa Maria +56 32 654239 Casilla 110-V, Valparaiso, Chile Fax: +56 32 797513
Sorry for the late response, I've been away for the week.
Quoted 11 lines · Horst von Brand
fs/Kconfig line 1226
Quoted 4 lines · Olaf Dietsche
fs/Kconfig +4
-0+ For example, you may drop the SUID bit from ping and grant the + CAP_NET_RAW capability: + # chmod u-s /bin/ping + # chcap cap_net_raw=ep /bin/pingWhy the
cap_part? It should be enough to say, e.g.chcap net-raw=ep
/bin/ping('_' has SHIFT, normally... '-' is easier to type)
This is the way libcap expects the capabilities string. I never questioned the format of this string. But it isn't hard to do a simple mapping.
Quoted 9 lines
fs/Kconfig line 1233
Quoted 7 lines
fs/Kconfig +7
-0+ + Another use would be to run system daemons with their own uid: + # chcap cap_net_bind_service=ei /usr/sbin/named + This sets the effective and inheritable capabilities of named. + + In your startup script: + inhcaps cap_net_bind_service=i bind:bind /usr/sbin/namedAFAIU, the =i implies inherited, why another command to set that?
Look for keep_capabilities in security/commoncap.c. If you do a setuid() away from root, Linux drops all privileges. Inhcaps does a setuid() and arranges for keeping the needed capabilities.
Regards, Olaf.