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 @@
#include <linux/module.h>
#include <linux/mount.h>
#include <asm/uaccess.h>
#include <linux/security.h>
#define DCACHE_PARANOIA 1
/* #define DCACHE_DEBUG 1 */
......@@ -699,6 +700,7 @@ struct dentry * d_alloc(struct dentry * parent, const struct qstr *name)
void d_instantiate(struct dentry *entry, struct inode * inode)
{
if (!list_empty(&entry->d_alias)) BUG();
security_d_instantiate(entry, inode);
spin_lock(&dcache_lock);
if (inode)
list_add(&entry->d_alias, &inode->i_dentry);
......@@ -825,6 +827,7 @@ struct dentry *d_splice_alias(struct inode *inode, struct dentry *dentry)
struct dentry *new = NULL;
if (inode && S_ISDIR(inode->i_mode)) {
security_d_instantiate(dentry, inode);
spin_lock(&dcache_lock);
if (!list_empty(&inode->i_dentry)) {
new = list_entry(inode->i_dentry.next, struct dentry, d_alias);
......
......@@ -353,7 +353,7 @@ static int get_name(struct dentry *dentry, char *name,
/*
* Open the directory ...
*/
error = init_private_file(&file, dentry, FMODE_READ);
error = open_private_file(&file, dentry, O_RDONLY);
if (error)
goto out;
error = -EINVAL;
......@@ -381,8 +381,7 @@ static int get_name(struct dentry *dentry, char *name,
}
out_close:
if (file.f_op->release)
file.f_op->release(dir, &file);
close_private_file(&file);
out:
return error;
}
......
......@@ -93,23 +93,42 @@ struct file * get_empty_filp(void)
/*
* Clear and initialize a (private) struct file for the given dentry,
* and call the open function (if any). The caller must verify that
* inode->i_fop is not NULL.
* allocate the security structure, and call the open function (if any).
* 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));
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);
filp->f_dentry = dentry;
filp->f_uid = current->fsuid;
filp->f_gid = current->fsgid;
filp->f_op = dentry->d_inode->i_fop;
if (filp->f_op->open)
return filp->f_op->open(dentry->d_inode, filp);
else
return 0;
error = security_file_alloc(filp);
if (!error)
if (filp->f_op && filp->f_op->open) {
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)
......
......@@ -372,10 +372,8 @@ static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, i
result = dir->i_op->lookup(dir, dentry);
if (result)
dput(dentry);
else {
else
result = dentry;
security_inode_post_lookup(dir, result);
}
}
up(&dir->i_sem);
return result;
......@@ -916,10 +914,9 @@ struct dentry * lookup_hash(struct qstr *name, struct dentry * base)
if (!new)
goto out;
dentry = inode->i_op->lookup(inode, new);
if (!dentry) {
if (!dentry)
dentry = new;
security_inode_post_lookup(inode, dentry);
} else
else
dput(new);
}
out:
......
......@@ -426,7 +426,7 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
{
struct dentry *dentry;
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",
......@@ -463,14 +463,12 @@ nfsd_open(struct svc_rqst *rqstp, struct svc_fh *fhp, int type,
goto out_nfserr;
flags = O_WRONLY|O_LARGEFILE;
mode = FMODE_WRITE;
DQUOT_INIT(inode);
}
err = init_private_file(filp, dentry, mode);
err = open_private_file(filp, dentry, flags);
if (!err) {
filp->f_flags = flags;
filp->f_vfsmnt = fhp->fh_export->ex_mnt;
} else if (access & MAY_WRITE)
put_write_access(inode);
......@@ -491,8 +489,7 @@ nfsd_close(struct file *filp)
struct dentry *dentry = filp->f_dentry;
struct inode *inode = dentry->d_inode;
if (filp->f_op->release)
filp->f_op->release(inode, filp);
close_private_file(filp);
if (filp->f_mode & FMODE_WRITE)
put_write_access(inode);
}
......
......@@ -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 super_block *sb = ERR_PTR(-ENOMEM);
struct vfsmount *mnt;
int error;
if (!type)
return ERR_PTR(-ENODEV);
......@@ -621,6 +622,13 @@ do_kern_mount(const char *fstype, int flags, char *name, void *data)
sb = type->get_sb(type, flags, name, data);
if (IS_ERR(sb))
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_root = dget(sb->s_root);
mnt->mnt_mountpoint = sb->s_root;
......
......@@ -457,7 +457,10 @@ extern spinlock_t files_lock;
#define get_file(x) atomic_inc(&(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)
......
......@@ -339,10 +339,6 @@ struct swap_info_struct;
* @mnt is the vfsmount where the dentry was looked up
* @dentry contains the dentry structure for the file.
* 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 contains the inode structure for deleted inode.
* This hook is called when a deleted inode is released (i.e. an inode
......@@ -814,6 +810,7 @@ struct security_operations {
int (*sb_alloc_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_mount) (char *dev_name, struct nameidata * nd,
char *type, unsigned long flags, void *data);
......@@ -867,7 +864,6 @@ struct security_operations {
int (*inode_permission_lite) (struct inode *inode, int mask);
int (*inode_setattr) (struct dentry *dentry, struct iattr *attr);
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);
int (*inode_setxattr) (struct dentry *dentry, char *name, void *value,
size_t size, int flags);
......@@ -952,6 +948,8 @@ struct security_operations {
struct security_operations *ops);
int (*unregister_security) (const char *name,
struct security_operations *ops);
void (*d_instantiate) (struct dentry * dentry, struct inode * inode);
};
/* global variables */
......@@ -1034,6 +1032,11 @@ static inline void security_sb_free (struct super_block *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)
{
return security_ops->sb_statfs (sb);
......@@ -1240,12 +1243,6 @@ static inline int security_inode_getattr (struct vfsmount *mnt,
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)
{
security_ops->inode_delete (inode);
......@@ -1543,6 +1540,11 @@ static inline int security_sem_semop (struct sem_array * sma,
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 */
extern int security_scaffolding_startup (void);
extern int register_security (struct security_operations *ops);
......@@ -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 int security_sb_kern_mount (struct super_block *sb)
{
return 0;
}
static inline int security_sb_statfs (struct super_block *sb)
{
return 0;
......@@ -1817,10 +1824,6 @@ static inline int security_inode_getattr (struct vfsmount *mnt,
return 0;
}
static inline void security_inode_post_lookup (struct inode *inode,
struct dentry *dentry)
{ }
static inline void security_inode_delete (struct inode *inode)
{ }
......@@ -2104,6 +2107,9 @@ static inline int security_sem_semop (struct sem_array * sma,
return 0;
}
static inline void security_d_instantiate (struct dentry *dentry, struct inode *inode)
{ }
#endif /* CONFIG_SECURITY */
#endif /* ! __LINUX_SECURITY_H */
......
......@@ -172,7 +172,8 @@ EXPORT_SYMBOL(mark_buffer_dirty);
EXPORT_SYMBOL(end_buffer_io_sync);
EXPORT_SYMBOL(__mark_inode_dirty);
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_close);
EXPORT_SYMBOL(put_filp);
......
......@@ -212,18 +212,25 @@ cond_syscall(sys_delete_module)
static int set_one_prio(struct task_struct *p, int niceval, int error)
{
int no_nice;
if (p->uid != current->euid &&
p->uid != current->uid && !capable(CAP_SYS_NICE)) {
error = -EPERM;
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)
error = 0;
if (niceval < task_nice(p) && !capable(CAP_SYS_NICE))
error = -EACCES;
else
set_user_nice(p, niceval);
set_user_nice(p, niceval);
out:
return error;
}
......@@ -944,6 +951,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
}
ok_pgid:
err = security_task_setpgid(p, pgid);
if (err)
goto out;
if (p->pgrp != pgid) {
detach_pid(p, PIDTYPE_PGID);
p->pgrp = pgid;
......
......@@ -120,6 +120,11 @@ static void dummy_sb_free_security (struct super_block *sb)
return;
}
static int dummy_sb_kern_mount (struct super_block *sb)
{
return 0;
}
static int dummy_sb_statfs (struct super_block *sb)
{
return 0;
......@@ -306,11 +311,6 @@ static int dummy_inode_getattr (struct vfsmount *mnt, struct dentry *dentry)
return 0;
}
static void dummy_inode_post_lookup (struct inode *ino, struct dentry *d)
{
return;
}
static void dummy_inode_delete (struct inode *ino)
{
return;
......@@ -607,6 +607,12 @@ static int dummy_unregister_security (const char *name, struct security_operatio
return -EINVAL;
}
static void dummy_d_instantiate (struct dentry *dentry, struct inode *inode)
{
return;
}
struct security_operations dummy_security_ops;
#define set_to_dummy_if_null(ops, function) \
......@@ -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, sb_alloc_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_mount);
set_to_dummy_if_null(ops, sb_check_sb);
......@@ -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_setattr);
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_setxattr);
set_to_dummy_if_null(ops, inode_getxattr);
......@@ -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, register_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