new capability patch, version 0.4.2 (now with fs support), part 1/4
Subsystems (7)
PATCH 1/1 new capability patch, version 0.4.2 (now with fs support), part 1/4
Here's the new version (0.4.2) of my capabilities patch, part 1/4 (increases capability sets to 64 bits).
Explanations are on <URL: http://www.madore.org/~david/linux/newcaps/ >.
fs/open.c | 3 ++- fs/proc/array.c | 6 +++--- include/linux/capability.h | 30 +++++++++++++++++++----------- kernel/capability.c | 44 +++++++++++++++++++++++++++++++++++--------- security/commoncap.c | 16 +++++++++++----- security/dummy.c | 6 +++--- 6 files changed, 73 insertions(+), 32 deletions(-)
fs/open.c +2 -1
@@ -515,7 +515,8 @@ asmlinkage long sys_faccessat(int dfd, c* but we cannot because user_path_walk can sleep. */ if (current->uid) -cap_clear (current->cap_effective); + current->cap_effective =cap_intersect (current->cap_effective, +CAP_REGULAR_SET );else current->cap_effective = current->cap_permitted;
fs/proc/array.c +3 -3
@@ -285,9 +285,9 @@ static inline char * task_sig(struct tasstatic inline char *task_cap (struct task_struct *p,char *buffer) { -return buffer +sprintf (buffer,"CapInh:\t%016x\n" -"CapPrm:\t%016x\n" -"CapEff:\t%016x\n" , +return buffer +sprintf (buffer,"CapInh:\t%016llx\n" +"CapPrm:\t%016llx\n" +"CapEff:\t%016llx\n" ,cap_t (p->cap_inheritable),cap_t (p->cap_permitted),cap_t (p->cap_effective));
include/linux/capability.h +19 -11
@@ -27,7 +27,8 @@ #include <linux/compiler.h>library since the draft standard requires the use of malloc/free etc.. */ -#define _LINUX_CAPABILITY_VERSION 0x19980330 +#define _LINUX_CAPABILITY_VERSION 0x20060903 +#define _LINUX_CAPABILITY_OLD_VERSION 0x19980330 typedef struct __user_cap_header_struct { __u32 version;
@@ -35,10 +36,16 @@ typedef struct __user_cap_header_struct }__user *cap_user_header_t;typedef struct __user_cap_data_struct { +__u64 effective; +__u64 permitted; +__u64 inheritable; +}__user *cap_user_data_t ; + +typedef struct __user_cap_data_old_struct {__u32 effective;__u32 permitted;__u32 inheritable; -}__user *cap_user_data_t ; +}__user *cap_user_data_old_t ;#ifdef __KERNEL__
@@ -50,12 +57,12 @@ #include <asm/current.h>#ifdef STRICT_CAP_T_TYPECHECKS typedef struct kernel_cap_struct { -__u32 cap; +__u64 cap; }kernel_cap_t ;#else -typedef __u32 kernel_cap_t ; +typedef __u64 kernel_cap_t ;#endif
@@ -310,12 +317,13 @@ #define cap_t(x) (x)#endif -#define CAP_EMPTY_SET to_cap_t(0) -#define CAP_FULL_SET to_cap_t(~0) -#define CAP_INIT_EFF_SET to_cap_t(~0 & ~CAP_TO_MASK(CAP_SETPCAP)) -#define CAP_INIT_INH_SET to_cap_t(0) +#define CAP_EMPTY_SET to_cap_t(0ULL) +#define CAP_FULL_SET to_cap_t(~0ULL) +#define CAP_REGULAR_SET to_cap_t(0xffffffff00000000ULL) +#define CAP_INIT_EFF_SET to_cap_t(~0ULL) +#define CAP_INIT_INH_SET to_cap_t(~0ULL) -#define CAP_TO_MASK (x) (1 << (x)) +#define CAP_TO_MASK (x) (1ULL << (x))#define cap_raise (c, flag) (cap_t(c) |= CAP_TO_MASK(flag))#define cap_lower (c, flag) (cap_t(c) &= ~CAP_TO_MASK(flag))#define cap_raised (c, flag) (cap_t(c) & CAP_TO_MASK(flag))
@@ -351,8 +359,8 @@ static inline kernel_cap_t cap_invert(ke#define cap_isclear (c) (!cap_t(c))#define cap_issubset (a,set) (!(cap_t(a) & ~cap_t(set))) -#define cap_clear (c) do { cap_t(c) = 0; } while(0) -#define cap_set_full (c) do { cap_t(c) = ~0; } while(0) +#define cap_clear (c) do { cap_t(c) = 0ULL; } while(0) +#define cap_set_full (c) do { cap_t(c) = ~0ULL; } while(0)#define cap_mask (c,mask) do { cap_t(c) &= cap_t(mask); } while(0)#define cap_is_fs_cap (c) (CAP_TO_MASK(c) & CAP_FS_MASK)
kernel/capability.c +35 -9
74 lines not on this page · raw message
security/commoncap.c +11 -5
@@ -244,13 +244,19 @@ static inline void cap_emulate_setxuid ( int old_suid) {if ((old_ruid ==0 || old_euid ==0 || old_suid ==0 ) && - (current->uid !=0 && current->euid !=0 && current->suid !=0 ) && - !current->keep_capabilities) { -cap_clear (current->cap_permitted); -cap_clear (current->cap_effective); + (current->uid !=0 && current->euid !=0 && current->suid !=0 )) { +if (!current->keep_capabilities) { + current->cap_permitted + =cap_intersect (current->cap_permitted, +CAP_REGULAR_SET ); + current->cap_effective + =cap_intersect (current->cap_effective, +CAP_REGULAR_SET ); + } }if (old_euid ==0 && current->euid !=0 ) { -cap_clear (current->cap_effective); + current->cap_effective =cap_intersect (current->cap_effective, +CAP_REGULAR_SET ); }if (old_euid !=0 && current->euid ==0 ) { current->cap_effective = current->cap_permitted;
security/dummy.c +3 -3
@@ -37,11 +37,11 @@ static int dummy_ptrace (struct task_strstatic int dummy_capget (struct task_struct *target,kernel_cap_t * effective,kernel_cap_t * inheritable,kernel_cap_t * permitted) { - *effective = *inheritable = *permitted =0 ; + *effective = *inheritable = *permitted =CAP_REGULAR_SET ;if (!issecure (SECURE_NOROOT )) {if (target->euid ==0 ) { - *permitted |= (~0 & ~CAP_FS_MASK ); - *effective |= (~0 & ~CAP_TO_MASK (CAP_SETPCAP ) & ~CAP_FS_MASK ); + *permitted |= (CAP_FULL_SET & ~CAP_FS_MASK ); + *effective |= (CAP_FULL_SET & ~CAP_TO_MASK (CAP_SETPCAP ) & ~CAP_FS_MASK ); }if (target->fsuid ==0 ) { *permitted |=CAP_FS_MASK ;
Signature · 3 lines
David A. Madore
([email protected],
http://www.madore.org/~david/ )PATCH 1/1 new capability patch, version 0.4.2 (now with fs support), part 2/4
Here's the new version (0.4.2) of my capabilities patch, part 2/4 (introduces the new semantics for inheritance).
Explanations are on <URL: http://www.madore.org/~david/linux/newcaps/ >.
fs/exec.c | 4 +++ include/linux/binfmts.h | 1 + kernel/capability.c | 2 + security/commoncap.c | 69 ++++++++++++++++++++++++++++------------------- 4 files changed, 47 insertions(+), 29 deletions(-)
fs/exec.c +4 -0
@@ -925,10 +925,13 @@ int prepare_binprm(struct linux_binprm * bprm->e_uid = current->euid; bprm->e_gid = current->egid; + bprm->is_suid =0 ; + bprm->is_sgid =0 ;if (!(bprm->file->f_vfsmnt->mnt_flags &MNT_NOSUID )) {/* Set-uid? */ if (mode &S_ISUID ) { + bprm->is_suid =1 ; current->personality &= ~PER_CLEAR_ON_SETID ; bprm->e_uid = inode->i_uid; }
@@ -940,6 +943,7 @@ int prepare_binprm(struct linux_binprm ** executable. */ if ((mode & (S_ISGID |S_IXGRP )) == (S_ISGID |S_IXGRP )) { + bprm->is_sgid =1 ; current->personality &= ~PER_CLEAR_ON_SETID ; bprm->e_gid = inode->i_gid; }
include/linux/binfmts.h +1 -0
@@ -29,6 +29,7 @@ struct linux_binprm{struct file * file;int e_uid, e_gid;kernel_cap_t cap_inheritable, cap_permitted, cap_effective; +char is_suid, is_sgid;void *security;int argc, envc;char * filename;/* Name of binary as seen by procps */
kernel/capability.c +1 -1
@@ -15,7 +15,7 @@ #include <linux/syscalls.h>#include <asm/uaccess.h> unsigned securebits =SECUREBITS_DEFAULT ;/* systemwide security settings */ -kernel_cap_t cap_bset =CAP_INIT_EFF_SET ; +kernel_cap_t cap_bset =CAP_INIT_INH_SET ;EXPORT_SYMBOL (securebits);EXPORT_SYMBOL (cap_bset);
security/commoncap.c +41 -28
140 lines not on this page · raw message
Signature · 3 lines
David A. Madore
([email protected],
http://www.madore.org/~david/ )PATCH 1/1 new capability patch, version 0.4.2 (now with fs support), part 3/4
In reply to David MadoreHere's the new version (0.4.2) of my capabilities patch, part 3/4 (introduces some new capabilities).
Explanations are on <URL: http://www.madore.org/~david/linux/newcaps/ >.
fs/exec.c | 7 +++++-- fs/namei.c | 2 +- fs/open.c | 26 ++++++++++++++++++++------ fs/xattr.c | 3 ++- include/linux/capability.h | 20 ++++++++++++++++++++ kernel/fork.c | 2 ++ 6 files changed, 50 insertions(+), 10 deletions(-)
fs/exec.c +5 -2
@@ -930,7 +930,7 @@ int prepare_binprm(struct linux_binprm *if (!(bprm->file->f_vfsmnt->mnt_flags &MNT_NOSUID )) {/* Set-uid? */ -if (mode &S_ISUID ) { +if (mode &S_ISUID &&capable (CAP_REG_SXID )) { bprm->is_suid =1 ; current->personality &= ~PER_CLEAR_ON_SETID ; bprm->e_uid = inode->i_uid;
@@ -942,7 +942,8 @@ int prepare_binprm(struct linux_binprm ** is a candidate for mandatory locking, not a setgid * executable. */ -if ((mode & (S_ISGID |S_IXGRP )) == (S_ISGID |S_IXGRP )) { +if ((mode & (S_ISGID |S_IXGRP )) == (S_ISGID |S_IXGRP ) + &&capable (CAP_REG_SXID )) { bprm->is_sgid =1 ; current->personality &= ~PER_CLEAR_ON_SETID ; bprm->e_gid = inode->i_gid;
@@ -1137,6 +1138,8 @@ int do_execve(char * filename,int retval;int i; +if (!capable (CAP_REG_EXEC )) +return -EPERM ; retval = -ENOMEM ; bprm =kzalloc (sizeof (*bprm),GFP_KERNEL );if (!bprm)
fs/namei.c +1 -1
@@ -242,7 +242,7 @@ int permission(struct inode *inode, int/* * Nobody gets write access to an immutable file. */ -if (IS_IMMUTABLE (inode)) +if (IS_IMMUTABLE (inode) || !capable (CAP_REG_WRITE ))return -EACCES ; }
fs/open.c +20 -6
@@ -253,7 +253,7 @@ static long do_sys_truncate(const char _ goto dput_and_out; error = -EPERM ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) +if (IS_IMMUTABLE (inode) ||IS_APPEND (inode) || !capable (CAP_REG_WRITE )) goto dput_and_out;/*
@@ -382,6 +382,10 @@ asmlinkage long sys_utime(char __user *if (IS_RDONLY (inode)) goto dput_and_out; + error = -EPERM ; +if (!capable (CAP_REG_WRITE )) + goto dput_and_out; +/* Don't worry, the checks are done in inode_change_ok() */ newattrs.ia_valid =ATTR_CTIME |ATTR_MTIME |ATTR_ATIME ;if (times) {
@@ -439,6 +443,10 @@ long do_utimes(int dfd, char __user *filif (IS_RDONLY (inode)) goto dput_and_out; + error = -EPERM ; +if (!capable (CAP_REG_WRITE )) + goto dput_and_out; +/* Don't worry, the checks are done in inode_change_ok() */ newattrs.ia_valid =ATTR_CTIME |ATTR_MTIME |ATTR_ATIME ;if (times) {
@@ -640,7 +648,7 @@ asmlinkage long sys_fchmod(unsigned intif (IS_RDONLY (inode)) goto out_putf; err = -EPERM ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) +if (IS_IMMUTABLE (inode) ||IS_APPEND (inode) || !capable (CAP_REG_WRITE )) goto out_putf;mutex_lock (&inode->i_mutex);if (mode == (mode_t) -1 )
@@ -674,7 +682,7 @@ asmlinkage long sys_fchmodat(int dfd, co goto dput_and_out; error = -EPERM ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) +if (IS_IMMUTABLE (inode) ||IS_APPEND (inode) || !capable (CAP_REG_WRITE )) goto dput_and_out;mutex_lock (&inode->i_mutex);
@@ -711,7 +719,7 @@ static int chown_common(struct dentry *if (IS_RDONLY (inode)) goto out; error = -EPERM ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) +if (IS_IMMUTABLE (inode) ||IS_APPEND (inode) || !capable (CAP_REG_WRITE )) goto out; newattrs.ia_valid =ATTR_CTIME ;if (user != (uid_t) -1 ) {
@@ -1105,7 +1113,10 @@ asmlinkage long sys_open(const char __usif (force_o_largefile ()) flags |=O_LARGEFILE ; - ret =do_sys_open (AT_FDCWD , filename, flags, mode); +if (capable (CAP_REG_OPEN )) + ret =do_sys_open (AT_FDCWD , filename, flags, mode); +else + ret = -EPERM ;/* avoid REGPARM breakage on x86: */ prevent_tail_call (ret);return ret;
@@ -1120,7 +1131,10 @@ asmlinkage long sys_openat(int dfd, consif (force_o_largefile ()) flags |=O_LARGEFILE ; - ret =do_sys_open (dfd, filename, flags, mode); +if (capable (CAP_REG_OPEN )) + ret =do_sys_open (dfd, filename, flags, mode); +else + ret = -EPERM ;/* avoid REGPARM breakage on x86: */ prevent_tail_call (ret);return ret;
fs/xattr.c +2 -1
@@ -35,7 +35,8 @@ xattr_permission(struct inode *inode, coif (mask &MAY_WRITE ) {if (IS_RDONLY (inode))return -EROFS ; -if (IS_IMMUTABLE (inode) ||IS_APPEND (inode)) +if (IS_IMMUTABLE (inode) ||IS_APPEND (inode) + || !capable (CAP_REG_WRITE ))return -EPERM ; }
include/linux/capability.h +20 -0
@@ -295,6 +295,26 @@ #define CAP_AUDIT_WRITE 29#define CAP_AUDIT_CONTROL 30 + +/** +** Regular capabilities (normally possessed by all processes). +**/ + +/* Can fork() */ +#define CAP_REG_FORK 32 + +/* Can open() */ +#define CAP_REG_OPEN 33 + +/* Can exec() */ +#define CAP_REG_EXEC 34 + +/* Might gain permissions on exec() */ +#define CAP_REG_SXID 35 + +/* Perform write access to the filesystem */ +#define CAP_REG_WRITE 36 +#ifdef __KERNEL__/* * Bounding set
kernel/fork.c +2 -0
@@ -1347,6 +1347,8 @@ long do_fork(unsigned long clone_flags,struct pid *pid =alloc_pid ();long nr; +if (!capable (CAP_REG_FORK )) +return -EPERM ;if (!pid)return -EAGAIN ; nr = pid->nr;
Signature · 3 lines
David A. Madore
([email protected],
http://www.madore.org/~david/ )PATCH 1/1 new capability patch, version 0.4.2 (now with fs support), part 4/4
In reply to David MadoreHere's the new version (0.4.2) of my capabilities patch, part 4/4 (the filesystem part, a merge of Serge Hallyn's patch).
Explanations are on <URL: http://www.madore.org/~david/linux/newcaps/ >.
include/linux/capability.h | 3 + include/linux/security.h | 10 ++- security/Kconfig | 10 +++ security/capability.c | 4 + security/commoncap.c | 155 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 178 insertions(+), 4 deletions(-)
include/linux/capability.h +3 -0
@@ -295,6 +295,9 @@ #define CAP_AUDIT_WRITE 29#define CAP_AUDIT_CONTROL 30 +/* Number of low (=system, =additional) caps */ +#define CAP_NUMCAPS_SYS 30 +/** ** Regular capabilities (normally possessed by all processes).
include/linux/security.h +7 -3
@@ -51,6 +51,10 @@ extern int cap_inode_setxattr(struct denextern int cap_inode_removexattr (struct dentry *dentry,char *name);extern int cap_task_post_setuid (uid_t old_ruid,uid_t old_euid,uid_t old_suid,int flags);extern void cap_task_reparent_to_init (struct task_struct *p); +extern int cap_task_kill (struct task_struct *p,struct siginfo *info,int sig,u32 secid); +extern int cap_task_setscheduler (struct task_struct *p,int policy,struct sched_param *lp); +extern int cap_task_setioprio (struct task_struct *p,int ioprio); +extern int cap_task_setnice (struct task_struct *p,int nice);extern int cap_syslog (int type);extern int cap_vm_enough_memory (long pages);
@@ -2544,12 +2548,12 @@ static inline int security_task_setgroupstatic inline int security_task_setnice (struct task_struct *p,int nice) { -return 0 ; +return cap_task_setnice (p, nice); }static inline int security_task_setioprio (struct task_struct *p,int ioprio) { -return 0 ; +return cap_task_setioprio (p, ioprio); }static inline int security_task_getioprio (struct task_struct *p)
@@ -2584,7 +2588,7 @@ static inline int security_task_kill (st struct siginfo *info, int sig, u32 secid) { - return 0; + return cap_task_kill(p, info, sig, secid); }static inline int security_task_wait (struct task_struct *p)
security/Kconfig +10 -0
@@ -80,6 +80,16 @@ config SECURITY_CAPABILITIES This enables the "default" Linux capabilities functionality. If you are unsure how to answer this question, answer Y. +config SECURITY_FS_CAPABILITIES + bool "Filesystem Capabilities" + depends on SECURITY_CAPABILITIES + default n + help + This enables filesystem capabilities, allowing you to give + binaries a subset of root's powers without using setuid 0. + + If in doubt, answer N. + config SECURITY_ROOTPLUG tristate "Root Plug Support" depends on USB && SECURITY
security/capability.c +4 -0
@@ -40,6 +40,10 @@ static struct security_operations capabi .inode_setxattr = cap_inode_setxattr, .inode_removexattr = cap_inode_removexattr, + .task_kill = cap_task_kill, + .task_setscheduler = cap_task_setscheduler, + .task_setioprio = cap_task_setioprio, + .task_setnice = cap_task_setnice, .task_post_setuid = cap_task_post_setuid, .task_reparent_to_init = cap_task_reparent_to_init,
security/commoncap.c +154 -1
189 lines not on this page · raw message
Signature · 3 lines
David A. Madore
([email protected],
http://www.madore.org/~david/ )Re: [PATCH] new capability patch, version 0.4.2 (now with fs support), part 3/4
In reply to David MadoreHi!
Quoted 5 lines
Here's the new version (0.4.2) of my capabilities patch, part 3/4 (introduces some new capabilities).
Explanations are on <URL:
http://www.madore.org/~david/linux/newcaps/ >.
Well, for merge you'll need to sign-off and put explanation to each patch. Link is not enough, because it will end in git.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH] new capability patch, version 0.4.2 (now with fs support), part 3/4
Quoted 2 lines · Pavel Machek
Well, for merge you'll need to sign-off and put explanation to each patch. Link is not enough, because it will end in git.
You'll have to excuse me for my ignorance: I have some knowledge of how git and the kernel work as programs, but none at all of how they are actually managed by the Powers That Be. So, what does it mean to "sign off", where should I append the explanations, which git repository will/might it end in, and how am I supposed to do things the right way? I mean, so far I'm just expecting people to read the patch and perhaps test it, but certainly not commit it anywhere "serious"...
Pointers are an acceptable answer, of course.
Signature · 3 lines
David A. Madore
([email protected],
http://www.madore.org/~david/ )Re: [PATCH] new capability patch, version 0.4.2 (now with fs support), part 3/4
Quoted 13 lines · David Madore
Quoted 2 lines · Pavel Machek
Well, for merge you'll need to sign-off and put explanation to each patch. Link is not enough, because it will end in git.
You'll have to excuse me for my ignorance: I have some knowledge of how git and the kernel work as programs, but none at all of how they are actually managed by the Powers That Be. So, what does it mean to "sign off", where should I append the explanations, which git repository will/might it end in, and how am I supposed to do things the right way? I mean, so far I'm just expecting people to read the patch and perhaps test it, but certainly not commit it anywhere "serious"...
Quoted 1 line
Pointers are an acceptable answer, of course.
And pointer is what you'll get ;-). Documentation/SubmittingPatches.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html