Commit 847106ff authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus' of...

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6: (25 commits)
  security: remove register_security hook
  security: remove dummy module fix
  security: remove dummy module
  security: remove unused sb_get_mnt_opts hook
  LSM/SELinux: show LSM mount options in /proc/mounts
  SELinux: allow fstype unknown to policy to use xattrs if present
  security: fix return of void-valued expressions
  SELinux: use do_each_thread as a proper do/while block
  SELinux: remove unused and shadowed addrlen variable
  SELinux: more user friendly unknown handling printk
  selinux: change handling of invalid classes (Was: Re: 2.6.26-rc5-mm1 selinux whine)
  SELinux: drop load_mutex in security_load_policy
  SELinux: fix off by 1 reference of class_to_string in context_struct_compute_av
  SELinux: open code sidtab lock
  SELinux: open code load_mutex
  SELinux: open code policy_rwlock
  selinux: fix endianness bug in network node address handling
  selinux: simplify ioctl checking
  SELinux: enable processes with mac_admin to get the raw inode contexts
  Security: split proc ptrace checking into read vs. attach
  ...
parents c142bda4 6f0f0fd4
...@@ -750,7 +750,7 @@ struct proc_fs_info { ...@@ -750,7 +750,7 @@ struct proc_fs_info {
const char *str; const char *str;
}; };
static void show_sb_opts(struct seq_file *m, struct super_block *sb) static int show_sb_opts(struct seq_file *m, struct super_block *sb)
{ {
static const struct proc_fs_info fs_info[] = { static const struct proc_fs_info fs_info[] = {
{ MS_SYNCHRONOUS, ",sync" }, { MS_SYNCHRONOUS, ",sync" },
...@@ -764,6 +764,8 @@ static void show_sb_opts(struct seq_file *m, struct super_block *sb) ...@@ -764,6 +764,8 @@ static void show_sb_opts(struct seq_file *m, struct super_block *sb)
if (sb->s_flags & fs_infop->flag) if (sb->s_flags & fs_infop->flag)
seq_puts(m, fs_infop->str); seq_puts(m, fs_infop->str);
} }
return security_sb_show_options(m, sb);
} }
static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt) static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
...@@ -806,11 +808,14 @@ static int show_vfsmnt(struct seq_file *m, void *v) ...@@ -806,11 +808,14 @@ static int show_vfsmnt(struct seq_file *m, void *v)
seq_putc(m, ' '); seq_putc(m, ' ');
show_type(m, mnt->mnt_sb); show_type(m, mnt->mnt_sb);
seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw"); seq_puts(m, __mnt_is_readonly(mnt) ? " ro" : " rw");
show_sb_opts(m, mnt->mnt_sb); err = show_sb_opts(m, mnt->mnt_sb);
if (err)
goto out;
show_mnt_opts(m, mnt); show_mnt_opts(m, mnt);
if (mnt->mnt_sb->s_op->show_options) if (mnt->mnt_sb->s_op->show_options)
err = mnt->mnt_sb->s_op->show_options(m, mnt); err = mnt->mnt_sb->s_op->show_options(m, mnt);
seq_puts(m, " 0 0\n"); seq_puts(m, " 0 0\n");
out:
return err; return err;
} }
...@@ -865,10 +870,13 @@ static int show_mountinfo(struct seq_file *m, void *v) ...@@ -865,10 +870,13 @@ static int show_mountinfo(struct seq_file *m, void *v)
seq_putc(m, ' '); seq_putc(m, ' ');
mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none"); mangle(m, mnt->mnt_devname ? mnt->mnt_devname : "none");
seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw"); seq_puts(m, sb->s_flags & MS_RDONLY ? " ro" : " rw");
show_sb_opts(m, sb); err = show_sb_opts(m, sb);
if (err)
goto out;
if (sb->s_op->show_options) if (sb->s_op->show_options)
err = sb->s_op->show_options(m, mnt); err = sb->s_op->show_options(m, mnt);
seq_putc(m, '\n'); seq_putc(m, '\n');
out:
return err; return err;
} }
......
...@@ -233,7 +233,7 @@ static int check_mem_permission(struct task_struct *task) ...@@ -233,7 +233,7 @@ static int check_mem_permission(struct task_struct *task)
*/ */
if (task->parent == current && (task->ptrace & PT_PTRACED) && if (task->parent == current && (task->ptrace & PT_PTRACED) &&
task_is_stopped_or_traced(task) && task_is_stopped_or_traced(task) &&
ptrace_may_attach(task)) ptrace_may_access(task, PTRACE_MODE_ATTACH))
return 0; return 0;
/* /*
...@@ -251,7 +251,8 @@ struct mm_struct *mm_for_maps(struct task_struct *task) ...@@ -251,7 +251,8 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
task_lock(task); task_lock(task);
if (task->mm != mm) if (task->mm != mm)
goto out; goto out;
if (task->mm != current->mm && __ptrace_may_attach(task) < 0) if (task->mm != current->mm &&
__ptrace_may_access(task, PTRACE_MODE_READ) < 0)
goto out; goto out;
task_unlock(task); task_unlock(task);
return mm; return mm;
...@@ -518,7 +519,7 @@ static int proc_fd_access_allowed(struct inode *inode) ...@@ -518,7 +519,7 @@ static int proc_fd_access_allowed(struct inode *inode)
*/ */
task = get_proc_task(inode); task = get_proc_task(inode);
if (task) { if (task) {
allowed = ptrace_may_attach(task); allowed = ptrace_may_access(task, PTRACE_MODE_READ);
put_task_struct(task); put_task_struct(task);
} }
return allowed; return allowed;
...@@ -904,7 +905,7 @@ static ssize_t environ_read(struct file *file, char __user *buf, ...@@ -904,7 +905,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
if (!task) if (!task)
goto out_no_task; goto out_no_task;
if (!ptrace_may_attach(task)) if (!ptrace_may_access(task, PTRACE_MODE_READ))
goto out; goto out;
ret = -ENOMEM; ret = -ENOMEM;
......
...@@ -210,7 +210,7 @@ static int show_map(struct seq_file *m, void *v) ...@@ -210,7 +210,7 @@ static int show_map(struct seq_file *m, void *v)
dev_t dev = 0; dev_t dev = 0;
int len; int len;
if (maps_protect && !ptrace_may_attach(task)) if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
return -EACCES; return -EACCES;
if (file) { if (file) {
...@@ -646,7 +646,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf, ...@@ -646,7 +646,7 @@ static ssize_t pagemap_read(struct file *file, char __user *buf,
goto out; goto out;
ret = -EACCES; ret = -EACCES;
if (!ptrace_may_attach(task)) if (!ptrace_may_access(task, PTRACE_MODE_READ))
goto out_task; goto out_task;
ret = -EINVAL; ret = -EINVAL;
...@@ -747,7 +747,7 @@ static int show_numa_map_checked(struct seq_file *m, void *v) ...@@ -747,7 +747,7 @@ static int show_numa_map_checked(struct seq_file *m, void *v)
struct proc_maps_private *priv = m->private; struct proc_maps_private *priv = m->private;
struct task_struct *task = priv->task; struct task_struct *task = priv->task;
if (maps_protect && !ptrace_may_attach(task)) if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
return -EACCES; return -EACCES;
return show_numa_map(m, v); return show_numa_map(m, v);
......
...@@ -113,7 +113,7 @@ static int show_map(struct seq_file *m, void *_vml) ...@@ -113,7 +113,7 @@ static int show_map(struct seq_file *m, void *_vml)
struct proc_maps_private *priv = m->private; struct proc_maps_private *priv = m->private;
struct task_struct *task = priv->task; struct task_struct *task = priv->task;
if (maps_protect && !ptrace_may_attach(task)) if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
return -EACCES; return -EACCES;
return nommu_vma_show(m, vml->vma); return nommu_vma_show(m, vml->vma);
......
...@@ -95,8 +95,12 @@ extern void __ptrace_link(struct task_struct *child, ...@@ -95,8 +95,12 @@ extern void __ptrace_link(struct task_struct *child,
struct task_struct *new_parent); struct task_struct *new_parent);
extern void __ptrace_unlink(struct task_struct *child); extern void __ptrace_unlink(struct task_struct *child);
extern void ptrace_untrace(struct task_struct *child); extern void ptrace_untrace(struct task_struct *child);
extern int ptrace_may_attach(struct task_struct *task); #define PTRACE_MODE_READ 1
extern int __ptrace_may_attach(struct task_struct *task); #define PTRACE_MODE_ATTACH 2
/* Returns 0 on success, -errno on denial. */
extern int __ptrace_may_access(struct task_struct *task, unsigned int mode);
/* Returns true on success, false on denial. */
extern bool ptrace_may_access(struct task_struct *task, unsigned int mode);
static inline int ptrace_reparented(struct task_struct *child) static inline int ptrace_reparented(struct task_struct *child)
{ {
......
...@@ -46,7 +46,8 @@ struct audit_krule; ...@@ -46,7 +46,8 @@ struct audit_krule;
*/ */
extern int cap_capable(struct task_struct *tsk, int cap); extern int cap_capable(struct task_struct *tsk, int cap);
extern int cap_settime(struct timespec *ts, struct timezone *tz); extern int cap_settime(struct timespec *ts, struct timezone *tz);
extern int cap_ptrace(struct task_struct *parent, struct task_struct *child); extern int cap_ptrace(struct task_struct *parent, struct task_struct *child,
unsigned int mode);
extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); extern int cap_capget(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
extern int cap_capset_check(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); extern int cap_capset_check(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
extern void cap_capset_set(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted); extern void cap_capset_set(struct task_struct *target, kernel_cap_t *effective, kernel_cap_t *inheritable, kernel_cap_t *permitted);
...@@ -79,6 +80,7 @@ struct xfrm_selector; ...@@ -79,6 +80,7 @@ struct xfrm_selector;
struct xfrm_policy; struct xfrm_policy;
struct xfrm_state; struct xfrm_state;
struct xfrm_user_sec_ctx; struct xfrm_user_sec_ctx;
struct seq_file;
extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb); extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
extern int cap_netlink_recv(struct sk_buff *skb, int cap); extern int cap_netlink_recv(struct sk_buff *skb, int cap);
...@@ -289,10 +291,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) ...@@ -289,10 +291,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
* Update module state after a successful pivot. * Update module state after a successful pivot.
* @old_path contains the path for the old root. * @old_path contains the path for the old root.
* @new_path contains the path for the new root. * @new_path contains the path for the new root.
* @sb_get_mnt_opts:
* Get the security relevant mount options used for a superblock
* @sb the superblock to get security mount options from
* @opts binary data structure containing all lsm mount data
* @sb_set_mnt_opts: * @sb_set_mnt_opts:
* Set the security relevant mount options used for a superblock * Set the security relevant mount options used for a superblock
* @sb the superblock to set security mount options for * @sb the superblock to set security mount options for
...@@ -1170,6 +1168,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) ...@@ -1170,6 +1168,7 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
* attributes would be changed by the execve. * attributes would be changed by the execve.
* @parent contains the task_struct structure for parent process. * @parent contains the task_struct structure for parent process.
* @child contains the task_struct structure for child process. * @child contains the task_struct structure for child process.
* @mode contains the PTRACE_MODE flags indicating the form of access.
* Return 0 if permission is granted. * Return 0 if permission is granted.
* @capget: * @capget:
* Get the @effective, @inheritable, and @permitted capability sets for * Get the @effective, @inheritable, and @permitted capability sets for
...@@ -1240,11 +1239,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) ...@@ -1240,11 +1239,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
* @pages contains the number of pages. * @pages contains the number of pages.
* Return 0 if permission is granted. * Return 0 if permission is granted.
* *
* @register_security:
* allow module stacking.
* @name contains the name of the security module being stacked.
* @ops contains a pointer to the struct security_operations of the module to stack.
*
* @secid_to_secctx: * @secid_to_secctx:
* Convert secid to security context. * Convert secid to security context.
* @secid contains the security ID. * @secid contains the security ID.
...@@ -1295,7 +1289,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts) ...@@ -1295,7 +1289,8 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
struct security_operations { struct security_operations {
char name[SECURITY_NAME_MAX + 1]; char name[SECURITY_NAME_MAX + 1];
int (*ptrace) (struct task_struct *parent, struct task_struct *child); int (*ptrace) (struct task_struct *parent, struct task_struct *child,
unsigned int mode);
int (*capget) (struct task_struct *target, int (*capget) (struct task_struct *target,
kernel_cap_t *effective, kernel_cap_t *effective,
kernel_cap_t *inheritable, kernel_cap_t *permitted); kernel_cap_t *inheritable, kernel_cap_t *permitted);
...@@ -1328,6 +1323,7 @@ struct security_operations { ...@@ -1328,6 +1323,7 @@ struct security_operations {
void (*sb_free_security) (struct super_block *sb); void (*sb_free_security) (struct super_block *sb);
int (*sb_copy_data) (char *orig, char *copy); int (*sb_copy_data) (char *orig, char *copy);
int (*sb_kern_mount) (struct super_block *sb, void *data); int (*sb_kern_mount) (struct super_block *sb, void *data);
int (*sb_show_options) (struct seq_file *m, struct super_block *sb);
int (*sb_statfs) (struct dentry *dentry); int (*sb_statfs) (struct dentry *dentry);
int (*sb_mount) (char *dev_name, struct path *path, int (*sb_mount) (char *dev_name, struct path *path,
char *type, unsigned long flags, void *data); char *type, unsigned long flags, void *data);
...@@ -1343,8 +1339,6 @@ struct security_operations { ...@@ -1343,8 +1339,6 @@ struct security_operations {
struct path *new_path); struct path *new_path);
void (*sb_post_pivotroot) (struct path *old_path, void (*sb_post_pivotroot) (struct path *old_path,
struct path *new_path); struct path *new_path);
int (*sb_get_mnt_opts) (const struct super_block *sb,
struct security_mnt_opts *opts);
int (*sb_set_mnt_opts) (struct super_block *sb, int (*sb_set_mnt_opts) (struct super_block *sb,
struct security_mnt_opts *opts); struct security_mnt_opts *opts);
void (*sb_clone_mnt_opts) (const struct super_block *oldsb, void (*sb_clone_mnt_opts) (const struct super_block *oldsb,
...@@ -1472,10 +1466,6 @@ struct security_operations { ...@@ -1472,10 +1466,6 @@ struct security_operations {
int (*netlink_send) (struct sock *sk, struct sk_buff *skb); int (*netlink_send) (struct sock *sk, struct sk_buff *skb);
int (*netlink_recv) (struct sk_buff *skb, int cap); int (*netlink_recv) (struct sk_buff *skb, int cap);
/* allow module stacking */
int (*register_security) (const char *name,
struct security_operations *ops);
void (*d_instantiate) (struct dentry *dentry, struct inode *inode); void (*d_instantiate) (struct dentry *dentry, struct inode *inode);
int (*getprocattr) (struct task_struct *p, char *name, char **value); int (*getprocattr) (struct task_struct *p, char *name, char **value);
...@@ -1565,7 +1555,6 @@ struct security_operations { ...@@ -1565,7 +1555,6 @@ struct security_operations {
extern int security_init(void); extern int security_init(void);
extern int security_module_enable(struct security_operations *ops); extern int security_module_enable(struct security_operations *ops);
extern int register_security(struct security_operations *ops); extern int register_security(struct security_operations *ops);
extern int mod_reg_security(const char *name, struct security_operations *ops);
extern struct dentry *securityfs_create_file(const char *name, mode_t mode, extern struct dentry *securityfs_create_file(const char *name, mode_t mode,
struct dentry *parent, void *data, struct dentry *parent, void *data,
const struct file_operations *fops); const struct file_operations *fops);
...@@ -1573,7 +1562,8 @@ extern struct dentry *securityfs_create_dir(const char *name, struct dentry *par ...@@ -1573,7 +1562,8 @@ extern struct dentry *securityfs_create_dir(const char *name, struct dentry *par
extern void securityfs_remove(struct dentry *dentry); extern void securityfs_remove(struct dentry *dentry);
/* Security operations */ /* Security operations */
int security_ptrace(struct task_struct *parent, struct task_struct *child); int security_ptrace(struct task_struct *parent, struct task_struct *child,
unsigned int mode);
int security_capget(struct task_struct *target, int security_capget(struct task_struct *target,
kernel_cap_t *effective, kernel_cap_t *effective,
kernel_cap_t *inheritable, kernel_cap_t *inheritable,
...@@ -1606,6 +1596,7 @@ int security_sb_alloc(struct super_block *sb); ...@@ -1606,6 +1596,7 @@ int security_sb_alloc(struct super_block *sb);
void security_sb_free(struct super_block *sb); void security_sb_free(struct super_block *sb);
int security_sb_copy_data(char *orig, char *copy); int security_sb_copy_data(char *orig, char *copy);
int security_sb_kern_mount(struct super_block *sb, void *data); int security_sb_kern_mount(struct super_block *sb, void *data);
int security_sb_show_options(struct seq_file *m, struct super_block *sb);
int security_sb_statfs(struct dentry *dentry); int security_sb_statfs(struct dentry *dentry);
int security_sb_mount(char *dev_name, struct path *path, int security_sb_mount(char *dev_name, struct path *path,
char *type, unsigned long flags, void *data); char *type, unsigned long flags, void *data);
...@@ -1617,8 +1608,6 @@ void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *d ...@@ -1617,8 +1608,6 @@ void security_sb_post_remount(struct vfsmount *mnt, unsigned long flags, void *d
void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint); void security_sb_post_addmount(struct vfsmount *mnt, struct path *mountpoint);
int security_sb_pivotroot(struct path *old_path, struct path *new_path); int security_sb_pivotroot(struct path *old_path, struct path *new_path);
void security_sb_post_pivotroot(struct path *old_path, struct path *new_path); void security_sb_post_pivotroot(struct path *old_path, struct path *new_path);
int security_sb_get_mnt_opts(const struct super_block *sb,
struct security_mnt_opts *opts);
int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts); int security_sb_set_mnt_opts(struct super_block *sb, struct security_mnt_opts *opts);
void security_sb_clone_mnt_opts(const struct super_block *oldsb, void security_sb_clone_mnt_opts(const struct super_block *oldsb,
struct super_block *newsb); struct super_block *newsb);
...@@ -1755,9 +1744,11 @@ static inline int security_init(void) ...@@ -1755,9 +1744,11 @@ static inline int security_init(void)
return 0; return 0;
} }
static inline int security_ptrace(struct task_struct *parent, struct task_struct *child) static inline int security_ptrace(struct task_struct *parent,
struct task_struct *child,
unsigned int mode)
{ {
return cap_ptrace(parent, child); return cap_ptrace(parent, child, mode);
} }
static inline int security_capget(struct task_struct *target, static inline int security_capget(struct task_struct *target,
...@@ -1881,6 +1872,12 @@ static inline int security_sb_kern_mount(struct super_block *sb, void *data) ...@@ -1881,6 +1872,12 @@ static inline int security_sb_kern_mount(struct super_block *sb, void *data)
return 0; return 0;
} }
static inline int security_sb_show_options(struct seq_file *m,
struct super_block *sb)
{
return 0;
}
static inline int security_sb_statfs(struct dentry *dentry) static inline int security_sb_statfs(struct dentry *dentry)
{ {
return 0; return 0;
...@@ -1927,12 +1924,6 @@ static inline int security_sb_pivotroot(struct path *old_path, ...@@ -1927,12 +1924,6 @@ static inline int security_sb_pivotroot(struct path *old_path,
static inline void security_sb_post_pivotroot(struct path *old_path, static inline void security_sb_post_pivotroot(struct path *old_path,
struct path *new_path) struct path *new_path)
{ } { }
static inline int security_sb_get_mnt_opts(const struct super_block *sb,
struct security_mnt_opts *opts)
{
security_init_mnt_opts(opts);
return 0;
}
static inline int security_sb_set_mnt_opts(struct super_block *sb, static inline int security_sb_set_mnt_opts(struct super_block *sb,
struct security_mnt_opts *opts) struct security_mnt_opts *opts)
......
...@@ -121,7 +121,7 @@ int ptrace_check_attach(struct task_struct *child, int kill) ...@@ -121,7 +121,7 @@ int ptrace_check_attach(struct task_struct *child, int kill)
return ret; return ret;
} }
int __ptrace_may_attach(struct task_struct *task) int __ptrace_may_access(struct task_struct *task, unsigned int mode)
{ {
/* May we inspect the given task? /* May we inspect the given task?
* This check is used both for attaching with ptrace * This check is used both for attaching with ptrace
...@@ -148,16 +148,16 @@ int __ptrace_may_attach(struct task_struct *task) ...@@ -148,16 +148,16 @@ int __ptrace_may_attach(struct task_struct *task)
if (!dumpable && !capable(CAP_SYS_PTRACE)) if (!dumpable && !capable(CAP_SYS_PTRACE))
return -EPERM; return -EPERM;
return security_ptrace(current, task); return security_ptrace(current, task, mode);
} }
int ptrace_may_attach(struct task_struct *task) bool ptrace_may_access(struct task_struct *task, unsigned int mode)
{ {
int err; int err;
task_lock(task); task_lock(task);
err = __ptrace_may_attach(task); err = __ptrace_may_access(task, mode);
task_unlock(task); task_unlock(task);
return !err; return (!err ? true : false);
} }
int ptrace_attach(struct task_struct *task) int ptrace_attach(struct task_struct *task)
...@@ -195,7 +195,7 @@ int ptrace_attach(struct task_struct *task) ...@@ -195,7 +195,7 @@ int ptrace_attach(struct task_struct *task)
/* the same process cannot be attached many times */ /* the same process cannot be attached many times */
if (task->ptrace & PT_PTRACED) if (task->ptrace & PT_PTRACED)
goto bad; goto bad;
retval = __ptrace_may_attach(task); retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH);
if (retval) if (retval)
goto bad; goto bad;
...@@ -494,7 +494,8 @@ int ptrace_traceme(void) ...@@ -494,7 +494,8 @@ int ptrace_traceme(void)
*/ */
task_lock(current); task_lock(current);
if (!(current->ptrace & PT_PTRACED)) { if (!(current->ptrace & PT_PTRACED)) {
ret = security_ptrace(current->parent, current); ret = security_ptrace(current->parent, current,
PTRACE_MODE_ATTACH);
/* /*
* Set the ptrace bit in the process ptrace flags. * Set the ptrace bit in the process ptrace flags.
*/ */
......
...@@ -73,17 +73,9 @@ config SECURITY_NETWORK_XFRM ...@@ -73,17 +73,9 @@ config SECURITY_NETWORK_XFRM
IPSec. IPSec.
If you are unsure how to answer this question, answer N. If you are unsure how to answer this question, answer N.
config SECURITY_CAPABILITIES
bool "Default Linux Capabilities"
depends on SECURITY
default y
help
This enables the "default" Linux capabilities functionality.
If you are unsure how to answer this question, answer Y.
config SECURITY_FILE_CAPABILITIES config SECURITY_FILE_CAPABILITIES
bool "File POSIX Capabilities (EXPERIMENTAL)" bool "File POSIX Capabilities (EXPERIMENTAL)"
depends on (SECURITY=n || SECURITY_CAPABILITIES!=n) && EXPERIMENTAL depends on EXPERIMENTAL
default n default n
help help
This enables filesystem capabilities, allowing you to give This enables filesystem capabilities, allowing you to give
......
...@@ -6,16 +6,13 @@ obj-$(CONFIG_KEYS) += keys/ ...@@ -6,16 +6,13 @@ obj-$(CONFIG_KEYS) += keys/
subdir-$(CONFIG_SECURITY_SELINUX) += selinux subdir-$(CONFIG_SECURITY_SELINUX) += selinux
subdir-$(CONFIG_SECURITY_SMACK) += smack subdir-$(CONFIG_SECURITY_SMACK) += smack
# if we don't select a security model, use the default capabilities # always enable default capabilities
ifneq ($(CONFIG_SECURITY),y)
obj-y += commoncap.o obj-y += commoncap.o
endif
# Object file lists # Object file lists
obj-$(CONFIG_SECURITY) += security.o dummy.o inode.o obj-$(CONFIG_SECURITY) += security.o capability.o inode.o
# Must precede capability.o in order to stack properly. # Must precede capability.o in order to stack properly.
obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o obj-$(CONFIG_SECURITY_SELINUX) += selinux/built-in.o
obj-$(CONFIG_SECURITY_SMACK) += commoncap.o smack/built-in.o obj-$(CONFIG_SECURITY_SMACK) += smack/built-in.o
obj-$(CONFIG_SECURITY_CAPABILITIES) += commoncap.o capability.o obj-$(CONFIG_SECURITY_ROOTPLUG) += root_plug.o
obj-$(CONFIG_SECURITY_ROOTPLUG) += commoncap.o root_plug.o
obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o
This diff is collapsed.
...@@ -63,7 +63,8 @@ int cap_settime(struct timespec *ts, struct timezone *tz) ...@@ -63,7 +63,8 @@ int cap_settime(struct timespec *ts, struct timezone *tz)
return 0; return 0;
} }
int cap_ptrace (struct task_struct *parent, struct task_struct *child) int cap_ptrace (struct task_struct *parent, struct task_struct *child,
unsigned int mode)
{ {
/* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */ /* Derived from arch/i386/kernel/ptrace.c:sys_ptrace. */
if (!cap_issubset(child->cap_permitted, parent->cap_permitted) && if (!cap_issubset(child->cap_permitted, parent->cap_permitted) &&
......
This diff is collapsed.
...@@ -28,9 +28,6 @@ ...@@ -28,9 +28,6 @@
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
/* flag to keep track of how we were registered */
static int secondary;
/* default is a generic type of usb to serial converter */ /* default is a generic type of usb to serial converter */
static int vendor_id = 0x0557; static int vendor_id = 0x0557;
static int product_id = 0x2008; static int product_id = 0x2008;
...@@ -97,14 +94,8 @@ static int __init rootplug_init (void) ...@@ -97,14 +94,8 @@ static int __init rootplug_init (void)
if (register_security (&rootplug_security_ops)) { if (register_security (&rootplug_security_ops)) {
printk (KERN_INFO printk (KERN_INFO
"Failure registering Root Plug module with the kernel\n"); "Failure registering Root Plug module with the kernel\n");
/* try registering with primary module */
if (mod_reg_security (MY_NAME, &rootplug_security_ops)) {
printk (KERN_INFO "Failure registering Root Plug "
" module with primary security module.\n");
return -EINVAL; return -EINVAL;
} }
secondary = 1;
}
printk (KERN_INFO "Root Plug module initialized, " printk (KERN_INFO "Root Plug module initialized, "
"vendor_id = %4.4x, product id = %4.4x\n", vendor_id, product_id); "vendor_id = %4.4x, product id = %4.4x\n", vendor_id, product_id);
return 0; return 0;
......
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
/* Boot-time LSM user choice */ /* Boot-time LSM user choice */
static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1]; static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1];
/* things that live in dummy.c */ /* things that live in capability.c */
extern struct security_operations dummy_security_ops; extern struct security_operations default_security_ops;
extern void security_fixup_ops(struct security_operations *ops); extern void security_fixup_ops(struct security_operations *ops);
struct security_operations *security_ops; /* Initialized to NULL */ struct security_operations *security_ops; /* Initialized to NULL */
...@@ -57,13 +57,8 @@ int __init security_init(void) ...@@ -57,13 +57,8 @@ int __init security_init(void)
{ {
printk(KERN_INFO "Security Framework initialized\n"); printk(KERN_INFO "Security Framework initialized\n");
if (verify(&dummy_security_ops)) { security_fixup_ops(&default_security_ops);
printk(KERN_ERR "%s could not verify " security_ops = &default_security_ops;
"dummy_security_ops structure.\n", __func__);
return -EIO;
}
security_ops = &dummy_security_ops;
do_security_initcalls(); do_security_initcalls();
return 0; return 0;
...@@ -122,7 +117,7 @@ int register_security(struct security_operations *ops) ...@@ -122,7 +117,7 @@ int register_security(struct security_operations *ops)
return -EINVAL; return -EINVAL;
} }
if (security_ops != &dummy_security_ops) if (security_ops != &default_security_ops)
return -EAGAIN; return -EAGAIN;
security_ops = ops; security_ops = ops;
...@@ -130,40 +125,12 @@ int register_security(struct security_operations *ops) ...@@ -130,40 +125,12 @@ int register_security(struct security_operations *ops)
return 0; return 0;
} }
/**
* mod_reg_security - allows security modules to be "stacked"
* @name: a pointer to a string with the name of the security_options to be registered
* @ops: a pointer to the struct security_options that is to be registered
*
* This function allows security modules to be stacked if the currently loaded
* security module allows this to happen. It passes the @name and @ops to the
* register_security function of the currently loaded security module.
*
* The return value depends on the currently loaded security module, with 0 as
* success.
*/
int mod_reg_security(const char *name, struct security_operations *ops)
{
if (verify(ops)) {
printk(KERN_INFO "%s could not verify "
"security operations.\n", __func__);
return -EINVAL;
}
if (ops == security_ops) {
printk(KERN_INFO "%s security operations "
"already registered.\n", __func__);
return -EINVAL;
}
return security_ops->register_security(name, ops);
}
/* Security operations */ /* Security operations */
int security_ptrace(struct task_struct *parent, struct task_struct *child) int security_ptrace(struct task_struct *parent, struct task_struct *child,
unsigned int mode)
{ {
return security_ops->ptrace(parent, child); return security_ops->ptrace(parent, child, mode);
} }
int security_capget(struct task_struct *target, int security_capget(struct task_struct *target,
...@@ -291,6 +258,11 @@ int security_sb_kern_mount(struct super_block *sb, void *data) ...@@ -291,6 +258,11 @@ int security_sb_kern_mount(struct super_block *sb, void *data)
return security_ops->sb_kern_mount(sb, data); return security_ops->sb_kern_mount(sb, data);
} }
int security_sb_show_options(struct seq_file *m, struct super_block *sb)
{
return security_ops->sb_show_options(m, sb);
}
int security_sb_statfs(struct dentry *dentry) int security_sb_statfs(struct dentry *dentry)
{ {
return security_ops->sb_statfs(dentry); return security_ops->sb_statfs(dentry);
...@@ -342,12 +314,6 @@ void security_sb_post_pivotroot(struct path *old_path, struct path *new_path) ...@@ -342,12 +314,6 @@ void security_sb_post_pivotroot(struct path *old_path, struct path *new_path)
security_ops->sb_post_pivotroot(old_path, new_path); security_ops->sb_post_pivotroot(old_path, new_path);
} }
int security_sb_get_mnt_opts(const struct super_block *sb,
struct security_mnt_opts *opts)
{
return security_ops->sb_get_mnt_opts(sb, opts);
}
int security_sb_set_mnt_opts(struct super_block *sb, int security_sb_set_mnt_opts(struct super_block *sb,
struct security_mnt_opts *opts) struct security_mnt_opts *opts)
{ {
...@@ -894,7 +860,7 @@ EXPORT_SYMBOL(security_secctx_to_secid); ...@@ -894,7 +860,7 @@ EXPORT_SYMBOL(security_secctx_to_secid);
void security_release_secctx(char *secdata, u32 seclen) void security_release_secctx(char *secdata, u32 seclen)
{ {
return security_ops->release_secctx(secdata, seclen); security_ops->release_secctx(secdata, seclen);
} }
EXPORT_SYMBOL(security_release_secctx); EXPORT_SYMBOL(security_release_secctx);
...@@ -1011,12 +977,12 @@ int security_sk_alloc(struct sock *sk, int family, gfp_t priority) ...@@ -1011,12 +977,12 @@ int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
void security_sk_free(struct sock *sk) void security_sk_free(struct sock *sk)
{ {
return security_ops->sk_free_security(sk); security_ops->sk_free_security(sk);
} }
void security_sk_clone(const struct sock *sk, struct sock *newsk) void security_sk_clone(const struct sock *sk, struct sock *newsk)
{ {
return security_ops->sk_clone_security(sk, newsk); security_ops->sk_clone_security(sk, newsk);
} }
void security_sk_classify_flow(struct sock *sk, struct flowi *fl) void security_sk_classify_flow(struct sock *sk, struct flowi *fl)
......
This diff is collapsed.
...@@ -80,8 +80,7 @@ struct avc_audit_data { ...@@ -80,8 +80,7 @@ struct avc_audit_data {
/* /*
* AVC statistics * AVC statistics
*/ */
struct avc_cache_stats struct avc_cache_stats {
{
unsigned int lookups; unsigned int lookups;
unsigned int hits; unsigned int hits;
unsigned int misses; unsigned int misses;
......
...@@ -44,7 +44,6 @@ struct inode_security_struct { ...@@ -44,7 +44,6 @@ struct inode_security_struct {
u16 sclass; /* security class of this object */ u16 sclass; /* security class of this object */
unsigned char initialized; /* initialization flag */ unsigned char initialized; /* initialization flag */
struct mutex lock; struct mutex lock;
unsigned char inherit; /* inherit SID from parent entry */
}; };
struct file_security_struct { struct file_security_struct {
......
...@@ -93,12 +93,17 @@ int security_change_sid(u32 ssid, u32 tsid, ...@@ -93,12 +93,17 @@ int security_change_sid(u32 ssid, u32 tsid,
int security_sid_to_context(u32 sid, char **scontext, int security_sid_to_context(u32 sid, char **scontext,
u32 *scontext_len); u32 *scontext_len);
int security_sid_to_context_force(u32 sid, char **scontext, u32 *scontext_len);
int security_context_to_sid(const char *scontext, u32 scontext_len, int security_context_to_sid(const char *scontext, u32 scontext_len,
u32 *out_sid); u32 *out_sid);
int security_context_to_sid_default(const char *scontext, u32 scontext_len, int security_context_to_sid_default(const char *scontext, u32 scontext_len,
u32 *out_sid, u32 def_sid, gfp_t gfp_flags); u32 *out_sid, u32 def_sid, gfp_t gfp_flags);
int security_context_to_sid_force(const char *scontext, u32 scontext_len,
u32 *sid);
int security_get_user_sids(u32 callsid, char *username, int security_get_user_sids(u32 callsid, char *username,
u32 **sids, u32 *nel); u32 **sids, u32 *nel);
...@@ -131,7 +136,7 @@ int security_get_allow_unknown(void); ...@@ -131,7 +136,7 @@ int security_get_allow_unknown(void);
#define SECURITY_FS_USE_MNTPOINT 6 /* use mountpoint labeling */ #define SECURITY_FS_USE_MNTPOINT 6 /* use mountpoint labeling */
int security_fs_use(const char *fstype, unsigned int *behavior, int security_fs_use(const char *fstype, unsigned int *behavior,
u32 *sid); u32 *sid, bool can_xattr);
int security_genfs_sid(const char *fstype, char *name, u16 sclass, int security_genfs_sid(const char *fstype, char *name, u16 sclass,
u32 *sid); u32 *sid);
......
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include <linux/ipv6.h> #include <linux/ipv6.h>
#include <net/ip.h> #include <net/ip.h>
#include <net/ipv6.h> #include <net/ipv6.h>
#include <asm/bug.h>
#include "netnode.h" #include "netnode.h"
#include "objsec.h" #include "objsec.h"
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <linux/ipv6.h> #include <linux/ipv6.h>
#include <net/ip.h> #include <net/ip.h>
#include <net/ipv6.h> #include <net/ipv6.h>
#include <asm/bug.h>
#include "netport.h" #include "netport.h"
#include "objsec.h" #include "objsec.h"
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/audit.h> #include <linux/audit.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
/* selinuxfs pseudo filesystem for exporting the security policy API. /* selinuxfs pseudo filesystem for exporting the security policy API.
Based on the proc code and the fs/nfsd/nfsctl.c code. */ Based on the proc code and the fs/nfsd/nfsctl.c code. */
...@@ -57,14 +57,18 @@ int selinux_compat_net = SELINUX_COMPAT_NET_VALUE; ...@@ -57,14 +57,18 @@ int selinux_compat_net = SELINUX_COMPAT_NET_VALUE;
static int __init checkreqprot_setup(char *str) static int __init checkreqprot_setup(char *str)
{ {
selinux_checkreqprot = simple_strtoul(str, NULL, 0) ? 1 : 0; unsigned long checkreqprot;
if (!strict_strtoul(str, 0, &checkreqprot))
selinux_checkreqprot = checkreqprot ? 1 : 0;
return 1; return 1;
} }
__setup("checkreqprot=", checkreqprot_setup); __setup("checkreqprot=", checkreqprot_setup);
static int __init selinux_compat_net_setup(char *str) static int __init selinux_compat_net_setup(char *str)
{ {
selinux_compat_net = simple_strtoul(str, NULL, 0) ? 1 : 0; unsigned long compat_net;
if (!strict_strtoul(str, 0, &compat_net))
selinux_compat_net = compat_net ? 1 : 0;
return 1; return 1;
} }
__setup("selinux_compat_net=", selinux_compat_net_setup); __setup("selinux_compat_net=", selinux_compat_net_setup);
...@@ -352,11 +356,6 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf, ...@@ -352,11 +356,6 @@ static ssize_t sel_write_load(struct file *file, const char __user *buf,
length = count; length = count;
out1: out1:
printk(KERN_INFO "SELinux: policy loaded with handle_unknown=%s\n",
(security_get_reject_unknown() ? "reject" :
(security_get_allow_unknown() ? "allow" : "deny")));
audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_POLICY_LOAD, audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
"policy loaded auid=%u ses=%u", "policy loaded auid=%u ses=%u",
audit_get_loginuid(current), audit_get_loginuid(current),
......
...@@ -311,7 +311,7 @@ void avtab_hash_eval(struct avtab *h, char *tag) ...@@ -311,7 +311,7 @@ void avtab_hash_eval(struct avtab *h, char *tag)
} }
printk(KERN_DEBUG "SELinux: %s: %d entries and %d/%d buckets used, " printk(KERN_DEBUG "SELinux: %s: %d entries and %d/%d buckets used, "
"longest chain length %d sum of chain length^2 %Lu\n", "longest chain length %d sum of chain length^2 %llu\n",
tag, h->nel, slots_used, h->nslot, max_chain_len, tag, h->nel, slots_used, h->nslot, max_chain_len,
chain2_len_sum); chain2_len_sum);
} }
......
...@@ -28,6 +28,8 @@ struct context { ...@@ -28,6 +28,8 @@ struct context {
u32 role; u32 role;
u32 type; u32 type;
struct mls_range range; struct mls_range range;
char *str; /* string representation if context cannot be mapped. */
u32 len; /* length of string in bytes */
}; };
static inline void mls_context_init(struct context *c) static inline void mls_context_init(struct context *c)
...@@ -106,20 +108,43 @@ static inline void context_init(struct context *c) ...@@ -106,20 +108,43 @@ static inline void context_init(struct context *c)
static inline int context_cpy(struct context *dst, struct context *src) static inline int context_cpy(struct context *dst, struct context *src)
{ {
int rc;
dst->user = src->user; dst->user = src->user;
dst->role = src->role; dst->role = src->role;
dst->type = src->type; dst->type = src->type;
return mls_context_cpy(dst, src); if (src->str) {
dst->str = kstrdup(src->str, GFP_ATOMIC);
if (!dst->str)
return -ENOMEM;
dst->len = src->len;
} else {
dst->str = NULL;
dst->len = 0;
}
rc = mls_context_cpy(dst, src);
if (rc) {
kfree(dst->str);
return rc;
}
return 0;
} }
static inline void context_destroy(struct context *c) static inline void context_destroy(struct context *c)
{ {
c->user = c->role = c->type = 0; c->user = c->role = c->type = 0;
kfree(c->str);
c->str = NULL;
c->len = 0;
mls_context_destroy(c); mls_context_destroy(c);
} }
static inline int context_cmp(struct context *c1, struct context *c2) static inline int context_cmp(struct context *c1, struct context *c2)
{ {
if (c1->len && c2->len)
return (c1->len == c2->len && !strcmp(c1->str, c2->str));
if (c1->len || c2->len)
return 0;
return ((c1->user == c2->user) && return ((c1->user == c2->user) &&
(c1->role == c2->role) && (c1->role == c2->role) &&
(c1->type == c2->type) && (c1->type == c2->type) &&
......
...@@ -239,7 +239,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c) ...@@ -239,7 +239,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c)
* Policy read-lock must be held for sidtab lookup. * Policy read-lock must be held for sidtab lookup.
* *
*/ */
int mls_context_to_sid(char oldc, int mls_context_to_sid(struct policydb *pol,
char oldc,
char **scontext, char **scontext,
struct context *context, struct context *context,
struct sidtab *s, struct sidtab *s,
...@@ -286,7 +287,7 @@ int mls_context_to_sid(char oldc, ...@@ -286,7 +287,7 @@ int mls_context_to_sid(char oldc,
*p++ = 0; *p++ = 0;
for (l = 0; l < 2; l++) { for (l = 0; l < 2; l++) {
levdatum = hashtab_search(policydb.p_levels.table, scontextp); levdatum = hashtab_search(pol->p_levels.table, scontextp);
if (!levdatum) { if (!levdatum) {
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
...@@ -311,7 +312,7 @@ int mls_context_to_sid(char oldc, ...@@ -311,7 +312,7 @@ int mls_context_to_sid(char oldc,
*rngptr++ = 0; *rngptr++ = 0;
} }
catdatum = hashtab_search(policydb.p_cats.table, catdatum = hashtab_search(pol->p_cats.table,
scontextp); scontextp);
if (!catdatum) { if (!catdatum) {
rc = -EINVAL; rc = -EINVAL;
...@@ -327,7 +328,7 @@ int mls_context_to_sid(char oldc, ...@@ -327,7 +328,7 @@ int mls_context_to_sid(char oldc,
if (rngptr) { if (rngptr) {
int i; int i;
rngdatum = hashtab_search(policydb.p_cats.table, rngptr); rngdatum = hashtab_search(pol->p_cats.table, rngptr);
if (!rngdatum) { if (!rngdatum) {
rc = -EINVAL; rc = -EINVAL;
goto out; goto out;
...@@ -395,7 +396,7 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask) ...@@ -395,7 +396,7 @@ int mls_from_string(char *str, struct context *context, gfp_t gfp_mask)
if (!tmpstr) { if (!tmpstr) {
rc = -ENOMEM; rc = -ENOMEM;
} else { } else {
rc = mls_context_to_sid(':', &tmpstr, context, rc = mls_context_to_sid(&policydb, ':', &tmpstr, context,
NULL, SECSID_NULL); NULL, SECSID_NULL);
kfree(freestr); kfree(freestr);
} }
...@@ -436,13 +437,13 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user, ...@@ -436,13 +437,13 @@ int mls_setup_user_range(struct context *fromcon, struct user_datum *user,
struct mls_level *usercon_clr = &(usercon->range.level[1]); struct mls_level *usercon_clr = &(usercon->range.level[1]);
/* Honor the user's default level if we can */ /* Honor the user's default level if we can */
if (mls_level_between(user_def, fromcon_sen, fromcon_clr)) { if (mls_level_between(user_def, fromcon_sen, fromcon_clr))
*usercon_sen = *user_def; *usercon_sen = *user_def;
} else if (mls_level_between(fromcon_sen, user_def, user_clr)) { else if (mls_level_between(fromcon_sen, user_def, user_clr))
*usercon_sen = *fromcon_sen; *usercon_sen = *fromcon_sen;
} else if (mls_level_between(fromcon_clr, user_low, user_def)) { else if (mls_level_between(fromcon_clr, user_low, user_def))
*usercon_sen = *user_low; *usercon_sen = *user_low;
} else else
return -EINVAL; return -EINVAL;
/* Lower the clearance of available contexts /* Lower the clearance of available contexts
......
...@@ -30,7 +30,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c); ...@@ -30,7 +30,8 @@ int mls_context_isvalid(struct policydb *p, struct context *c);
int mls_range_isvalid(struct policydb *p, struct mls_range *r); int mls_range_isvalid(struct policydb *p, struct mls_range *r);
int mls_level_isvalid(struct policydb *p, struct mls_level *l); int mls_level_isvalid(struct policydb *p, struct mls_level *l);
int mls_context_to_sid(char oldc, int mls_context_to_sid(struct policydb *p,
char oldc,
char **scontext, char **scontext,
struct context *context, struct context *context,
struct sidtab *s, struct sidtab *s,
......
...@@ -1478,7 +1478,8 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1478,7 +1478,8 @@ int policydb_read(struct policydb *p, void *fp)
struct ocontext *l, *c, *newc; struct ocontext *l, *c, *newc;
struct genfs *genfs_p, *genfs, *newgenfs; struct genfs *genfs_p, *genfs, *newgenfs;
int i, j, rc; int i, j, rc;
__le32 buf[8]; __le32 buf[4];
u32 nodebuf[8];
u32 len, len2, config, nprim, nel, nel2; u32 len, len2, config, nprim, nel, nel2;
char *policydb_str; char *policydb_str;
struct policydb_compat_info *info; struct policydb_compat_info *info;
...@@ -1749,11 +1750,11 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1749,11 +1750,11 @@ int policydb_read(struct policydb *p, void *fp)
goto bad; goto bad;
break; break;
case OCON_NODE: case OCON_NODE:
rc = next_entry(buf, fp, sizeof(u32) * 2); rc = next_entry(nodebuf, fp, sizeof(u32) * 2);
if (rc < 0) if (rc < 0)
goto bad; goto bad;
c->u.node.addr = le32_to_cpu(buf[0]); c->u.node.addr = nodebuf[0]; /* network order */
c->u.node.mask = le32_to_cpu(buf[1]); c->u.node.mask = nodebuf[1]; /* network order */
rc = context_read_and_validate(&c->context[0], p, fp); rc = context_read_and_validate(&c->context[0], p, fp);
if (rc) if (rc)
goto bad; goto bad;
...@@ -1782,13 +1783,13 @@ int policydb_read(struct policydb *p, void *fp) ...@@ -1782,13 +1783,13 @@ int policydb_read(struct policydb *p, void *fp)
case OCON_NODE6: { case OCON_NODE6: {
int k; int k;
rc = next_entry(buf, fp, sizeof(u32) * 8); rc = next_entry(nodebuf, fp, sizeof(u32) * 8);
if (rc < 0) if (rc < 0)
goto bad; goto bad;
for (k = 0; k < 4; k++) for (k = 0; k < 4; k++)
c->u.node6.addr[k] = le32_to_cpu(buf[k]); c->u.node6.addr[k] = nodebuf[k];
for (k = 0; k < 4; k++) for (k = 0; k < 4; k++)
c->u.node6.mask[k] = le32_to_cpu(buf[k+4]); c->u.node6.mask[k] = nodebuf[k+4];
if (context_read_and_validate(&c->context[0], p, fp)) if (context_read_and_validate(&c->context[0], p, fp))
goto bad; goto bad;
break; break;
......
This diff is collapsed.
...@@ -14,10 +14,6 @@ ...@@ -14,10 +14,6 @@
#define SIDTAB_HASH(sid) \ #define SIDTAB_HASH(sid) \
(sid & SIDTAB_HASH_MASK) (sid & SIDTAB_HASH_MASK)
#define INIT_SIDTAB_LOCK(s) spin_lock_init(&s->lock)
#define SIDTAB_LOCK(s, x) spin_lock_irqsave(&s->lock, x)
#define SIDTAB_UNLOCK(s, x) spin_unlock_irqrestore(&s->lock, x)
int sidtab_init(struct sidtab *s) int sidtab_init(struct sidtab *s)
{ {
int i; int i;
...@@ -30,7 +26,7 @@ int sidtab_init(struct sidtab *s) ...@@ -30,7 +26,7 @@ int sidtab_init(struct sidtab *s)
s->nel = 0; s->nel = 0;
s->next_sid = 1; s->next_sid = 1;
s->shutdown = 0; s->shutdown = 0;
INIT_SIDTAB_LOCK(s); spin_lock_init(&s->lock);
return 0; return 0;
} }
...@@ -86,7 +82,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context) ...@@ -86,7 +82,7 @@ int sidtab_insert(struct sidtab *s, u32 sid, struct context *context)
return rc; return rc;
} }
struct context *sidtab_search(struct sidtab *s, u32 sid) static struct context *sidtab_search_core(struct sidtab *s, u32 sid, int force)
{ {
int hvalue; int hvalue;
struct sidtab_node *cur; struct sidtab_node *cur;
...@@ -99,7 +95,10 @@ struct context *sidtab_search(struct sidtab *s, u32 sid) ...@@ -99,7 +95,10 @@ struct context *sidtab_search(struct sidtab *s, u32 sid)
while (cur != NULL && sid > cur->sid) while (cur != NULL && sid > cur->sid)
cur = cur->next; cur = cur->next;
if (cur == NULL || sid != cur->sid) { if (force && cur && sid == cur->sid && cur->context.len)
return &cur->context;
if (cur == NULL || sid != cur->sid || cur->context.len) {
/* Remap invalid SIDs to the unlabeled SID. */ /* Remap invalid SIDs to the unlabeled SID. */
sid = SECINITSID_UNLABELED; sid = SECINITSID_UNLABELED;
hvalue = SIDTAB_HASH(sid); hvalue = SIDTAB_HASH(sid);
...@@ -113,6 +112,16 @@ struct context *sidtab_search(struct sidtab *s, u32 sid) ...@@ -113,6 +112,16 @@ struct context *sidtab_search(struct sidtab *s, u32 sid)
return &cur->context; return &cur->context;
} }
struct context *sidtab_search(struct sidtab *s, u32 sid)
{
return sidtab_search_core(s, sid, 0);
}
struct context *sidtab_search_force(struct sidtab *s, u32 sid)
{
return sidtab_search_core(s, sid, 1);
}
int sidtab_map(struct sidtab *s, int sidtab_map(struct sidtab *s,
int (*apply) (u32 sid, int (*apply) (u32 sid,
struct context *context, struct context *context,
...@@ -138,43 +147,6 @@ int sidtab_map(struct sidtab *s, ...@@ -138,43 +147,6 @@ int sidtab_map(struct sidtab *s,
return rc; return rc;
} }
void sidtab_map_remove_on_error(struct sidtab *s,
int (*apply) (u32 sid,
struct context *context,
void *args),
void *args)
{
int i, ret;
struct sidtab_node *last, *cur, *temp;
if (!s)
return;
for (i = 0; i < SIDTAB_SIZE; i++) {
last = NULL;
cur = s->htable[i];
while (cur != NULL) {
ret = apply(cur->sid, &cur->context, args);
if (ret) {
if (last)
last->next = cur->next;
else
s->htable[i] = cur->next;
temp = cur;
cur = cur->next;
context_destroy(&temp->context);
kfree(temp);
s->nel--;
} else {
last = cur;
cur = cur->next;
}
}
}
return;
}
static inline u32 sidtab_search_context(struct sidtab *s, static inline u32 sidtab_search_context(struct sidtab *s,
struct context *context) struct context *context)
{ {
...@@ -204,7 +176,7 @@ int sidtab_context_to_sid(struct sidtab *s, ...@@ -204,7 +176,7 @@ int sidtab_context_to_sid(struct sidtab *s,
sid = sidtab_search_context(s, context); sid = sidtab_search_context(s, context);
if (!sid) { if (!sid) {
SIDTAB_LOCK(s, flags); spin_lock_irqsave(&s->lock, flags);
/* Rescan now that we hold the lock. */ /* Rescan now that we hold the lock. */
sid = sidtab_search_context(s, context); sid = sidtab_search_context(s, context);
if (sid) if (sid)
...@@ -215,11 +187,15 @@ int sidtab_context_to_sid(struct sidtab *s, ...@@ -215,11 +187,15 @@ int sidtab_context_to_sid(struct sidtab *s,
goto unlock_out; goto unlock_out;
} }
sid = s->next_sid++; sid = s->next_sid++;
if (context->len)
printk(KERN_INFO
"SELinux: Context %s is not valid (left unmapped).\n",
context->str);
ret = sidtab_insert(s, sid, context); ret = sidtab_insert(s, sid, context);
if (ret) if (ret)
s->next_sid--; s->next_sid--;
unlock_out: unlock_out:
SIDTAB_UNLOCK(s, flags); spin_unlock_irqrestore(&s->lock, flags);
} }
if (ret) if (ret)
...@@ -284,19 +260,19 @@ void sidtab_set(struct sidtab *dst, struct sidtab *src) ...@@ -284,19 +260,19 @@ void sidtab_set(struct sidtab *dst, struct sidtab *src)
{ {
unsigned long flags; unsigned long flags;
SIDTAB_LOCK(src, flags); spin_lock_irqsave(&src->lock, flags);
dst->htable = src->htable; dst->htable = src->htable;
dst->nel = src->nel; dst->nel = src->nel;
dst->next_sid = src->next_sid; dst->next_sid = src->next_sid;
dst->shutdown = 0; dst->shutdown = 0;
SIDTAB_UNLOCK(src, flags); spin_unlock_irqrestore(&src->lock, flags);
} }
void sidtab_shutdown(struct sidtab *s) void sidtab_shutdown(struct sidtab *s)
{ {
unsigned long flags; unsigned long flags;
SIDTAB_LOCK(s, flags); spin_lock_irqsave(&s->lock, flags);
s->shutdown = 1; s->shutdown = 1;
SIDTAB_UNLOCK(s, flags); spin_unlock_irqrestore(&s->lock, flags);
} }
...@@ -32,6 +32,7 @@ struct sidtab { ...@@ -32,6 +32,7 @@ struct sidtab {
int sidtab_init(struct sidtab *s); int sidtab_init(struct sidtab *s);
int sidtab_insert(struct sidtab *s, u32 sid, struct context *context); int sidtab_insert(struct sidtab *s, u32 sid, struct context *context);
struct context *sidtab_search(struct sidtab *s, u32 sid); struct context *sidtab_search(struct sidtab *s, u32 sid);
struct context *sidtab_search_force(struct sidtab *s, u32 sid);
int sidtab_map(struct sidtab *s, int sidtab_map(struct sidtab *s,
int (*apply) (u32 sid, int (*apply) (u32 sid,
...@@ -39,12 +40,6 @@ int sidtab_map(struct sidtab *s, ...@@ -39,12 +40,6 @@ int sidtab_map(struct sidtab *s,
void *args), void *args),
void *args); void *args);
void sidtab_map_remove_on_error(struct sidtab *s,
int (*apply) (u32 sid,
struct context *context,
void *args),
void *args);
int sidtab_context_to_sid(struct sidtab *s, int sidtab_context_to_sid(struct sidtab *s,
struct context *context, struct context *context,
u32 *sid); u32 *sid);
......
...@@ -95,11 +95,12 @@ struct inode_smack *new_inode_smack(char *smack) ...@@ -95,11 +95,12 @@ struct inode_smack *new_inode_smack(char *smack)
* *
* Do the capability checks, and require read and write. * Do the capability checks, and require read and write.
*/ */
static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp) static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp,
unsigned int mode)
{ {
int rc; int rc;
rc = cap_ptrace(ptp, ctp); rc = cap_ptrace(ptp, ctp, mode);
if (rc != 0) if (rc != 0)
return rc; return rc;
...@@ -1821,27 +1822,6 @@ static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid) ...@@ -1821,27 +1822,6 @@ static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
*secid = smack_to_secid(smack); *secid = smack_to_secid(smack);
} }
/* module stacking operations */
/**
* smack_register_security - stack capability module
* @name: module name
* @ops: module operations - ignored
*
* Allow the capability module to register.
*/
static int smack_register_security(const char *name,
struct security_operations *ops)
{
if (strcmp(name, "capability") != 0)
return -EINVAL;
printk(KERN_INFO "%s: Registering secondary module %s\n",
__func__, name);
return 0;
}
/** /**
* smack_d_instantiate - Make sure the blob is correct on an inode * smack_d_instantiate - Make sure the blob is correct on an inode
* @opt_dentry: unused * @opt_dentry: unused
...@@ -2672,8 +2652,6 @@ struct security_operations smack_ops = { ...@@ -2672,8 +2652,6 @@ struct security_operations smack_ops = {
.netlink_send = cap_netlink_send, .netlink_send = cap_netlink_send,
.netlink_recv = cap_netlink_recv, .netlink_recv = cap_netlink_recv,
.register_security = smack_register_security,
.d_instantiate = smack_d_instantiate, .d_instantiate = smack_d_instantiate,
.getprocattr = smack_getprocattr, .getprocattr = smack_getprocattr,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment