Skip to content

Commit

Permalink
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  Remove two unneeded exports and make two symbols static in fs/mpage.c
  Cleanup after commit 585d3bc
  Trim includes of fdtable.h
  Don't crap into descriptor table in binfmt_som
  Trim includes in binfmt_elf
  Don't mess with descriptor table in load_elf_binary()
  Get rid of indirect include of fs_struct.h
  New helper - current_umask()
  check_unsafe_exec() doesn't care about signal handlers sharing
  New locking/refcounting for fs_struct
  Take fs_struct handling to new file (fs/fs_struct.c)
  Get rid of bumping fs_struct refcount in pivot_root(2)
  Kill unsharing fs_struct in __set_personality()
  • Loading branch information
torvalds committed Apr 3, 2009
2 parents c2eb2fa + ced117c commit 8fe74cf
Show file tree
Hide file tree
Showing 57 changed files with 337 additions and 268 deletions.
1 change: 0 additions & 1 deletion arch/cris/kernel/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <asm/system.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/fs_struct.h>
#include <linux/init_task.h>
#include <linux/sched.h>
#include <linux/fs.h>
Expand Down
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/cell/spufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
if (dentry->d_inode)
goto out_dput;

mode &= ~current->fs->umask;
mode &= ~current_umask();

if (flags & SPU_CREATE_GANG)
ret = spufs_create_gang(nd->path.dentry->d_inode,
Expand Down
2 changes: 0 additions & 2 deletions drivers/char/tty_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/

#include <linux/audit.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/tty.h>

struct tty_audit_buf {
Expand Down
1 change: 0 additions & 1 deletion drivers/char/tty_ldisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <linux/tty_flip.h>
#include <linux/devpts_fs.h>
#include <linux/file.h>
#include <linux/fdtable.h>
#include <linux/console.h>
#include <linux/timer.h>
#include <linux/ctype.h>
Expand Down
2 changes: 1 addition & 1 deletion fs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ obj-y := open.o read_write.o file_table.o super.o \
attr.o bad_inode.o file.o filesystems.o namespace.o \
seq_file.o xattr.o libfs.o fs-writeback.o \
pnode.o drop_caches.o splice.o sync.o utimes.o \
stack.o
stack.o fs_struct.o

ifeq ($(CONFIG_BLOCK),y)
obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
Expand Down
22 changes: 2 additions & 20 deletions fs/binfmt_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,22 @@
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/time.h>
#include <linux/mm.h>
#include <linux/mman.h>
#include <linux/errno.h>
#include <linux/signal.h>
#include <linux/binfmts.h>
#include <linux/string.h>
#include <linux/file.h>
#include <linux/fcntl.h>
#include <linux/ptrace.h>
#include <linux/slab.h>
#include <linux/shm.h>
#include <linux/personality.h>
#include <linux/elfcore.h>
#include <linux/init.h>
#include <linux/highuid.h>
#include <linux/smp.h>
#include <linux/compiler.h>
#include <linux/highmem.h>
#include <linux/pagemap.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/random.h>
#include <linux/elf.h>
#include <linux/utsname.h>
Expand Down Expand Up @@ -576,7 +569,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
unsigned long error;
struct elf_phdr *elf_ppnt, *elf_phdata;
unsigned long elf_bss, elf_brk;
int elf_exec_fileno;
int retval, i;
unsigned int size;
unsigned long elf_entry;
Expand Down Expand Up @@ -631,12 +623,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
goto out_free_ph;
}

retval = get_unused_fd();
if (retval < 0)
goto out_free_ph;
get_file(bprm->file);
fd_install(elf_exec_fileno = retval, bprm->file);

elf_ppnt = elf_phdata;
elf_bss = 0;
elf_brk = 0;
Expand All @@ -655,13 +641,13 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
retval = -ENOEXEC;
if (elf_ppnt->p_filesz > PATH_MAX ||
elf_ppnt->p_filesz < 2)
goto out_free_file;
goto out_free_ph;

retval = -ENOMEM;
elf_interpreter = kmalloc(elf_ppnt->p_filesz,
GFP_KERNEL);
if (!elf_interpreter)
goto out_free_file;
goto out_free_ph;

retval = kernel_read(bprm->file, elf_ppnt->p_offset,
elf_interpreter,
Expand Down Expand Up @@ -956,8 +942,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)

kfree(elf_phdata);

sys_close(elf_exec_fileno);

set_binfmt(&elf_format);

#ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES
Expand Down Expand Up @@ -1028,8 +1012,6 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
fput(interpreter);
out_free_interp:
kfree(elf_interpreter);
out_free_file:
sys_close(elf_exec_fileno);
out_free_ph:
kfree(elf_phdata);
goto out;
Expand Down
7 changes: 0 additions & 7 deletions fs/binfmt_som.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ static int map_som_binary(struct file *file,
static int
load_som_binary(struct linux_binprm * bprm, struct pt_regs * regs)
{
int som_exec_fileno;
int retval;
unsigned int size;
unsigned long som_entry;
Expand Down Expand Up @@ -220,12 +219,6 @@ load_som_binary(struct linux_binprm * bprm, struct pt_regs * regs)
goto out_free;
}

retval = get_unused_fd();
if (retval < 0)
goto out_free;
get_file(bprm->file);
fd_install(som_exec_fileno = retval, bprm->file);

/* Flush all traces of the currently running executable */
retval = flush_old_exec(bprm);
if (retval)
Expand Down
1 change: 1 addition & 0 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ int fsync_bdev(struct block_device *bdev)
}
return sync_blockdev(bdev);
}
EXPORT_SYMBOL(fsync_bdev);

