Commit bee902e3 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge bk://lsm.bkbits.net/linus-2.5

into kernel.bkbits.net:/home/gregkh/linux/lsm-2.5
parents 5ad0c942 aa91db06
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/mount.h> #include <linux/mount.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/security.h>
#define DCACHE_PARANOIA 1 #define DCACHE_PARANOIA 1
/* #define DCACHE_DEBUG 1 */ /* #define DCACHE_DEBUG 1 */
...@@ -699,6 +700,7 @@ struct dentry * d_alloc(struct dentry * parent, const struct qstr *name) ...@@ -699,6 +700,7 @@ struct dentry * d_alloc(struct dentry * parent, const struct qstr *name)
void d_instantiate(struct dentry *entry, struct inode * inode) void d_instantiate(struct dentry *entry, struct inode * inode)
{ {
if (!list_empty(&entry->d_alias)) BUG(); if (!list_empty(&entry->d_alias)) BUG();
security_d_instantiate(entry, inode);
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
if (inode) if (inode)
list_add(&entry->d_alias, &inode->i_dentry); list_add(&entry->d_alias, &inode->i_dentry);
...@@ -825,6 +827,7 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry) ...@@ -825,6 +827,7 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
struct dentry *new = NULL; struct dentry *new = NULL;
if (inode && S_ISDIR(inode->i_mode)) { if (inode && S_ISDIR(inode->i_mode)) {
security_d_instantiate(dentry, inode);
spin_lock(&dcache_lock); spin_lock(&dcache_lock);
if (!list_empty(&inode->i_dentry)) { if (!list_empty(&inode->i_dentry)) {
new = list_entry(inode->i_dentry.next, struct dentry, d_alias); new = list_entry(inode->i_dentry.next, struct dentry, d_alias);
......
...@@ -353,7 +353,7 @@ static int get_name(struct dentry *dentry, char *name, ...@@ -353,7 +353,7 @@ static int get_name(struct dentry *dentry, char *name,
/* /*
* Open the directory ... * Open the directory ...
*/ */
error = init_private_file(&file, dentry, FMODE_READ); error = open_private_file(&file, dentry, O_RDONLY);
if (error) if (error)
goto out; goto out;
error = -EINVAL; error = -EINVAL;
...@@ -381,8 +381,7 @@ static int get_name(struct dentry *dentry, char *name, ...@@ -381,8 +381,7 @@ static int get_name(struct dentry *dentry, char *name,
} }
out_close: out_close:
if (file.f_op->release) close_private_file(&file);
file.f_op->release(dir, &file);
out: out:
return error; return error;
} }
......
...@@ -93,23 +93,42 @@ struct file * get_empty_filp(void) ...@@ -93,23 +93,42 @@ struct file * get_empty_filp(void)
/* /*
* Clear and initialize a (private) struct file for the given dentry, * Clear and initialize a (private) struct file for the given dentry,
* and call the open function (if any). The caller must verify that * allocate the security structure, and call the open function (if any).
* inode->i_fop is not NULL. * The file should be released using close_private_file.
*/ */
int init_private_file(struct file *filp, struct dentry *dentry, int mode) int open_private_file(struct file *filp, struct dentry *dentry, int flags)
{ {
int error;
memset(filp, 0, sizeof(*filp)); memset(filp, 0, sizeof(*filp));
eventpoll_init_file(filp); eventpoll_init_file(filp);
filp->f_mode = mode; filp->f_flags = flags;
filp->f_mode = (flags+1) & O_ACCMODE;
atomic_set(&filp->f_count, 1); atomic_set(&filp->f_count, 1);
filp->f_dentry = dentry; filp->f_dentry = dentry;
filp->f_uid = current->fsuid; filp->f_uid = current->fsuid;
filp->f_gid = current->fsgid; filp->f_gid = current->fsgid;
filp->f_op = dentry->d_inode->i_fop; filp->f_op = dentry->d_inode->i_fop;
if (filp->f_op->open) error = security_file_alloc(filp);
return filp->f_op->open(dentry->d_inode, filp); if (!error)
else if (filp->f_op && filp->f_op->open) {
return 0; error = filp->f_op->open(dentry->d_inode, filp);
if (error)
security_file_free(filp);
}
return error;
}
/*
* Release a private file by calling the release function (if any) and
* freeing the security structure.
*/
void close_private_file(struct file *file)
{
struct inode * inode = file->f_dentry->d_inode;
if (file->f_op && file->f_op->release)
file->f_op->release(inode, file);
security_file_free(file);
} }
void fput(struct file * file) void fput(struct file * file)
......
...@@ -372,10 +372,8 @@ static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, i ...@@ -372,10 +372,8 @@ static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, i
result = dir->i_op->lookup(dir, dentry); result = dir->i_op->lookup(dir, dentry);
if (result) if (result)
dput(dentry); dput(dentry);
else { else
result = dentry; result = dentry;
security_inode_post_lookup(dir, result);
}
} }
up(&dir->i_sem); up(&dir->i_sem);
return result; return result;
...@@ -916,10 +914,9 @@ struct dentry * lookup_hash(struct qstr *name, struct dentry * base) ...@@ -916,10 +914,9 @@ struct dentry * lookup_hash(struct qstr *name, struct dentry * base)
if (!new) if (!new)
goto out; goto out;
dentry = inode->i_op->lookup(inode, new); dentry = inode->i_op->lookup(inode, new);
if (!dentry) { if (!dentry)
dentry = new; dentry = new;
security_inode_post_lookup(inode, dentry); else
} else
dput(new); dput(new);
} }
out: out:
......
...@@ -426,7 +426,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, ...@@ -426,7 +426,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
int flags = O_RDONLY|O_LARGEFILE, mode = FMODE_READ, err; int flags = O_RDONLY|O_LARGEFILE, err;
/* /*
* If we get here, then the client has already done an "open", * If we get here, then the client has already done an "open",
...@@ -463,14 +463,12 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, ...@@ -463,14 +463,12 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
goto out_nfserr; goto out_nfserr;
flags = O_WRONLY|O_LARGEFILE; flags = O_WRONLY|O_LARGEFILE;
mode = FMODE_WRITE;
DQUOT_INIT(inode); DQUOT_INIT(inode);
} }
err = init_private_file(filp, dentry, mode); err = open_private_file(filp, dentry, flags);
if (!err) { if (!err) {
filp->f_flags = flags;
filp->f_vfsmnt = fhp->fh_export->ex_mnt; filp->f_vfsmnt = fhp->fh_export->ex_mnt;
} else if (access & MAY_WRITE) } else if (access & MAY_WRITE)
put_write_access(inode); put_write_access(inode);
...@@ -491,8 +489,7 @@ nfsd_close(struct file *filp) ...@@ -491,8 +489,7 @@ nfsd_close(struct file *filp)
struct dentry *dentry = filp->f_dentry; struct dentry *dentry = filp->f_dentry;
struct inode *inode = dentry->d_inode; struct inode *inode = dentry->d_inode;
if (filp->f_op->release) close_private_file(filp);
filp->f_op->release(inode, filp);
if (filp->f_mode & FMODE_WRITE) if (filp->f_mode & FMODE_WRITE)
put_write_access(inode); put_write_access(inode);
} }
......
...@@ -611,6 +611,7 @@ do_kern_mount(const char *fstype, int flags, char *name, void *data) ...@@ -611,6 +611,7 @@ do_kern_mount(const char *fstype, int flags, char *name, void *data)
struct file_system_type *type = get_fs_type(fstype); struct file_system_type *type = get_fs_type(fstype);
struct super_block *sb = ERR_PTR(-ENOMEM); struct super_block *sb = ERR_PTR(-ENOMEM);
struct vfsmount *mnt; struct vfsmount *mnt;
int error;
if (!type) if (!type)
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
...@@ -621,6 +622,13 @@ do_kern_mount(const char *fstype, int flags, char *name, void *data) ...@@ -621,6 +622,13 @@ do_kern_mount(const char *fstype, int flags, char *name, void *data)
sb = type->get_sb(type, flags, name, data); sb = type->get_sb(type, flags, name, data);
if (IS_ERR(sb)) if (IS_ERR(sb))
goto out_mnt; goto out_mnt;
error = security_sb_kern_mount(sb);
if (error) {
up_write(&sb->s_umount);
deactivate_super(sb);
sb = ERR_PTR(error);
goto out_mnt;
}
mnt->mnt_sb = sb; mnt->mnt_sb = sb;
mnt->mnt_root = dget(sb->s_root); mnt->mnt_root = dget(sb->s_root);
mnt->mnt_mountpoint = sb->s_root; mnt->mnt_mountpoint = sb->s_root;
......
...@@ -457,7 +457,10 @@ extern spinlock_t files_lock; ...@@ -457,7 +457,10 @@ extern spinlock_t files_lock;
#define get_file(x) atomic_inc(&(x)->f_count) #define get_file(x) atomic_inc(&(x)->f_count)
#define file_count(x) atomic_read(&(x)->f_count) #define file_count(x) atomic_read(&(x)->f_count)
extern int init_private_file(struct file *, struct dentry *, int); /* Initialize and open a private file and allocate its security structure. */
extern int open_private_file(struct file *, struct dentry *, int);
/* Release a private file and free its security structure. */
extern void close_private_file(struct file *file);
#define MAX_NON_LFS ((1UL<<31) - 1) #define MAX_NON_LFS ((1UL<<31) - 1)
......
...@@ -339,10 +339,6 @@ struct swap_info_struct; ...@@ -339,10 +339,6 @@ struct swap_info_struct;
* @mnt is the vfsmount where the dentry was looked up * @mnt is the vfsmount where the dentry was looked up
* @dentry contains the dentry structure for the file. * @dentry contains the dentry structure for the file.
* Return 0 if permission is granted. * Return 0 if permission is granted.
* @inode_post_lookup:
* Set the security attributes for a file after it has been looked up.
* @inode contains the inode structure for parent directory.
* @d contains the dentry structure for the file.
* @inode_delete: * @inode_delete:
* @inode contains the inode structure for deleted inode. * @inode contains the inode structure for deleted inode.
* This hook is called when a deleted inode is released (i.e. an inode * This hook is called when a deleted inode is released (i.e. an inode
...@@ -814,6 +810,7 @@ struct security_operations { ...@@ -814,6 +810,7 @@ struct security_operations {
int (*sb_alloc_security) (struct super_block * sb); int (*sb_alloc_security) (struct super_block * sb);
void (*sb_free_security) (struct super_block * sb); void (*sb_free_security) (struct super_block * sb);
int (*sb_kern_mount) (struct super_block *sb);
int (*sb_statfs) (struct super_block * sb); int (*sb_statfs) (struct super_block * sb);
int (*sb_mount) (char *dev_name, struct nameidata * nd, int (*sb_mount) (char *dev_name, struct nameidata * nd,
char *type, unsigned long flags, void *data); char *type, unsigned long flags, void *data);
...@@ -867,7 +864,6 @@ struct security_operations { ...@@ -867,7 +864,6 @@ struct security_operations {
int (*inode_permission_lite) (struct inode *inode, int mask); int (*inode_permission_lite) (struct inode *inode, int mask);
int (*inode_setattr) (struct dentry *dentry, struct iattr *attr); int (*inode_setattr) (struct dentry *dentry, struct iattr *attr);
int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry); int (*inode_getattr) (struct vfsmount *mnt, struct dentry *dentry);
void (*inode_post_lookup) (struct inode *inode, struct dentry *d);
void (*inode_delete) (struct inode *inode); void (*inode_delete) (struct inode *inode);
int (*inode_setxattr) (struct dentry *dentry, char *name, void *value, int (*inode_setxattr) (struct dentry *dentry, char *name, void *value,
size_t size, int flags); size_t size, int flags);
...@@ -952,6 +948,8 @@ struct security_operations { ...@@ -952,6 +948,8 @@ struct security_operations {
struct security_operations *ops); struct security_operations *ops);
int (*unregister_security) (const char *name, int (*unregister_security) (const char *name,
struct security_operations *ops); struct security_operations *ops);
void (*d_instantiate) (struct dentry * dentry, struct inode * inode);
}; };
/* global variables */ /* global variables */
...@@ -1034,6 +1032,11 @@ static inline void security_sb_free (struct super_block *sb) ...@@ -1034,6 +1032,11 @@ static inline void security_sb_free (struct super_block *sb)
security_ops->sb_free_security (sb); security_ops->sb_free_security (sb);
} }
static inline int security_sb_kern_mount (struct super_block *sb)
{
return security_ops->sb_kern_mount (sb);
}
static inline int security_sb_statfs (struct super_block *sb) static inline int security_sb_statfs (struct super_block *sb)
{ {
return security_ops->sb_statfs (sb); return security_ops->sb_statfs (sb);
...@@ -1240,12 +1243,6 @@ static inline int security_inode_getattr (struct vfsmount *mnt, ...@@ -1240,12 +1243,6 @@ static inline int security_inode_getattr (struct vfsmount *mnt,
return security_ops->inode_getattr (mnt, dentry); return security_ops->inode_getattr (mnt, dentry);
} }
static inline void security_inode_post_lookup (struct inode *inode,
struct dentry *dentry)
{
security_ops->inode_post_lookup (inode, dentry);
}
static inline void security_inode_delete (struct inode *inode) static inline void security_inode_delete (struct inode *inode)
{ {
security_ops->inode_delete (inode); security_ops->inode_delete (inode);
...@@ -1543,6 +1540,11 @@ static inline int security_sem_semop (struct sem_array * sma, ...@@ -1543,6 +1540,11 @@ static inline int security_sem_semop (struct sem_array * sma,
return security_ops->sem_semop(sma, sops, nsops, alter); return security_ops->sem_semop(sma, sops, nsops, alter);
} }
static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
{
security_ops->d_instantiate (dentry, inode);
}
/* prototypes */ /* prototypes */
extern int security_scaffolding_startup (void); extern int security_scaffolding_startup (void);
extern int register_security (struct security_operations *ops); extern int register_security (struct security_operations *ops);
...@@ -1639,6 +1641,11 @@ static inline int security_sb_alloc (struct super_block *sb) ...@@ -1639,6 +1641,11 @@ static inline int security_sb_alloc (struct super_block *sb)
static inline void security_sb_free (struct super_block *sb) static inline void security_sb_free (struct super_block *sb)
{ } { }
static inline int security_sb_kern_mount (struct super_block *sb)
{
return 0;
}
static inline int security_sb_statfs (struct super_block *sb) static inline int security_sb_statfs (struct super_block *sb)
{ {
return 0; return 0;
...@@ -1817,10 +1824,6 @@ static inline int security_inode_getattr (struct vfsmount *mnt, ...@@ -1817,10 +1824,6 @@ static inline int security_inode_getattr (struct vfsmount *mnt,
return 0; return 0;
} }
static inline void security_inode_post_lookup (struct inode *inode,
struct dentry *dentry)
{ }
static inline void security_inode_delete (struct inode *inode) static inline void security_inode_delete (struct inode *inode)
{ } { }
...@@ -2104,6 +2107,9 @@ static inline int security_sem_semop (struct sem_array * sma, ...@@ -2104,6 +2107,9 @@ static inline int security_sem_semop (struct sem_array * sma,
return 0; return 0;
} }
static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
{ }
#endif /* CONFIG_SECURITY */ #endif /* CONFIG_SECURITY */
#endif /* ! __LINUX_SECURITY_H */ #endif /* ! __LINUX_SECURITY_H */
......
...@@ -172,7 +172,8 @@ EXPORT_SYMBOL(mark_buffer_dirty); ...@@ -172,7 +172,8 @@ EXPORT_SYMBOL(mark_buffer_dirty);
EXPORT_SYMBOL(end_buffer_io_sync); EXPORT_SYMBOL(end_buffer_io_sync);
EXPORT_SYMBOL(__mark_inode_dirty); EXPORT_SYMBOL(__mark_inode_dirty);
EXPORT_SYMBOL(get_empty_filp); EXPORT_SYMBOL(get_empty_filp);
EXPORT_SYMBOL(init_private_file); EXPORT_SYMBOL(open_private_file);
EXPORT_SYMBOL(close_private_file);
EXPORT_SYMBOL(filp_open); EXPORT_SYMBOL(filp_open);
EXPORT_SYMBOL(filp_close); EXPORT_SYMBOL(filp_close);
EXPORT_SYMBOL(put_filp); EXPORT_SYMBOL(put_filp);
......
...@@ -212,18 +212,25 @@ cond_syscall(sys_delete_module) ...@@ -212,18 +212,25 @@ cond_syscall(sys_delete_module)
static int set_one_prio(struct task_struct *p, int niceval, int error) static int set_one_prio(struct task_struct *p, int niceval, int error)
{ {
int no_nice;
if (p->uid != current->euid && if (p->uid != current->euid &&
p->uid != current->uid && !capable(CAP_SYS_NICE)) { p->uid != current->uid && !capable(CAP_SYS_NICE)) {
error = -EPERM; error = -EPERM;
goto out; goto out;
} }
if (niceval < task_nice(p) && !capable(CAP_SYS_NICE)) {
error = -EACCES;
goto out;
}
no_nice = security_task_setnice(p, niceval);
if (no_nice) {
error = no_nice;
goto out;
}
if (error == -ESRCH) if (error == -ESRCH)
error = 0; error = 0;
if (niceval < task_nice(p) && !capable(CAP_SYS_NICE)) set_user_nice(p, niceval);
error = -EACCES;
else
set_user_nice(p, niceval);
out: out:
return error; return error;
} }
...@@ -944,6 +951,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -944,6 +951,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
} }
ok_pgid: ok_pgid:
err = security_task_setpgid(p, pgid);
if (err)
goto out;
if (p->pgrp != pgid) { if (p->pgrp != pgid) {
detach_pid(p, PIDTYPE_PGID); detach_pid(p, PIDTYPE_PGID);
p->pgrp = pgid; p->pgrp = pgid;
......
...@@ -120,6 +120,11 @@ static void dummy_sb_free_security (struct super_block *sb) ...@@ -120,6 +120,11 @@ static void dummy_sb_free_security (struct super_block *sb)
return; return;
} }
static int dummy_sb_kern_mount (struct super_block *sb)
{
return 0;
}
static int dummy_sb_statfs (struct super_block *sb) static int dummy_sb_statfs (struct super_block *sb)
{ {
return 0; return 0;
...@@ -306,11 +311,6 @@ static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry) ...@@ -306,11 +311,6 @@ static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry)
return 0; return 0;
} }
static void dummy_inode_post_lookup (struct inode *ino, struct dentry *d)
{
return;
}
static void dummy_inode_delete (struct inode *ino) static void dummy_inode_delete (struct inode *ino)
{ {
return; return;
...@@ -607,6 +607,12 @@ static int dummy_unregister_security (const char *name, struct security_operatio ...@@ -607,6 +607,12 @@ static int dummy_unregister_security (const char *name, struct security_operatio
return -EINVAL; return -EINVAL;
} }
static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
{
return;
}
struct security_operations dummy_security_ops; struct security_operations dummy_security_ops;
#define set_to_dummy_if_null(ops, function) \ #define set_to_dummy_if_null(ops, function) \
...@@ -635,6 +641,7 @@ void security_fixup_ops (struct security_operations *ops) ...@@ -635,6 +641,7 @@ void security_fixup_ops (struct security_operations *ops)
set_to_dummy_if_null(ops, bprm_check_security); set_to_dummy_if_null(ops, bprm_check_security);
set_to_dummy_if_null(ops, sb_alloc_security); set_to_dummy_if_null(ops, sb_alloc_security);
set_to_dummy_if_null(ops, sb_free_security); set_to_dummy_if_null(ops, sb_free_security);
set_to_dummy_if_null(ops, sb_kern_mount);
set_to_dummy_if_null(ops, sb_statfs); set_to_dummy_if_null(ops, sb_statfs);
set_to_dummy_if_null(ops, sb_mount); set_to_dummy_if_null(ops, sb_mount);
set_to_dummy_if_null(ops, sb_check_sb); set_to_dummy_if_null(ops, sb_check_sb);
...@@ -668,7 +675,6 @@ void security_fixup_ops (struct security_operations *ops) ...@@ -668,7 +675,6 @@ void security_fixup_ops (struct security_operations *ops)
set_to_dummy_if_null(ops, inode_permission_lite); set_to_dummy_if_null(ops, inode_permission_lite);
set_to_dummy_if_null(ops, inode_setattr); set_to_dummy_if_null(ops, inode_setattr);
set_to_dummy_if_null(ops, inode_getattr); set_to_dummy_if_null(ops, inode_getattr);
set_to_dummy_if_null(ops, inode_post_lookup);
set_to_dummy_if_null(ops, inode_delete); set_to_dummy_if_null(ops, inode_delete);
set_to_dummy_if_null(ops, inode_setxattr); set_to_dummy_if_null(ops, inode_setxattr);
set_to_dummy_if_null(ops, inode_getxattr); set_to_dummy_if_null(ops, inode_getxattr);
...@@ -725,5 +731,6 @@ void security_fixup_ops (struct security_operations *ops) ...@@ -725,5 +731,6 @@ void security_fixup_ops (struct security_operations *ops)
set_to_dummy_if_null(ops, sem_semop); set_to_dummy_if_null(ops, sem_semop);
set_to_dummy_if_null(ops, register_security); set_to_dummy_if_null(ops, register_security);
set_to_dummy_if_null(ops, unregister_security); set_to_dummy_if_null(ops, unregister_security);
set_to_dummy_if_null(ops, d_instantiate);
} }
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