Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 71163
b: refs/heads/master
c: 72c2d58
h: refs/heads/master
i:
  71161: 32c16e7
  71159: 3f6d1a1
v: v3
  • Loading branch information
Andrew Morgan authored and Linus Torvalds committed Oct 18, 2007
1 parent 7e11865 commit bd2103c
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 25 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7058cb02ddab4bce70a46e519804fccb7ac0a060
refs/heads/master: 72c2d5823fc7be799a12184974c3bdc57acea3c4
4 changes: 0 additions & 4 deletions trunk/include/linux/capability.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,6 @@ typedef __u32 kernel_cap_t;
#define CAP_SETFCAP 31

#ifdef __KERNEL__
/*
* Bounding set
*/
extern kernel_cap_t cap_bset;

/*
* Internal kernel functions only
Expand Down
7 changes: 7 additions & 0 deletions trunk/include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
#include <linux/xfrm.h>
#include <net/flow.h>

/*
* Bounding set
*/
extern kernel_cap_t cap_bset;

extern unsigned securebits;

struct ctl_table;

/*
Expand Down
5 changes: 1 addition & 4 deletions trunk/kernel/capability.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 1997 Andrew Main <zefram@fysh.org>
*
* Integrated into 2.1.97+, Andrew G. Morgan <morgan@transmeta.com>
* Integrated into 2.1.97+, Andrew G. Morgan <morgan@kernel.org>
* 30 May 2002: Cleanup, Robert M. Love <rml@tech9.net>
*/

Expand All @@ -14,9 +14,6 @@
#include <linux/syscalls.h>
#include <asm/uaccess.h>

unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
kernel_cap_t cap_bset = CAP_INIT_EFF_SET;

/*
* This lock protects task->cap_* for all tasks including current.
* Locking rule: acquire this prior to tasklist_lock.
Expand Down
8 changes: 6 additions & 2 deletions trunk/kernel/sysctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <linux/slab.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/capability.h>
#include <linux/security.h>
#include <linux/ctype.h>
#include <linux/utsname.h>
#include <linux/smp_lock.h>
Expand Down Expand Up @@ -371,13 +371,15 @@ static struct ctl_table kern_table[] = {
.proc_handler = &proc_dointvec_taint,
},
#endif
#ifdef CONFIG_SECURITY_CAPABILITIES
{
.procname = "cap-bound",
.data = &cap_bset,
.maxlen = sizeof(kernel_cap_t),
.mode = 0600,
.proc_handler = &proc_dointvec_bset,
},
#endif /* def CONFIG_SECURITY_CAPABILITIES */
#ifdef CONFIG_BLK_DEV_INITRD
{
.ctl_name = KERN_REALROOTDEV,
Expand Down Expand Up @@ -1872,10 +1874,11 @@ static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
return 0;
}

#ifdef CONFIG_SECURITY_CAPABILITIES
/*
* init may raise the set.
*/

int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
Expand All @@ -1889,6 +1892,7 @@ int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
do_proc_dointvec_bset_conv,&op);
}
#endif /* def CONFIG_SECURITY_CAPABILITIES */

/*
* Taint values can only be increased
Expand Down
5 changes: 5 additions & 0 deletions trunk/kernel/sysctl_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ static struct trans_ctl_table trans_kern_table[] = {
{ KERN_NODENAME, "hostname" },
{ KERN_DOMAINNAME, "domainname" },

#ifdef CONFIG_SECURITY_CAPABILITIES
{ KERN_CAP_BSET, "cap-bound" },
#endif /* def CONFIG_SECURITY_CAPABILITIES */

{ KERN_PANIC, "panic" },
{ KERN_REALROOTDEV, "real-root-dev" },