/**
* freeze_bdev -- lock a filesystem and force it into a consistent state
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int btrfs_init_acl(struct inode *inode, struct inode *dir)
}

if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}

if (IS_POSIXACL(dir) && acl) {
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static noinline int btrfs_mksubvol(struct path *parent, char *name,
goto out_dput;

if (!IS_POSIXACL(parent->dentry->d_inode))
mode &= ~current->fs->umask;
mode &= ~current_umask();

error = mnt_want_write(parent->mnt);
if (error)
Expand Down
1 change: 0 additions & 1 deletion fs/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3315,7 +3315,6 @@ EXPORT_SYMBOL(cont_write_begin);
EXPORT_SYMBOL(end_buffer_read_sync);
EXPORT_SYMBOL(end_buffer_write_sync);
EXPORT_SYMBOL(file_fsync);
EXPORT_SYMBOL(fsync_bdev);
EXPORT_SYMBOL(generic_block_bmap);
EXPORT_SYMBOL(generic_cont_expand_simple);
EXPORT_SYMBOL(init_buffer);
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
return -ENOMEM;
}

mode &= ~current->fs->umask;
mode &= ~current_umask();
if (oplockEnabled)
oplock = REQ_OPLOCK;

Expand Down Expand Up @@ -479,7 +479,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
rc = -ENOMEM;
else if (pTcon->unix_ext) {
struct cifs_unix_set_info_args args = {
.mode = mode & ~current->fs->umask,
.mode = mode & ~current_umask(),
.ctime = NO_CHANGE_64,
.atime = NO_CHANGE_64,
.mtime = NO_CHANGE_64,
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
goto mkdir_out;
}

mode &= ~current->fs->umask;
mode &= ~current_umask();
rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT,
mode, NULL /* netfid */, pInfo, &oplock,
full_path, cifs_sb->local_nls,
Expand Down Expand Up @@ -1204,7 +1204,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
if ((direntry->d_inode) && (direntry->d_inode->i_nlink < 2))
direntry->d_inode->i_nlink = 2;

mode &= ~current->fs->umask;
mode &= ~current_umask();
/* must turn on setgid bit if parent dir has it */
if (inode->i_mode & S_ISGID)
mode |= S_ISGID;
Expand Down
16 changes: 14 additions & 2 deletions fs/compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include <linux/poll.h>
#include <linux/mm.h>
#include <linux/eventpoll.h>
#include <linux/fs_struct.h>

