Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/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 585d3bc06f4ca57f975a5a1f698f65a45ea66225
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()

+337 -268
-1
arch/cris/kernel/process.c
··· 19 #include <asm/system.h> 20 #include <linux/module.h> 21 #include <linux/spinlock.h> 22 - #include <linux/fs_struct.h> 23 #include <linux/init_task.h> 24 #include <linux/sched.h> 25 #include <linux/fs.h>
··· 19 #include <asm/system.h> 20 #include <linux/module.h> 21 #include <linux/spinlock.h> 22 #include <linux/init_task.h> 23 #include <linux/sched.h> 24 #include <linux/fs.h>
+1 -1
arch/powerpc/platforms/cell/spufs/inode.c
··· 635 if (dentry->d_inode) 636 goto out_dput; 637 638 - mode &= ~current->fs->umask; 639 640 if (flags & SPU_CREATE_GANG) 641 ret = spufs_create_gang(nd->path.dentry->d_inode,
··· 635 if (dentry->d_inode) 636 goto out_dput; 637 638 + mode &= ~current_umask(); 639 640 if (flags & SPU_CREATE_GANG) 641 ret = spufs_create_gang(nd->path.dentry->d_inode,
-2
drivers/char/tty_audit.c
··· 10 */ 11 12 #include <linux/audit.h> 13 - #include <linux/file.h> 14 - #include <linux/fdtable.h> 15 #include <linux/tty.h> 16 17 struct tty_audit_buf {
··· 10 */ 11 12 #include <linux/audit.h> 13 #include <linux/tty.h> 14 15 struct tty_audit_buf {
-1
drivers/char/tty_ldisc.c
··· 10 #include <linux/tty_flip.h> 11 #include <linux/devpts_fs.h> 12 #include <linux/file.h> 13 - #include <linux/fdtable.h> 14 #include <linux/console.h> 15 #include <linux/timer.h> 16 #include <linux/ctype.h>
··· 10 #include <linux/tty_flip.h> 11 #include <linux/devpts_fs.h> 12 #include <linux/file.h> 13 #include <linux/console.h> 14 #include <linux/timer.h> 15 #include <linux/ctype.h>
+1 -1
fs/Makefile
··· 11 attr.o bad_inode.o file.o filesystems.o namespace.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o \ 13 pnode.o drop_caches.o splice.o sync.o utimes.o \ 14 - stack.o 15 16 ifeq ($(CONFIG_BLOCK),y) 17 obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
··· 11 attr.o bad_inode.o file.o filesystems.o namespace.o \ 12 seq_file.o xattr.o libfs.o fs-writeback.o \ 13 pnode.o drop_caches.o splice.o sync.o utimes.o \ 14 + stack.o fs_struct.o 15 16 ifeq ($(CONFIG_BLOCK),y) 17 obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
+2 -20
fs/binfmt_elf.c
··· 12 #include <linux/module.h> 13 #include <linux/kernel.h> 14 #include <linux/fs.h> 15 - #include <linux/stat.h> 16 - #include <linux/time.h> 17 #include <linux/mm.h> 18 #include <linux/mman.h> 19 #include <linux/errno.h> ··· 19 #include <linux/binfmts.h> 20 #include <linux/string.h> 21 #include <linux/file.h> 22 - #include <linux/fcntl.h> 23 - #include <linux/ptrace.h> 24 #include <linux/slab.h> 25 - #include <linux/shm.h> 26 #include <linux/personality.h> 27 #include <linux/elfcore.h> 28 #include <linux/init.h> 29 #include <linux/highuid.h> 30 - #include <linux/smp.h> 31 #include <linux/compiler.h> 32 #include <linux/highmem.h> 33 #include <linux/pagemap.h> 34 #include <linux/security.h> 35 - #include <linux/syscalls.h> 36 #include <linux/random.h> 37 #include <linux/elf.h> 38 #include <linux/utsname.h> ··· 569 unsigned long error; 570 struct elf_phdr *elf_ppnt, *elf_phdata; 571 unsigned long elf_bss, elf_brk; 572 - int elf_exec_fileno; 573 int retval, i; 574 unsigned int size; 575 unsigned long elf_entry; ··· 623 goto out_free_ph; 624 } 625 626 - retval = get_unused_fd(); 627 - if (retval < 0) 628 - goto out_free_ph; 629 - get_file(bprm->file); 630 - fd_install(elf_exec_fileno = retval, bprm->file); 631 - 632 elf_ppnt = elf_phdata; 633 elf_bss = 0; 634 elf_brk = 0; ··· 641 retval = -ENOEXEC; 642 if (elf_ppnt->p_filesz > PATH_MAX || 643 elf_ppnt->p_filesz < 2) 644 - goto out_free_file; 645 646 retval = -ENOMEM; 647 elf_interpreter = kmalloc(elf_ppnt->p_filesz, 648 GFP_KERNEL); 649 if (!elf_interpreter) 650 - goto out_free_file; 651 652 retval = kernel_read(bprm->file, elf_ppnt->p_offset, 653 elf_interpreter, ··· 942 943 kfree(elf_phdata); 944 945 - sys_close(elf_exec_fileno); 946 - 947 set_binfmt(&elf_format); 948 949 #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES ··· 1012 fput(interpreter); 1013 out_free_interp: 1014 kfree(elf_interpreter); 1015 - out_free_file: 1016 - sys_close(elf_exec_fileno); 1017 out_free_ph: 1018 kfree(elf_phdata); 1019 goto out;
··· 12 #include <linux/module.h> 13 #include <linux/kernel.h> 14 #include <linux/fs.h> 15 #include <linux/mm.h> 16 #include <linux/mman.h> 17 #include <linux/errno.h> ··· 21 #include <linux/binfmts.h> 22 #include <linux/string.h> 23 #include <linux/file.h> 24 #include <linux/slab.h> 25 #include <linux/personality.h> 26 #include <linux/elfcore.h> 27 #include <linux/init.h> 28 #include <linux/highuid.h> 29 #include <linux/compiler.h> 30 #include <linux/highmem.h> 31 #include <linux/pagemap.h> 32 #include <linux/security.h> 33 #include <linux/random.h> 34 #include <linux/elf.h> 35 #include <linux/utsname.h> ··· 576 unsigned long error; 577 struct elf_phdr *elf_ppnt, *elf_phdata; 578 unsigned long elf_bss, elf_brk; 579 int retval, i; 580 unsigned int size; 581 unsigned long elf_entry; ··· 631 goto out_free_ph; 632 } 633 634 elf_ppnt = elf_phdata; 635 elf_bss = 0; 636 elf_brk = 0; ··· 655 retval = -ENOEXEC; 656 if (elf_ppnt->p_filesz > PATH_MAX || 657 elf_ppnt->p_filesz < 2) 658 + goto out_free_ph; 659 660 retval = -ENOMEM; 661 elf_interpreter = kmalloc(elf_ppnt->p_filesz, 662 GFP_KERNEL); 663 if (!elf_interpreter) 664 + goto out_free_ph; 665 666 retval = kernel_read(bprm->file, elf_ppnt->p_offset, 667 elf_interpreter, ··· 956 957 kfree(elf_phdata); 958 959 set_binfmt(&elf_format); 960 961 #ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES ··· 1028 fput(interpreter); 1029 out_free_interp: 1030 kfree(elf_interpreter); 1031 out_free_ph: 1032 kfree(elf_phdata); 1033 goto out;
-7
fs/binfmt_som.c
··· 188 static int 189 load_som_binary(struct linux_binprm * bprm, struct pt_regs * regs) 190 { 191 - int som_exec_fileno; 192 int retval; 193 unsigned int size; 194 unsigned long som_entry; ··· 218 retval = -EIO; 219 goto out_free; 220 } 221 - 222 - retval = get_unused_fd(); 223 - if (retval < 0) 224 - goto out_free; 225 - get_file(bprm->file); 226 - fd_install(som_exec_fileno = retval, bprm->file); 227 228 /* Flush all traces of the currently running executable */ 229 retval = flush_old_exec(bprm);
··· 188 static int 189 load_som_binary(struct linux_binprm * bprm, struct pt_regs * regs) 190 { 191 int retval; 192 unsigned int size; 193 unsigned long som_entry; ··· 219 retval = -EIO; 220 goto out_free; 221 } 222 223 /* Flush all traces of the currently running executable */ 224 retval = flush_old_exec(bprm);
+1
fs/block_dev.c
··· 204 } 205 return sync_blockdev(bdev); 206 } 207 208 /** 209 * freeze_bdev -- lock a filesystem and force it into a consistent state
··· 204 } 205 return sync_blockdev(bdev); 206 } 207 + EXPORT_SYMBOL(fsync_bdev); 208 209 /** 210 * freeze_bdev -- lock a filesystem and force it into a consistent state
+1 -1
fs/btrfs/acl.c
··· 256 } 257 258 if (!acl) 259 - inode->i_mode &= ~current->fs->umask; 260 } 261 262 if (IS_POSIXACL(dir) && acl) {
··· 256 } 257 258 if (!acl) 259 + inode->i_mode &= ~current_umask(); 260 } 261 262 if (IS_POSIXACL(dir) && acl) {
+1 -1
fs/btrfs/ioctl.c
··· 267 goto out_dput; 268 269 if (!IS_POSIXACL(parent->dentry->d_inode)) 270 - mode &= ~current->fs->umask; 271 272 error = mnt_want_write(parent->mnt); 273 if (error)
··· 267 goto out_dput; 268 269 if (!IS_POSIXACL(parent->dentry->d_inode)) 270 + mode &= ~current_umask(); 271 272 error = mnt_want_write(parent->mnt); 273 if (error)
-1
fs/buffer.c
··· 3315 EXPORT_SYMBOL(end_buffer_read_sync); 3316 EXPORT_SYMBOL(end_buffer_write_sync); 3317 EXPORT_SYMBOL(file_fsync); 3318 - EXPORT_SYMBOL(fsync_bdev); 3319 EXPORT_SYMBOL(generic_block_bmap); 3320 EXPORT_SYMBOL(generic_cont_expand_simple); 3321 EXPORT_SYMBOL(init_buffer);
··· 3315 EXPORT_SYMBOL(end_buffer_read_sync); 3316 EXPORT_SYMBOL(end_buffer_write_sync); 3317 EXPORT_SYMBOL(file_fsync); 3318 EXPORT_SYMBOL(generic_block_bmap); 3319 EXPORT_SYMBOL(generic_cont_expand_simple); 3320 EXPORT_SYMBOL(init_buffer);
+2 -2
fs/cifs/dir.c
··· 254 return -ENOMEM; 255 } 256 257 - mode &= ~current->fs->umask; 258 if (oplockEnabled) 259 oplock = REQ_OPLOCK; 260 ··· 479 rc = -ENOMEM; 480 else if (pTcon->unix_ext) { 481 struct cifs_unix_set_info_args args = { 482 - .mode = mode & ~current->fs->umask, 483 .ctime = NO_CHANGE_64, 484 .atime = NO_CHANGE_64, 485 .mtime = NO_CHANGE_64,
··· 254 return -ENOMEM; 255 } 256 257 + mode &= ~current_umask(); 258 if (oplockEnabled) 259 oplock = REQ_OPLOCK; 260 ··· 479 rc = -ENOMEM; 480 else if (pTcon->unix_ext) { 481 struct cifs_unix_set_info_args args = { 482 + .mode = mode & ~current_umask(), 483 .ctime = NO_CHANGE_64, 484 .atime = NO_CHANGE_64, 485 .mtime = NO_CHANGE_64,
+2 -2
fs/cifs/inode.c
··· 1125 goto mkdir_out; 1126 } 1127 1128 - mode &= ~current->fs->umask; 1129 rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT, 1130 mode, NULL /* netfid */, pInfo, &oplock, 1131 full_path, cifs_sb->local_nls, ··· 1204 if ((direntry->d_inode) && (direntry->d_inode->i_nlink < 2)) 1205 direntry->d_inode->i_nlink = 2; 1206 1207 - mode &= ~current->fs->umask; 1208 /* must turn on setgid bit if parent dir has it */ 1209 if (inode->i_mode & S_ISGID) 1210 mode |= S_ISGID;
··· 1125 goto mkdir_out; 1126 } 1127 1128 + mode &= ~current_umask(); 1129 rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT, 1130 mode, NULL /* netfid */, pInfo, &oplock, 1131 full_path, cifs_sb->local_nls, ··· 1204 if ((direntry->d_inode) && (direntry->d_inode->i_nlink < 2)) 1205 direntry->d_inode->i_nlink = 2; 1206 1207 + mode &= ~current_umask(); 1208 /* must turn on setgid bit if parent dir has it */ 1209 if (inode->i_mode & S_ISGID) 1210 mode |= S_ISGID;
+14 -2
fs/compat.c
··· 51 #include <linux/poll.h> 52 #include <linux/mm.h> 53 #include <linux/eventpoll.h> 54 55 #include <asm/uaccess.h> 56 #include <asm/mmu_context.h> ··· 1503 bprm->cred = prepare_exec_creds(); 1504 if (!bprm->cred) 1505 goto out_unlock; 1506 - check_unsafe_exec(bprm); 1507 1508 file = open_exec(filename); 1509 retval = PTR_ERR(file); 1510 if (IS_ERR(file)) 1511 - goto out_unlock; 1512 1513 sched_exec(); 1514 ··· 1553 goto out; 1554 1555 /* execve succeeded */ 1556 current->in_execve = 0; 1557 mutex_unlock(&current->cred_exec_mutex); 1558 acct_update_integrals(current); ··· 1573 allow_write_access(bprm->file); 1574 fput(bprm->file); 1575 } 1576 1577 out_unlock: 1578 current->in_execve = 0;
··· 51 #include <linux/poll.h> 52 #include <linux/mm.h> 53 #include <linux/eventpoll.h> 54 + #include <linux/fs_struct.h> 55 56 #include <asm/uaccess.h> 57 #include <asm/mmu_context.h> ··· 1502 bprm->cred = prepare_exec_creds(); 1503 if (!bprm->cred) 1504 goto out_unlock; 1505 + 1506 + retval = check_unsafe_exec(bprm); 1507 + if (retval) 1508 + goto out_unlock; 1509 1510 file = open_exec(filename); 1511 retval = PTR_ERR(file); 1512 if (IS_ERR(file)) 1513 + goto out_unmark; 1514 1515 sched_exec(); 1516 ··· 1549 goto out; 1550 1551 /* execve succeeded */ 1552 + write_lock(&current->fs->lock); 1553 + current->fs->in_exec = 0; 1554 + write_unlock(&current->fs->lock); 1555 current->in_execve = 0; 1556 mutex_unlock(&current->cred_exec_mutex); 1557 acct_update_integrals(current); ··· 1566 allow_write_access(bprm->file); 1567 fput(bprm->file); 1568 } 1569 + 1570 + out_unmark: 1571 + write_lock(&current->fs->lock); 1572 + current->fs->in_exec = 0; 1573 + write_unlock(&current->fs->lock); 1574 1575 out_unlock: 1576 current->in_execve = 0;
+1 -1
fs/dcache.c
··· 17 #include <linux/syscalls.h> 18 #include <linux/string.h> 19 #include <linux/mm.h> 20 - #include <linux/fdtable.h> 21 #include <linux/fs.h> 22 #include <linux/fsnotify.h> 23 #include <linux/slab.h> ··· 31 #include <linux/seqlock.h> 32 #include <linux/swap.h> 33 #include <linux/bootmem.h> 34 #include "internal.h" 35 36 int sysctl_vfs_cache_pressure __read_mostly = 100;
··· 17 #include <linux/syscalls.h> 18 #include <linux/string.h> 19 #include <linux/mm.h> 20 #include <linux/fs.h> 21 #include <linux/fsnotify.h> 22 #include <linux/slab.h> ··· 32 #include <linux/seqlock.h> 33 #include <linux/swap.h> 34 #include <linux/bootmem.h> 35 + #include <linux/fs_struct.h> 36 #include "internal.h" 37 38 int sysctl_vfs_cache_pressure __read_mostly = 100;
+27 -8
fs/exec.c
··· 53 #include <linux/tracehook.h> 54 #include <linux/kmod.h> 55 #include <linux/fsnotify.h> 56 57 #include <asm/uaccess.h> 58 #include <asm/mmu_context.h> ··· 1057 * - the caller must hold current->cred_exec_mutex to protect against 1058 * PTRACE_ATTACH 1059 */ 1060 - void check_unsafe_exec(struct linux_binprm *bprm) 1061 { 1062 struct task_struct *p = current, *t; 1063 unsigned long flags; 1064 - unsigned n_fs, n_sighand; 1065 1066 bprm->unsafe = tracehook_unsafe_exec(p); 1067 1068 n_fs = 1; 1069 - n_sighand = 1; 1070 lock_task_sighand(p, &flags); 1071 for (t = next_thread(p); t != p; t = next_thread(t)) { 1072 if (t->fs == p->fs) 1073 n_fs++; 1074 - n_sighand++; 1075 } 1076 1077 - if (atomic_read(&p->fs->count) > n_fs || 1078 - atomic_read(&p->sighand->count) > n_sighand) 1079 bprm->unsafe |= LSM_UNSAFE_SHARE; 1080 1081 unlock_task_sighand(p, &flags); 1082 } 1083 1084 /* ··· 1304 bprm->cred = prepare_exec_creds(); 1305 if (!bprm->cred) 1306 goto out_unlock; 1307 - check_unsafe_exec(bprm); 1308 1309 file = open_exec(filename); 1310 retval = PTR_ERR(file); 1311 if (IS_ERR(file)) 1312 - goto out_unlock; 1313 1314 sched_exec(); 1315 ··· 1355 goto out; 1356 1357 /* execve succeeded */ 1358 current->in_execve = 0; 1359 mutex_unlock(&current->cred_exec_mutex); 1360 acct_update_integrals(current); ··· 1375 allow_write_access(bprm->file); 1376 fput(bprm->file); 1377 } 1378 1379 out_unlock: 1380 current->in_execve = 0;
··· 53 #include <linux/tracehook.h> 54 #include <linux/kmod.h> 55 #include <linux/fsnotify.h> 56 + #include <linux/fs_struct.h> 57 58 #include <asm/uaccess.h> 59 #include <asm/mmu_context.h> ··· 1056 * - the caller must hold current->cred_exec_mutex to protect against 1057 * PTRACE_ATTACH 1058 */ 1059 + int check_unsafe_exec(struct linux_binprm *bprm) 1060 { 1061 struct task_struct *p = current, *t; 1062 unsigned long flags; 1063 + unsigned n_fs; 1064 + int res = 0; 1065 1066 bprm->unsafe = tracehook_unsafe_exec(p); 1067 1068 n_fs = 1; 1069 + write_lock(&p->fs->lock); 1070 lock_task_sighand(p, &flags); 1071 for (t = next_thread(p); t != p; t = next_thread(t)) { 1072 if (t->fs == p->fs) 1073 n_fs++; 1074 } 1075 1076 + if (p->fs->users > n_fs) { 1077 bprm->unsafe |= LSM_UNSAFE_SHARE; 1078 + } else { 1079 + if (p->fs->in_exec) 1080 + res = -EAGAIN; 1081 + p->fs->in_exec = 1; 1082 + } 1083 1084 unlock_task_sighand(p, &flags); 1085 + write_unlock(&p->fs->lock); 1086 + 1087 + return res; 1088 } 1089 1090 /* ··· 1296 bprm->cred = prepare_exec_creds(); 1297 if (!bprm->cred) 1298 goto out_unlock; 1299 + 1300 + retval = check_unsafe_exec(bprm); 1301 + if (retval) 1302 + goto out_unlock; 1303 1304 file = open_exec(filename); 1305 retval = PTR_ERR(file); 1306 if (IS_ERR(file)) 1307 + goto out_unmark; 1308 1309 sched_exec(); 1310 ··· 1344 goto out; 1345 1346 /* execve succeeded */ 1347 + write_lock(&current->fs->lock); 1348 + current->fs->in_exec = 0; 1349 + write_unlock(&current->fs->lock); 1350 current->in_execve = 0; 1351 mutex_unlock(&current->cred_exec_mutex); 1352 acct_update_integrals(current); ··· 1361 allow_write_access(bprm->file); 1362 fput(bprm->file); 1363 } 1364 + 1365 + out_unmark: 1366 + write_lock(&current->fs->lock); 1367 + current->fs->in_exec = 0; 1368 + write_unlock(&current->fs->lock); 1369 1370 out_unlock: 1371 current->in_execve = 0;
+1 -1
fs/ext2/acl.c
··· 318 return PTR_ERR(acl); 319 } 320 if (!acl) 321 - inode->i_mode &= ~current->fs->umask; 322 } 323 if (test_opt(inode->i_sb, POSIX_ACL) && acl) { 324 struct posix_acl *clone;
··· 318 return PTR_ERR(acl); 319 } 320 if (!acl) 321 + inode->i_mode &= ~current_umask(); 322 } 323 if (test_opt(inode->i_sb, POSIX_ACL) && acl) { 324 struct posix_acl *clone;
+1 -1
fs/ext3/acl.c
··· 323 return PTR_ERR(acl); 324 } 325 if (!acl) 326 - inode->i_mode &= ~current->fs->umask; 327 } 328 if (test_opt(inode->i_sb, POSIX_ACL) && acl) { 329 struct posix_acl *clone;
··· 323 return PTR_ERR(acl); 324 } 325 if (!acl) 326 + inode->i_mode &= ~current_umask(); 327 } 328 if (test_opt(inode->i_sb, POSIX_ACL) && acl) { 329 struct posix_acl *clone;
+1 -1
fs/ext4/acl.c
··· 323 return PTR_ERR(acl); 324 } 325 if (!acl) 326 - inode->i_mode &= ~current->fs->umask; 327 } 328 if (test_opt(inode->i_sb, POSIX_ACL) && acl) { 329 struct posix_acl *clone;
··· 323 return PTR_ERR(acl); 324 } 325 if (!acl) 326 + inode->i_mode &= ~current_umask(); 327 } 328 if (test_opt(inode->i_sb, POSIX_ACL) && acl) { 329 struct posix_acl *clone;
+1 -1
fs/fat/inode.c
··· 934 935 opts->fs_uid = current_uid(); 936 opts->fs_gid = current_gid(); 937 - opts->fs_fmask = opts->fs_dmask = current->fs->umask; 938 opts->allow_utime = -1; 939 opts->codepage = fat_default_codepage; 940 opts->iocharset = fat_default_iocharset;
··· 934 935 opts->fs_uid = current_uid(); 936 opts->fs_gid = current_gid(); 937 + opts->fs_fmask = current_umask(); 938 opts->allow_utime = -1; 939 opts->codepage = fat_default_codepage; 940 opts->iocharset = fat_default_iocharset;
+177
fs/fs_struct.c
···
··· 1 + #include <linux/module.h> 2 + #include <linux/sched.h> 3 + #include <linux/fs.h> 4 + #include <linux/path.h> 5 + #include <linux/slab.h> 6 + #include <linux/fs_struct.h> 7 + 8 + /* 9 + * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values. 10 + * It can block. 11 + */ 12 + void set_fs_root(struct fs_struct *fs, struct path *path) 13 + { 14 + struct path old_root; 15 + 16 + write_lock(&fs->lock); 17 + old_root = fs->root; 18 + fs->root = *path; 19 + path_get(path); 20 + write_unlock(&fs->lock); 21 + if (old_root.dentry) 22 + path_put(&old_root); 23 + } 24 + 25 + /* 26 + * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values. 27 + * It can block. 28 + */ 29 + void set_fs_pwd(struct fs_struct *fs, struct path *path) 30 + { 31 + struct path old_pwd; 32 + 33 + write_lock(&fs->lock); 34 + old_pwd = fs->pwd; 35 + fs->pwd = *path; 36 + path_get(path); 37 + write_unlock(&fs->lock); 38 + 39 + if (old_pwd.dentry) 40 + path_put(&old_pwd); 41 + } 42 + 43 + void chroot_fs_refs(struct path *old_root, struct path *new_root) 44 + { 45 + struct task_struct *g, *p; 46 + struct fs_struct *fs; 47 + int count = 0; 48 + 49 + read_lock(&tasklist_lock); 50 + do_each_thread(g, p) { 51 + task_lock(p); 52 + fs = p->fs; 53 + if (fs) { 54 + write_lock(&fs->lock); 55 + if (fs->root.dentry == old_root->dentry 56 + && fs->root.mnt == old_root->mnt) { 57 + path_get(new_root); 58 + fs->root = *new_root; 59 + count++; 60 + } 61 + if (fs->pwd.dentry == old_root->dentry 62 + && fs->pwd.mnt == old_root->mnt) { 63 + path_get(new_root); 64 + fs->pwd = *new_root; 65 + count++; 66 + } 67 + write_unlock(&fs->lock); 68 + } 69 + task_unlock(p); 70 + } while_each_thread(g, p); 71 + read_unlock(&tasklist_lock); 72 + while (count--) 73 + path_put(old_root); 74 + } 75 + 76 + void free_fs_struct(struct fs_struct *fs) 77 + { 78 + path_put(&fs->root); 79 + path_put(&fs->pwd); 80 + kmem_cache_free(fs_cachep, fs); 81 + } 82 + 83 + void exit_fs(struct task_struct *tsk) 84 + { 85 + struct fs_struct *fs = tsk->fs; 86 + 87 + if (fs) { 88 + int kill; 89 + task_lock(tsk); 90 + write_lock(&fs->lock); 91 + tsk->fs = NULL; 92 + kill = !--fs->users; 93 + write_unlock(&fs->lock); 94 + task_unlock(tsk); 95 + if (kill) 96 + free_fs_struct(fs); 97 + } 98 + } 99 + 100 + struct fs_struct *copy_fs_struct(struct fs_struct *old) 101 + { 102 + struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL); 103 + /* We don't need to lock fs - think why ;-) */ 104 + if (fs) { 105 + fs->users = 1; 106 + fs->in_exec = 0; 107 + rwlock_init(&fs->lock); 108 + fs->umask = old->umask; 109 + read_lock(&old->lock); 110 + fs->root = old->root; 111 + path_get(&old->root); 112 + fs->pwd = old->pwd; 113 + path_get(&old->pwd); 114 + read_unlock(&old->lock); 115 + } 116 + return fs; 117 + } 118 + 119 + int unshare_fs_struct(void) 120 + { 121 + struct fs_struct *fs = current->fs; 122 + struct fs_struct *new_fs = copy_fs_struct(fs); 123 + int kill; 124 + 125 + if (!new_fs) 126 + return -ENOMEM; 127 + 128 + task_lock(current); 129 + write_lock(&fs->lock); 130 + kill = !--fs->users; 131 + current->fs = new_fs; 132 + write_unlock(&fs->lock); 133 + task_unlock(current); 134 + 135 + if (kill) 136 + free_fs_struct(fs); 137 + 138 + return 0; 139 + } 140 + EXPORT_SYMBOL_GPL(unshare_fs_struct); 141 + 142 + int current_umask(void) 143 + { 144 + return current->fs->umask; 145 + } 146 + EXPORT_SYMBOL(current_umask); 147 + 148 + /* to be mentioned only in INIT_TASK */ 149 + struct fs_struct init_fs = { 150 + .users = 1, 151 + .lock = __RW_LOCK_UNLOCKED(init_fs.lock), 152 + .umask = 0022, 153 + }; 154 + 155 + void daemonize_fs_struct(void) 156 + { 157 + struct fs_struct *fs = current->fs; 158 + 159 + if (fs) { 160 + int kill; 161 + 162 + task_lock(current); 163 + 164 + write_lock(&init_fs.lock); 165 + init_fs.users++; 166 + write_unlock(&init_fs.lock); 167 + 168 + write_lock(&fs->lock); 169 + current->fs = &init_fs; 170 + kill = !--fs->users; 171 + write_unlock(&fs->lock); 172 + 173 + task_unlock(current); 174 + if (kill) 175 + free_fs_struct(fs); 176 + } 177 + }
+1 -1
fs/generic_acl.c
··· 134 mode_t mode = inode->i_mode; 135 int error; 136 137 - inode->i_mode = mode & ~current->fs->umask; 138 if (!S_ISLNK(inode->i_mode)) 139 acl = ops->getacl(dir, ACL_TYPE_DEFAULT); 140 if (acl) {
··· 134 mode_t mode = inode->i_mode; 135 int error; 136 137 + inode->i_mode = mode & ~current_umask(); 138 if (!S_ISLNK(inode->i_mode)) 139 acl = ops->getacl(dir, ACL_TYPE_DEFAULT); 140 if (acl) {
+1 -1
fs/gfs2/acl.c
··· 215 if (error) 216 return error; 217 if (!acl) { 218 - mode &= ~current->fs->umask; 219 if (mode != ip->i_inode.i_mode) 220 error = munge_mode(ip, mode); 221 return error;
··· 215 if (error) 216 return error; 217 if (!acl) { 218 + mode &= ~current_umask(); 219 if (mode != ip->i_inode.i_mode) 220 error = munge_mode(ip, mode); 221 return error;
+1 -1
fs/hfsplus/options.c
··· 48 49 opts->creator = HFSPLUS_DEF_CR_TYPE; 50 opts->type = HFSPLUS_DEF_CR_TYPE; 51 - opts->umask = current->fs->umask; 52 opts->uid = current_uid(); 53 opts->gid = current_gid(); 54 opts->part = -1;
··· 48 49 opts->creator = HFSPLUS_DEF_CR_TYPE; 50 opts->type = HFSPLUS_DEF_CR_TYPE; 51 + opts->umask = current_umask(); 52 opts->uid = current_uid(); 53 opts->gid = current_gid(); 54 opts->part = -1;
+1 -1
fs/hpfs/super.c
··· 480 481 uid = current_uid(); 482 gid = current_gid(); 483 - umask = current->fs->umask; 484 lowercase = 0; 485 conv = CONV_BINARY; 486 eas = 2;
··· 480 481 uid = current_uid(); 482 gid = current_gid(); 483 + umask = current_umask(); 484 lowercase = 0; 485 conv = CONV_BINARY; 486 eas = 2;
+7 -1
fs/internal.h
··· 11 12 struct super_block; 13 struct linux_binprm; 14 15 /* 16 * block_dev.c ··· 44 /* 45 * exec.c 46 */ 47 - extern void check_unsafe_exec(struct linux_binprm *); 48 49 /* 50 * namespace.c ··· 61 extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); 62 63 extern void __init mnt_init(void);
··· 11 12 struct super_block; 13 struct linux_binprm; 14 + struct path; 15 16 /* 17 * block_dev.c ··· 43 /* 44 * exec.c 45 */ 46 + extern int check_unsafe_exec(struct linux_binprm *); 47 48 /* 49 * namespace.c ··· 60 extern struct vfsmount *copy_tree(struct vfsmount *, struct dentry *, int); 61 62 extern void __init mnt_init(void); 63 + 64 + /* 65 + * fs_struct.c 66 + */ 67 + extern void chroot_fs_refs(struct path *, struct path *);
+1 -1
fs/jffs2/acl.c
··· 336 return PTR_ERR(acl); 337 338 if (!acl) { 339 - *i_mode &= ~current->fs->umask; 340 } else { 341 if (S_ISDIR(*i_mode)) 342 jffs2_iset_acl(inode, &f->i_acl_default, acl);
··· 336 return PTR_ERR(acl); 337 338 if (!acl) { 339 + *i_mode &= ~current_umask(); 340 } else { 341 if (S_ISDIR(*i_mode)) 342 jffs2_iset_acl(inode, &f->i_acl_default, acl);
+1 -1
fs/jfs/acl.c
··· 182 cleanup: 183 posix_acl_release(acl); 184 } else 185 - inode->i_mode &= ~current->fs->umask; 186 187 JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) | 188 inode->i_mode;
··· 182 cleanup: 183 posix_acl_release(acl); 184 } else 185 + inode->i_mode &= ~current_umask(); 186 187 JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) | 188 inode->i_mode;
+9 -4
fs/mpage.c
··· 82 bio_put(bio); 83 } 84 85 - struct bio *mpage_bio_submit(int rw, struct bio *bio) 86 { 87 bio->bi_end_io = mpage_end_io_read; 88 if (rw == WRITE) ··· 90 submit_bio(rw, bio); 91 return NULL; 92 } 93 - EXPORT_SYMBOL(mpage_bio_submit); 94 95 static struct bio * 96 mpage_alloc(struct block_device *bdev, ··· 438 * just allocate full-size (16-page) BIOs. 439 */ 440 441 - int __mpage_writepage(struct page *page, struct writeback_control *wbc, 442 void *data) 443 { 444 struct mpage_data *mpd = data; ··· 654 mpd->bio = bio; 655 return ret; 656 } 657 - EXPORT_SYMBOL(__mpage_writepage); 658 659 /** 660 * mpage_writepages - walk the list of dirty pages of the given address space & writepage() all of them
··· 82 bio_put(bio); 83 } 84 85 + static struct bio *mpage_bio_submit(int rw, struct bio *bio) 86 { 87 bio->bi_end_io = mpage_end_io_read; 88 if (rw == WRITE) ··· 90 submit_bio(rw, bio); 91 return NULL; 92 } 93 94 static struct bio * 95 mpage_alloc(struct block_device *bdev, ··· 439 * just allocate full-size (16-page) BIOs. 440 */ 441 442 + struct mpage_data { 443 + struct bio *bio; 444 + sector_t last_block_in_bio; 445 + get_block_t *get_block; 446 + unsigned use_writepage; 447 + }; 448 + 449 + static int __mpage_writepage(struct page *page, struct writeback_control *wbc, 450 void *data) 451 { 452 struct mpage_data *mpd = data; ··· 648 mpd->bio = bio; 649 return ret; 650 } 651 652 /** 653 * mpage_writepages - walk the list of dirty pages of the given address space & writepage() all of them
+4 -10
fs/namei.c
··· 32 #include <linux/file.h> 33 #include <linux/fcntl.h> 34 #include <linux/device_cgroup.h> 35 #include <asm/uaccess.h> 36 37 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) ··· 1579 struct dentry *dir = nd->path.dentry; 1580 1581 if (!IS_POSIXACL(dir->d_inode)) 1582 - mode &= ~current->fs->umask; 1583 error = security_path_mknod(&nd->path, path->dentry, mode, 0); 1584 if (error) 1585 goto out_unlock; ··· 1990 goto out_unlock; 1991 } 1992 if (!IS_POSIXACL(nd.path.dentry->d_inode)) 1993 - mode &= ~current->fs->umask; 1994 error = may_mknod(mode); 1995 if (error) 1996 goto out_dput; ··· 2068 goto out_unlock; 2069 2070 if (!IS_POSIXACL(nd.path.dentry->d_inode)) 2071 - mode &= ~current->fs->umask; 2072 error = mnt_want_write(nd.path.mnt); 2073 if (error) 2074 goto out_dput; ··· 2898 EXPORT_SYMBOL(vfs_unlink); 2899 EXPORT_SYMBOL(dentry_unhash); 2900 EXPORT_SYMBOL(generic_readlink); 2901 - 2902 - /* to be mentioned only in INIT_TASK */ 2903 - struct fs_struct init_fs = { 2904 - .count = ATOMIC_INIT(1), 2905 - .lock = __RW_LOCK_UNLOCKED(init_fs.lock), 2906 - .umask = 0022, 2907 - };
··· 32 #include <linux/file.h> 33 #include <linux/fcntl.h> 34 #include <linux/device_cgroup.h> 35 + #include <linux/fs_struct.h> 36 #include <asm/uaccess.h> 37 38 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) ··· 1578 struct dentry *dir = nd->path.dentry; 1579 1580 if (!IS_POSIXACL(dir->d_inode)) 1581 + mode &= ~current_umask(); 1582 error = security_path_mknod(&nd->path, path->dentry, mode, 0); 1583 if (error) 1584 goto out_unlock; ··· 1989 goto out_unlock; 1990 } 1991 if (!IS_POSIXACL(nd.path.dentry->d_inode)) 1992 + mode &= ~current_umask(); 1993 error = may_mknod(mode); 1994 if (error) 1995 goto out_dput; ··· 2067 goto out_unlock; 2068 2069 if (!IS_POSIXACL(nd.path.dentry->d_inode)) 2070 + mode &= ~current_umask(); 2071 error = mnt_want_write(nd.path.mnt); 2072 if (error) 2073 goto out_dput; ··· 2897 EXPORT_SYMBOL(vfs_unlink); 2898 EXPORT_SYMBOL(dentry_unhash); 2899 EXPORT_SYMBOL(generic_readlink);
+1 -60
fs/namespace.c
··· 27 #include <linux/ramfs.h> 28 #include <linux/log2.h> 29 #include <linux/idr.h> 30 #include <asm/uaccess.h> 31 #include <asm/unistd.h> 32 #include "pnode.h" ··· 2091 out1: 2092 free_page(type_page); 2093 return retval; 2094 - } 2095 - 2096 - /* 2097 - * Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values. 2098 - * It can block. Requires the big lock held. 2099 - */ 2100 - void set_fs_root(struct fs_struct *fs, struct path *path) 2101 - { 2102 - struct path old_root; 2103 - 2104 - write_lock(&fs->lock); 2105 - old_root = fs->root; 2106 - fs->root = *path; 2107 - path_get(path); 2108 - write_unlock(&fs->lock); 2109 - if (old_root.dentry) 2110 - path_put(&old_root); 2111 - } 2112 - 2113 - /* 2114 - * Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values. 2115 - * It can block. Requires the big lock held. 2116 - */ 2117 - void set_fs_pwd(struct fs_struct *fs, struct path *path) 2118 - { 2119 - struct path old_pwd; 2120 - 2121 - write_lock(&fs->lock); 2122 - old_pwd = fs->pwd; 2123 - fs->pwd = *path; 2124 - path_get(path); 2125 - write_unlock(&fs->lock); 2126 - 2127 - if (old_pwd.dentry) 2128 - path_put(&old_pwd); 2129 - } 2130 - 2131 - static void chroot_fs_refs(struct path *old_root, struct path *new_root) 2132 - { 2133 - struct task_struct *g, *p; 2134 - struct fs_struct *fs; 2135 - 2136 - read_lock(&tasklist_lock); 2137 - do_each_thread(g, p) { 2138 - task_lock(p); 2139 - fs = p->fs; 2140 - if (fs) { 2141 - atomic_inc(&fs->count); 2142 - task_unlock(p); 2143 - if (fs->root.dentry == old_root->dentry 2144 - && fs->root.mnt == old_root->mnt) 2145 - set_fs_root(fs, new_root); 2146 - if (fs->pwd.dentry == old_root->dentry 2147 - && fs->pwd.mnt == old_root->mnt) 2148 - set_fs_pwd(fs, new_root); 2149 - put_fs_struct(fs); 2150 - } else 2151 - task_unlock(p); 2152 - } while_each_thread(g, p); 2153 - read_unlock(&tasklist_lock); 2154 } 2155 2156 /*
··· 27 #include <linux/ramfs.h> 28 #include <linux/log2.h> 29 #include <linux/idr.h> 30 + #include <linux/fs_struct.h> 31 #include <asm/uaccess.h> 32 #include <asm/unistd.h> 33 #include "pnode.h" ··· 2090 out1: 2091 free_page(type_page); 2092 return retval; 2093 } 2094 2095 /*
+3 -3
fs/nfs/nfs3proc.c
··· 328 data->arg.create.verifier[1] = current->pid; 329 } 330 331 - sattr->ia_mode &= ~current->fs->umask; 332 333 for (;;) { 334 status = nfs3_do_create(dir, dentry, data); ··· 528 529 dprintk("NFS call mkdir %s\n", dentry->d_name.name); 530 531 - sattr->ia_mode &= ~current->fs->umask; 532 533 data = nfs3_alloc_createdata(); 534 if (data == NULL) ··· 639 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name, 640 MAJOR(rdev), MINOR(rdev)); 641 642 - sattr->ia_mode &= ~current->fs->umask; 643 644 data = nfs3_alloc_createdata(); 645 if (data == NULL)
··· 328 data->arg.create.verifier[1] = current->pid; 329 } 330 331 + sattr->ia_mode &= ~current_umask(); 332 333 for (;;) { 334 status = nfs3_do_create(dir, dentry, data); ··· 528 529 dprintk("NFS call mkdir %s\n", dentry->d_name.name); 530 531 + sattr->ia_mode &= ~current_umask(); 532 533 data = nfs3_alloc_createdata(); 534 if (data == NULL) ··· 639 dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name, 640 MAJOR(rdev), MINOR(rdev)); 641 642 + sattr->ia_mode &= ~current_umask(); 643 644 data = nfs3_alloc_createdata(); 645 if (data == NULL)
+1 -1
fs/nfs/nfs4proc.c
··· 1501 attr.ia_mode = nd->intent.open.create_mode; 1502 attr.ia_valid = ATTR_MODE; 1503 if (!IS_POSIXACL(dir)) 1504 - attr.ia_mode &= ~current->fs->umask; 1505 } else { 1506 attr.ia_valid = 0; 1507 BUG_ON(nd->intent.open.flags & O_CREAT);
··· 1501 attr.ia_mode = nd->intent.open.create_mode; 1502 attr.ia_valid = ATTR_MODE; 1503 if (!IS_POSIXACL(dir)) 1504 + attr.ia_mode &= ~current_umask(); 1505 } else { 1506 attr.ia_valid = 0; 1507 BUG_ON(nd->intent.open.flags & O_CREAT);
+2 -5
fs/nfsd/nfssvc.c
··· 403 nfsd(void *vrqstp) 404 { 405 struct svc_rqst *rqstp = (struct svc_rqst *) vrqstp; 406 - struct fs_struct *fsp; 407 int err, preverr = 0; 408 409 /* Lock module and set up kernel thread */ ··· 411 /* At this point, the thread shares current->fs 412 * with the init process. We need to create files with a 413 * umask of 0 instead of init's umask. */ 414 - fsp = copy_fs_struct(current->fs); 415 - if (!fsp) { 416 printk("Unable to start nfsd thread: out of memory\n"); 417 goto out; 418 } 419 - exit_fs(current); 420 - current->fs = fsp; 421 current->fs->umask = 0; 422 423 /*
··· 403 nfsd(void *vrqstp) 404 { 405 struct svc_rqst *rqstp = (struct svc_rqst *) vrqstp; 406 int err, preverr = 0; 407 408 /* Lock module and set up kernel thread */ ··· 412 /* At this point, the thread shares current->fs 413 * with the init process. We need to create files with a 414 * umask of 0 instead of init's umask. */ 415 + if (unshare_fs_struct() < 0) { 416 printk("Unable to start nfsd thread: out of memory\n"); 417 goto out; 418 } 419 + 420 current->fs->umask = 0; 421 422 /*
+1 -1
fs/ocfs2/acl.c
··· 296 return PTR_ERR(acl); 297 } 298 if (!acl) 299 - inode->i_mode &= ~current->fs->umask; 300 } 301 if ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) && acl) { 302 struct posix_acl *clone;
··· 296 return PTR_ERR(acl); 297 } 298 if (!acl) 299 + inode->i_mode &= ~current_umask(); 300 } 301 if ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) && acl) { 302 struct posix_acl *clone;
+1 -1
fs/omfs/inode.c
··· 426 427 sbi->s_uid = current_uid(); 428 sbi->s_gid = current_gid(); 429 - sbi->s_dmask = sbi->s_fmask = current->fs->umask; 430 431 if (!parse_options((char *) data, sbi)) 432 goto end;
··· 426 427 sbi->s_uid = current_uid(); 428 sbi->s_gid = current_gid(); 429 + sbi->s_dmask = sbi->s_fmask = current_umask(); 430 431 if (!parse_options((char *) data, sbi)) 432 goto end;
+1
fs/open.c
··· 29 #include <linux/rcupdate.h> 30 #include <linux/audit.h> 31 #include <linux/falloc.h> 32 33 int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) 34 {
··· 29 #include <linux/rcupdate.h> 30 #include <linux/audit.h> 31 #include <linux/falloc.h> 32 + #include <linux/fs_struct.h> 33 34 int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) 35 {
+1
fs/proc/base.c
··· 80 #include <linux/oom.h> 81 #include <linux/elf.h> 82 #include <linux/pid_namespace.h> 83 #include "internal.h" 84 85 /* NOTE:
··· 80 #include <linux/oom.h> 81 #include <linux/elf.h> 82 #include <linux/pid_namespace.h> 83 + #include <linux/fs_struct.h> 84 #include "internal.h" 85 86 /* NOTE:
+2 -1
fs/proc/task_nommu.c
··· 2 #include <linux/mm.h> 3 #include <linux/file.h> 4 #include <linux/fdtable.h> 5 #include <linux/mount.h> 6 #include <linux/ptrace.h> 7 #include <linux/seq_file.h> ··· 50 else 51 bytes += kobjsize(mm); 52 53 - if (current->fs && atomic_read(&current->fs->count) > 1) 54 sbytes += kobjsize(current->fs); 55 else 56 bytes += kobjsize(current->fs);
··· 2 #include <linux/mm.h> 3 #include <linux/file.h> 4 #include <linux/fdtable.h> 5 + #include <linux/fs_struct.h> 6 #include <linux/mount.h> 7 #include <linux/ptrace.h> 8 #include <linux/seq_file.h> ··· 49 else 50 bytes += kobjsize(mm); 51 52 + if (current->fs && current->fs->users > 1) 53 sbytes += kobjsize(current->fs); 54 else 55 bytes += kobjsize(current->fs);
+1 -1
fs/reiserfs/xattr_acl.c
··· 428 } else { 429 apply_umask: 430 /* no ACL, apply umask */ 431 - inode->i_mode &= ~current->fs->umask; 432 } 433 434 return err;
··· 428 } else { 429 apply_umask: 430 /* no ACL, apply umask */ 431 + inode->i_mode &= ~current_umask(); 432 } 433 434 return err;
+2 -2
fs/xfs/linux-2.6/xfs_iops.c
··· 227 xfs_dentry_to_name(&name, dentry); 228 229 if (IS_POSIXACL(dir) && !default_acl) 230 - mode &= ~current->fs->umask; 231 232 switch (mode & S_IFMT) { 233 case S_IFCHR: ··· 416 mode_t mode; 417 418 mode = S_IFLNK | 419 - (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO); 420 xfs_dentry_to_name(&name, dentry); 421 422 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
··· 227 xfs_dentry_to_name(&name, dentry); 228 229 if (IS_POSIXACL(dir) && !default_acl) 230 + mode &= ~current_umask(); 231 232 switch (mode & S_IFMT) { 233 case S_IFCHR: ··· 416 mode_t mode; 417 418 mode = S_IFLNK | 419 + (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO); 420 xfs_dentry_to_name(&name, dentry); 421 422 error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
-12
include/linux/buffer_head.h
··· 332 333 static inline void buffer_init(void) {} 334 static inline int try_to_free_buffers(struct page *page) { return 1; } 335 - static inline int sync_blockdev(struct block_device *bdev) { return 0; } 336 static inline int inode_has_buffers(struct inode *inode) { return 0; } 337 static inline void invalidate_inode_buffers(struct inode *inode) {} 338 static inline int remove_inode_buffers(struct inode *inode) { return 1; } 339 static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; } 340 - static inline void invalidate_bdev(struct block_device *bdev) {} 341 - 342 - static inline struct super_block *freeze_bdev(struct block_device *sb) 343 - { 344 - return NULL; 345 - } 346 - 347 - static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb) 348 - { 349 - return 0; 350 - } 351 352 #endif /* CONFIG_BLOCK */ 353 #endif /* _LINUX_BUFFER_HEAD_H */
··· 332 333 static inline void buffer_init(void) {} 334 static inline int try_to_free_buffers(struct page *page) { return 1; } 335 static inline int inode_has_buffers(struct inode *inode) { return 0; } 336 static inline void invalidate_inode_buffers(struct inode *inode) {} 337 static inline int remove_inode_buffers(struct inode *inode) { return 1; } 338 static inline int sync_mapping_buffers(struct address_space *mapping) { return 0; } 339 340 #endif /* CONFIG_BLOCK */ 341 #endif /* _LINUX_BUFFER_HEAD_H */
+14
include/linux/fs.h
··· 1741 1742 extern int vfs_statfs(struct dentry *, struct kstatfs *); 1743 1744 /* /sys/fs */ 1745 extern struct kobject *fs_kobj; 1746 ··· 1887 extern int fsync_no_super(struct block_device *); 1888 #else 1889 static inline void bd_forget(struct inode *inode) {} 1890 #endif 1891 extern const struct file_operations def_blk_fops; 1892 extern const struct file_operations def_chr_fops;
··· 1741 1742 extern int vfs_statfs(struct dentry *, struct kstatfs *); 1743 1744 + extern int current_umask(void); 1745 + 1746 /* /sys/fs */ 1747 extern struct kobject *fs_kobj; 1748 ··· 1885 extern int fsync_no_super(struct block_device *); 1886 #else 1887 static inline void bd_forget(struct inode *inode) {} 1888 + static inline int sync_blockdev(struct block_device *bdev) { return 0; } 1889 + static inline void invalidate_bdev(struct block_device *bdev) {} 1890 + 1891 + static inline struct super_block *freeze_bdev(struct block_device *sb) 1892 + { 1893 + return NULL; 1894 + } 1895 + 1896 + static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb) 1897 + { 1898 + return 0; 1899 + } 1900 #endif 1901 extern const struct file_operations def_blk_fops; 1902 extern const struct file_operations def_chr_fops;
+5 -5
include/linux/fs_struct.h
··· 4 #include <linux/path.h> 5 6 struct fs_struct { 7 - atomic_t count; /* This usage count is used by check_unsafe_exec() for 8 - * security checking purposes - therefore it may not be 9 - * incremented, except by clone(CLONE_FS). 10 - */ 11 rwlock_t lock; 12 int umask; 13 struct path root, pwd; 14 }; 15 ··· 17 extern void set_fs_root(struct fs_struct *, struct path *); 18 extern void set_fs_pwd(struct fs_struct *, struct path *); 19 extern struct fs_struct *copy_fs_struct(struct fs_struct *); 20 - extern void put_fs_struct(struct fs_struct *); 21 22 #endif /* _LINUX_FS_STRUCT_H */
··· 4 #include <linux/path.h> 5 6 struct fs_struct { 7 + int users; 8 rwlock_t lock; 9 int umask; 10 + int in_exec; 11 struct path root, pwd; 12 }; 13 ··· 19 extern void set_fs_root(struct fs_struct *, struct path *); 20 extern void set_fs_pwd(struct fs_struct *, struct path *); 21 extern struct fs_struct *copy_fs_struct(struct fs_struct *); 22 + extern void free_fs_struct(struct fs_struct *); 23 + extern void daemonize_fs_struct(void); 24 + extern int unshare_fs_struct(void); 25 26 #endif /* _LINUX_FS_STRUCT_H */
+2
include/linux/mnt_namespace.h
··· 22 int event; 23 }; 24 25 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, 26 struct fs_struct *); 27 extern void __put_mnt_ns(struct mnt_namespace *ns);
··· 22 int event; 23 }; 24 25 + struct fs_struct; 26 + 27 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, 28 struct fs_struct *); 29 extern void __put_mnt_ns(struct mnt_namespace *ns);
-10
include/linux/mpage.h
··· 11 */ 12 #ifdef CONFIG_BLOCK 13 14 - struct mpage_data { 15 - struct bio *bio; 16 - sector_t last_block_in_bio; 17 - get_block_t *get_block; 18 - unsigned use_writepage; 19 - }; 20 - 21 struct writeback_control; 22 23 - struct bio *mpage_bio_submit(int rw, struct bio *bio); 24 int mpage_readpages(struct address_space *mapping, struct list_head *pages, 25 unsigned nr_pages, get_block_t get_block); 26 int mpage_readpage(struct page *page, get_block_t get_block); 27 - int __mpage_writepage(struct page *page, struct writeback_control *wbc, 28 - void *data); 29 int mpage_writepages(struct address_space *mapping, 30 struct writeback_control *wbc, get_block_t get_block); 31 int mpage_writepage(struct page *page, get_block_t *get_block,
··· 11 */ 12 #ifdef CONFIG_BLOCK 13 14 struct writeback_control; 15 16 int mpage_readpages(struct address_space *mapping, struct list_head *pages, 17 unsigned nr_pages, get_block_t get_block); 18 int mpage_readpage(struct page *page, get_block_t get_block); 19 int mpage_writepages(struct address_space *mapping, 20 struct writeback_control *wbc, get_block_t get_block); 21 int mpage_writepage(struct page *page, get_block_t *get_block,
+1
include/linux/nsproxy.h
··· 8 struct uts_namespace; 9 struct ipc_namespace; 10 struct pid_namespace; 11 12 /* 13 * A structure to contain pointers to all per-process
··· 8 struct uts_namespace; 9 struct ipc_namespace; 10 struct pid_namespace; 11 + struct fs_struct; 12 13 /* 14 * A structure to contain pointers to all per-process
+2 -1
include/linux/sched.h
··· 68 #include <linux/smp.h> 69 #include <linux/sem.h> 70 #include <linux/signal.h> 71 - #include <linux/fs_struct.h> 72 #include <linux/compiler.h> 73 #include <linux/completion.h> 74 #include <linux/pid.h> ··· 97 struct robust_list_head; 98 struct bio; 99 struct bts_tracer; 100 101 /* 102 * List of flags we want to share for kernel threads,
··· 68 #include <linux/smp.h> 69 #include <linux/sem.h> 70 #include <linux/signal.h> 71 + #include <linux/path.h> 72 #include <linux/compiler.h> 73 #include <linux/completion.h> 74 #include <linux/pid.h> ··· 97 struct robust_list_head; 98 struct bio; 99 struct bts_tracer; 100 + struct fs_struct; 101 102 /* 103 * List of flags we want to share for kernel threads,
+1
init/do_mounts.c
··· 14 #include <linux/fs.h> 15 #include <linux/initrd.h> 16 #include <linux/async.h> 17 18 #include <linux/nfs_fs.h> 19 #include <linux/nfs_fs_sb.h>
··· 14 #include <linux/fs.h> 15 #include <linux/initrd.h> 16 #include <linux/async.h> 17 + #include <linux/fs_struct.h> 18 19 #include <linux/nfs_fs.h> 20 #include <linux/nfs_fs_sb.h>
+1 -1
ipc/mqueue.c
··· 602 dentry->d_fsdata = attr; 603 } 604 605 - mode &= ~current->fs->umask; 606 ret = mnt_want_write(mqueue_mnt); 607 if (ret) 608 goto out;
··· 602 dentry->d_fsdata = attr; 603 } 604 605 + mode &= ~current_umask(); 606 ret = mnt_want_write(mqueue_mnt); 607 if (ret) 608 goto out;
+1
kernel/auditsc.c
··· 66 #include <linux/syscalls.h> 67 #include <linux/inotify.h> 68 #include <linux/capability.h> 69 70 #include "audit.h" 71
··· 66 #include <linux/syscalls.h> 67 #include <linux/inotify.h> 68 #include <linux/capability.h> 69 + #include <linux/fs_struct.h> 70 71 #include "audit.h" 72
+1 -22
kernel/exec_domain.c
··· 18 #include <linux/syscalls.h> 19 #include <linux/sysctl.h> 20 #include <linux/types.h> 21 22 23 static void default_handler(int, struct pt_regs *); ··· 145 module_put(ep->module); 146 return 0; 147 } 148 - 149 - if (atomic_read(&current->fs->count) != 1) { 150 - struct fs_struct *fsp, *ofsp; 151 - 152 - fsp = copy_fs_struct(current->fs); 153 - if (fsp == NULL) { 154 - module_put(ep->module); 155 - return -ENOMEM; 156 - } 157 - 158 - task_lock(current); 159 - ofsp = current->fs; 160 - current->fs = fsp; 161 - task_unlock(current); 162 - 163 - put_fs_struct(ofsp); 164 - } 165 - 166 - /* 167 - * At that point we are guaranteed to be the sole owner of 168 - * current->fs. 169 - */ 170 171 current->personality = personality; 172 oep = current_thread_info()->exec_domain;
··· 18 #include <linux/syscalls.h> 19 #include <linux/sysctl.h> 20 #include <linux/types.h> 21 + #include <linux/fs_struct.h> 22 23 24 static void default_handler(int, struct pt_regs *); ··· 144 module_put(ep->module); 145 return 0; 146 } 147 148 current->personality = personality; 149 oep = current_thread_info()->exec_domain;
+2 -30
kernel/exit.c
··· 46 #include <linux/blkdev.h> 47 #include <linux/task_io_accounting_ops.h> 48 #include <linux/tracehook.h> 49 #include <linux/init_task.h> 50 #include <trace/sched.h> 51 ··· 421 void daemonize(const char *name, ...) 422 { 423 va_list args; 424 - struct fs_struct *fs; 425 sigset_t blocked; 426 427 va_start(args, name); ··· 453 454 /* Become as one with the init task */ 455 456 - exit_fs(current); /* current->fs->count--; */ 457 - fs = init_task.fs; 458 - current->fs = fs; 459 - atomic_inc(&fs->count); 460 - 461 exit_files(current); 462 current->files = init_task.files; 463 atomic_inc(&current->files->count); ··· 551 put_files_struct(files); 552 } 553 } 554 - 555 - void put_fs_struct(struct fs_struct *fs) 556 - { 557 - /* No need to hold fs->lock if we are killing it */ 558 - if (atomic_dec_and_test(&fs->count)) { 559 - path_put(&fs->root); 560 - path_put(&fs->pwd); 561 - kmem_cache_free(fs_cachep, fs); 562 - } 563 - } 564 - 565 - void exit_fs(struct task_struct *tsk) 566 - { 567 - struct fs_struct * fs = tsk->fs; 568 - 569 - if (fs) { 570 - task_lock(tsk); 571 - tsk->fs = NULL; 572 - task_unlock(tsk); 573 - put_fs_struct(fs); 574 - } 575 - } 576 - 577 - EXPORT_SYMBOL_GPL(exit_fs); 578 579 #ifdef CONFIG_MM_OWNER 580 /*
··· 46 #include <linux/blkdev.h> 47 #include <linux/task_io_accounting_ops.h> 48 #include <linux/tracehook.h> 49 + #include <linux/fs_struct.h> 50 #include <linux/init_task.h> 51 #include <trace/sched.h> 52 ··· 420 void daemonize(const char *name, ...) 421 { 422 va_list args; 423 sigset_t blocked; 424 425 va_start(args, name); ··· 453 454 /* Become as one with the init task */ 455 456 + daemonize_fs_struct(); 457 exit_files(current); 458 current->files = init_task.files; 459 atomic_inc(&current->files->count); ··· 555 put_files_struct(files); 556 } 557 } 558 559 #ifdef CONFIG_MM_OWNER 560 /*
+28 -35
kernel/fork.c
··· 60 #include <linux/tty.h> 61 #include <linux/proc_fs.h> 62 #include <linux/blkdev.h> 63 #include <trace/sched.h> 64 #include <linux/magic.h> 65 ··· 682 return retval; 683 } 684 685 - static struct fs_struct *__copy_fs_struct(struct fs_struct *old) 686 - { 687 - struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL); 688 - /* We don't need to lock fs - think why ;-) */ 689 - if (fs) { 690 - atomic_set(&fs->count, 1); 691 - rwlock_init(&fs->lock); 692 - fs->umask = old->umask; 693 - read_lock(&old->lock); 694 - fs->root = old->root; 695 - path_get(&old->root); 696 - fs->pwd = old->pwd; 697 - path_get(&old->pwd); 698 - read_unlock(&old->lock); 699 - } 700 - return fs; 701 - } 702 - 703 - struct fs_struct *copy_fs_struct(struct fs_struct *old) 704 - { 705 - return __copy_fs_struct(old); 706 - } 707 - 708 - EXPORT_SYMBOL_GPL(copy_fs_struct); 709 - 710 static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) 711 { 712 if (clone_flags & CLONE_FS) { 713 - atomic_inc(&current->fs->count); 714 return 0; 715 } 716 - tsk->fs = __copy_fs_struct(current->fs); 717 if (!tsk->fs) 718 return -ENOMEM; 719 return 0; ··· 1528 { 1529 struct fs_struct *fs = current->fs; 1530 1531 - if ((unshare_flags & CLONE_FS) && 1532 - (fs && atomic_read(&fs->count) > 1)) { 1533 - *new_fsp = __copy_fs_struct(current->fs); 1534 - if (!*new_fsp) 1535 - return -ENOMEM; 1536 - } 1537 1538 return 0; 1539 } ··· 1653 1654 if (new_fs) { 1655 fs = current->fs; 1656 current->fs = new_fs; 1657 - new_fs = fs; 1658 } 1659 1660 if (new_mm) { ··· 1698 1699 bad_unshare_cleanup_fs: 1700 if (new_fs) 1701 - put_fs_struct(new_fs); 1702 1703 bad_unshare_cleanup_thread: 1704 bad_unshare_out:
··· 60 #include <linux/tty.h> 61 #include <linux/proc_fs.h> 62 #include <linux/blkdev.h> 63 + #include <linux/fs_struct.h> 64 #include <trace/sched.h> 65 #include <linux/magic.h> 66 ··· 681 return retval; 682 } 683 684 static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) 685 { 686 + struct fs_struct *fs = current->fs; 687 if (clone_flags & CLONE_FS) { 688 + /* tsk->fs is already what we want */ 689 + write_lock(&fs->lock); 690 + if (fs->in_exec) { 691 + write_unlock(&fs->lock); 692 + return -EAGAIN; 693 + } 694 + fs->users++; 695 + write_unlock(&fs->lock); 696 return 0; 697 } 698 + tsk->fs = copy_fs_struct(fs); 699 if (!tsk->fs) 700 return -ENOMEM; 701 return 0; ··· 1544 { 1545 struct fs_struct *fs = current->fs; 1546 1547 + if (!(unshare_flags & CLONE_FS) || !fs) 1548 + return 0; 1549 + 1550 + /* don't need lock here; in the worst case we'll do useless copy */ 1551 + if (fs->users == 1) 1552 + return 0; 1553 + 1554 + *new_fsp = copy_fs_struct(fs); 1555 + if (!*new_fsp) 1556 + return -ENOMEM; 1557 1558 return 0; 1559 } ··· 1665 1666 if (new_fs) { 1667 fs = current->fs; 1668 + write_lock(&fs->lock); 1669 current->fs = new_fs; 1670 + if (--fs->users) 1671 + new_fs = NULL; 1672 + else 1673 + new_fs = fs; 1674 + write_unlock(&fs->lock); 1675 } 1676 1677 if (new_mm) { ··· 1705 1706 bad_unshare_cleanup_fs: 1707 if (new_fs) 1708 + free_fs_struct(new_fs); 1709 1710 bad_unshare_cleanup_thread: 1711 bad_unshare_out:
+1
kernel/sys.c
··· 34 #include <linux/seccomp.h> 35 #include <linux/cpu.h> 36 #include <linux/ptrace.h> 37 38 #include <linux/compat.h> 39 #include <linux/syscalls.h>
··· 34 #include <linux/seccomp.h> 35 #include <linux/cpu.h> 36 #include <linux/ptrace.h> 37 + #include <linux/fs_struct.h> 38 39 #include <linux/compat.h> 40 #include <linux/syscalls.h>
+1 -1
net/unix/af_unix.c
··· 832 * All right, let's create it. 833 */ 834 mode = S_IFSOCK | 835 - (SOCK_INODE(sock)->i_mode & ~current->fs->umask); 836 err = mnt_want_write(nd.path.mnt); 837 if (err) 838 goto out_mknod_dput;
··· 832 * All right, let's create it. 833 */ 834 mode = S_IFSOCK | 835 + (SOCK_INODE(sock)->i_mode & ~current_umask()); 836 err = mnt_want_write(nd.path.mnt); 837 if (err) 838 goto out_mknod_dput;
+1
security/tomoyo/realpath.c
··· 12 #include <linux/types.h> 13 #include <linux/mount.h> 14 #include <linux/mnt_namespace.h> 15 #include "common.h" 16 #include "realpath.h" 17
··· 12 #include <linux/types.h> 13 #include <linux/mount.h> 14 #include <linux/mnt_namespace.h> 15 + #include <linux/fs_struct.h> 16 #include "common.h" 17 #include "realpath.h" 18