Expand Down Expand Up @@ -1532,7 +1535,9 @@ int sysctl_check_table(struct ctl_table *table)
(table->strategy == sysctl_ms_jiffies) ||
(table->proc_handler == proc_dostring) ||
(table->proc_handler == proc_dointvec) ||
#ifdef CONFIG_SECURITY_CAPABILITIES
(table->proc_handler == proc_dointvec_bset) ||
#endif /* def CONFIG_SECURITY_CAPABILITIES */
(table->proc_handler == proc_dointvec_minmax) ||
(table->proc_handler == proc_dointvec_jiffies) ||
(table->proc_handler == proc_dointvec_userhz_jiffies) ||
Expand Down
59 changes: 54 additions & 5 deletions trunk/security/commoncap.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@
#include <linux/hugetlb.h>
#include <linux/mount.h>

#ifdef CONFIG_SECURITY_FILE_CAPABILITIES
/*
* Because of the reduced scope of CAP_SETPCAP when filesystem
* capabilities are in effect, it is safe to allow this capability to
* be available in the default configuration.
*/
# define CAP_INIT_BSET CAP_FULL_SET
#else /* ie. ndef CONFIG_SECURITY_FILE_CAPABILITIES */
# define CAP_INIT_BSET CAP_INIT_EFF_SET
#endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */

kernel_cap_t cap_bset = CAP_INIT_BSET; /* systemwide capability bound */
EXPORT_SYMBOL(cap_bset);

/* Global security state */

unsigned securebits = SECUREBITS_DEFAULT; /* systemwide security settings */
EXPORT_SYMBOL(securebits);

int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
{
NETLINK_CB(skb).eff_cap = current->cap_effective;
Expand Down Expand Up @@ -73,14 +92,44 @@ int cap_capget (struct task_struct *target, kernel_cap_t *effective,
return 0;
}

#ifdef CONFIG_SECURITY_FILE_CAPABILITIES

static inline int cap_block_setpcap(struct task_struct *target)
{
/*
* No support for remote process capability manipulation with
* filesystem capability support.
*/
return (target != current);
}

static inline int cap_inh_is_capped(void)
{
/*
* return 1 if changes to the inheritable set are limited
* to the old permitted set.
*/
return !cap_capable(current, CAP_SETPCAP);
}

#else /* ie., ndef CONFIG_SECURITY_FILE_CAPABILITIES */

static inline int cap_block_setpcap(struct task_struct *t) { return 0; }
static inline int cap_inh_is_capped(void) { return 1; }

#endif /* def CONFIG_SECURITY_FILE_CAPABILITIES */

int cap_capset_check (struct task_struct *target, kernel_cap_t *effective,
kernel_cap_t *inheritable, kernel_cap_t *permitted)
{
/* Derived from kernel/capability.c:sys_capset. */
/* verify restrictions on target's new Inheritable set */
if (!cap_issubset (*inheritable,
cap_combine (target->cap_inheritable,
current->cap_permitted))) {
if (cap_block_setpcap(target)) {
return -EPERM;
}
if (cap_inh_is_capped()
&& !cap_issubset(*inheritable,
cap_combine(target->cap_inheritable,
current->cap_permitted))) {
/* incapable of using this inheritable set */
return -EPERM;
}

Expand Down
16 changes: 7 additions & 9 deletions trunk/security/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ static int dummy_capget (struct task_struct *target, kernel_cap_t * effective,
kernel_cap_t * inheritable, kernel_cap_t * permitted)
{
*effective = *inheritable = *permitted = 0;
if (!issecure(SECURE_NOROOT)) {
if (target->euid == 0) {
*permitted |= (~0 & ~CAP_FS_MASK);
*effective |= (~0 & ~CAP_TO_MASK(CAP_SETPCAP) & ~CAP_FS_MASK);
}
if (target->fsuid == 0) {
*permitted |= CAP_FS_MASK;
*effective |= CAP_FS_MASK;
}
if (target->euid == 0) {
*permitted |= (~0 & ~CAP_FS_MASK);
*effective |= (~0 & ~CAP_TO_MASK(CAP_SETPCAP) & ~CAP_FS_MASK);
}
if (target->fsuid == 0) {
*permitted |= CAP_FS_MASK;
*effective |= CAP_FS_MASK;
}
return 0;
}
Expand Down

0 comments on commit bd2103c

Please sign in to comment.