#include <asm/uaccess.h>
#include <asm/mmu_context.h>
Expand Down Expand Up @@ -1502,12 +1503,15 @@ int compat_do_execve(char * filename,
bprm->cred = prepare_exec_creds();
if (!bprm->cred)
goto out_unlock;
check_unsafe_exec(bprm);

retval = check_unsafe_exec(bprm);
if (retval)
goto out_unlock;

file = open_exec(filename);
retval = PTR_ERR(file);
if (IS_ERR(file))
goto out_unlock;
goto out_unmark;

sched_exec();

Expand Down Expand Up @@ -1549,6 +1553,9 @@ int compat_do_execve(char * filename,
goto out;

/* execve succeeded */
write_lock(&current->fs->lock);
current->fs->in_exec = 0;
write_unlock(&current->fs->lock);
current->in_execve = 0;
mutex_unlock(&current->cred_exec_mutex);
acct_update_integrals(current);
Expand All @@ -1567,6 +1574,11 @@ int compat_do_execve(char * filename,
fput(bprm->file);
}

out_unmark:
write_lock(&current->fs->lock);
current->fs->in_exec = 0;
write_unlock(&current->fs->lock);

out_unlock:
current->in_execve = 0;
mutex_unlock(&current->cred_exec_mutex);
Expand Down
2 changes: 1 addition & 1 deletion fs/dcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <linux/syscalls.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/fdtable.h>
#include <linux/fs.h>
#include <linux/fsnotify.h>
#include <linux/slab.h>
Expand All @@ -32,6 +31,7 @@
#include <linux/seqlock.h>
#include <linux/swap.h>
#include <linux/bootmem.h>
#include <linux/fs_struct.h>
#include "internal.h"

int sysctl_vfs_cache_pressure __read_mostly = 100;
Expand Down
35 changes: 27 additions & 8 deletions fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <linux/tracehook.h>
#include <linux/kmod.h>
#include <linux/fsnotify.h>
#include <linux/fs_struct.h>

#include <asm/uaccess.h>
#include <asm/mmu_context.h>
Expand Down Expand Up @@ -1056,28 +1057,35 @@ EXPORT_SYMBOL(install_exec_creds);
* - the caller must hold current->cred_exec_mutex to protect against
* PTRACE_ATTACH
*/
void check_unsafe_exec(struct linux_binprm *bprm)
int check_unsafe_exec(struct linux_binprm *bprm)
{
struct task_struct *p = current, *t;
unsigned long flags;
unsigned n_fs, n_sighand;
unsigned n_fs;
int res = 0;

bprm->unsafe = tracehook_unsafe_exec(p);

n_fs = 1;
n_sighand = 1;
write_lock(&p->fs->lock);
lock_task_sighand(p, &flags);
for (t = next_thread(p); t != p; t = next_thread(t)) {
if (t->fs == p->fs)
n_fs++;
n_sighand++;
}

if (atomic_read(&p->fs->count) > n_fs ||
atomic_read(&p->sighand->count) > n_sighand)
if (p->fs->users > n_fs) {
bprm->unsafe |= LSM_UNSAFE_SHARE;
} else {
if (p->fs->in_exec)
res = -EAGAIN;
p->fs->in_exec = 1;
}

unlock_task_sighand(p, &flags);
write_unlock(&p->fs->lock);

return res;
}

/*
Expand Down Expand Up @@ -1296,12 +1304,15 @@ int do_execve(char * filename,
bprm->cred = prepare_exec_creds();
if (!bprm->cred)
goto out_unlock;
check_unsafe_exec(bprm);

retval = check_unsafe_exec(bprm);
if (retval)
goto out_unlock;

file = open_exec(filename);
retval = PTR_ERR(file);
if (IS_ERR(file))
goto out_unlock;
goto out_unmark;

sched_exec();

Expand Down Expand Up @@ -1344,6 +1355,9 @@ int do_execve(char * filename,
goto out;

/* execve succeeded */
write_lock(&current->fs->lock);
current->fs->in_exec = 0;
write_unlock(&current->fs->lock);
current->in_execve = 0;
mutex_unlock(&current->cred_exec_mutex);
acct_update_integrals(current);
Expand All @@ -1362,6 +1376,11 @@ int do_execve(char * filename,
fput(bprm->file);
}

out_unmark:
write_lock(&current->fs->lock);
current->fs->in_exec = 0;
write_unlock(&current->fs->lock);

out_unlock:
current->in_execve = 0;
mutex_unlock(&current->cred_exec_mutex);
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext3/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
Loading

0 comments on commit 8fe74cf

Please sign in to comment.