Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6: (38 commits)
direct I/O fallback sync simplification
ocfs: stop using do_sync_mapping_range
cleanup blockdev_direct_IO locking
make generic_acl slightly more generic
sanitize xattr handler prototypes
libfs: move EXPORT_SYMBOL for d_alloc_name
vfs: force reval of target when following LAST_BIND symlinks (try #7)
ima: limit imbalance msg
Untangling ima mess, part 3: kill dead code in ima
Untangling ima mess, part 2: deal with counters
Untangling ima mess, part 1: alloc_file()
O_TRUNC open shouldn't fail after file truncation
ima: call ima_inode_free ima_inode_free
IMA: clean up the IMA counts updating code
ima: only insert at inode creation time
ima: valid return code from ima_inode_alloc
fs: move get_empty_filp() deffinition to internal.h
Sanitize exec_permission_lite()
Kill cached_lookup() and real_lookup()
Kill path_lookup_open()
...

Trivial conflicts in fs/direct-io.c

+1173 -1832
+8 -7
arch/ia64/kernel/perfmon.c
··· 2200 { 2201 struct file *file; 2202 struct inode *inode; 2203 - struct dentry *dentry; 2204 char name[32]; 2205 struct qstr this; 2206 ··· 2225 /* 2226 * allocate a new dcache entry 2227 */ 2228 - dentry = d_alloc(pfmfs_mnt->mnt_sb->s_root, &this); 2229 - if (!dentry) { 2230 iput(inode); 2231 return ERR_PTR(-ENOMEM); 2232 } 2233 2234 - dentry->d_op = &pfmfs_dentry_operations; 2235 - d_add(dentry, inode); 2236 2237 - file = alloc_file(pfmfs_mnt, dentry, FMODE_READ, &pfm_file_ops); 2238 if (!file) { 2239 - dput(dentry); 2240 return ERR_PTR(-ENFILE); 2241 } 2242
··· 2200 { 2201 struct file *file; 2202 struct inode *inode; 2203 + struct path path; 2204 char name[32]; 2205 struct qstr this; 2206 ··· 2225 /* 2226 * allocate a new dcache entry 2227 */ 2228 + path.dentry = d_alloc(pfmfs_mnt->mnt_sb->s_root, &this); 2229 + if (!path.dentry) { 2230 iput(inode); 2231 return ERR_PTR(-ENOMEM); 2232 } 2233 + path.mnt = mntget(pfmfs_mnt); 2234 2235 + path.dentry->d_op = &pfmfs_dentry_operations; 2236 + d_add(path.dentry, inode); 2237 2238 + file = alloc_file(&path, FMODE_READ, &pfm_file_ops); 2239 if (!file) { 2240 + path_put(&path); 2241 return ERR_PTR(-ENFILE); 2242 } 2243
+1 -6
arch/parisc/hpux/sys_hpux.c
··· 445 446 int hpux_pipe(int *kstack_fildes) 447 { 448 - int error; 449 - 450 - lock_kernel(); 451 - error = do_pipe_flags(kstack_fildes, 0); 452 - unlock_kernel(); 453 - return error; 454 } 455 456 /* lies - says it works, but it really didn't lock anything */
··· 445 446 int hpux_pipe(int *kstack_fildes) 447 { 448 + return do_pipe_flags(kstack_fildes, 0); 449 } 450 451 /* lies - says it works, but it really didn't lock anything */
-1
arch/x86/include/asm/sys_ia32.h
··· 30 asmlinkage long sys32_mmap(struct mmap_arg_struct __user *); 31 asmlinkage long sys32_mprotect(unsigned long, size_t, unsigned long); 32 33 - asmlinkage long sys32_pipe(int __user *); 34 struct sigaction32; 35 struct old_sigaction32; 36 asmlinkage long sys32_rt_sigaction(int, struct sigaction32 __user *,
··· 30 asmlinkage long sys32_mmap(struct mmap_arg_struct __user *); 31 asmlinkage long sys32_mprotect(unsigned long, size_t, unsigned long); 32 33 struct sigaction32; 34 struct old_sigaction32; 35 asmlinkage long sys32_rt_sigaction(int, struct sigaction32 __user *,
-1
arch/xtensa/include/asm/syscall.h
··· 12 struct sigaction; 13 asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*); 14 asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*); 15 - asmlinkage long xtensa_pipe(int __user *); 16 asmlinkage long xtensa_ptrace(long, long, long, long); 17 asmlinkage long xtensa_sigreturn(struct pt_regs*); 18 asmlinkage long xtensa_rt_sigreturn(struct pt_regs*);
··· 12 struct sigaction; 13 asmlinkage long xtensa_execve(char*, char**, char**, struct pt_regs*); 14 asmlinkage long xtensa_clone(unsigned long, unsigned long, struct pt_regs*); 15 asmlinkage long xtensa_ptrace(long, long, long, long); 16 asmlinkage long xtensa_sigreturn(struct pt_regs*); 17 asmlinkage long xtensa_rt_sigreturn(struct pt_regs*);
+1 -1
arch/xtensa/include/asm/unistd.h
··· 94 #define __NR_mknod 36 95 __SYSCALL( 36, sys_mknod, 3) 96 #define __NR_pipe 37 97 - __SYSCALL( 37, xtensa_pipe, 1) 98 #define __NR_unlink 38 99 __SYSCALL( 38, sys_unlink, 1) 100 #define __NR_rmdir 39
··· 94 #define __NR_mknod 36 95 __SYSCALL( 36, sys_mknod, 3) 96 #define __NR_pipe 37 97 + __SYSCALL( 37, sys_pipe, 1) 98 #define __NR_unlink 38 99 __SYSCALL( 38, sys_unlink, 1) 100 #define __NR_rmdir 39
-18
arch/xtensa/kernel/syscall.c
··· 39 #include <asm/unistd.h> 40 }; 41 42 - /* 43 - * xtensa_pipe() is the normal C calling standard for creating a pipe. It's not 44 - * the way unix traditional does this, though. 45 - */ 46 - 47 - asmlinkage long xtensa_pipe(int __user *userfds) 48 - { 49 - int fd[2]; 50 - int error; 51 - 52 - error = do_pipe_flags(fd, 0); 53 - if (!error) { 54 - if (copy_to_user(userfds, fd, 2 * sizeof(int))) 55 - error = -EFAULT; 56 - } 57 - return error; 58 - } 59 - 60 asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) 61 { 62 unsigned long ret;
··· 39 #include <asm/unistd.h> 40 }; 41 42 asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg) 43 { 44 unsigned long ret;
+7 -2
drivers/infiniband/core/uverbs_main.c
··· 492 int is_async, int *fd) 493 { 494 struct ib_uverbs_event_file *ev_file; 495 struct file *filp; 496 int ret; 497 ··· 520 * system call on a uverbs file, which will already have a 521 * module reference. 522 */ 523 - filp = alloc_file(uverbs_event_mnt, dget(uverbs_event_mnt->mnt_root), 524 - FMODE_READ, fops_get(&uverbs_event_fops)); 525 if (!filp) { 526 ret = -ENFILE; 527 goto err_fd; ··· 534 return filp; 535 536 err_fd: 537 put_unused_fd(*fd); 538 539 err:
··· 492 int is_async, int *fd) 493 { 494 struct ib_uverbs_event_file *ev_file; 495 + struct path path; 496 struct file *filp; 497 int ret; 498 ··· 519 * system call on a uverbs file, which will already have a 520 * module reference. 521 */ 522 + path.mnt = uverbs_event_mnt; 523 + path.dentry = uverbs_event_mnt->mnt_root; 524 + path_get(&path); 525 + filp = alloc_file(&path, FMODE_READ, fops_get(&uverbs_event_fops)); 526 if (!filp) { 527 ret = -ENFILE; 528 goto err_fd; ··· 531 return filp; 532 533 err_fd: 534 + fops_put(&uverbs_event_fops); 535 + path_put(&path); 536 put_unused_fd(*fd); 537 538 err:
+5 -41
drivers/staging/dst/dcore.c
··· 403 404 if (n->bdev) { 405 sync_blockdev(n->bdev); 406 - blkdev_put(n->bdev, FMODE_READ|FMODE_WRITE); 407 } 408 409 dst_state_lock(st); ··· 464 } 465 466 /* 467 - * This function finds devices major/minor numbers for given pathname. 468 - */ 469 - static int dst_lookup_device(const char *path, dev_t *dev) 470 - { 471 - int err; 472 - struct nameidata nd; 473 - struct inode *inode; 474 - 475 - err = path_lookup(path, LOOKUP_FOLLOW, &nd); 476 - if (err) 477 - return err; 478 - 479 - inode = nd.path.dentry->d_inode; 480 - if (!inode) { 481 - err = -ENOENT; 482 - goto out; 483 - } 484 - 485 - if (!S_ISBLK(inode->i_mode)) { 486 - err = -ENOTBLK; 487 - goto out; 488 - } 489 - 490 - *dev = inode->i_rdev; 491 - 492 - out: 493 - path_put(&nd.path); 494 - return err; 495 - } 496 - 497 - /* 498 * Setting up export device: lookup by the name, get its size 499 * and setup listening socket, which will accept clients, which 500 * will submit IO for given storage. ··· 472 struct dst_export_ctl *le) 473 { 474 int err; 475 - dev_t dev = 0; /* gcc likes to scream here */ 476 477 snprintf(n->info->local, sizeof(n->info->local), "%s", le->device); 478 479 - err = dst_lookup_device(le->device, &dev); 480 - if (err) 481 - return err; 482 - 483 - n->bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE); 484 - if (!n->bdev) 485 - return -ENODEV; 486 487 if (n->size != 0) 488 n->size = min_t(loff_t, n->bdev->bd_inode->i_size, n->size); ··· 492 return 0; 493 494 err_out_cleanup: 495 - blkdev_put(n->bdev, FMODE_READ|FMODE_WRITE); 496 n->bdev = NULL; 497 498 return err;
··· 403 404 if (n->bdev) { 405 sync_blockdev(n->bdev); 406 + close_bdev_exclusive(n->bdev, FMODE_READ|FMODE_WRITE); 407 } 408 409 dst_state_lock(st); ··· 464 } 465 466 /* 467 * Setting up export device: lookup by the name, get its size 468 * and setup listening socket, which will accept clients, which 469 * will submit IO for given storage. ··· 503 struct dst_export_ctl *le) 504 { 505 int err; 506 507 snprintf(n->info->local, sizeof(n->info->local), "%s", le->device); 508 509 + n->bdev = open_bdev_exclusive(le->device, FMODE_READ|FMODE_WRITE, NULL); 510 + if (IS_ERR(n->bdev)) 511 + return PTR_ERR(n->bdev); 512 513 if (n->size != 0) 514 n->size = min_t(loff_t, n->bdev->bd_inode->i_size, n->size); ··· 528 return 0; 529 530 err_out_cleanup: 531 + close_bdev_exclusive(n->bdev, FMODE_READ|FMODE_WRITE); 532 n->bdev = NULL; 533 534 return err;
+9 -9
fs/anon_inodes.c
··· 88 void *priv, int flags) 89 { 90 struct qstr this; 91 - struct dentry *dentry; 92 struct file *file; 93 int error; 94 ··· 106 this.name = name; 107 this.len = strlen(name); 108 this.hash = 0; 109 - dentry = d_alloc(anon_inode_mnt->mnt_sb->s_root, &this); 110 - if (!dentry) 111 goto err_module; 112 113 /* 114 * We know the anon_inode inode count is always greater than zero, 115 * so we can avoid doing an igrab() and we can use an open-coded ··· 118 */ 119 atomic_inc(&anon_inode_inode->i_count); 120 121 - dentry->d_op = &anon_inodefs_dentry_operations; 122 /* Do not publish this dentry inside the global dentry hash table */ 123 - dentry->d_flags &= ~DCACHE_UNHASHED; 124 - d_instantiate(dentry, anon_inode_inode); 125 126 error = -ENFILE; 127 - file = alloc_file(anon_inode_mnt, dentry, 128 - FMODE_READ | FMODE_WRITE, fops); 129 if (!file) 130 goto err_dput; 131 file->f_mapping = anon_inode_inode->i_mapping; ··· 137 return file; 138 139 err_dput: 140 - dput(dentry); 141 err_module: 142 module_put(fops->owner); 143 return ERR_PTR(error);
··· 88 void *priv, int flags) 89 { 90 struct qstr this; 91 + struct path path; 92 struct file *file; 93 int error; 94 ··· 106 this.name = name; 107 this.len = strlen(name); 108 this.hash = 0; 109 + path.dentry = d_alloc(anon_inode_mnt->mnt_sb->s_root, &this); 110 + if (!path.dentry) 111 goto err_module; 112 113 + path.mnt = mntget(anon_inode_mnt); 114 /* 115 * We know the anon_inode inode count is always greater than zero, 116 * so we can avoid doing an igrab() and we can use an open-coded ··· 117 */ 118 atomic_inc(&anon_inode_inode->i_count); 119 120 + path.dentry->d_op = &anon_inodefs_dentry_operations; 121 /* Do not publish this dentry inside the global dentry hash table */ 122 + path.dentry->d_flags &= ~DCACHE_UNHASHED; 123 + d_instantiate(path.dentry, anon_inode_inode); 124 125 error = -ENFILE; 126 + file = alloc_file(&path, FMODE_READ | FMODE_WRITE, fops); 127 if (!file) 128 goto err_dput; 129 file->f_mapping = anon_inode_inode->i_mapping; ··· 137 return file; 138 139 err_dput: 140 + path_put(&path); 141 err_module: 142 module_put(fops->owner); 143 return ERR_PTR(error);
+12 -35
fs/btrfs/acl.c
··· 73 return acl; 74 } 75 76 - static int btrfs_xattr_get_acl(struct inode *inode, int type, 77 - void *value, size_t size) 78 { 79 struct posix_acl *acl; 80 int ret = 0; 81 82 - acl = btrfs_get_acl(inode, type); 83 84 if (IS_ERR(acl)) 85 return PTR_ERR(acl); ··· 151 return ret; 152 } 153 154 - static int btrfs_xattr_set_acl(struct inode *inode, int type, 155 - const void *value, size_t size) 156 { 157 int ret = 0; 158 struct posix_acl *acl = NULL; ··· 167 } 168 } 169 170 - ret = btrfs_set_acl(inode, acl, type); 171 172 posix_acl_release(acl); 173 174 return ret; 175 - } 176 - 177 - 178 - static int btrfs_xattr_acl_access_get(struct inode *inode, const char *name, 179 - void *value, size_t size) 180 - { 181 - return btrfs_xattr_get_acl(inode, ACL_TYPE_ACCESS, value, size); 182 - } 183 - 184 - static int btrfs_xattr_acl_access_set(struct inode *inode, const char *name, 185 - const void *value, size_t size, int flags) 186 - { 187 - return btrfs_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 188 - } 189 - 190 - static int btrfs_xattr_acl_default_get(struct inode *inode, const char *name, 191 - void *value, size_t size) 192 - { 193 - return btrfs_xattr_get_acl(inode, ACL_TYPE_DEFAULT, value, size); 194 - } 195 - 196 - static int btrfs_xattr_acl_default_set(struct inode *inode, const char *name, 197 - const void *value, size_t size, int flags) 198 - { 199 - return btrfs_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 200 } 201 202 int btrfs_check_acl(struct inode *inode, int mask) ··· 278 279 struct xattr_handler btrfs_xattr_acl_default_handler = { 280 .prefix = POSIX_ACL_XATTR_DEFAULT, 281 - .get = btrfs_xattr_acl_default_get, 282 - .set = btrfs_xattr_acl_default_set, 283 }; 284 285 struct xattr_handler btrfs_xattr_acl_access_handler = { 286 .prefix = POSIX_ACL_XATTR_ACCESS, 287 - .get = btrfs_xattr_acl_access_get, 288 - .set = btrfs_xattr_acl_access_set, 289 }; 290 291 #else /* CONFIG_BTRFS_FS_POSIX_ACL */
··· 73 return acl; 74 } 75 76 + static int btrfs_xattr_acl_get(struct dentry *dentry, const char *name, 77 + void *value, size_t size, int type) 78 { 79 struct posix_acl *acl; 80 int ret = 0; 81 82 + acl = btrfs_get_acl(dentry->d_inode, type); 83 84 if (IS_ERR(acl)) 85 return PTR_ERR(acl); ··· 151 return ret; 152 } 153 154 + static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, 155 + const void *value, size_t size, int flags, int type) 156 { 157 int ret = 0; 158 struct posix_acl *acl = NULL; ··· 167 } 168 } 169 170 + ret = btrfs_set_acl(dentry->d_inode, acl, type); 171 172 posix_acl_release(acl); 173 174 return ret; 175 } 176 177 int btrfs_check_acl(struct inode *inode, int mask) ··· 303 304 struct xattr_handler btrfs_xattr_acl_default_handler = { 305 .prefix = POSIX_ACL_XATTR_DEFAULT, 306 + .flags = ACL_TYPE_DEFAULT, 307 + .get = btrfs_xattr_acl_get, 308 + .set = btrfs_xattr_acl_set, 309 }; 310 311 struct xattr_handler btrfs_xattr_acl_access_handler = { 312 .prefix = POSIX_ACL_XATTR_ACCESS, 313 + .flags = ACL_TYPE_ACCESS, 314 + .get = btrfs_xattr_acl_get, 315 + .set = btrfs_xattr_acl_set, 316 }; 317 318 #else /* CONFIG_BTRFS_FS_POSIX_ACL */
+4 -7
fs/cachefiles/bind.c
··· 84 static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache) 85 { 86 struct cachefiles_object *fsdef; 87 - struct nameidata nd; 88 struct kstatfs stats; 89 struct dentry *graveyard, *cachedir, *root; 90 const struct cred *saved_cred; ··· 114 _debug("- fsdef %p", fsdef); 115 116 /* look up the directory at the root of the cache */ 117 - memset(&nd, 0, sizeof(nd)); 118 - 119 - ret = path_lookup(cache->rootdirname, LOOKUP_DIRECTORY, &nd); 120 if (ret < 0) 121 goto error_open_root; 122 123 - cache->mnt = mntget(nd.path.mnt); 124 - root = dget(nd.path.dentry); 125 - path_put(&nd.path); 126 127 /* check parameters */ 128 ret = -EOPNOTSUPP;
··· 84 static int cachefiles_daemon_add_cache(struct cachefiles_cache *cache) 85 { 86 struct cachefiles_object *fsdef; 87 + struct path path; 88 struct kstatfs stats; 89 struct dentry *graveyard, *cachedir, *root; 90 const struct cred *saved_cred; ··· 114 _debug("- fsdef %p", fsdef); 115 116 /* look up the directory at the root of the cache */ 117 + ret = kern_path(cache->rootdirname, LOOKUP_DIRECTORY, &path); 118 if (ret < 0) 119 goto error_open_root; 120 121 + cache->mnt = path.mnt; 122 + root = path.dentry; 123 124 /* check parameters */ 125 ret = -EOPNOTSUPP;
-2
fs/cachefiles/rdwr.c
··· 11 12 #include <linux/mount.h> 13 #include <linux/file.h> 14 - #include <linux/ima.h> 15 #include "internal.h" 16 17 /* ··· 922 if (IS_ERR(file)) { 923 ret = PTR_ERR(file); 924 } else { 925 - ima_counts_get(file); 926 ret = -EIO; 927 if (file->f_op->write) { 928 pos = (loff_t) page->index << PAGE_SHIFT;
··· 11 12 #include <linux/mount.h> 13 #include <linux/file.h> 14 #include "internal.h" 15 16 /* ··· 923 if (IS_ERR(file)) { 924 ret = PTR_ERR(file); 925 } else { 926 ret = -EIO; 927 if (file->f_op->write) { 928 pos = (loff_t) page->index << PAGE_SHIFT;
+1
fs/dcache.c
··· 978 q.hash = full_name_hash(q.name, q.len); 979 return d_alloc(parent, &q); 980 } 981 982 /* the caller must hold dcache_lock */ 983 static void __d_instantiate(struct dentry *dentry, struct inode *inode)
··· 978 q.hash = full_name_hash(q.name, q.len); 979 return d_alloc(parent, &q); 980 } 981 + EXPORT_SYMBOL(d_alloc_name); 982 983 /* the caller must hold dcache_lock */ 984 static void __d_instantiate(struct dentry *dentry, struct inode *inode)
+1 -6
fs/ecryptfs/main.c
··· 35 #include <linux/key.h> 36 #include <linux/parser.h> 37 #include <linux/fs_stack.h> 38 - #include <linux/ima.h> 39 #include "ecryptfs_kernel.h" 40 41 /** ··· 118 const struct cred *cred = current_cred(); 119 struct ecryptfs_inode_info *inode_info = 120 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); 121 - int opened_lower_file = 0; 122 int rc = 0; 123 124 mutex_lock(&inode_info->lower_file_mutex); ··· 134 "for lower_dentry [0x%p] and lower_mnt [0x%p]; " 135 "rc = [%d]\n", lower_dentry, lower_mnt, rc); 136 inode_info->lower_file = NULL; 137 - } else 138 - opened_lower_file = 1; 139 } 140 mutex_unlock(&inode_info->lower_file_mutex); 141 - if (opened_lower_file) 142 - ima_counts_get(inode_info->lower_file); 143 return rc; 144 } 145
··· 35 #include <linux/key.h> 36 #include <linux/parser.h> 37 #include <linux/fs_stack.h> 38 #include "ecryptfs_kernel.h" 39 40 /** ··· 119 const struct cred *cred = current_cred(); 120 struct ecryptfs_inode_info *inode_info = 121 ecryptfs_inode_to_private(ecryptfs_dentry->d_inode); 122 int rc = 0; 123 124 mutex_lock(&inode_info->lower_file_mutex); ··· 136 "for lower_dentry [0x%p] and lower_mnt [0x%p]; " 137 "rc = [%d]\n", lower_dentry, lower_mnt, rc); 138 inode_info->lower_file = NULL; 139 + } 140 } 141 mutex_unlock(&inode_info->lower_file_mutex); 142 return rc; 143 } 144
+25 -54
fs/ext2/acl.c
··· 339 * Extended attribut handlers 340 */ 341 static size_t 342 - ext2_xattr_list_acl_access(struct inode *inode, char *list, size_t list_size, 343 - const char *name, size_t name_len) 344 { 345 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 346 347 - if (!test_opt(inode->i_sb, POSIX_ACL)) 348 return 0; 349 if (list && size <= list_size) 350 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 352 } 353 354 static size_t 355 - ext2_xattr_list_acl_default(struct inode *inode, char *list, size_t list_size, 356 - const char *name, size_t name_len) 357 { 358 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 359 360 - if (!test_opt(inode->i_sb, POSIX_ACL)) 361 return 0; 362 if (list && size <= list_size) 363 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 365 } 366 367 static int 368 - ext2_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) 369 { 370 struct posix_acl *acl; 371 int error; 372 373 - if (!test_opt(inode->i_sb, POSIX_ACL)) 374 return -EOPNOTSUPP; 375 376 - acl = ext2_get_acl(inode, type); 377 if (IS_ERR(acl)) 378 return PTR_ERR(acl); 379 if (acl == NULL) ··· 388 } 389 390 static int 391 - ext2_xattr_get_acl_access(struct inode *inode, const char *name, 392 - void *buffer, size_t size) 393 - { 394 - if (strcmp(name, "") != 0) 395 - return -EINVAL; 396 - return ext2_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 397 - } 398 - 399 - static int 400 - ext2_xattr_get_acl_default(struct inode *inode, const char *name, 401 - void *buffer, size_t size) 402 - { 403 - if (strcmp(name, "") != 0) 404 - return -EINVAL; 405 - return ext2_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 406 - } 407 - 408 - static int 409 - ext2_xattr_set_acl(struct inode *inode, int type, const void *value, 410 - size_t size) 411 { 412 struct posix_acl *acl; 413 int error; 414 415 - if (!test_opt(inode->i_sb, POSIX_ACL)) 416 return -EOPNOTSUPP; 417 - if (!is_owner_or_cap(inode)) 418 return -EPERM; 419 420 if (value) { ··· 413 } else 414 acl = NULL; 415 416 - error = ext2_set_acl(inode, type, acl); 417 418 release_and_out: 419 posix_acl_release(acl); 420 return error; 421 } 422 423 - static int 424 - ext2_xattr_set_acl_access(struct inode *inode, const char *name, 425 - const void *value, size_t size, int flags) 426 - { 427 - if (strcmp(name, "") != 0) 428 - return -EINVAL; 429 - return ext2_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 430 - } 431 - 432 - static int 433 - ext2_xattr_set_acl_default(struct inode *inode, const char *name, 434 - const void *value, size_t size, int flags) 435 - { 436 - if (strcmp(name, "") != 0) 437 - return -EINVAL; 438 - return ext2_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 439 - } 440 - 441 struct xattr_handler ext2_xattr_acl_access_handler = { 442 .prefix = POSIX_ACL_XATTR_ACCESS, 443 .list = ext2_xattr_list_acl_access, 444 - .get = ext2_xattr_get_acl_access, 445 - .set = ext2_xattr_set_acl_access, 446 }; 447 448 struct xattr_handler ext2_xattr_acl_default_handler = { 449 .prefix = POSIX_ACL_XATTR_DEFAULT, 450 .list = ext2_xattr_list_acl_default, 451 - .get = ext2_xattr_get_acl_default, 452 - .set = ext2_xattr_set_acl_default, 453 };
··· 339 * Extended attribut handlers 340 */ 341 static size_t 342 + ext2_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_size, 343 + const char *name, size_t name_len, int type) 344 { 345 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 346 347 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 348 return 0; 349 if (list && size <= list_size) 350 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 352 } 353 354 static size_t 355 + ext2_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_size, 356 + const char *name, size_t name_len, int type) 357 { 358 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 359 360 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 361 return 0; 362 if (list && size <= list_size) 363 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 365 } 366 367 static int 368 + ext2_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, 369 + size_t size, int type) 370 { 371 struct posix_acl *acl; 372 int error; 373 374 + if (strcmp(name, "") != 0) 375 + return -EINVAL; 376 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 377 return -EOPNOTSUPP; 378 379 + acl = ext2_get_acl(dentry->d_inode, type); 380 if (IS_ERR(acl)) 381 return PTR_ERR(acl); 382 if (acl == NULL) ··· 385 } 386 387 static int 388 + ext2_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, 389 + size_t size, int flags, int type) 390 { 391 struct posix_acl *acl; 392 int error; 393 394 + if (strcmp(name, "") != 0) 395 + return -EINVAL; 396 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 397 return -EOPNOTSUPP; 398 + if (!is_owner_or_cap(dentry->d_inode)) 399 return -EPERM; 400 401 if (value) { ··· 426 } else 427 acl = NULL; 428 429 + error = ext2_set_acl(dentry->d_inode, type, acl); 430 431 release_and_out: 432 posix_acl_release(acl); 433 return error; 434 } 435 436 struct xattr_handler ext2_xattr_acl_access_handler = { 437 .prefix = POSIX_ACL_XATTR_ACCESS, 438 + .flags = ACL_TYPE_ACCESS, 439 .list = ext2_xattr_list_acl_access, 440 + .get = ext2_xattr_get_acl, 441 + .set = ext2_xattr_set_acl, 442 }; 443 444 struct xattr_handler ext2_xattr_acl_default_handler = { 445 .prefix = POSIX_ACL_XATTR_DEFAULT, 446 + .flags = ACL_TYPE_DEFAULT, 447 .list = ext2_xattr_list_acl_default, 448 + .get = ext2_xattr_get_acl, 449 + .set = ext2_xattr_set_acl, 450 };
+7 -4
fs/ext2/xattr.c
··· 60 #include <linux/mbcache.h> 61 #include <linux/quotaops.h> 62 #include <linux/rwsem.h> 63 #include "ext2.h" 64 #include "xattr.h" 65 #include "acl.h" ··· 250 * used / required on success. 251 */ 252 static int 253 - ext2_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 254 { 255 struct buffer_head *bh = NULL; 256 struct ext2_xattr_entry *entry; 257 char *end; ··· 302 ext2_xattr_handler(entry->e_name_index); 303 304 if (handler) { 305 - size_t size = handler->list(inode, buffer, rest, 306 entry->e_name, 307 - entry->e_name_len); 308 if (buffer) { 309 if (size > rest) { 310 error = -ERANGE; ··· 333 ssize_t 334 ext2_listxattr(struct dentry *dentry, char *buffer, size_t size) 335 { 336 - return ext2_xattr_list(dentry->d_inode, buffer, size); 337 } 338 339 /*
··· 60 #include <linux/mbcache.h> 61 #include <linux/quotaops.h> 62 #include <linux/rwsem.h> 63 + #include <linux/security.h> 64 #include "ext2.h" 65 #include "xattr.h" 66 #include "acl.h" ··· 249 * used / required on success. 250 */ 251 static int 252 + ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size) 253 { 254 + struct inode *inode = dentry->d_inode; 255 struct buffer_head *bh = NULL; 256 struct ext2_xattr_entry *entry; 257 char *end; ··· 300 ext2_xattr_handler(entry->e_name_index); 301 302 if (handler) { 303 + size_t size = handler->list(dentry, buffer, rest, 304 entry->e_name, 305 + entry->e_name_len, 306 + handler->flags); 307 if (buffer) { 308 if (size > rest) { 309 error = -ERANGE; ··· 330 ssize_t 331 ext2_listxattr(struct dentry *dentry, char *buffer, size_t size) 332 { 333 + return ext2_xattr_list(dentry, buffer, size); 334 } 335 336 /*
+8 -8
fs/ext2/xattr_security.c
··· 11 #include "xattr.h" 12 13 static size_t 14 - ext2_xattr_security_list(struct inode *inode, char *list, size_t list_size, 15 - const char *name, size_t name_len) 16 { 17 const int prefix_len = XATTR_SECURITY_PREFIX_LEN; 18 const size_t total_len = prefix_len + name_len + 1; ··· 26 } 27 28 static int 29 - ext2_xattr_security_get(struct inode *inode, const char *name, 30 - void *buffer, size_t size) 31 { 32 if (strcmp(name, "") == 0) 33 return -EINVAL; 34 - return ext2_xattr_get(inode, EXT2_XATTR_INDEX_SECURITY, name, 35 buffer, size); 36 } 37 38 static int 39 - ext2_xattr_security_set(struct inode *inode, const char *name, 40 - const void *value, size_t size, int flags) 41 { 42 if (strcmp(name, "") == 0) 43 return -EINVAL; 44 - return ext2_xattr_set(inode, EXT2_XATTR_INDEX_SECURITY, name, 45 value, size, flags); 46 } 47
··· 11 #include "xattr.h" 12 13 static size_t 14 + ext2_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, 15 + const char *name, size_t name_len, int type) 16 { 17 const int prefix_len = XATTR_SECURITY_PREFIX_LEN; 18 const size_t total_len = prefix_len + name_len + 1; ··· 26 } 27 28 static int 29 + ext2_xattr_security_get(struct dentry *dentry, const char *name, 30 + void *buffer, size_t size, int type) 31 { 32 if (strcmp(name, "") == 0) 33 return -EINVAL; 34 + return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_SECURITY, name, 35 buffer, size); 36 } 37 38 static int 39 + ext2_xattr_security_set(struct dentry *dentry, const char *name, 40 + const void *value, size_t size, int flags, int type) 41 { 42 if (strcmp(name, "") == 0) 43 return -EINVAL; 44 + return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_SECURITY, name, 45 value, size, flags); 46 } 47
+8 -8
fs/ext2/xattr_trusted.c
··· 13 #include "xattr.h" 14 15 static size_t 16 - ext2_xattr_trusted_list(struct inode *inode, char *list, size_t list_size, 17 - const char *name, size_t name_len) 18 { 19 const int prefix_len = XATTR_TRUSTED_PREFIX_LEN; 20 const size_t total_len = prefix_len + name_len + 1; ··· 31 } 32 33 static int 34 - ext2_xattr_trusted_get(struct inode *inode, const char *name, 35 - void *buffer, size_t size) 36 { 37 if (strcmp(name, "") == 0) 38 return -EINVAL; 39 - return ext2_xattr_get(inode, EXT2_XATTR_INDEX_TRUSTED, name, 40 buffer, size); 41 } 42 43 static int 44 - ext2_xattr_trusted_set(struct inode *inode, const char *name, 45 - const void *value, size_t size, int flags) 46 { 47 if (strcmp(name, "") == 0) 48 return -EINVAL; 49 - return ext2_xattr_set(inode, EXT2_XATTR_INDEX_TRUSTED, name, 50 value, size, flags); 51 } 52
··· 13 #include "xattr.h" 14 15 static size_t 16 + ext2_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, 17 + const char *name, size_t name_len, int type) 18 { 19 const int prefix_len = XATTR_TRUSTED_PREFIX_LEN; 20 const size_t total_len = prefix_len + name_len + 1; ··· 31 } 32 33 static int 34 + ext2_xattr_trusted_get(struct dentry *dentry, const char *name, 35 + void *buffer, size_t size, int type) 36 { 37 if (strcmp(name, "") == 0) 38 return -EINVAL; 39 + return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name, 40 buffer, size); 41 } 42 43 static int 44 + ext2_xattr_trusted_set(struct dentry *dentry, const char *name, 45 + const void *value, size_t size, int flags, int type) 46 { 47 if (strcmp(name, "") == 0) 48 return -EINVAL; 49 + return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_TRUSTED, name, 50 value, size, flags); 51 } 52
+13 -12
fs/ext2/xattr_user.c
··· 12 #include "xattr.h" 13 14 static size_t 15 - ext2_xattr_user_list(struct inode *inode, char *list, size_t list_size, 16 - const char *name, size_t name_len) 17 { 18 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 19 const size_t total_len = prefix_len + name_len + 1; 20 21 - if (!test_opt(inode->i_sb, XATTR_USER)) 22 return 0; 23 24 if (list && total_len <= list_size) { ··· 30 } 31 32 static int 33 - ext2_xattr_user_get(struct inode *inode, const char *name, 34 - void *buffer, size_t size) 35 { 36 if (strcmp(name, "") == 0) 37 return -EINVAL; 38 - if (!test_opt(inode->i_sb, XATTR_USER)) 39 return -EOPNOTSUPP; 40 - return ext2_xattr_get(inode, EXT2_XATTR_INDEX_USER, name, buffer, size); 41 } 42 43 static int 44 - ext2_xattr_user_set(struct inode *inode, const char *name, 45 - const void *value, size_t size, int flags) 46 { 47 if (strcmp(name, "") == 0) 48 return -EINVAL; 49 - if (!test_opt(inode->i_sb, XATTR_USER)) 50 return -EOPNOTSUPP; 51 52 - return ext2_xattr_set(inode, EXT2_XATTR_INDEX_USER, name, 53 - value, size, flags); 54 } 55 56 struct xattr_handler ext2_xattr_user_handler = {
··· 12 #include "xattr.h" 13 14 static size_t 15 + ext2_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, 16 + const char *name, size_t name_len, int type) 17 { 18 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 19 const size_t total_len = prefix_len + name_len + 1; 20 21 + if (!test_opt(dentry->d_sb, XATTR_USER)) 22 return 0; 23 24 if (list && total_len <= list_size) { ··· 30 } 31 32 static int 33 + ext2_xattr_user_get(struct dentry *dentry, const char *name, 34 + void *buffer, size_t size, int type) 35 { 36 if (strcmp(name, "") == 0) 37 return -EINVAL; 38 + if (!test_opt(dentry->d_sb, XATTR_USER)) 39 return -EOPNOTSUPP; 40 + return ext2_xattr_get(dentry->d_inode, EXT2_XATTR_INDEX_USER, 41 + name, buffer, size); 42 } 43 44 static int 45 + ext2_xattr_user_set(struct dentry *dentry, const char *name, 46 + const void *value, size_t size, int flags, int type) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 + if (!test_opt(dentry->d_sb, XATTR_USER)) 51 return -EOPNOTSUPP; 52 53 + return ext2_xattr_set(dentry->d_inode, EXT2_XATTR_INDEX_USER, 54 + name, value, size, flags); 55 } 56 57 struct xattr_handler ext2_xattr_user_handler = {
+23 -51
fs/ext3/acl.c
··· 366 * Extended attribute handlers 367 */ 368 static size_t 369 - ext3_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len, 370 - const char *name, size_t name_len) 371 { 372 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 373 374 - if (!test_opt(inode->i_sb, POSIX_ACL)) 375 return 0; 376 if (list && size <= list_len) 377 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 379 } 380 381 static size_t 382 - ext3_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len, 383 - const char *name, size_t name_len) 384 { 385 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 386 387 - if (!test_opt(inode->i_sb, POSIX_ACL)) 388 return 0; 389 if (list && size <= list_len) 390 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 392 } 393 394 static int 395 - ext3_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) 396 { 397 struct posix_acl *acl; 398 int error; 399 400 - if (!test_opt(inode->i_sb, POSIX_ACL)) 401 return -EOPNOTSUPP; 402 403 - acl = ext3_get_acl(inode, type); 404 if (IS_ERR(acl)) 405 return PTR_ERR(acl); 406 if (acl == NULL) ··· 415 } 416 417 static int 418 - ext3_xattr_get_acl_access(struct inode *inode, const char *name, 419 - void *buffer, size_t size) 420 { 421 - if (strcmp(name, "") != 0) 422 - return -EINVAL; 423 - return ext3_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 424 - } 425 - 426 - static int 427 - ext3_xattr_get_acl_default(struct inode *inode, const char *name, 428 - void *buffer, size_t size) 429 - { 430 - if (strcmp(name, "") != 0) 431 - return -EINVAL; 432 - return ext3_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 433 - } 434 - 435 - static int 436 - ext3_xattr_set_acl(struct inode *inode, int type, const void *value, 437 - size_t size) 438 - { 439 handle_t *handle; 440 struct posix_acl *acl; 441 int error, retries = 0; 442 443 if (!test_opt(inode->i_sb, POSIX_ACL)) 444 return -EOPNOTSUPP; 445 if (!is_owner_or_cap(inode)) ··· 456 return error; 457 } 458 459 - static int 460 - ext3_xattr_set_acl_access(struct inode *inode, const char *name, 461 - const void *value, size_t size, int flags) 462 - { 463 - if (strcmp(name, "") != 0) 464 - return -EINVAL; 465 - return ext3_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 466 - } 467 - 468 - static int 469 - ext3_xattr_set_acl_default(struct inode *inode, const char *name, 470 - const void *value, size_t size, int flags) 471 - { 472 - if (strcmp(name, "") != 0) 473 - return -EINVAL; 474 - return ext3_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 475 - } 476 - 477 struct xattr_handler ext3_xattr_acl_access_handler = { 478 .prefix = POSIX_ACL_XATTR_ACCESS, 479 .list = ext3_xattr_list_acl_access, 480 - .get = ext3_xattr_get_acl_access, 481 - .set = ext3_xattr_set_acl_access, 482 }; 483 484 struct xattr_handler ext3_xattr_acl_default_handler = { 485 .prefix = POSIX_ACL_XATTR_DEFAULT, 486 .list = ext3_xattr_list_acl_default, 487 - .get = ext3_xattr_get_acl_default, 488 - .set = ext3_xattr_set_acl_default, 489 };
··· 366 * Extended attribute handlers 367 */ 368 static size_t 369 + ext3_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_len, 370 + const char *name, size_t name_len, int type) 371 { 372 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 373 374 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 375 return 0; 376 if (list && size <= list_len) 377 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 379 } 380 381 static size_t 382 + ext3_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_len, 383 + const char *name, size_t name_len, int type) 384 { 385 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 386 387 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 388 return 0; 389 if (list && size <= list_len) 390 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 392 } 393 394 static int 395 + ext3_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, 396 + size_t size, int type) 397 { 398 struct posix_acl *acl; 399 int error; 400 401 + if (strcmp(name, "") != 0) 402 + return -EINVAL; 403 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 404 return -EOPNOTSUPP; 405 406 + acl = ext3_get_acl(dentry->d_inode, type); 407 if (IS_ERR(acl)) 408 return PTR_ERR(acl); 409 if (acl == NULL) ··· 412 } 413 414 static int 415 + ext3_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, 416 + size_t size, int flags, int type) 417 { 418 + struct inode *inode = dentry->d_inode; 419 handle_t *handle; 420 struct posix_acl *acl; 421 int error, retries = 0; 422 423 + if (strcmp(name, "") != 0) 424 + return -EINVAL; 425 if (!test_opt(inode->i_sb, POSIX_ACL)) 426 return -EOPNOTSUPP; 427 if (!is_owner_or_cap(inode)) ··· 468 return error; 469 } 470 471 struct xattr_handler ext3_xattr_acl_access_handler = { 472 .prefix = POSIX_ACL_XATTR_ACCESS, 473 + .flags = ACL_TYPE_ACCESS, 474 .list = ext3_xattr_list_acl_access, 475 + .get = ext3_xattr_get_acl, 476 + .set = ext3_xattr_set_acl, 477 }; 478 479 struct xattr_handler ext3_xattr_acl_default_handler = { 480 .prefix = POSIX_ACL_XATTR_DEFAULT, 481 + .flags = ACL_TYPE_DEFAULT, 482 .list = ext3_xattr_list_acl_default, 483 + .get = ext3_xattr_get_acl, 484 + .set = ext3_xattr_set_acl, 485 };
+17 -14
fs/ext3/xattr.c
··· 99 struct mb_cache_entry **); 100 static void ext3_xattr_rehash(struct ext3_xattr_header *, 101 struct ext3_xattr_entry *); 102 - static int ext3_xattr_list(struct inode *inode, char *buffer, 103 size_t buffer_size); 104 105 static struct mb_cache *ext3_xattr_cache; ··· 147 ssize_t 148 ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) 149 { 150 - return ext3_xattr_list(dentry->d_inode, buffer, size); 151 } 152 153 static int ··· 332 } 333 334 static int 335 - ext3_xattr_list_entries(struct inode *inode, struct ext3_xattr_entry *entry, 336 char *buffer, size_t buffer_size) 337 { 338 size_t rest = buffer_size; ··· 342 ext3_xattr_handler(entry->e_name_index); 343 344 if (handler) { 345 - size_t size = handler->list(inode, buffer, rest, 346 entry->e_name, 347 - entry->e_name_len); 348 if (buffer) { 349 if (size > rest) 350 return -ERANGE; ··· 358 } 359 360 static int 361 - ext3_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) 362 { 363 struct buffer_head *bh = NULL; 364 int error; 365 ··· 385 goto cleanup; 386 } 387 ext3_xattr_cache_insert(bh); 388 - error = ext3_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size); 389 390 cleanup: 391 brelse(bh); ··· 394 } 395 396 static int 397 - ext3_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) 398 { 399 struct ext3_xattr_ibody_header *header; 400 struct ext3_inode *raw_inode; 401 struct ext3_iloc iloc; ··· 414 error = ext3_xattr_check_names(IFIRST(header), end); 415 if (error) 416 goto cleanup; 417 - error = ext3_xattr_list_entries(inode, IFIRST(header), 418 buffer, buffer_size); 419 420 cleanup: ··· 433 * used / required on success. 434 */ 435 static int 436 - ext3_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 437 { 438 int i_error, b_error; 439 440 - down_read(&EXT3_I(inode)->xattr_sem); 441 - i_error = ext3_xattr_ibody_list(inode, buffer, buffer_size); 442 if (i_error < 0) { 443 b_error = 0; 444 } else { ··· 446 buffer += i_error; 447 buffer_size -= i_error; 448 } 449 - b_error = ext3_xattr_block_list(inode, buffer, buffer_size); 450 if (b_error < 0) 451 i_error = 0; 452 } 453 - up_read(&EXT3_I(inode)->xattr_sem); 454 return i_error + b_error; 455 } 456
··· 99 struct mb_cache_entry **); 100 static void ext3_xattr_rehash(struct ext3_xattr_header *, 101 struct ext3_xattr_entry *); 102 + static int ext3_xattr_list(struct dentry *dentry, char *buffer, 103 size_t buffer_size); 104 105 static struct mb_cache *ext3_xattr_cache; ··· 147 ssize_t 148 ext3_listxattr(struct dentry *dentry, char *buffer, size_t size) 149 { 150 + return ext3_xattr_list(dentry, buffer, size); 151 } 152 153 static int ··· 332 } 333 334 static int 335 + ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry, 336 char *buffer, size_t buffer_size) 337 { 338 size_t rest = buffer_size; ··· 342 ext3_xattr_handler(entry->e_name_index); 343 344 if (handler) { 345 + size_t size = handler->list(dentry, buffer, rest, 346 entry->e_name, 347 + entry->e_name_len, 348 + handler->flags); 349 if (buffer) { 350 if (size > rest) 351 return -ERANGE; ··· 357 } 358 359 static int 360 + ext3_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size) 361 { 362 + struct inode *inode = dentry->d_inode; 363 struct buffer_head *bh = NULL; 364 int error; 365 ··· 383 goto cleanup; 384 } 385 ext3_xattr_cache_insert(bh); 386 + error = ext3_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size); 387 388 cleanup: 389 brelse(bh); ··· 392 } 393 394 static int 395 + ext3_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size) 396 { 397 + struct inode *inode = dentry->d_inode; 398 struct ext3_xattr_ibody_header *header; 399 struct ext3_inode *raw_inode; 400 struct ext3_iloc iloc; ··· 411 error = ext3_xattr_check_names(IFIRST(header), end); 412 if (error) 413 goto cleanup; 414 + error = ext3_xattr_list_entries(dentry, IFIRST(header), 415 buffer, buffer_size); 416 417 cleanup: ··· 430 * used / required on success. 431 */ 432 static int 433 + ext3_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size) 434 { 435 int i_error, b_error; 436 437 + down_read(&EXT3_I(dentry->d_inode)->xattr_sem); 438 + i_error = ext3_xattr_ibody_list(dentry, buffer, buffer_size); 439 if (i_error < 0) { 440 b_error = 0; 441 } else { ··· 443 buffer += i_error; 444 buffer_size -= i_error; 445 } 446 + b_error = ext3_xattr_block_list(dentry, buffer, buffer_size); 447 if (b_error < 0) 448 i_error = 0; 449 } 450 + up_read(&EXT3_I(dentry->d_inode)->xattr_sem); 451 return i_error + b_error; 452 } 453
+10 -10
fs/ext3/xattr_security.c
··· 12 #include "xattr.h" 13 14 static size_t 15 - ext3_xattr_security_list(struct inode *inode, char *list, size_t list_size, 16 - const char *name, size_t name_len) 17 { 18 const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; 19 const size_t total_len = prefix_len + name_len + 1; ··· 28 } 29 30 static int 31 - ext3_xattr_security_get(struct inode *inode, const char *name, 32 - void *buffer, size_t size) 33 { 34 if (strcmp(name, "") == 0) 35 return -EINVAL; 36 - return ext3_xattr_get(inode, EXT3_XATTR_INDEX_SECURITY, name, 37 - buffer, size); 38 } 39 40 static int 41 - ext3_xattr_security_set(struct inode *inode, const char *name, 42 - const void *value, size_t size, int flags) 43 { 44 if (strcmp(name, "") == 0) 45 return -EINVAL; 46 - return ext3_xattr_set(inode, EXT3_XATTR_INDEX_SECURITY, name, 47 - value, size, flags); 48 } 49 50 int
··· 12 #include "xattr.h" 13 14 static size_t 15 + ext3_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, 16 + const char *name, size_t name_len, int type) 17 { 18 const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; 19 const size_t total_len = prefix_len + name_len + 1; ··· 28 } 29 30 static int 31 + ext3_xattr_security_get(struct dentry *dentry, const char *name, 32 + void *buffer, size_t size, int type) 33 { 34 if (strcmp(name, "") == 0) 35 return -EINVAL; 36 + return ext3_xattr_get(dentry->d_inode, EXT3_XATTR_INDEX_SECURITY, 37 + name, buffer, size); 38 } 39 40 static int 41 + ext3_xattr_security_set(struct dentry *dentry, const char *name, 42 + const void *value, size_t size, int flags, int type) 43 { 44 if (strcmp(name, "") == 0) 45 return -EINVAL; 46 + return ext3_xattr_set(dentry->d_inode, EXT3_XATTR_INDEX_SECURITY, 47 + name, value, size, flags); 48 } 49 50 int
+9 -9
fs/ext3/xattr_trusted.c
··· 14 #include "xattr.h" 15 16 static size_t 17 - ext3_xattr_trusted_list(struct inode *inode, char *list, size_t list_size, 18 - const char *name, size_t name_len) 19 { 20 const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; 21 const size_t total_len = prefix_len + name_len + 1; ··· 32 } 33 34 static int 35 - ext3_xattr_trusted_get(struct inode *inode, const char *name, 36 - void *buffer, size_t size) 37 { 38 if (strcmp(name, "") == 0) 39 return -EINVAL; 40 - return ext3_xattr_get(inode, EXT3_XATTR_INDEX_TRUSTED, name, 41 - buffer, size); 42 } 43 44 static int 45 - ext3_xattr_trusted_set(struct inode *inode, const char *name, 46 - const void *value, size_t size, int flags) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 - return ext3_xattr_set(inode, EXT3_XATTR_INDEX_TRUSTED, name, 51 value, size, flags); 52 } 53
··· 14 #include "xattr.h" 15 16 static size_t 17 + ext3_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, 18 + const char *name, size_t name_len, int type) 19 { 20 const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; 21 const size_t total_len = prefix_len + name_len + 1; ··· 32 } 33 34 static int 35 + ext3_xattr_trusted_get(struct dentry *dentry, const char *name, 36 + void *buffer, size_t size, int type) 37 { 38 if (strcmp(name, "") == 0) 39 return -EINVAL; 40 + return ext3_xattr_get(dentry->d_inode, EXT3_XATTR_INDEX_TRUSTED, 41 + name, buffer, size); 42 } 43 44 static int 45 + ext3_xattr_trusted_set(struct dentry *dentry, const char *name, 46 + const void *value, size_t size, int flags, int type) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 + return ext3_xattr_set(dentry->d_inode, EXT3_XATTR_INDEX_TRUSTED, name, 51 value, size, flags); 52 } 53
+13 -12
fs/ext3/xattr_user.c
··· 13 #include "xattr.h" 14 15 static size_t 16 - ext3_xattr_user_list(struct inode *inode, char *list, size_t list_size, 17 - const char *name, size_t name_len) 18 { 19 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 20 const size_t total_len = prefix_len + name_len + 1; 21 22 - if (!test_opt(inode->i_sb, XATTR_USER)) 23 return 0; 24 25 if (list && total_len <= list_size) { ··· 31 } 32 33 static int 34 - ext3_xattr_user_get(struct inode *inode, const char *name, 35 - void *buffer, size_t size) 36 { 37 if (strcmp(name, "") == 0) 38 return -EINVAL; 39 - if (!test_opt(inode->i_sb, XATTR_USER)) 40 return -EOPNOTSUPP; 41 - return ext3_xattr_get(inode, EXT3_XATTR_INDEX_USER, name, buffer, size); 42 } 43 44 static int 45 - ext3_xattr_user_set(struct inode *inode, const char *name, 46 - const void *value, size_t size, int flags) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 - if (!test_opt(inode->i_sb, XATTR_USER)) 51 return -EOPNOTSUPP; 52 - return ext3_xattr_set(inode, EXT3_XATTR_INDEX_USER, name, 53 - value, size, flags); 54 } 55 56 struct xattr_handler ext3_xattr_user_handler = {
··· 13 #include "xattr.h" 14 15 static size_t 16 + ext3_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, 17 + const char *name, size_t name_len, int type) 18 { 19 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 20 const size_t total_len = prefix_len + name_len + 1; 21 22 + if (!test_opt(dentry->d_sb, XATTR_USER)) 23 return 0; 24 25 if (list && total_len <= list_size) { ··· 31 } 32 33 static int 34 + ext3_xattr_user_get(struct dentry *dentry, const char *name, void *buffer, 35 + size_t size, int type) 36 { 37 if (strcmp(name, "") == 0) 38 return -EINVAL; 39 + if (!test_opt(dentry->d_sb, XATTR_USER)) 40 return -EOPNOTSUPP; 41 + return ext3_xattr_get(dentry->d_inode, EXT3_XATTR_INDEX_USER, 42 + name, buffer, size); 43 } 44 45 static int 46 + ext3_xattr_user_set(struct dentry *dentry, const char *name, 47 + const void *value, size_t size, int flags, int type) 48 { 49 if (strcmp(name, "") == 0) 50 return -EINVAL; 51 + if (!test_opt(dentry->d_sb, XATTR_USER)) 52 return -EOPNOTSUPP; 53 + return ext3_xattr_set(dentry->d_inode, EXT3_XATTR_INDEX_USER, 54 + name, value, size, flags); 55 } 56 57 struct xattr_handler ext3_xattr_user_handler = {
+23 -51
fs/ext4/acl.c
··· 364 * Extended attribute handlers 365 */ 366 static size_t 367 - ext4_xattr_list_acl_access(struct inode *inode, char *list, size_t list_len, 368 - const char *name, size_t name_len) 369 { 370 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 371 372 - if (!test_opt(inode->i_sb, POSIX_ACL)) 373 return 0; 374 if (list && size <= list_len) 375 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 377 } 378 379 static size_t 380 - ext4_xattr_list_acl_default(struct inode *inode, char *list, size_t list_len, 381 - const char *name, size_t name_len) 382 { 383 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 384 385 - if (!test_opt(inode->i_sb, POSIX_ACL)) 386 return 0; 387 if (list && size <= list_len) 388 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 390 } 391 392 static int 393 - ext4_xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) 394 { 395 struct posix_acl *acl; 396 int error; 397 398 - if (!test_opt(inode->i_sb, POSIX_ACL)) 399 return -EOPNOTSUPP; 400 401 - acl = ext4_get_acl(inode, type); 402 if (IS_ERR(acl)) 403 return PTR_ERR(acl); 404 if (acl == NULL) ··· 413 } 414 415 static int 416 - ext4_xattr_get_acl_access(struct inode *inode, const char *name, 417 - void *buffer, size_t size) 418 { 419 - if (strcmp(name, "") != 0) 420 - return -EINVAL; 421 - return ext4_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 422 - } 423 - 424 - static int 425 - ext4_xattr_get_acl_default(struct inode *inode, const char *name, 426 - void *buffer, size_t size) 427 - { 428 - if (strcmp(name, "") != 0) 429 - return -EINVAL; 430 - return ext4_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 431 - } 432 - 433 - static int 434 - ext4_xattr_set_acl(struct inode *inode, int type, const void *value, 435 - size_t size) 436 - { 437 handle_t *handle; 438 struct posix_acl *acl; 439 int error, retries = 0; 440 441 if (!test_opt(inode->i_sb, POSIX_ACL)) 442 return -EOPNOTSUPP; 443 if (!is_owner_or_cap(inode)) ··· 454 return error; 455 } 456 457 - static int 458 - ext4_xattr_set_acl_access(struct inode *inode, const char *name, 459 - const void *value, size_t size, int flags) 460 - { 461 - if (strcmp(name, "") != 0) 462 - return -EINVAL; 463 - return ext4_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 464 - } 465 - 466 - static int 467 - ext4_xattr_set_acl_default(struct inode *inode, const char *name, 468 - const void *value, size_t size, int flags) 469 - { 470 - if (strcmp(name, "") != 0) 471 - return -EINVAL; 472 - return ext4_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 473 - } 474 - 475 struct xattr_handler ext4_xattr_acl_access_handler = { 476 .prefix = POSIX_ACL_XATTR_ACCESS, 477 .list = ext4_xattr_list_acl_access, 478 - .get = ext4_xattr_get_acl_access, 479 - .set = ext4_xattr_set_acl_access, 480 }; 481 482 struct xattr_handler ext4_xattr_acl_default_handler = { 483 .prefix = POSIX_ACL_XATTR_DEFAULT, 484 .list = ext4_xattr_list_acl_default, 485 - .get = ext4_xattr_get_acl_default, 486 - .set = ext4_xattr_set_acl_default, 487 };
··· 364 * Extended attribute handlers 365 */ 366 static size_t 367 + ext4_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_len, 368 + const char *name, size_t name_len, int type) 369 { 370 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 371 372 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 373 return 0; 374 if (list && size <= list_len) 375 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 377 } 378 379 static size_t 380 + ext4_xattr_list_acl_default(struct dentry *dentry, char *list, size_t list_len, 381 + const char *name, size_t name_len, int type) 382 { 383 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 384 385 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 386 return 0; 387 if (list && size <= list_len) 388 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 390 } 391 392 static int 393 + ext4_xattr_get_acl(struct dentry *dentry, const char *name, void *buffer, 394 + size_t size, int type) 395 { 396 struct posix_acl *acl; 397 int error; 398 399 + if (strcmp(name, "") != 0) 400 + return -EINVAL; 401 + if (!test_opt(dentry->d_sb, POSIX_ACL)) 402 return -EOPNOTSUPP; 403 404 + acl = ext4_get_acl(dentry->d_inode, type); 405 if (IS_ERR(acl)) 406 return PTR_ERR(acl); 407 if (acl == NULL) ··· 410 } 411 412 static int 413 + ext4_xattr_set_acl(struct dentry *dentry, const char *name, const void *value, 414 + size_t size, int flags, int type) 415 { 416 + struct inode *inode = dentry->d_inode; 417 handle_t *handle; 418 struct posix_acl *acl; 419 int error, retries = 0; 420 421 + if (strcmp(name, "") != 0) 422 + return -EINVAL; 423 if (!test_opt(inode->i_sb, POSIX_ACL)) 424 return -EOPNOTSUPP; 425 if (!is_owner_or_cap(inode)) ··· 466 return error; 467 } 468 469 struct xattr_handler ext4_xattr_acl_access_handler = { 470 .prefix = POSIX_ACL_XATTR_ACCESS, 471 + .flags = ACL_TYPE_ACCESS, 472 .list = ext4_xattr_list_acl_access, 473 + .get = ext4_xattr_get_acl, 474 + .set = ext4_xattr_set_acl, 475 }; 476 477 struct xattr_handler ext4_xattr_acl_default_handler = { 478 .prefix = POSIX_ACL_XATTR_DEFAULT, 479 + .flags = ACL_TYPE_DEFAULT, 480 .list = ext4_xattr_list_acl_default, 481 + .get = ext4_xattr_get_acl, 482 + .set = ext4_xattr_set_acl, 483 };
+17 -14
fs/ext4/xattr.c
··· 92 struct mb_cache_entry **); 93 static void ext4_xattr_rehash(struct ext4_xattr_header *, 94 struct ext4_xattr_entry *); 95 - static int ext4_xattr_list(struct inode *inode, char *buffer, 96 size_t buffer_size); 97 98 static struct mb_cache *ext4_xattr_cache; ··· 140 ssize_t 141 ext4_listxattr(struct dentry *dentry, char *buffer, size_t size) 142 { 143 - return ext4_xattr_list(dentry->d_inode, buffer, size); 144 } 145 146 static int ··· 325 } 326 327 static int 328 - ext4_xattr_list_entries(struct inode *inode, struct ext4_xattr_entry *entry, 329 char *buffer, size_t buffer_size) 330 { 331 size_t rest = buffer_size; ··· 335 ext4_xattr_handler(entry->e_name_index); 336 337 if (handler) { 338 - size_t size = handler->list(inode, buffer, rest, 339 entry->e_name, 340 - entry->e_name_len); 341 if (buffer) { 342 if (size > rest) 343 return -ERANGE; ··· 351 } 352 353 static int 354 - ext4_xattr_block_list(struct inode *inode, char *buffer, size_t buffer_size) 355 { 356 struct buffer_head *bh = NULL; 357 int error; 358 ··· 378 goto cleanup; 379 } 380 ext4_xattr_cache_insert(bh); 381 - error = ext4_xattr_list_entries(inode, BFIRST(bh), buffer, buffer_size); 382 383 cleanup: 384 brelse(bh); ··· 387 } 388 389 static int 390 - ext4_xattr_ibody_list(struct inode *inode, char *buffer, size_t buffer_size) 391 { 392 struct ext4_xattr_ibody_header *header; 393 struct ext4_inode *raw_inode; 394 struct ext4_iloc iloc; ··· 407 error = ext4_xattr_check_names(IFIRST(header), end); 408 if (error) 409 goto cleanup; 410 - error = ext4_xattr_list_entries(inode, IFIRST(header), 411 buffer, buffer_size); 412 413 cleanup: ··· 426 * used / required on success. 427 */ 428 static int 429 - ext4_xattr_list(struct inode *inode, char *buffer, size_t buffer_size) 430 { 431 int i_error, b_error; 432 433 - down_read(&EXT4_I(inode)->xattr_sem); 434 - i_error = ext4_xattr_ibody_list(inode, buffer, buffer_size); 435 if (i_error < 0) { 436 b_error = 0; 437 } else { ··· 439 buffer += i_error; 440 buffer_size -= i_error; 441 } 442 - b_error = ext4_xattr_block_list(inode, buffer, buffer_size); 443 if (b_error < 0) 444 i_error = 0; 445 } 446 - up_read(&EXT4_I(inode)->xattr_sem); 447 return i_error + b_error; 448 } 449
··· 92 struct mb_cache_entry **); 93 static void ext4_xattr_rehash(struct ext4_xattr_header *, 94 struct ext4_xattr_entry *); 95 + static int ext4_xattr_list(struct dentry *dentry, char *buffer, 96 size_t buffer_size); 97 98 static struct mb_cache *ext4_xattr_cache; ··· 140 ssize_t 141 ext4_listxattr(struct dentry *dentry, char *buffer, size_t size) 142 { 143 + return ext4_xattr_list(dentry, buffer, size); 144 } 145 146 static int ··· 325 } 326 327 static int 328 + ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry, 329 char *buffer, size_t buffer_size) 330 { 331 size_t rest = buffer_size; ··· 335 ext4_xattr_handler(entry->e_name_index); 336 337 if (handler) { 338 + size_t size = handler->list(dentry, buffer, rest, 339 entry->e_name, 340 + entry->e_name_len, 341 + handler->flags); 342 if (buffer) { 343 if (size > rest) 344 return -ERANGE; ··· 350 } 351 352 static int 353 + ext4_xattr_block_list(struct dentry *dentry, char *buffer, size_t buffer_size) 354 { 355 + struct inode *inode = dentry->d_inode; 356 struct buffer_head *bh = NULL; 357 int error; 358 ··· 376 goto cleanup; 377 } 378 ext4_xattr_cache_insert(bh); 379 + error = ext4_xattr_list_entries(dentry, BFIRST(bh), buffer, buffer_size); 380 381 cleanup: 382 brelse(bh); ··· 385 } 386 387 static int 388 + ext4_xattr_ibody_list(struct dentry *dentry, char *buffer, size_t buffer_size) 389 { 390 + struct inode *inode = dentry->d_inode; 391 struct ext4_xattr_ibody_header *header; 392 struct ext4_inode *raw_inode; 393 struct ext4_iloc iloc; ··· 404 error = ext4_xattr_check_names(IFIRST(header), end); 405 if (error) 406 goto cleanup; 407 + error = ext4_xattr_list_entries(dentry, IFIRST(header), 408 buffer, buffer_size); 409 410 cleanup: ··· 423 * used / required on success. 424 */ 425 static int 426 + ext4_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size) 427 { 428 int i_error, b_error; 429 430 + down_read(&EXT4_I(dentry->d_inode)->xattr_sem); 431 + i_error = ext4_xattr_ibody_list(dentry, buffer, buffer_size); 432 if (i_error < 0) { 433 b_error = 0; 434 } else { ··· 436 buffer += i_error; 437 buffer_size -= i_error; 438 } 439 + b_error = ext4_xattr_block_list(dentry, buffer, buffer_size); 440 if (b_error < 0) 441 i_error = 0; 442 } 443 + up_read(&EXT4_I(dentry->d_inode)->xattr_sem); 444 return i_error + b_error; 445 } 446
+10 -10
fs/ext4/xattr_security.c
··· 12 #include "xattr.h" 13 14 static size_t 15 - ext4_xattr_security_list(struct inode *inode, char *list, size_t list_size, 16 - const char *name, size_t name_len) 17 { 18 const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1; 19 const size_t total_len = prefix_len + name_len + 1; ··· 28 } 29 30 static int 31 - ext4_xattr_security_get(struct inode *inode, const char *name, 32 - void *buffer, size_t size) 33 { 34 if (strcmp(name, "") == 0) 35 return -EINVAL; 36 - return ext4_xattr_get(inode, EXT4_XATTR_INDEX_SECURITY, name, 37 - buffer, size); 38 } 39 40 static int 41 - ext4_xattr_security_set(struct inode *inode, const char *name, 42 - const void *value, size_t size, int flags) 43 { 44 if (strcmp(name, "") == 0) 45 return -EINVAL; 46 - return ext4_xattr_set(inode, EXT4_XATTR_INDEX_SECURITY, name, 47 - value, size, flags); 48 } 49 50 int
··· 12 #include "xattr.h" 13 14 static size_t 15 + ext4_xattr_security_list(struct dentry *dentry, char *list, size_t list_size, 16 + const char *name, size_t name_len, int type) 17 { 18 const size_t prefix_len = sizeof(XATTR_SECURITY_PREFIX)-1; 19 const size_t total_len = prefix_len + name_len + 1; ··· 28 } 29 30 static int 31 + ext4_xattr_security_get(struct dentry *dentry, const char *name, 32 + void *buffer, size_t size, int type) 33 { 34 if (strcmp(name, "") == 0) 35 return -EINVAL; 36 + return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_SECURITY, 37 + name, buffer, size); 38 } 39 40 static int 41 + ext4_xattr_security_set(struct dentry *dentry, const char *name, 42 + const void *value, size_t size, int flags, int type) 43 { 44 if (strcmp(name, "") == 0) 45 return -EINVAL; 46 + return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_SECURITY, 47 + name, value, size, flags); 48 } 49 50 int
+10 -10
fs/ext4/xattr_trusted.c
··· 14 #include "xattr.h" 15 16 static size_t 17 - ext4_xattr_trusted_list(struct inode *inode, char *list, size_t list_size, 18 - const char *name, size_t name_len) 19 { 20 const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; 21 const size_t total_len = prefix_len + name_len + 1; ··· 32 } 33 34 static int 35 - ext4_xattr_trusted_get(struct inode *inode, const char *name, 36 - void *buffer, size_t size) 37 { 38 if (strcmp(name, "") == 0) 39 return -EINVAL; 40 - return ext4_xattr_get(inode, EXT4_XATTR_INDEX_TRUSTED, name, 41 - buffer, size); 42 } 43 44 static int 45 - ext4_xattr_trusted_set(struct inode *inode, const char *name, 46 - const void *value, size_t size, int flags) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 - return ext4_xattr_set(inode, EXT4_XATTR_INDEX_TRUSTED, name, 51 - value, size, flags); 52 } 53 54 struct xattr_handler ext4_xattr_trusted_handler = {
··· 14 #include "xattr.h" 15 16 static size_t 17 + ext4_xattr_trusted_list(struct dentry *dentry, char *list, size_t list_size, 18 + const char *name, size_t name_len, int type) 19 { 20 const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; 21 const size_t total_len = prefix_len + name_len + 1; ··· 32 } 33 34 static int 35 + ext4_xattr_trusted_get(struct dentry *dentry, const char *name, void *buffer, 36 + size_t size, int type) 37 { 38 if (strcmp(name, "") == 0) 39 return -EINVAL; 40 + return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED, 41 + name, buffer, size); 42 } 43 44 static int 45 + ext4_xattr_trusted_set(struct dentry *dentry, const char *name, 46 + const void *value, size_t size, int flags, int type) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 + return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_TRUSTED, 51 + name, value, size, flags); 52 } 53 54 struct xattr_handler ext4_xattr_trusted_handler = {
+13 -12
fs/ext4/xattr_user.c
··· 13 #include "xattr.h" 14 15 static size_t 16 - ext4_xattr_user_list(struct inode *inode, char *list, size_t list_size, 17 - const char *name, size_t name_len) 18 { 19 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 20 const size_t total_len = prefix_len + name_len + 1; 21 22 - if (!test_opt(inode->i_sb, XATTR_USER)) 23 return 0; 24 25 if (list && total_len <= list_size) { ··· 31 } 32 33 static int 34 - ext4_xattr_user_get(struct inode *inode, const char *name, 35 - void *buffer, size_t size) 36 { 37 if (strcmp(name, "") == 0) 38 return -EINVAL; 39 - if (!test_opt(inode->i_sb, XATTR_USER)) 40 return -EOPNOTSUPP; 41 - return ext4_xattr_get(inode, EXT4_XATTR_INDEX_USER, name, buffer, size); 42 } 43 44 static int 45 - ext4_xattr_user_set(struct inode *inode, const char *name, 46 - const void *value, size_t size, int flags) 47 { 48 if (strcmp(name, "") == 0) 49 return -EINVAL; 50 - if (!test_opt(inode->i_sb, XATTR_USER)) 51 return -EOPNOTSUPP; 52 - return ext4_xattr_set(inode, EXT4_XATTR_INDEX_USER, name, 53 - value, size, flags); 54 } 55 56 struct xattr_handler ext4_xattr_user_handler = {
··· 13 #include "xattr.h" 14 15 static size_t 16 + ext4_xattr_user_list(struct dentry *dentry, char *list, size_t list_size, 17 + const char *name, size_t name_len, int type) 18 { 19 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 20 const size_t total_len = prefix_len + name_len + 1; 21 22 + if (!test_opt(dentry->d_sb, XATTR_USER)) 23 return 0; 24 25 if (list && total_len <= list_size) { ··· 31 } 32 33 static int 34 + ext4_xattr_user_get(struct dentry *dentry, const char *name, 35 + void *buffer, size_t size, int type) 36 { 37 if (strcmp(name, "") == 0) 38 return -EINVAL; 39 + if (!test_opt(dentry->d_sb, XATTR_USER)) 40 return -EOPNOTSUPP; 41 + return ext4_xattr_get(dentry->d_inode, EXT4_XATTR_INDEX_USER, 42 + name, buffer, size); 43 } 44 45 static int 46 + ext4_xattr_user_set(struct dentry *dentry, const char *name, 47 + const void *value, size_t size, int flags, int type) 48 { 49 if (strcmp(name, "") == 0) 50 return -EINVAL; 51 + if (!test_opt(dentry->d_sb, XATTR_USER)) 52 return -EOPNOTSUPP; 53 + return ext4_xattr_set(dentry->d_inode, EXT4_XATTR_INDEX_USER, 54 + name, value, size, flags); 55 } 56 57 struct xattr_handler ext4_xattr_user_handler = {
+12 -37
fs/file_table.c
··· 21 #include <linux/fsnotify.h> 22 #include <linux/sysctl.h> 23 #include <linux/percpu_counter.h> 24 25 #include <asm/atomic.h> 26 27 /* sysctl tunables... */ 28 struct files_stat_struct files_stat = { ··· 150 return NULL; 151 } 152 153 - EXPORT_SYMBOL(get_empty_filp); 154 - 155 /** 156 * alloc_file - allocate and initialize a 'struct file' 157 * @mnt: the vfsmount on which the file will reside ··· 165 * If all the callers of init_file() are eliminated, its 166 * code should be moved into this function. 167 */ 168 - struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry, 169 - fmode_t mode, const struct file_operations *fop) 170 { 171 struct file *file; 172 ··· 174 if (!file) 175 return NULL; 176 177 - init_file(file, mnt, dentry, mode, fop); 178 - return file; 179 - } 180 - EXPORT_SYMBOL(alloc_file); 181 - 182 - /** 183 - * init_file - initialize a 'struct file' 184 - * @file: the already allocated 'struct file' to initialized 185 - * @mnt: the vfsmount on which the file resides 186 - * @dentry: the dentry representing this file 187 - * @mode: the mode the file is opened with 188 - * @fop: the 'struct file_operations' for this file 189 - * 190 - * Use this instead of setting the members directly. Doing so 191 - * avoids making mistakes like forgetting the mntget() or 192 - * forgetting to take a write on the mnt. 193 - * 194 - * Note: This is a crappy interface. It is here to make 195 - * merging with the existing users of get_empty_filp() 196 - * who have complex failure logic easier. All users 197 - * of this should be moving to alloc_file(). 198 - */ 199 - int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry, 200 - fmode_t mode, const struct file_operations *fop) 201 - { 202 - int error = 0; 203 - file->f_path.dentry = dentry; 204 - file->f_path.mnt = mntget(mnt); 205 - file->f_mapping = dentry->d_inode->i_mapping; 206 file->f_mode = mode; 207 file->f_op = fop; 208 ··· 185 * visible. We do this for consistency, and so 186 * that we can do debugging checks at __fput() 187 */ 188 - if ((mode & FMODE_WRITE) && !special_file(dentry->d_inode->i_mode)) { 189 file_take_write(file); 190 - error = mnt_clone_write(mnt); 191 WARN_ON(error); 192 } 193 - return error; 194 } 195 - EXPORT_SYMBOL(init_file); 196 197 void fput(struct file *file) 198 {
··· 21 #include <linux/fsnotify.h> 22 #include <linux/sysctl.h> 23 #include <linux/percpu_counter.h> 24 + #include <linux/ima.h> 25 26 #include <asm/atomic.h> 27 + 28 + #include "internal.h" 29 30 /* sysctl tunables... */ 31 struct files_stat_struct files_stat = { ··· 147 return NULL; 148 } 149 150 /** 151 * alloc_file - allocate and initialize a 'struct file' 152 * @mnt: the vfsmount on which the file will reside ··· 164 * If all the callers of init_file() are eliminated, its 165 * code should be moved into this function. 166 */ 167 + struct file *alloc_file(struct path *path, fmode_t mode, 168 + const struct file_operations *fop) 169 { 170 struct file *file; 171 ··· 173 if (!file) 174 return NULL; 175 176 + file->f_path = *path; 177 + file->f_mapping = path->dentry->d_inode->i_mapping; 178 file->f_mode = mode; 179 file->f_op = fop; 180 ··· 211 * visible. We do this for consistency, and so 212 * that we can do debugging checks at __fput() 213 */ 214 + if ((mode & FMODE_WRITE) && !special_file(path->dentry->d_inode->i_mode)) { 215 + int error = 0; 216 file_take_write(file); 217 + error = mnt_clone_write(path->mnt); 218 WARN_ON(error); 219 } 220 + ima_counts_get(file); 221 + return file; 222 } 223 224 void fput(struct file *file) 225 {
+89 -69
fs/generic_acl.c
··· 1 /* 2 - * fs/generic_acl.c 3 - * 4 * (C) 2005 Andreas Gruenbacher <agruen@suse.de> 5 * 6 * This file is released under the GPL. 7 */ 8 9 #include <linux/sched.h> 10 #include <linux/fs.h> 11 #include <linux/generic_acl.h> 12 13 - /** 14 - * generic_acl_list - Generic xattr_handler->list() operation 15 - * @ops: Filesystem specific getacl and setacl callbacks 16 - */ 17 - size_t 18 - generic_acl_list(struct inode *inode, struct generic_acl_operations *ops, 19 - int type, char *list, size_t list_size) 20 { 21 struct posix_acl *acl; 22 - const char *name; 23 size_t size; 24 25 - acl = ops->getacl(inode, type); 26 if (!acl) 27 return 0; 28 posix_acl_release(acl); 29 30 - switch(type) { 31 - case ACL_TYPE_ACCESS: 32 - name = POSIX_ACL_XATTR_ACCESS; 33 - break; 34 - 35 - case ACL_TYPE_DEFAULT: 36 - name = POSIX_ACL_XATTR_DEFAULT; 37 - break; 38 - 39 - default: 40 - return 0; 41 } 42 - size = strlen(name) + 1; 43 if (list && size <= list_size) 44 - memcpy(list, name, size); 45 return size; 46 } 47 48 - /** 49 - * generic_acl_get - Generic xattr_handler->get() operation 50 - * @ops: Filesystem specific getacl and setacl callbacks 51 - */ 52 - int 53 - generic_acl_get(struct inode *inode, struct generic_acl_operations *ops, 54 - int type, void *buffer, size_t size) 55 { 56 struct posix_acl *acl; 57 int error; 58 59 - acl = ops->getacl(inode, type); 60 if (!acl) 61 return -ENODATA; 62 error = posix_acl_to_xattr(acl, buffer, size); ··· 61 return error; 62 } 63 64 - /** 65 - * generic_acl_set - Generic xattr_handler->set() operation 66 - * @ops: Filesystem specific getacl and setacl callbacks 67 - */ 68 - int 69 - generic_acl_set(struct inode *inode, struct generic_acl_operations *ops, 70 - int type, const void *value, size_t size) 71 { 72 struct posix_acl *acl = NULL; 73 int error; 74 75 if (S_ISLNK(inode->i_mode)) 76 return -EOPNOTSUPP; 77 if (!is_owner_or_cap(inode)) ··· 86 error = posix_acl_valid(acl); 87 if (error) 88 goto failed; 89 - switch(type) { 90 - case ACL_TYPE_ACCESS: 91 - mode = inode->i_mode; 92 - error = posix_acl_equiv_mode(acl, &mode); 93 - if (error < 0) 94 - goto failed; 95 - inode->i_mode = mode; 96 - if (error == 0) { 97 - posix_acl_release(acl); 98 - acl = NULL; 99 - } 100 - break; 101 - 102 - case ACL_TYPE_DEFAULT: 103 - if (!S_ISDIR(inode->i_mode)) { 104 - error = -EINVAL; 105 - goto failed; 106 - } 107 - break; 108 } 109 } 110 - ops->setacl(inode, type, acl); 111 error = 0; 112 failed: 113 posix_acl_release(acl); ··· 115 116 /** 117 * generic_acl_init - Take care of acl inheritance at @inode create time 118 - * @ops: Filesystem specific getacl and setacl callbacks 119 * 120 * Files created inside a directory with a default ACL inherit the 121 * directory's default ACL. 122 */ 123 int 124 - generic_acl_init(struct inode *inode, struct inode *dir, 125 - struct generic_acl_operations *ops) 126 { 127 struct posix_acl *acl = NULL; 128 mode_t mode = inode->i_mode; ··· 128 129 inode->i_mode = mode & ~current_umask(); 130 if (!S_ISLNK(inode->i_mode)) 131 - acl = ops->getacl(dir, ACL_TYPE_DEFAULT); 132 if (acl) { 133 struct posix_acl *clone; 134 ··· 137 error = -ENOMEM; 138 if (!clone) 139 goto cleanup; 140 - ops->setacl(inode, ACL_TYPE_DEFAULT, clone); 141 posix_acl_release(clone); 142 } 143 clone = posix_acl_clone(acl, GFP_KERNEL); ··· 148 if (error >= 0) { 149 inode->i_mode = mode; 150 if (error > 0) 151 - ops->setacl(inode, ACL_TYPE_ACCESS, clone); 152 } 153 posix_acl_release(clone); 154 } ··· 161 162 /** 163 * generic_acl_chmod - change the access acl of @inode upon chmod() 164 - * @ops: FIlesystem specific getacl and setacl callbacks 165 * 166 * A chmod also changes the permissions of the owner, group/mask, and 167 * other ACL entries. 168 */ 169 int 170 - generic_acl_chmod(struct inode *inode, struct generic_acl_operations *ops) 171 { 172 struct posix_acl *acl, *clone; 173 int error = 0; 174 175 if (S_ISLNK(inode->i_mode)) 176 return -EOPNOTSUPP; 177 - acl = ops->getacl(inode, ACL_TYPE_ACCESS); 178 if (acl) { 179 clone = posix_acl_clone(acl, GFP_KERNEL); 180 posix_acl_release(acl); ··· 181 return -ENOMEM; 182 error = posix_acl_chmod_masq(clone, inode->i_mode); 183 if (!error) 184 - ops->setacl(inode, ACL_TYPE_ACCESS, clone); 185 posix_acl_release(clone); 186 } 187 return error; 188 }
··· 1 /* 2 * (C) 2005 Andreas Gruenbacher <agruen@suse.de> 3 * 4 * This file is released under the GPL. 5 + * 6 + * Generic ACL support for in-memory filesystems. 7 */ 8 9 #include <linux/sched.h> 10 #include <linux/fs.h> 11 #include <linux/generic_acl.h> 12 + #include <linux/posix_acl.h> 13 + #include <linux/posix_acl_xattr.h> 14 15 + 16 + static size_t 17 + generic_acl_list(struct dentry *dentry, char *list, size_t list_size, 18 + const char *name, size_t name_len, int type) 19 { 20 struct posix_acl *acl; 21 + const char *xname; 22 size_t size; 23 24 + acl = get_cached_acl(dentry->d_inode, type); 25 if (!acl) 26 return 0; 27 posix_acl_release(acl); 28 29 + switch (type) { 30 + case ACL_TYPE_ACCESS: 31 + xname = POSIX_ACL_XATTR_ACCESS; 32 + break; 33 + case ACL_TYPE_DEFAULT: 34 + xname = POSIX_ACL_XATTR_DEFAULT; 35 + break; 36 + default: 37 + return 0; 38 } 39 + size = strlen(xname) + 1; 40 if (list && size <= list_size) 41 + memcpy(list, xname, size); 42 return size; 43 } 44 45 + static int 46 + generic_acl_get(struct dentry *dentry, const char *name, void *buffer, 47 + size_t size, int type) 48 { 49 struct posix_acl *acl; 50 int error; 51 52 + if (strcmp(name, "") != 0) 53 + return -EINVAL; 54 + 55 + acl = get_cached_acl(dentry->d_inode, type); 56 if (!acl) 57 return -ENODATA; 58 error = posix_acl_to_xattr(acl, buffer, size); ··· 65 return error; 66 } 67 68 + static int 69 + generic_acl_set(struct dentry *dentry, const char *name, const void *value, 70 + size_t size, int flags, int type) 71 { 72 + struct inode *inode = dentry->d_inode; 73 struct posix_acl *acl = NULL; 74 int error; 75 76 + if (strcmp(name, "") != 0) 77 + return -EINVAL; 78 if (S_ISLNK(inode->i_mode)) 79 return -EOPNOTSUPP; 80 if (!is_owner_or_cap(inode)) ··· 91 error = posix_acl_valid(acl); 92 if (error) 93 goto failed; 94 + switch (type) { 95 + case ACL_TYPE_ACCESS: 96 + mode = inode->i_mode; 97 + error = posix_acl_equiv_mode(acl, &mode); 98 + if (error < 0) 99 + goto failed; 100 + inode->i_mode = mode; 101 + if (error == 0) { 102 + posix_acl_release(acl); 103 + acl = NULL; 104 + } 105 + break; 106 + case ACL_TYPE_DEFAULT: 107 + if (!S_ISDIR(inode->i_mode)) { 108 + error = -EINVAL; 109 + goto failed; 110 + } 111 + break; 112 } 113 } 114 + set_cached_acl(inode, type, acl); 115 error = 0; 116 failed: 117 posix_acl_release(acl); ··· 121 122 /** 123 * generic_acl_init - Take care of acl inheritance at @inode create time 124 * 125 * Files created inside a directory with a default ACL inherit the 126 * directory's default ACL. 127 */ 128 int 129 + generic_acl_init(struct inode *inode, struct inode *dir) 130 { 131 struct posix_acl *acl = NULL; 132 mode_t mode = inode->i_mode; ··· 136 137 inode->i_mode = mode & ~current_umask(); 138 if (!S_ISLNK(inode->i_mode)) 139 + acl = get_cached_acl(dir, ACL_TYPE_DEFAULT); 140 if (acl) { 141 struct posix_acl *clone; 142 ··· 145 error = -ENOMEM; 146 if (!clone) 147 goto cleanup; 148 + set_cached_acl(inode, ACL_TYPE_DEFAULT, clone); 149 posix_acl_release(clone); 150 } 151 clone = posix_acl_clone(acl, GFP_KERNEL); ··· 156 if (error >= 0) { 157 inode->i_mode = mode; 158 if (error > 0) 159 + set_cached_acl(inode, ACL_TYPE_ACCESS, clone); 160 } 161 posix_acl_release(clone); 162 } ··· 169 170 /** 171 * generic_acl_chmod - change the access acl of @inode upon chmod() 172 * 173 * A chmod also changes the permissions of the owner, group/mask, and 174 * other ACL entries. 175 */ 176 int 177 + generic_acl_chmod(struct inode *inode) 178 { 179 struct posix_acl *acl, *clone; 180 int error = 0; 181 182 if (S_ISLNK(inode->i_mode)) 183 return -EOPNOTSUPP; 184 + acl = get_cached_acl(inode, ACL_TYPE_ACCESS); 185 if (acl) { 186 clone = posix_acl_clone(acl, GFP_KERNEL); 187 posix_acl_release(acl); ··· 190 return -ENOMEM; 191 error = posix_acl_chmod_masq(clone, inode->i_mode); 192 if (!error) 193 + set_cached_acl(inode, ACL_TYPE_ACCESS, clone); 194 posix_acl_release(clone); 195 } 196 return error; 197 } 198 + 199 + int 200 + generic_check_acl(struct inode *inode, int mask) 201 + { 202 + struct posix_acl *acl = get_cached_acl(inode, ACL_TYPE_ACCESS); 203 + 204 + if (acl) { 205 + int error = posix_acl_permission(inode, acl, mask); 206 + posix_acl_release(acl); 207 + return error; 208 + } 209 + return -EAGAIN; 210 + } 211 + 212 + struct xattr_handler generic_acl_access_handler = { 213 + .prefix = POSIX_ACL_XATTR_ACCESS, 214 + .flags = ACL_TYPE_ACCESS, 215 + .list = generic_acl_list, 216 + .get = generic_acl_get, 217 + .set = generic_acl_set, 218 + }; 219 + 220 + struct xattr_handler generic_acl_default_handler = { 221 + .prefix = POSIX_ACL_XATTR_DEFAULT, 222 + .flags = ACL_TYPE_DEFAULT, 223 + .list = generic_acl_list, 224 + .get = generic_acl_get, 225 + .set = generic_acl_set, 226 + };
+10 -6
fs/gfs2/acl.c
··· 126 error = posix_acl_to_xattr(acl, data, len); 127 if (error < 0) 128 goto out; 129 - error = gfs2_xattr_set(inode, GFS2_EATYPE_SYS, name, data, len, 0); 130 if (!error) 131 set_cached_acl(inode, type, acl); 132 out: ··· 232 return -EINVAL; 233 } 234 235 - static int gfs2_xattr_system_get(struct inode *inode, const char *name, 236 - void *buffer, size_t size) 237 { 238 struct posix_acl *acl; 239 int type; 240 int error; ··· 256 return error; 257 } 258 259 - static int gfs2_xattr_system_set(struct inode *inode, const char *name, 260 - const void *value, size_t size, int flags) 261 { 262 struct gfs2_sbd *sdp = GFS2_SB(inode); 263 struct posix_acl *acl = NULL; 264 int error = 0, type; ··· 322 } 323 324 set_acl: 325 - error = gfs2_xattr_set(inode, GFS2_EATYPE_SYS, name, value, size, 0); 326 if (!error) { 327 if (acl) 328 set_cached_acl(inode, type, acl); ··· 337 338 struct xattr_handler gfs2_xattr_system_handler = { 339 .prefix = XATTR_SYSTEM_PREFIX, 340 .get = gfs2_xattr_system_get, 341 .set = gfs2_xattr_system_set, 342 };
··· 126 error = posix_acl_to_xattr(acl, data, len); 127 if (error < 0) 128 goto out; 129 + error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS); 130 if (!error) 131 set_cached_acl(inode, type, acl); 132 out: ··· 232 return -EINVAL; 233 } 234 235 + static int gfs2_xattr_system_get(struct dentry *dentry, const char *name, 236 + void *buffer, size_t size, int xtype) 237 { 238 + struct inode *inode = dentry->d_inode; 239 struct posix_acl *acl; 240 int type; 241 int error; ··· 255 return error; 256 } 257 258 + static int gfs2_xattr_system_set(struct dentry *dentry, const char *name, 259 + const void *value, size_t size, int flags, 260 + int xtype) 261 { 262 + struct inode *inode = dentry->d_inode; 263 struct gfs2_sbd *sdp = GFS2_SB(inode); 264 struct posix_acl *acl = NULL; 265 int error = 0, type; ··· 319 } 320 321 set_acl: 322 + error = __gfs2_xattr_set(inode, name, value, size, 0, GFS2_EATYPE_SYS); 323 if (!error) { 324 if (acl) 325 set_cached_acl(inode, type, acl); ··· 334 335 struct xattr_handler gfs2_xattr_system_handler = { 336 .prefix = XATTR_SYSTEM_PREFIX, 337 + .flags = GFS2_EATYPE_SYS, 338 .get = gfs2_xattr_system_get, 339 .set = gfs2_xattr_system_set, 340 };
+2 -1
fs/gfs2/inode.c
··· 801 return err; 802 } 803 804 - err = gfs2_xattr_set(&ip->i_inode, GFS2_EATYPE_SECURITY, name, value, len, 0); 805 kfree(value); 806 kfree(name); 807
··· 801 return err; 802 } 803 804 + err = __gfs2_xattr_set(&ip->i_inode, name, value, len, 0, 805 + GFS2_EATYPE_SECURITY); 806 kfree(value); 807 kfree(name); 808
+26 -43
fs/gfs2/xattr.c
··· 567 /** 568 * gfs2_xattr_get - Get a GFS2 extended attribute 569 * @inode: The inode 570 - * @type: The type of extended attribute 571 * @name: The name of the extended attribute 572 * @buffer: The buffer to write the result into 573 * @size: The size of the buffer 574 * 575 * Returns: actual size of data on success, -errno on error 576 */ 577 - 578 - int gfs2_xattr_get(struct inode *inode, int type, const char *name, 579 - void *buffer, size_t size) 580 { 581 - struct gfs2_inode *ip = GFS2_I(inode); 582 struct gfs2_ea_location el; 583 int error; 584 ··· 1118 1119 /** 1120 * gfs2_xattr_remove - Remove a GFS2 extended attribute 1121 - * @inode: The inode 1122 * @type: The type of the extended attribute 1123 * @name: The name of the extended attribute 1124 * ··· 1129 * Returns: 0, or errno on failure 1130 */ 1131 1132 - static int gfs2_xattr_remove(struct inode *inode, int type, const char *name) 1133 { 1134 - struct gfs2_inode *ip = GFS2_I(inode); 1135 struct gfs2_ea_location el; 1136 int error; 1137 ··· 1154 } 1155 1156 /** 1157 - * gfs2_xattr_set - Set (or remove) a GFS2 extended attribute 1158 - * @inode: The inode 1159 - * @type: The type of the extended attribute 1160 * @name: The name of the extended attribute 1161 * @value: The value of the extended attribute (NULL for remove) 1162 * @size: The size of the @value argument 1163 * @flags: Create or Replace 1164 * 1165 * See gfs2_xattr_remove() for details of the removal of xattrs. 1166 * 1167 * Returns: 0 or errno on failure 1168 */ 1169 1170 - int gfs2_xattr_set(struct inode *inode, int type, const char *name, 1171 - const void *value, size_t size, int flags) 1172 { 1173 - struct gfs2_sbd *sdp = GFS2_SB(inode); 1174 struct gfs2_inode *ip = GFS2_I(inode); 1175 struct gfs2_ea_location el; 1176 unsigned int namel = strlen(name); 1177 int error; ··· 1182 return -ERANGE; 1183 1184 if (value == NULL) 1185 - return gfs2_xattr_remove(inode, type, name); 1186 1187 if (ea_check_size(sdp, namel, size)) 1188 return -ERANGE; ··· 1220 error = ea_set_i(ip, type, name, value, size, NULL); 1221 1222 return error; 1223 } 1224 1225 static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, ··· 1534 return error; 1535 } 1536 1537 - static int gfs2_xattr_user_get(struct inode *inode, const char *name, 1538 - void *buffer, size_t size) 1539 - { 1540 - return gfs2_xattr_get(inode, GFS2_EATYPE_USR, name, buffer, size); 1541 - } 1542 - 1543 - static int gfs2_xattr_user_set(struct inode *inode, const char *name, 1544 - const void *value, size_t size, int flags) 1545 - { 1546 - return gfs2_xattr_set(inode, GFS2_EATYPE_USR, name, value, size, flags); 1547 - } 1548 - 1549 - static int gfs2_xattr_security_get(struct inode *inode, const char *name, 1550 - void *buffer, size_t size) 1551 - { 1552 - return gfs2_xattr_get(inode, GFS2_EATYPE_SECURITY, name, buffer, size); 1553 - } 1554 - 1555 - static int gfs2_xattr_security_set(struct inode *inode, const char *name, 1556 - const void *value, size_t size, int flags) 1557 - { 1558 - return gfs2_xattr_set(inode, GFS2_EATYPE_SECURITY, name, value, size, flags); 1559 - } 1560 - 1561 static struct xattr_handler gfs2_xattr_user_handler = { 1562 .prefix = XATTR_USER_PREFIX, 1563 - .get = gfs2_xattr_user_get, 1564 - .set = gfs2_xattr_user_set, 1565 }; 1566 1567 static struct xattr_handler gfs2_xattr_security_handler = { 1568 .prefix = XATTR_SECURITY_PREFIX, 1569 - .get = gfs2_xattr_security_get, 1570 - .set = gfs2_xattr_security_set, 1571 }; 1572 1573 struct xattr_handler *gfs2_xattr_handlers[] = {
··· 567 /** 568 * gfs2_xattr_get - Get a GFS2 extended attribute 569 * @inode: The inode 570 * @name: The name of the extended attribute 571 * @buffer: The buffer to write the result into 572 * @size: The size of the buffer 573 + * @type: The type of extended attribute 574 * 575 * Returns: actual size of data on success, -errno on error 576 */ 577 + static int gfs2_xattr_get(struct dentry *dentry, const char *name, 578 + void *buffer, size_t size, int type) 579 { 580 + struct gfs2_inode *ip = GFS2_I(dentry->d_inode); 581 struct gfs2_ea_location el; 582 int error; 583 ··· 1119 1120 /** 1121 * gfs2_xattr_remove - Remove a GFS2 extended attribute 1122 + * @ip: The inode 1123 * @type: The type of the extended attribute 1124 * @name: The name of the extended attribute 1125 * ··· 1130 * Returns: 0, or errno on failure 1131 */ 1132 1133 + static int gfs2_xattr_remove(struct gfs2_inode *ip, int type, const char *name) 1134 { 1135 struct gfs2_ea_location el; 1136 int error; 1137 ··· 1156 } 1157 1158 /** 1159 + * __gfs2_xattr_set - Set (or remove) a GFS2 extended attribute 1160 + * @ip: The inode 1161 * @name: The name of the extended attribute 1162 * @value: The value of the extended attribute (NULL for remove) 1163 * @size: The size of the @value argument 1164 * @flags: Create or Replace 1165 + * @type: The type of the extended attribute 1166 * 1167 * See gfs2_xattr_remove() for details of the removal of xattrs. 1168 * 1169 * Returns: 0 or errno on failure 1170 */ 1171 1172 + int __gfs2_xattr_set(struct inode *inode, const char *name, 1173 + const void *value, size_t size, int flags, int type) 1174 { 1175 struct gfs2_inode *ip = GFS2_I(inode); 1176 + struct gfs2_sbd *sdp = GFS2_SB(inode); 1177 struct gfs2_ea_location el; 1178 unsigned int namel = strlen(name); 1179 int error; ··· 1184 return -ERANGE; 1185 1186 if (value == NULL) 1187 + return gfs2_xattr_remove(ip, type, name); 1188 1189 if (ea_check_size(sdp, namel, size)) 1190 return -ERANGE; ··· 1222 error = ea_set_i(ip, type, name, value, size, NULL); 1223 1224 return error; 1225 + } 1226 + 1227 + static int gfs2_xattr_set(struct dentry *dentry, const char *name, 1228 + const void *value, size_t size, int flags, int type) 1229 + { 1230 + return __gfs2_xattr_set(dentry->d_inode, name, value, 1231 + size, flags, type); 1232 } 1233 1234 static int ea_acl_chmod_unstuffed(struct gfs2_inode *ip, ··· 1529 return error; 1530 } 1531 1532 static struct xattr_handler gfs2_xattr_user_handler = { 1533 .prefix = XATTR_USER_PREFIX, 1534 + .flags = GFS2_EATYPE_USR, 1535 + .get = gfs2_xattr_get, 1536 + .set = gfs2_xattr_set, 1537 }; 1538 1539 static struct xattr_handler gfs2_xattr_security_handler = { 1540 .prefix = XATTR_SECURITY_PREFIX, 1541 + .flags = GFS2_EATYPE_SECURITY, 1542 + .get = gfs2_xattr_get, 1543 + .set = gfs2_xattr_set, 1544 }; 1545 1546 struct xattr_handler *gfs2_xattr_handlers[] = {
+3 -4
fs/gfs2/xattr.h
··· 53 struct gfs2_ea_header *el_prev; 54 }; 55 56 - extern int gfs2_xattr_get(struct inode *inode, int type, const char *name, 57 - void *buffer, size_t size); 58 - extern int gfs2_xattr_set(struct inode *inode, int type, const char *name, 59 - const void *value, size_t size, int flags); 60 extern ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size); 61 extern int gfs2_ea_dealloc(struct gfs2_inode *ip); 62
··· 53 struct gfs2_ea_header *el_prev; 54 }; 55 56 + extern int __gfs2_xattr_set(struct inode *inode, const char *name, 57 + const void *value, size_t size, 58 + int flags, int type); 59 extern ssize_t gfs2_listxattr(struct dentry *dentry, char *buffer, size_t size); 60 extern int gfs2_ea_dealloc(struct gfs2_inode *ip); 61
+8 -9
fs/hugetlbfs/inode.c
··· 30 #include <linux/dnotify.h> 31 #include <linux/statfs.h> 32 #include <linux/security.h> 33 - #include <linux/ima.h> 34 #include <linux/magic.h> 35 36 #include <asm/uaccess.h> ··· 921 int error = -ENOMEM; 922 struct file *file; 923 struct inode *inode; 924 - struct dentry *dentry, *root; 925 struct qstr quick_string; 926 927 *user = NULL; ··· 944 quick_string.name = name; 945 quick_string.len = strlen(quick_string.name); 946 quick_string.hash = 0; 947 - dentry = d_alloc(root, &quick_string); 948 - if (!dentry) 949 goto out_shm_unlock; 950 951 error = -ENOSPC; 952 inode = hugetlbfs_get_inode(root->d_sb, current_fsuid(), 953 current_fsgid(), S_IFREG | S_IRWXUGO, 0); ··· 961 acctflag)) 962 goto out_inode; 963 964 - d_instantiate(dentry, inode); 965 inode->i_size = size; 966 inode->i_nlink = 0; 967 968 error = -ENFILE; 969 - file = alloc_file(hugetlbfs_vfsmount, dentry, 970 - FMODE_WRITE | FMODE_READ, 971 &hugetlbfs_file_operations); 972 if (!file) 973 goto out_dentry; /* inode is already attached */ 974 - ima_counts_get(file); 975 976 return file; 977 978 out_inode: 979 iput(inode); 980 out_dentry: 981 - dput(dentry); 982 out_shm_unlock: 983 if (*user) { 984 user_shm_unlock(size, *user);
··· 30 #include <linux/dnotify.h> 31 #include <linux/statfs.h> 32 #include <linux/security.h> 33 #include <linux/magic.h> 34 35 #include <asm/uaccess.h> ··· 922 int error = -ENOMEM; 923 struct file *file; 924 struct inode *inode; 925 + struct path path; 926 + struct dentry *root; 927 struct qstr quick_string; 928 929 *user = NULL; ··· 944 quick_string.name = name; 945 quick_string.len = strlen(quick_string.name); 946 quick_string.hash = 0; 947 + path.dentry = d_alloc(root, &quick_string); 948 + if (!path.dentry) 949 goto out_shm_unlock; 950 951 + path.mnt = mntget(hugetlbfs_vfsmount); 952 error = -ENOSPC; 953 inode = hugetlbfs_get_inode(root->d_sb, current_fsuid(), 954 current_fsgid(), S_IFREG | S_IRWXUGO, 0); ··· 960 acctflag)) 961 goto out_inode; 962 963 + d_instantiate(path.dentry, inode); 964 inode->i_size = size; 965 inode->i_nlink = 0; 966 967 error = -ENFILE; 968 + file = alloc_file(&path, FMODE_WRITE | FMODE_READ, 969 &hugetlbfs_file_operations); 970 if (!file) 971 goto out_dentry; /* inode is already attached */ 972 973 return file; 974 975 out_inode: 976 iput(inode); 977 out_dentry: 978 + path_put(&path); 979 out_shm_unlock: 980 if (*user) { 981 user_shm_unlock(size, *user);
+1
fs/internal.h
··· 79 * file_table.c 80 */ 81 extern void mark_files_ro(struct super_block *); 82 83 /* 84 * super.c
··· 79 * file_table.c 80 */ 81 extern void mark_files_ro(struct super_block *); 82 + extern struct file *get_empty_filp(void); 83 84 /* 85 * super.c
+22 -43
fs/jffs2/acl.c
··· 350 return rc; 351 } 352 353 - static size_t jffs2_acl_access_listxattr(struct inode *inode, char *list, size_t list_size, 354 - const char *name, size_t name_len) 355 { 356 const int retlen = sizeof(POSIX_ACL_XATTR_ACCESS); 357 ··· 360 return retlen; 361 } 362 363 - static size_t jffs2_acl_default_listxattr(struct inode *inode, char *list, size_t list_size, 364 - const char *name, size_t name_len) 365 { 366 const int retlen = sizeof(POSIX_ACL_XATTR_DEFAULT); 367 ··· 370 return retlen; 371 } 372 373 - static int jffs2_acl_getxattr(struct inode *inode, int type, void *buffer, size_t size) 374 { 375 struct posix_acl *acl; 376 int rc; 377 378 - acl = jffs2_get_acl(inode, type); 379 if (IS_ERR(acl)) 380 return PTR_ERR(acl); 381 if (!acl) ··· 390 return rc; 391 } 392 393 - static int jffs2_acl_access_getxattr(struct inode *inode, const char *name, void *buffer, size_t size) 394 - { 395 - if (name[0] != '\0') 396 - return -EINVAL; 397 - return jffs2_acl_getxattr(inode, ACL_TYPE_ACCESS, buffer, size); 398 - } 399 - 400 - static int jffs2_acl_default_getxattr(struct inode *inode, const char *name, void *buffer, size_t size) 401 - { 402 - if (name[0] != '\0') 403 - return -EINVAL; 404 - return jffs2_acl_getxattr(inode, ACL_TYPE_DEFAULT, buffer, size); 405 - } 406 - 407 - static int jffs2_acl_setxattr(struct inode *inode, int type, const void *value, size_t size) 408 { 409 struct posix_acl *acl; 410 int rc; 411 412 - if (!is_owner_or_cap(inode)) 413 return -EPERM; 414 415 if (value) { ··· 413 } else { 414 acl = NULL; 415 } 416 - rc = jffs2_set_acl(inode, type, acl); 417 out: 418 posix_acl_release(acl); 419 return rc; 420 } 421 422 - static int jffs2_acl_access_setxattr(struct inode *inode, const char *name, 423 - const void *buffer, size_t size, int flags) 424 - { 425 - if (name[0] != '\0') 426 - return -EINVAL; 427 - return jffs2_acl_setxattr(inode, ACL_TYPE_ACCESS, buffer, size); 428 - } 429 - 430 - static int jffs2_acl_default_setxattr(struct inode *inode, const char *name, 431 - const void *buffer, size_t size, int flags) 432 - { 433 - if (name[0] != '\0') 434 - return -EINVAL; 435 - return jffs2_acl_setxattr(inode, ACL_TYPE_DEFAULT, buffer, size); 436 - } 437 - 438 struct xattr_handler jffs2_acl_access_xattr_handler = { 439 .prefix = POSIX_ACL_XATTR_ACCESS, 440 .list = jffs2_acl_access_listxattr, 441 - .get = jffs2_acl_access_getxattr, 442 - .set = jffs2_acl_access_setxattr, 443 }; 444 445 struct xattr_handler jffs2_acl_default_xattr_handler = { 446 .prefix = POSIX_ACL_XATTR_DEFAULT, 447 .list = jffs2_acl_default_listxattr, 448 - .get = jffs2_acl_default_getxattr, 449 - .set = jffs2_acl_default_setxattr, 450 };
··· 350 return rc; 351 } 352 353 + static size_t jffs2_acl_access_listxattr(struct dentry *dentry, char *list, 354 + size_t list_size, const char *name, size_t name_len, int type) 355 { 356 const int retlen = sizeof(POSIX_ACL_XATTR_ACCESS); 357 ··· 360 return retlen; 361 } 362 363 + static size_t jffs2_acl_default_listxattr(struct dentry *dentry, char *list, 364 + size_t list_size, const char *name, size_t name_len, int type) 365 { 366 const int retlen = sizeof(POSIX_ACL_XATTR_DEFAULT); 367 ··· 370 return retlen; 371 } 372 373 + static int jffs2_acl_getxattr(struct dentry *dentry, const char *name, 374 + void *buffer, size_t size, int type) 375 { 376 struct posix_acl *acl; 377 int rc; 378 379 + if (name[0] != '\0') 380 + return -EINVAL; 381 + 382 + acl = jffs2_get_acl(dentry->d_inode, type); 383 if (IS_ERR(acl)) 384 return PTR_ERR(acl); 385 if (!acl) ··· 386 return rc; 387 } 388 389 + static int jffs2_acl_setxattr(struct dentry *dentry, const char *name, 390 + const void *value, size_t size, int flags, int type) 391 { 392 struct posix_acl *acl; 393 int rc; 394 395 + if (name[0] != '\0') 396 + return -EINVAL; 397 + if (!is_owner_or_cap(dentry->d_inode)) 398 return -EPERM; 399 400 if (value) { ··· 420 } else { 421 acl = NULL; 422 } 423 + rc = jffs2_set_acl(dentry->d_inode, type, acl); 424 out: 425 posix_acl_release(acl); 426 return rc; 427 } 428 429 struct xattr_handler jffs2_acl_access_xattr_handler = { 430 .prefix = POSIX_ACL_XATTR_ACCESS, 431 + .flags = ACL_TYPE_DEFAULT, 432 .list = jffs2_acl_access_listxattr, 433 + .get = jffs2_acl_getxattr, 434 + .set = jffs2_acl_setxattr, 435 }; 436 437 struct xattr_handler jffs2_acl_default_xattr_handler = { 438 .prefix = POSIX_ACL_XATTR_DEFAULT, 439 + .flags = ACL_TYPE_DEFAULT, 440 .list = jffs2_acl_default_listxattr, 441 + .get = jffs2_acl_getxattr, 442 + .set = jffs2_acl_setxattr, 443 };
+10 -8
fs/jffs2/security.c
··· 44 } 45 46 /* ---- XATTR Handler for "security.*" ----------------- */ 47 - static int jffs2_security_getxattr(struct inode *inode, const char *name, 48 - void *buffer, size_t size) 49 { 50 if (!strcmp(name, "")) 51 return -EINVAL; 52 53 - return do_jffs2_getxattr(inode, JFFS2_XPREFIX_SECURITY, name, buffer, size); 54 } 55 56 - static int jffs2_security_setxattr(struct inode *inode, const char *name, const void *buffer, 57 - size_t size, int flags) 58 { 59 if (!strcmp(name, "")) 60 return -EINVAL; 61 62 - return do_jffs2_setxattr(inode, JFFS2_XPREFIX_SECURITY, name, buffer, size, flags); 63 } 64 65 - static size_t jffs2_security_listxattr(struct inode *inode, char *list, size_t list_size, 66 - const char *name, size_t name_len) 67 { 68 size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1; 69
··· 44 } 45 46 /* ---- XATTR Handler for "security.*" ----------------- */ 47 + static int jffs2_security_getxattr(struct dentry *dentry, const char *name, 48 + void *buffer, size_t size, int type) 49 { 50 if (!strcmp(name, "")) 51 return -EINVAL; 52 53 + return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, 54 + name, buffer, size); 55 } 56 57 + static int jffs2_security_setxattr(struct dentry *dentry, const char *name, 58 + const void *buffer, size_t size, int flags, int type) 59 { 60 if (!strcmp(name, "")) 61 return -EINVAL; 62 63 + return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_SECURITY, 64 + name, buffer, size, flags); 65 } 66 67 + static size_t jffs2_security_listxattr(struct dentry *dentry, char *list, 68 + size_t list_size, const char *name, size_t name_len, int type) 69 { 70 size_t retlen = XATTR_SECURITY_PREFIX_LEN + name_len + 1; 71
+4 -2
fs/jffs2/xattr.c
··· 990 if (!xhandle) 991 continue; 992 if (buffer) { 993 - rc = xhandle->list(inode, buffer+len, size-len, xd->xname, xd->name_len); 994 } else { 995 - rc = xhandle->list(inode, NULL, 0, xd->xname, xd->name_len); 996 } 997 if (rc < 0) 998 goto out;
··· 990 if (!xhandle) 991 continue; 992 if (buffer) { 993 + rc = xhandle->list(dentry, buffer+len, size-len, 994 + xd->xname, xd->name_len, xd->flags); 995 } else { 996 + rc = xhandle->list(dentry, NULL, 0, xd->xname, 997 + xd->name_len, xd->flags); 998 } 999 if (rc < 0) 1000 goto out;
+10 -8
fs/jffs2/xattr_trusted.c
··· 16 #include <linux/mtd/mtd.h> 17 #include "nodelist.h" 18 19 - static int jffs2_trusted_getxattr(struct inode *inode, const char *name, 20 - void *buffer, size_t size) 21 { 22 if (!strcmp(name, "")) 23 return -EINVAL; 24 - return do_jffs2_getxattr(inode, JFFS2_XPREFIX_TRUSTED, name, buffer, size); 25 } 26 27 - static int jffs2_trusted_setxattr(struct inode *inode, const char *name, const void *buffer, 28 - size_t size, int flags) 29 { 30 if (!strcmp(name, "")) 31 return -EINVAL; 32 - return do_jffs2_setxattr(inode, JFFS2_XPREFIX_TRUSTED, name, buffer, size, flags); 33 } 34 35 - static size_t jffs2_trusted_listxattr(struct inode *inode, char *list, size_t list_size, 36 - const char *name, size_t name_len) 37 { 38 size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1; 39
··· 16 #include <linux/mtd/mtd.h> 17 #include "nodelist.h" 18 19 + static int jffs2_trusted_getxattr(struct dentry *dentry, const char *name, 20 + void *buffer, size_t size, int type) 21 { 22 if (!strcmp(name, "")) 23 return -EINVAL; 24 + return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_TRUSTED, 25 + name, buffer, size); 26 } 27 28 + static int jffs2_trusted_setxattr(struct dentry *dentry, const char *name, 29 + const void *buffer, size_t size, int flags, int type) 30 { 31 if (!strcmp(name, "")) 32 return -EINVAL; 33 + return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_TRUSTED, 34 + name, buffer, size, flags); 35 } 36 37 + static size_t jffs2_trusted_listxattr(struct dentry *dentry, char *list, 38 + size_t list_size, const char *name, size_t name_len, int type) 39 { 40 size_t retlen = XATTR_TRUSTED_PREFIX_LEN + name_len + 1; 41
+10 -8
fs/jffs2/xattr_user.c
··· 16 #include <linux/mtd/mtd.h> 17 #include "nodelist.h" 18 19 - static int jffs2_user_getxattr(struct inode *inode, const char *name, 20 - void *buffer, size_t size) 21 { 22 if (!strcmp(name, "")) 23 return -EINVAL; 24 - return do_jffs2_getxattr(inode, JFFS2_XPREFIX_USER, name, buffer, size); 25 } 26 27 - static int jffs2_user_setxattr(struct inode *inode, const char *name, const void *buffer, 28 - size_t size, int flags) 29 { 30 if (!strcmp(name, "")) 31 return -EINVAL; 32 - return do_jffs2_setxattr(inode, JFFS2_XPREFIX_USER, name, buffer, size, flags); 33 } 34 35 - static size_t jffs2_user_listxattr(struct inode *inode, char *list, size_t list_size, 36 - const char *name, size_t name_len) 37 { 38 size_t retlen = XATTR_USER_PREFIX_LEN + name_len + 1; 39
··· 16 #include <linux/mtd/mtd.h> 17 #include "nodelist.h" 18 19 + static int jffs2_user_getxattr(struct dentry *dentry, const char *name, 20 + void *buffer, size_t size, int type) 21 { 22 if (!strcmp(name, "")) 23 return -EINVAL; 24 + return do_jffs2_getxattr(dentry->d_inode, JFFS2_XPREFIX_USER, 25 + name, buffer, size); 26 } 27 28 + static int jffs2_user_setxattr(struct dentry *dentry, const char *name, 29 + const void *buffer, size_t size, int flags, int type) 30 { 31 if (!strcmp(name, "")) 32 return -EINVAL; 33 + return do_jffs2_setxattr(dentry->d_inode, JFFS2_XPREFIX_USER, 34 + name, buffer, size, flags); 35 } 36 37 + static size_t jffs2_user_listxattr(struct dentry *dentry, char *list, 38 + size_t list_size, const char *name, size_t name_len, int type) 39 { 40 size_t retlen = XATTR_USER_PREFIX_LEN + name_len + 1; 41
-1
fs/libfs.c
··· 848 EXPORT_SYMBOL(simple_dir_inode_operations); 849 EXPORT_SYMBOL(simple_dir_operations); 850 EXPORT_SYMBOL(simple_empty); 851 - EXPORT_SYMBOL(d_alloc_name); 852 EXPORT_SYMBOL(simple_fill_super); 853 EXPORT_SYMBOL(simple_getattr); 854 EXPORT_SYMBOL(simple_link);
··· 848 EXPORT_SYMBOL(simple_dir_inode_operations); 849 EXPORT_SYMBOL(simple_dir_operations); 850 EXPORT_SYMBOL(simple_empty); 851 EXPORT_SYMBOL(simple_fill_super); 852 EXPORT_SYMBOL(simple_getattr); 853 EXPORT_SYMBOL(simple_link);
+233 -233
fs/namei.c
··· 35 #include <linux/fs_struct.h> 36 #include <asm/uaccess.h> 37 38 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) 39 40 /* [Feb-1997 T. Schoebel-Theuer] ··· 109 * implemented. Let's see if raised priority of ->s_vfs_rename_mutex gives 110 * any extra contention... 111 */ 112 - 113 - static int __link_path_walk(const char *name, struct nameidata *nd); 114 115 /* In order to reduce some races, while at the same time doing additional 116 * checking and hopefully speeding things up, we copy filenames to the ··· 414 } 415 416 /* 417 - * Internal lookup() using the new generic dcache. 418 - * SMP-safe 419 */ 420 - static struct dentry * cached_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd) 421 { 422 - struct dentry * dentry = __d_lookup(parent, name); 423 424 - /* lockess __d_lookup may fail due to concurrent d_move() 425 - * in some unrelated directory, so try with d_lookup 426 */ 427 - if (!dentry) 428 - dentry = d_lookup(parent, name); 429 430 - if (dentry && dentry->d_op && dentry->d_op->d_revalidate) 431 - dentry = do_revalidate(dentry, nd); 432 433 - return dentry; 434 } 435 436 /* 437 - * Short-cut version of permission(), for calling by 438 - * path_walk(), when dcache lock is held. Combines parts 439 - * of permission() and generic_permission(), and tests ONLY for 440 - * MAY_EXEC permission. 441 * 442 * If appropriate, check DAC only. If not appropriate, or 443 - * short-cut DAC fails, then call permission() to do more 444 * complete permission check. 445 */ 446 - static int exec_permission_lite(struct inode *inode) 447 { 448 int ret; 449 ··· 484 return security_inode_permission(inode, MAY_EXEC); 485 } 486 487 - /* 488 - * This is called when everything else fails, and we actually have 489 - * to go to the low-level filesystem to find out what we should do.. 490 - * 491 - * We get the directory semaphore, and after getting that we also 492 - * make sure that nobody added the entry to the dcache in the meantime.. 493 - * SMP-safe 494 - */ 495 - static struct dentry * real_lookup(struct dentry * parent, struct qstr * name, struct nameidata *nd) 496 - { 497 - struct dentry * result; 498 - struct inode *dir = parent->d_inode; 499 - 500 - mutex_lock(&dir->i_mutex); 501 - /* 502 - * First re-do the cached lookup just in case it was created 503 - * while we waited for the directory semaphore.. 504 - * 505 - * FIXME! This could use version numbering or similar to 506 - * avoid unnecessary cache lookups. 507 - * 508 - * The "dcache_lock" is purely to protect the RCU list walker 509 - * from concurrent renames at this point (we mustn't get false 510 - * negatives from the RCU list walk here, unlike the optimistic 511 - * fast walk). 512 - * 513 - * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup 514 - */ 515 - result = d_lookup(parent, name); 516 - if (!result) { 517 - struct dentry *dentry; 518 - 519 - /* Don't create child dentry for a dead directory. */ 520 - result = ERR_PTR(-ENOENT); 521 - if (IS_DEADDIR(dir)) 522 - goto out_unlock; 523 - 524 - dentry = d_alloc(parent, name); 525 - result = ERR_PTR(-ENOMEM); 526 - if (dentry) { 527 - result = dir->i_op->lookup(dir, dentry, nd); 528 - if (result) 529 - dput(dentry); 530 - else 531 - result = dentry; 532 - } 533 - out_unlock: 534 - mutex_unlock(&dir->i_mutex); 535 - return result; 536 - } 537 - 538 - /* 539 - * Uhhuh! Nasty case: the cache was re-populated while 540 - * we waited on the semaphore. Need to revalidate. 541 - */ 542 - mutex_unlock(&dir->i_mutex); 543 - if (result->d_op && result->d_op->d_revalidate) { 544 - result = do_revalidate(result, nd); 545 - if (!result) 546 - result = ERR_PTR(-ENOENT); 547 - } 548 - return result; 549 - } 550 - 551 - /* 552 - * Wrapper to retry pathname resolution whenever the underlying 553 - * file system returns an ESTALE. 554 - * 555 - * Retry the whole path once, forcing real lookup requests 556 - * instead of relying on the dcache. 557 - */ 558 - static __always_inline int link_path_walk(const char *name, struct nameidata *nd) 559 - { 560 - struct path save = nd->path; 561 - int result; 562 - 563 - /* make sure the stuff we saved doesn't go away */ 564 - path_get(&save); 565 - 566 - result = __link_path_walk(name, nd); 567 - if (result == -ESTALE) { 568 - /* nd->path had been dropped */ 569 - nd->path = save; 570 - path_get(&nd->path); 571 - nd->flags |= LOOKUP_REVAL; 572 - result = __link_path_walk(name, nd); 573 - } 574 - 575 - path_put(&save); 576 - 577 - return result; 578 - } 579 - 580 static __always_inline void set_root(struct nameidata *nd) 581 { 582 if (!nd->root.mnt) { ··· 494 read_unlock(&fs->lock); 495 } 496 } 497 498 static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link) 499 { ··· 569 error = 0; 570 if (s) 571 error = __vfs_follow_link(nd, s); 572 if (dentry->d_inode->i_op->put_link) 573 dentry->d_inode->i_op->put_link(dentry, nd, cookie); 574 } 575 - path_put(path); 576 - 577 return error; 578 } 579 ··· 603 current->total_link_count++; 604 nd->depth++; 605 err = __do_follow_link(path, nd); 606 current->link_count--; 607 nd->depth--; 608 return err; ··· 729 struct path *path) 730 { 731 struct vfsmount *mnt = nd->path.mnt; 732 - struct dentry *dentry = __d_lookup(nd->path.dentry, name); 733 734 if (!dentry) 735 goto need_lookup; 736 if (dentry->d_op && dentry->d_op->d_revalidate) ··· 753 return 0; 754 755 need_lookup: 756 - dentry = real_lookup(nd->path.dentry, name, nd); 757 if (IS_ERR(dentry)) 758 goto fail; 759 goto done; ··· 830 * Returns 0 and nd will have valid dentry and mnt on success. 831 * Returns error and drops reference to input namei data on failure. 832 */ 833 - static int __link_path_walk(const char *name, struct nameidata *nd) 834 { 835 struct path next; 836 struct inode *inode; ··· 853 unsigned int c; 854 855 nd->flags |= LOOKUP_CONTINUE; 856 - err = exec_permission_lite(inode); 857 if (err) 858 break; 859 ··· 892 /* fallthrough */ 893 case 1: 894 continue; 895 - } 896 - /* 897 - * See if the low-level filesystem might want 898 - * to use its own hash.. 899 - */ 900 - if (nd->path.dentry->d_op && nd->path.dentry->d_op->d_hash) { 901 - err = nd->path.dentry->d_op->d_hash(nd->path.dentry, 902 - &this); 903 - if (err < 0) 904 - break; 905 } 906 /* This does the actual lookups.. */ 907 err = do_lookup(nd, &this, &next); ··· 937 /* fallthrough */ 938 case 1: 939 goto return_reval; 940 - } 941 - if (nd->path.dentry->d_op && nd->path.dentry->d_op->d_hash) { 942 - err = nd->path.dentry->d_op->d_hash(nd->path.dentry, 943 - &this); 944 - if (err < 0) 945 - break; 946 } 947 err = do_lookup(nd, &this, &next); 948 if (err) ··· 996 997 static int path_walk(const char *name, struct nameidata *nd) 998 { 999 current->total_link_count = 0; 1000 - return link_path_walk(name, nd); 1001 } 1002 1003 static int path_init(int dfd, const char *name, unsigned int flags, struct nameidata *nd) ··· 1139 return retval; 1140 } 1141 1142 - /** 1143 - * path_lookup_open - lookup a file path with open intent 1144 - * @dfd: the directory to use as base, or AT_FDCWD 1145 - * @name: pointer to file name 1146 - * @lookup_flags: lookup intent flags 1147 - * @nd: pointer to nameidata 1148 - * @open_flags: open intent flags 1149 - */ 1150 - static int path_lookup_open(int dfd, const char *name, 1151 - unsigned int lookup_flags, struct nameidata *nd, int open_flags) 1152 - { 1153 - struct file *filp = get_empty_filp(); 1154 - int err; 1155 - 1156 - if (filp == NULL) 1157 - return -ENFILE; 1158 - nd->intent.open.file = filp; 1159 - nd->intent.open.flags = open_flags; 1160 - nd->intent.open.create_mode = 0; 1161 - err = do_path_lookup(dfd, name, lookup_flags|LOOKUP_OPEN, nd); 1162 - if (IS_ERR(nd->intent.open.file)) { 1163 - if (err == 0) { 1164 - err = PTR_ERR(nd->intent.open.file); 1165 - path_put(&nd->path); 1166 - } 1167 - } else if (err != 0) 1168 - release_open_intent(nd); 1169 - return err; 1170 - } 1171 - 1172 static struct dentry *__lookup_hash(struct qstr *name, 1173 struct dentry *base, struct nameidata *nd) 1174 { ··· 1159 goto out; 1160 } 1161 1162 - dentry = cached_lookup(base, name, nd); 1163 if (!dentry) { 1164 struct dentry *new; 1165 ··· 1201 { 1202 int err; 1203 1204 - err = inode_permission(nd->path.dentry->d_inode, MAY_EXEC); 1205 if (err) 1206 return ERR_PTR(err); 1207 return __lookup_hash(&nd->last, nd->path.dentry, nd); ··· 1251 if (err) 1252 return ERR_PTR(err); 1253 1254 - err = inode_permission(base->d_inode, MAY_EXEC); 1255 if (err) 1256 return ERR_PTR(err); 1257 return __lookup_hash(&this, base, NULL); ··· 1489 if (error) 1490 return error; 1491 1492 - error = ima_path_check(path, acc_mode ? 1493 - acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC) : 1494 - ACC_MODE(flag) & (MAY_READ | MAY_WRITE), 1495 - IMA_COUNT_UPDATE); 1496 - 1497 - if (error) 1498 - return error; 1499 /* 1500 * An append-only file must be opened in append mode for writing. 1501 */ 1502 if (IS_APPEND(inode)) { 1503 - error = -EPERM; 1504 if ((flag & FMODE_WRITE) && !(flag & O_APPEND)) 1505 - goto err_out; 1506 if (flag & O_TRUNC) 1507 - goto err_out; 1508 } 1509 1510 /* O_NOATIME can only be set by the owner or superuser */ 1511 - if (flag & O_NOATIME) 1512 - if (!is_owner_or_cap(inode)) { 1513 - error = -EPERM; 1514 - goto err_out; 1515 - } 1516 1517 /* 1518 * Ensure there are no outstanding leases on the file. 1519 */ 1520 - error = break_lease(inode, flag); 1521 if (error) 1522 - goto err_out; 1523 - 1524 - if (flag & O_TRUNC) { 1525 - error = get_write_access(inode); 1526 - if (error) 1527 - goto err_out; 1528 - 1529 - /* 1530 - * Refuse to truncate files with mandatory locks held on them. 1531 - */ 1532 - error = locks_verify_locked(inode); 1533 - if (!error) 1534 - error = security_path_truncate(path, 0, 1535 - ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); 1536 - if (!error) { 1537 - vfs_dq_init(inode); 1538 - 1539 - error = do_truncate(dentry, 0, 1540 - ATTR_MTIME|ATTR_CTIME|ATTR_OPEN, 1541 - NULL); 1542 - } 1543 - put_write_access(inode); 1544 - if (error) 1545 - goto err_out; 1546 - } else 1547 - if (flag & FMODE_WRITE) 1548 - vfs_dq_init(inode); 1549 - 1550 - return 0; 1551 - err_out: 1552 - ima_counts_put(path, acc_mode ? 1553 - acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC) : 1554 - ACC_MODE(flag) & (MAY_READ | MAY_WRITE)); 1555 return error; 1556 } 1557 ··· 1582 return flag; 1583 } 1584 1585 - static int open_will_write_to_fs(int flag, struct inode *inode) 1586 { 1587 /* 1588 * We'll never write to the fs underlying ··· 1604 struct file *filp; 1605 struct nameidata nd; 1606 int error; 1607 - struct path path; 1608 struct dentry *dir; 1609 int count = 0; 1610 - int will_write; 1611 int flag = open_to_namei_flags(open_flag); 1612 1613 /* ··· 1635 * The simplest case - just a plain lookup. 1636 */ 1637 if (!(flag & O_CREAT)) { 1638 - error = path_lookup_open(dfd, pathname, lookup_flags(flag), 1639 - &nd, flag); 1640 if (error) 1641 return ERR_PTR(error); 1642 goto ok; ··· 1726 goto exit; 1727 } 1728 filp = nameidata_to_filp(&nd, open_flag); 1729 - if (IS_ERR(filp)) 1730 - ima_counts_put(&nd.path, 1731 - acc_mode & (MAY_READ | MAY_WRITE | 1732 - MAY_EXEC)); 1733 mnt_drop_write(nd.path.mnt); 1734 if (nd.root.mnt) 1735 path_put(&nd.root); 1736 return filp; 1737 } 1738 ··· 1777 * be avoided. Taking this mnt write here 1778 * ensures that (2) can not occur. 1779 */ 1780 - will_write = open_will_write_to_fs(flag, nd.path.dentry->d_inode); 1781 - if (will_write) { 1782 error = mnt_want_write(nd.path.mnt); 1783 if (error) 1784 goto exit; 1785 } 1786 error = may_open(&nd.path, acc_mode, flag); 1787 if (error) { 1788 - if (will_write) 1789 mnt_drop_write(nd.path.mnt); 1790 goto exit; 1791 } 1792 filp = nameidata_to_filp(&nd, open_flag); 1793 - if (IS_ERR(filp)) 1794 - ima_counts_put(&nd.path, 1795 - acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC)); 1796 /* 1797 * It is now safe to drop the mnt write 1798 * because the filp has had a write taken 1799 * on its behalf. 1800 */ 1801 - if (will_write) 1802 mnt_drop_write(nd.path.mnt); 1803 if (nd.root.mnt) 1804 path_put(&nd.root); ··· 1852 error = security_inode_follow_link(path.dentry, &nd); 1853 if (error) 1854 goto exit_dput; 1855 error = __do_follow_link(&path, &nd); 1856 if (error) { 1857 /* Does someone understand code flow here? Or it is only 1858 * me so stupid? Anathema to whoever designed this non-sense
··· 35 #include <linux/fs_struct.h> 36 #include <asm/uaccess.h> 37 38 + #include "internal.h" 39 + 40 #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE]) 41 42 /* [Feb-1997 T. Schoebel-Theuer] ··· 107 * implemented. Let's see if raised priority of ->s_vfs_rename_mutex gives 108 * any extra contention... 109 */ 110 111 /* In order to reduce some races, while at the same time doing additional 112 * checking and hopefully speeding things up, we copy filenames to the ··· 414 } 415 416 /* 417 + * force_reval_path - force revalidation of a dentry 418 + * 419 + * In some situations the path walking code will trust dentries without 420 + * revalidating them. This causes problems for filesystems that depend on 421 + * d_revalidate to handle file opens (e.g. NFSv4). When FS_REVAL_DOT is set 422 + * (which indicates that it's possible for the dentry to go stale), force 423 + * a d_revalidate call before proceeding. 424 + * 425 + * Returns 0 if the revalidation was successful. If the revalidation fails, 426 + * either return the error returned by d_revalidate or -ESTALE if the 427 + * revalidation it just returned 0. If d_revalidate returns 0, we attempt to 428 + * invalidate the dentry. It's up to the caller to handle putting references 429 + * to the path if necessary. 430 */ 431 + static int 432 + force_reval_path(struct path *path, struct nameidata *nd) 433 { 434 + int status; 435 + struct dentry *dentry = path->dentry; 436 437 + /* 438 + * only check on filesystems where it's possible for the dentry to 439 + * become stale. It's assumed that if this flag is set then the 440 + * d_revalidate op will also be defined. 441 */ 442 + if (!(dentry->d_sb->s_type->fs_flags & FS_REVAL_DOT)) 443 + return 0; 444 445 + status = dentry->d_op->d_revalidate(dentry, nd); 446 + if (status > 0) 447 + return 0; 448 449 + if (!status) { 450 + d_invalidate(dentry); 451 + status = -ESTALE; 452 + } 453 + return status; 454 } 455 456 /* 457 + * Short-cut version of permission(), for calling on directories 458 + * during pathname resolution. Combines parts of permission() 459 + * and generic_permission(), and tests ONLY for MAY_EXEC permission. 460 * 461 * If appropriate, check DAC only. If not appropriate, or 462 + * short-cut DAC fails, then call ->permission() to do more 463 * complete permission check. 464 */ 465 + static int exec_permission(struct inode *inode) 466 { 467 int ret; 468 ··· 465 return security_inode_permission(inode, MAY_EXEC); 466 } 467 468 static __always_inline void set_root(struct nameidata *nd) 469 { 470 if (!nd->root.mnt) { ··· 568 read_unlock(&fs->lock); 569 } 570 } 571 + 572 + static int link_path_walk(const char *, struct nameidata *); 573 574 static __always_inline int __vfs_follow_link(struct nameidata *nd, const char *link) 575 { ··· 641 error = 0; 642 if (s) 643 error = __vfs_follow_link(nd, s); 644 + else if (nd->last_type == LAST_BIND) { 645 + error = force_reval_path(&nd->path, nd); 646 + if (error) 647 + path_put(&nd->path); 648 + } 649 if (dentry->d_inode->i_op->put_link) 650 dentry->d_inode->i_op->put_link(dentry, nd, cookie); 651 } 652 return error; 653 } 654 ··· 672 current->total_link_count++; 673 nd->depth++; 674 err = __do_follow_link(path, nd); 675 + path_put(path); 676 current->link_count--; 677 nd->depth--; 678 return err; ··· 797 struct path *path) 798 { 799 struct vfsmount *mnt = nd->path.mnt; 800 + struct dentry *dentry, *parent; 801 + struct inode *dir; 802 + /* 803 + * See if the low-level filesystem might want 804 + * to use its own hash.. 805 + */ 806 + if (nd->path.dentry->d_op && nd->path.dentry->d_op->d_hash) { 807 + int err = nd->path.dentry->d_op->d_hash(nd->path.dentry, name); 808 + if (err < 0) 809 + return err; 810 + } 811 812 + dentry = __d_lookup(nd->path.dentry, name); 813 if (!dentry) 814 goto need_lookup; 815 if (dentry->d_op && dentry->d_op->d_revalidate) ··· 810 return 0; 811 812 need_lookup: 813 + parent = nd->path.dentry; 814 + dir = parent->d_inode; 815 + 816 + mutex_lock(&dir->i_mutex); 817 + /* 818 + * First re-do the cached lookup just in case it was created 819 + * while we waited for the directory semaphore.. 820 + * 821 + * FIXME! This could use version numbering or similar to 822 + * avoid unnecessary cache lookups. 823 + * 824 + * The "dcache_lock" is purely to protect the RCU list walker 825 + * from concurrent renames at this point (we mustn't get false 826 + * negatives from the RCU list walk here, unlike the optimistic 827 + * fast walk). 828 + * 829 + * so doing d_lookup() (with seqlock), instead of lockfree __d_lookup 830 + */ 831 + dentry = d_lookup(parent, name); 832 + if (!dentry) { 833 + struct dentry *new; 834 + 835 + /* Don't create child dentry for a dead directory. */ 836 + dentry = ERR_PTR(-ENOENT); 837 + if (IS_DEADDIR(dir)) 838 + goto out_unlock; 839 + 840 + new = d_alloc(parent, name); 841 + dentry = ERR_PTR(-ENOMEM); 842 + if (new) { 843 + dentry = dir->i_op->lookup(dir, new, nd); 844 + if (dentry) 845 + dput(new); 846 + else 847 + dentry = new; 848 + } 849 + out_unlock: 850 + mutex_unlock(&dir->i_mutex); 851 + if (IS_ERR(dentry)) 852 + goto fail; 853 + goto done; 854 + } 855 + 856 + /* 857 + * Uhhuh! Nasty case: the cache was re-populated while 858 + * we waited on the semaphore. Need to revalidate. 859 + */ 860 + mutex_unlock(&dir->i_mutex); 861 + if (dentry->d_op && dentry->d_op->d_revalidate) { 862 + dentry = do_revalidate(dentry, nd); 863 + if (!dentry) 864 + dentry = ERR_PTR(-ENOENT); 865 + } 866 if (IS_ERR(dentry)) 867 goto fail; 868 goto done; ··· 835 * Returns 0 and nd will have valid dentry and mnt on success. 836 * Returns error and drops reference to input namei data on failure. 837 */ 838 + static int link_path_walk(const char *name, struct nameidata *nd) 839 { 840 struct path next; 841 struct inode *inode; ··· 858 unsigned int c; 859 860 nd->flags |= LOOKUP_CONTINUE; 861 + err = exec_permission(inode); 862 if (err) 863 break; 864 ··· 897 /* fallthrough */ 898 case 1: 899 continue; 900 } 901 /* This does the actual lookups.. */ 902 err = do_lookup(nd, &this, &next); ··· 952 /* fallthrough */ 953 case 1: 954 goto return_reval; 955 } 956 err = do_lookup(nd, &this, &next); 957 if (err) ··· 1017 1018 static int path_walk(const char *name, struct nameidata *nd) 1019 { 1020 + struct path save = nd->path; 1021 + int result; 1022 + 1023 current->total_link_count = 0; 1024 + 1025 + /* make sure the stuff we saved doesn't go away */ 1026 + path_get(&save); 1027 + 1028 + result = link_path_walk(name, nd); 1029 + if (result == -ESTALE) { 1030 + /* nd->path had been dropped */ 1031 + current->total_link_count = 0; 1032 + nd->path = save; 1033 + path_get(&nd->path); 1034 + nd->flags |= LOOKUP_REVAL; 1035 + result = link_path_walk(name, nd); 1036 + } 1037 + 1038 + path_put(&save); 1039 + 1040 + return result; 1041 } 1042 1043 static int path_init(int dfd, const char *name, unsigned int flags, struct nameidata *nd) ··· 1141 return retval; 1142 } 1143 1144 static struct dentry *__lookup_hash(struct qstr *name, 1145 struct dentry *base, struct nameidata *nd) 1146 { ··· 1191 goto out; 1192 } 1193 1194 + dentry = __d_lookup(base, name); 1195 + 1196 + /* lockess __d_lookup may fail due to concurrent d_move() 1197 + * in some unrelated directory, so try with d_lookup 1198 + */ 1199 + if (!dentry) 1200 + dentry = d_lookup(base, name); 1201 + 1202 + if (dentry && dentry->d_op && dentry->d_op->d_revalidate) 1203 + dentry = do_revalidate(dentry, nd); 1204 + 1205 if (!dentry) { 1206 struct dentry *new; 1207 ··· 1223 { 1224 int err; 1225 1226 + err = exec_permission(nd->path.dentry->d_inode); 1227 if (err) 1228 return ERR_PTR(err); 1229 return __lookup_hash(&nd->last, nd->path.dentry, nd); ··· 1273 if (err) 1274 return ERR_PTR(err); 1275 1276 + err = exec_permission(base->d_inode); 1277 if (err) 1278 return ERR_PTR(err); 1279 return __lookup_hash(&this, base, NULL); ··· 1511 if (error) 1512 return error; 1513 1514 /* 1515 * An append-only file must be opened in append mode for writing. 1516 */ 1517 if (IS_APPEND(inode)) { 1518 if ((flag & FMODE_WRITE) && !(flag & O_APPEND)) 1519 + return -EPERM; 1520 if (flag & O_TRUNC) 1521 + return -EPERM; 1522 } 1523 1524 /* O_NOATIME can only be set by the owner or superuser */ 1525 + if (flag & O_NOATIME && !is_owner_or_cap(inode)) 1526 + return -EPERM; 1527 1528 /* 1529 * Ensure there are no outstanding leases on the file. 1530 */ 1531 + return break_lease(inode, flag); 1532 + } 1533 + 1534 + static int handle_truncate(struct path *path) 1535 + { 1536 + struct inode *inode = path->dentry->d_inode; 1537 + int error = get_write_access(inode); 1538 if (error) 1539 + return error; 1540 + /* 1541 + * Refuse to truncate files with mandatory locks held on them. 1542 + */ 1543 + error = locks_verify_locked(inode); 1544 + if (!error) 1545 + error = security_path_truncate(path, 0, 1546 + ATTR_MTIME|ATTR_CTIME|ATTR_OPEN); 1547 + if (!error) { 1548 + error = do_truncate(path->dentry, 0, 1549 + ATTR_MTIME|ATTR_CTIME|ATTR_OPEN, 1550 + NULL); 1551 + } 1552 + put_write_access(inode); 1553 return error; 1554 } 1555 ··· 1628 return flag; 1629 } 1630 1631 + static int open_will_truncate(int flag, struct inode *inode) 1632 { 1633 /* 1634 * We'll never write to the fs underlying ··· 1650 struct file *filp; 1651 struct nameidata nd; 1652 int error; 1653 + struct path path, save; 1654 struct dentry *dir; 1655 int count = 0; 1656 + int will_truncate; 1657 int flag = open_to_namei_flags(open_flag); 1658 1659 /* ··· 1681 * The simplest case - just a plain lookup. 1682 */ 1683 if (!(flag & O_CREAT)) { 1684 + filp = get_empty_filp(); 1685 + 1686 + if (filp == NULL) 1687 + return ERR_PTR(-ENFILE); 1688 + nd.intent.open.file = filp; 1689 + nd.intent.open.flags = flag; 1690 + nd.intent.open.create_mode = 0; 1691 + error = do_path_lookup(dfd, pathname, 1692 + lookup_flags(flag)|LOOKUP_OPEN, &nd); 1693 + if (IS_ERR(nd.intent.open.file)) { 1694 + if (error == 0) { 1695 + error = PTR_ERR(nd.intent.open.file); 1696 + path_put(&nd.path); 1697 + } 1698 + } else if (error) 1699 + release_open_intent(&nd); 1700 if (error) 1701 return ERR_PTR(error); 1702 goto ok; ··· 1758 goto exit; 1759 } 1760 filp = nameidata_to_filp(&nd, open_flag); 1761 mnt_drop_write(nd.path.mnt); 1762 if (nd.root.mnt) 1763 path_put(&nd.root); 1764 + if (!IS_ERR(filp)) { 1765 + error = ima_path_check(&filp->f_path, filp->f_mode & 1766 + (MAY_READ | MAY_WRITE | MAY_EXEC)); 1767 + if (error) { 1768 + fput(filp); 1769 + filp = ERR_PTR(error); 1770 + } 1771 + } 1772 return filp; 1773 } 1774 ··· 1805 * be avoided. Taking this mnt write here 1806 * ensures that (2) can not occur. 1807 */ 1808 + will_truncate = open_will_truncate(flag, nd.path.dentry->d_inode); 1809 + if (will_truncate) { 1810 error = mnt_want_write(nd.path.mnt); 1811 if (error) 1812 goto exit; 1813 } 1814 error = may_open(&nd.path, acc_mode, flag); 1815 if (error) { 1816 + if (will_truncate) 1817 mnt_drop_write(nd.path.mnt); 1818 goto exit; 1819 } 1820 filp = nameidata_to_filp(&nd, open_flag); 1821 + if (!IS_ERR(filp)) { 1822 + error = ima_path_check(&filp->f_path, filp->f_mode & 1823 + (MAY_READ | MAY_WRITE | MAY_EXEC)); 1824 + if (error) { 1825 + fput(filp); 1826 + filp = ERR_PTR(error); 1827 + } 1828 + } 1829 + if (!IS_ERR(filp)) { 1830 + if (acc_mode & MAY_WRITE) 1831 + vfs_dq_init(nd.path.dentry->d_inode); 1832 + 1833 + if (will_truncate) { 1834 + error = handle_truncate(&nd.path); 1835 + if (error) { 1836 + fput(filp); 1837 + filp = ERR_PTR(error); 1838 + } 1839 + } 1840 + } 1841 /* 1842 * It is now safe to drop the mnt write 1843 * because the filp has had a write taken 1844 * on its behalf. 1845 */ 1846 + if (will_truncate) 1847 mnt_drop_write(nd.path.mnt); 1848 if (nd.root.mnt) 1849 path_put(&nd.root); ··· 1863 error = security_inode_follow_link(path.dentry, &nd); 1864 if (error) 1865 goto exit_dput; 1866 + save = nd.path; 1867 + path_get(&save); 1868 error = __do_follow_link(&path, &nd); 1869 + if (error == -ESTALE) { 1870 + /* nd.path had been dropped */ 1871 + nd.path = save; 1872 + path_get(&nd.path); 1873 + nd.flags |= LOOKUP_REVAL; 1874 + error = __do_follow_link(&path, &nd); 1875 + } 1876 + path_put(&save); 1877 + path_put(&path); 1878 if (error) { 1879 /* Does someone understand code flow here? Or it is only 1880 * me so stupid? Anathema to whoever designed this non-sense
+1 -2
fs/namespace.c
··· 2068 * create_mnt_ns - creates a private namespace and adds a root filesystem 2069 * @mnt: pointer to the new root filesystem mountpoint 2070 */ 2071 - struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) 2072 { 2073 struct mnt_namespace *new_ns; 2074 ··· 2080 } 2081 return new_ns; 2082 } 2083 - EXPORT_SYMBOL(create_mnt_ns); 2084 2085 SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 2086 char __user *, type, unsigned long, flags, void __user *, data)
··· 2068 * create_mnt_ns - creates a private namespace and adds a root filesystem 2069 * @mnt: pointer to the new root filesystem mountpoint 2070 */ 2071 + static struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt) 2072 { 2073 struct mnt_namespace *new_ns; 2074 ··· 2080 } 2081 return new_ns; 2082 } 2083 2084 SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 2085 char __user *, type, unsigned long, flags, void __user *, data)
-8
fs/nfs/super.c
··· 2648 static int nfs_follow_remote_path(struct vfsmount *root_mnt, 2649 const char *export_path, struct vfsmount *mnt_target) 2650 { 2651 - struct mnt_namespace *ns_private; 2652 struct nameidata nd; 2653 struct super_block *s; 2654 int ret; 2655 2656 - ns_private = create_mnt_ns(root_mnt); 2657 - ret = PTR_ERR(ns_private); 2658 - if (IS_ERR(ns_private)) 2659 - goto out_mntput; 2660 - 2661 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, 2662 export_path, LOOKUP_FOLLOW, &nd); 2663 - 2664 - put_mnt_ns(ns_private); 2665 2666 if (ret != 0) 2667 goto out_err;
··· 2648 static int nfs_follow_remote_path(struct vfsmount *root_mnt, 2649 const char *export_path, struct vfsmount *mnt_target) 2650 { 2651 struct nameidata nd; 2652 struct super_block *s; 2653 int ret; 2654 2655 ret = vfs_path_lookup(root_mnt->mnt_root, root_mnt, 2656 export_path, LOOKUP_FOLLOW, &nd); 2657 2658 if (ret != 0) 2659 goto out_err;
+1 -4
fs/nfsd/vfs.c
··· 752 flags, current_cred()); 753 if (IS_ERR(*filp)) 754 host_err = PTR_ERR(*filp); 755 - else 756 - ima_counts_get(*filp); 757 out_nfserr: 758 err = nfserrno(host_err); 759 out: ··· 2130 */ 2131 path.mnt = exp->ex_path.mnt; 2132 path.dentry = dentry; 2133 - err = ima_path_check(&path, acc & (MAY_READ | MAY_WRITE | MAY_EXEC), 2134 - IMA_COUNT_LEAVE); 2135 nfsd_out: 2136 return err? nfserrno(err) : 0; 2137 }
··· 752 flags, current_cred()); 753 if (IS_ERR(*filp)) 754 host_err = PTR_ERR(*filp); 755 out_nfserr: 756 err = nfserrno(host_err); 757 out: ··· 2132 */ 2133 path.mnt = exp->ex_path.mnt; 2134 path.dentry = dentry; 2135 + err = ima_path_check(&path, acc & (MAY_READ | MAY_WRITE | MAY_EXEC)); 2136 nfsd_out: 2137 return err? nfserrno(err) : 0; 2138 }
+1 -2
fs/nilfs2/super.c
··· 1118 /* Abandoning the newly allocated superblock */ 1119 mutex_unlock(&nilfs->ns_mount_mutex); 1120 put_nilfs(nilfs); 1121 - up_write(&s->s_umount); 1122 - deactivate_super(s); 1123 /* 1124 * deactivate_super() invokes close_bdev_exclusive(). 1125 * We must finish all post-cleaning before this call;
··· 1118 /* Abandoning the newly allocated superblock */ 1119 mutex_unlock(&nilfs->ns_mount_mutex); 1120 put_nilfs(nilfs); 1121 + deactivate_locked_super(s); 1122 /* 1123 * deactivate_super() invokes close_bdev_exclusive(). 1124 * We must finish all post-cleaning before this call;
+14 -15
fs/notify/inotify/inotify_user.c
··· 646 struct fsnotify_group *group; 647 struct user_struct *user; 648 struct file *filp; 649 int fd, ret; 650 651 /* Check the IN_* constants for consistency. */ ··· 659 fd = get_unused_fd_flags(flags & O_CLOEXEC); 660 if (fd < 0) 661 return fd; 662 - 663 - filp = get_empty_filp(); 664 - if (!filp) { 665 - ret = -ENFILE; 666 - goto out_put_fd; 667 - } 668 669 user = get_current_user(); 670 if (unlikely(atomic_read(&user->inotify_devs) >= ··· 674 goto out_free_uid; 675 } 676 677 - filp->f_op = &inotify_fops; 678 - filp->f_path.mnt = mntget(inotify_mnt); 679 - filp->f_path.dentry = dget(inotify_mnt->mnt_root); 680 - filp->f_mapping = filp->f_path.dentry->d_inode->i_mapping; 681 - filp->f_mode = FMODE_READ; 682 filp->f_flags = O_RDONLY | (flags & O_NONBLOCK); 683 filp->private_data = group; 684 - 685 - atomic_inc(&user->inotify_devs); 686 687 fd_install(fd, filp); 688 689 return fd; 690 691 out_free_uid: 692 free_uid(user); 693 - put_filp(filp); 694 - out_put_fd: 695 put_unused_fd(fd); 696 return ret; 697 }
··· 646 struct fsnotify_group *group; 647 struct user_struct *user; 648 struct file *filp; 649 + struct path path; 650 int fd, ret; 651 652 /* Check the IN_* constants for consistency. */ ··· 658 fd = get_unused_fd_flags(flags & O_CLOEXEC); 659 if (fd < 0) 660 return fd; 661 662 user = get_current_user(); 663 if (unlikely(atomic_read(&user->inotify_devs) >= ··· 679 goto out_free_uid; 680 } 681 682 + atomic_inc(&user->inotify_devs); 683 + 684 + path.mnt = inotify_mnt; 685 + path.dentry = inotify_mnt->mnt_root; 686 + path_get(&path); 687 + filp = alloc_file(&path, FMODE_READ, &inotify_fops); 688 + if (!filp) 689 + goto Enfile; 690 + 691 filp->f_flags = O_RDONLY | (flags & O_NONBLOCK); 692 filp->private_data = group; 693 694 fd_install(fd, filp); 695 696 return fd; 697 698 + Enfile: 699 + ret = -ENFILE; 700 + path_put(&path); 701 + atomic_dec(&user->inotify_devs); 702 out_free_uid: 703 free_uid(user); 704 put_unused_fd(fd); 705 return ret; 706 }
+25 -62
fs/ocfs2/acl.c
··· 331 return ret; 332 } 333 334 - static size_t ocfs2_xattr_list_acl_access(struct inode *inode, 335 char *list, 336 size_t list_len, 337 const char *name, 338 - size_t name_len) 339 { 340 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 341 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 342 343 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) ··· 349 return size; 350 } 351 352 - static size_t ocfs2_xattr_list_acl_default(struct inode *inode, 353 char *list, 354 size_t list_len, 355 const char *name, 356 - size_t name_len) 357 { 358 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 359 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 360 361 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) ··· 367 return size; 368 } 369 370 - static int ocfs2_xattr_get_acl(struct inode *inode, 371 - int type, 372 - void *buffer, 373 - size_t size) 374 { 375 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 376 struct posix_acl *acl; 377 int ret; 378 379 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) 380 return -EOPNOTSUPP; 381 382 - acl = ocfs2_get_acl(inode, type); 383 if (IS_ERR(acl)) 384 return PTR_ERR(acl); 385 if (acl == NULL) ··· 390 return ret; 391 } 392 393 - static int ocfs2_xattr_get_acl_access(struct inode *inode, 394 - const char *name, 395 - void *buffer, 396 - size_t size) 397 { 398 - if (strcmp(name, "") != 0) 399 - return -EINVAL; 400 - return ocfs2_xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 401 - } 402 - 403 - static int ocfs2_xattr_get_acl_default(struct inode *inode, 404 - const char *name, 405 - void *buffer, 406 - size_t size) 407 - { 408 - if (strcmp(name, "") != 0) 409 - return -EINVAL; 410 - return ocfs2_xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 411 - } 412 - 413 - static int ocfs2_xattr_set_acl(struct inode *inode, 414 - int type, 415 - const void *value, 416 - size_t size) 417 - { 418 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 419 struct posix_acl *acl; 420 int ret = 0; 421 422 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) 423 return -EOPNOTSUPP; 424 ··· 425 return ret; 426 } 427 428 - static int ocfs2_xattr_set_acl_access(struct inode *inode, 429 - const char *name, 430 - const void *value, 431 - size_t size, 432 - int flags) 433 - { 434 - if (strcmp(name, "") != 0) 435 - return -EINVAL; 436 - return ocfs2_xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 437 - } 438 - 439 - static int ocfs2_xattr_set_acl_default(struct inode *inode, 440 - const char *name, 441 - const void *value, 442 - size_t size, 443 - int flags) 444 - { 445 - if (strcmp(name, "") != 0) 446 - return -EINVAL; 447 - return ocfs2_xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 448 - } 449 - 450 struct xattr_handler ocfs2_xattr_acl_access_handler = { 451 .prefix = POSIX_ACL_XATTR_ACCESS, 452 .list = ocfs2_xattr_list_acl_access, 453 - .get = ocfs2_xattr_get_acl_access, 454 - .set = ocfs2_xattr_set_acl_access, 455 }; 456 457 struct xattr_handler ocfs2_xattr_acl_default_handler = { 458 .prefix = POSIX_ACL_XATTR_DEFAULT, 459 .list = ocfs2_xattr_list_acl_default, 460 - .get = ocfs2_xattr_get_acl_default, 461 - .set = ocfs2_xattr_set_acl_default, 462 };
··· 331 return ret; 332 } 333 334 + static size_t ocfs2_xattr_list_acl_access(struct dentry *dentry, 335 char *list, 336 size_t list_len, 337 const char *name, 338 + size_t name_len, 339 + int type) 340 { 341 + struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 342 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 343 344 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) ··· 348 return size; 349 } 350 351 + static size_t ocfs2_xattr_list_acl_default(struct dentry *dentry, 352 char *list, 353 size_t list_len, 354 const char *name, 355 + size_t name_len, 356 + int type) 357 { 358 + struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 359 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 360 361 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) ··· 365 return size; 366 } 367 368 + static int ocfs2_xattr_get_acl(struct dentry *dentry, const char *name, 369 + void *buffer, size_t size, int type) 370 { 371 + struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 372 struct posix_acl *acl; 373 int ret; 374 375 + if (strcmp(name, "") != 0) 376 + return -EINVAL; 377 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) 378 return -EOPNOTSUPP; 379 380 + acl = ocfs2_get_acl(dentry->d_inode, type); 381 if (IS_ERR(acl)) 382 return PTR_ERR(acl); 383 if (acl == NULL) ··· 388 return ret; 389 } 390 391 + static int ocfs2_xattr_set_acl(struct dentry *dentry, const char *name, 392 + const void *value, size_t size, int flags, int type) 393 { 394 + struct inode *inode = dentry->d_inode; 395 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 396 struct posix_acl *acl; 397 int ret = 0; 398 399 + if (strcmp(name, "") != 0) 400 + return -EINVAL; 401 if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL)) 402 return -EOPNOTSUPP; 403 ··· 442 return ret; 443 } 444 445 struct xattr_handler ocfs2_xattr_acl_access_handler = { 446 .prefix = POSIX_ACL_XATTR_ACCESS, 447 + .flags = ACL_TYPE_ACCESS, 448 .list = ocfs2_xattr_list_acl_access, 449 + .get = ocfs2_xattr_get_acl, 450 + .set = ocfs2_xattr_set_acl, 451 }; 452 453 struct xattr_handler ocfs2_xattr_acl_default_handler = { 454 .prefix = POSIX_ACL_XATTR_DEFAULT, 455 + .flags = ACL_TYPE_DEFAULT, 456 .list = ocfs2_xattr_list_acl_default, 457 + .get = ocfs2_xattr_get_acl, 458 + .set = ocfs2_xattr_set_acl, 459 };
+2 -2
fs/ocfs2/alloc.c
··· 7190 * wait on them - the truncate_inode_pages() call later will 7191 * do that for us. 7192 */ 7193 - ret = do_sync_mapping_range(inode->i_mapping, range_start, 7194 - range_end - 1, SYNC_FILE_RANGE_WRITE); 7195 if (ret) 7196 mlog_errno(ret); 7197
··· 7190 * wait on them - the truncate_inode_pages() call later will 7191 * do that for us. 7192 */ 7193 + ret = filemap_fdatawrite_range(inode->i_mapping, range_start, 7194 + range_end - 1); 7195 if (ret) 7196 mlog_errno(ret); 7197
+35 -37
fs/ocfs2/xattr.c
··· 205 int offset, 206 struct ocfs2_xattr_value_root **xv, 207 struct buffer_head **bh); 208 - static int ocfs2_xattr_security_set(struct inode *inode, const char *name, 209 - const void *value, size_t size, int flags); 210 211 static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) 212 { ··· 6976 6977 ret = ocfs2_init_security_get(inode, dir, &si); 6978 if (!ret) { 6979 - ret = ocfs2_xattr_security_set(inode, si.name, 6980 - si.value, si.value_len, 6981 - XATTR_CREATE); 6982 if (ret) { 6983 mlog_errno(ret); 6984 goto leave; ··· 7006 /* 7007 * 'security' attributes support 7008 */ 7009 - static size_t ocfs2_xattr_security_list(struct inode *inode, char *list, 7010 size_t list_size, const char *name, 7011 - size_t name_len) 7012 { 7013 const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; 7014 const size_t total_len = prefix_len + name_len + 1; ··· 7021 return total_len; 7022 } 7023 7024 - static int ocfs2_xattr_security_get(struct inode *inode, const char *name, 7025 - void *buffer, size_t size) 7026 { 7027 if (strcmp(name, "") == 0) 7028 return -EINVAL; 7029 - return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_SECURITY, name, 7030 - buffer, size); 7031 } 7032 7033 - static int ocfs2_xattr_security_set(struct inode *inode, const char *name, 7034 - const void *value, size_t size, int flags) 7035 { 7036 if (strcmp(name, "") == 0) 7037 return -EINVAL; 7038 7039 - return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, name, value, 7040 - size, flags); 7041 } 7042 7043 int ocfs2_init_security_get(struct inode *inode, ··· 7074 /* 7075 * 'trusted' attributes support 7076 */ 7077 - static size_t ocfs2_xattr_trusted_list(struct inode *inode, char *list, 7078 size_t list_size, const char *name, 7079 - size_t name_len) 7080 { 7081 const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; 7082 const size_t total_len = prefix_len + name_len + 1; ··· 7089 return total_len; 7090 } 7091 7092 - static int ocfs2_xattr_trusted_get(struct inode *inode, const char *name, 7093 - void *buffer, size_t size) 7094 { 7095 if (strcmp(name, "") == 0) 7096 return -EINVAL; 7097 - return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_TRUSTED, name, 7098 - buffer, size); 7099 } 7100 7101 - static int ocfs2_xattr_trusted_set(struct inode *inode, const char *name, 7102 - const void *value, size_t size, int flags) 7103 { 7104 if (strcmp(name, "") == 0) 7105 return -EINVAL; 7106 7107 - return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_TRUSTED, name, value, 7108 - size, flags); 7109 } 7110 7111 struct xattr_handler ocfs2_xattr_trusted_handler = { ··· 7118 /* 7119 * 'user' attributes support 7120 */ 7121 - static size_t ocfs2_xattr_user_list(struct inode *inode, char *list, 7122 size_t list_size, const char *name, 7123 - size_t name_len) 7124 { 7125 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 7126 const size_t total_len = prefix_len + name_len + 1; 7127 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 7128 7129 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7130 return 0; ··· 7137 return total_len; 7138 } 7139 7140 - static int ocfs2_xattr_user_get(struct inode *inode, const char *name, 7141 - void *buffer, size_t size) 7142 { 7143 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 7144 7145 if (strcmp(name, "") == 0) 7146 return -EINVAL; 7147 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7148 return -EOPNOTSUPP; 7149 - return ocfs2_xattr_get(inode, OCFS2_XATTR_INDEX_USER, name, 7150 buffer, size); 7151 } 7152 7153 - static int ocfs2_xattr_user_set(struct inode *inode, const char *name, 7154 - const void *value, size_t size, int flags) 7155 { 7156 - struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); 7157 7158 if (strcmp(name, "") == 0) 7159 return -EINVAL; 7160 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7161 return -EOPNOTSUPP; 7162 7163 - return ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_USER, name, value, 7164 - size, flags); 7165 } 7166 7167 struct xattr_handler ocfs2_xattr_user_handler = {
··· 205 int offset, 206 struct ocfs2_xattr_value_root **xv, 207 struct buffer_head **bh); 208 209 static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) 210 { ··· 6978 6979 ret = ocfs2_init_security_get(inode, dir, &si); 6980 if (!ret) { 6981 + ret = ocfs2_xattr_set(inode, OCFS2_XATTR_INDEX_SECURITY, 6982 + si.name, si.value, si.value_len, 6983 + XATTR_CREATE); 6984 if (ret) { 6985 mlog_errno(ret); 6986 goto leave; ··· 7008 /* 7009 * 'security' attributes support 7010 */ 7011 + static size_t ocfs2_xattr_security_list(struct dentry *dentry, char *list, 7012 size_t list_size, const char *name, 7013 + size_t name_len, int type) 7014 { 7015 const size_t prefix_len = XATTR_SECURITY_PREFIX_LEN; 7016 const size_t total_len = prefix_len + name_len + 1; ··· 7023 return total_len; 7024 } 7025 7026 + static int ocfs2_xattr_security_get(struct dentry *dentry, const char *name, 7027 + void *buffer, size_t size, int type) 7028 { 7029 if (strcmp(name, "") == 0) 7030 return -EINVAL; 7031 + return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, 7032 + name, buffer, size); 7033 } 7034 7035 + static int ocfs2_xattr_security_set(struct dentry *dentry, const char *name, 7036 + const void *value, size_t size, int flags, int type) 7037 { 7038 if (strcmp(name, "") == 0) 7039 return -EINVAL; 7040 7041 + return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_SECURITY, 7042 + name, value, size, flags); 7043 } 7044 7045 int ocfs2_init_security_get(struct inode *inode, ··· 7076 /* 7077 * 'trusted' attributes support 7078 */ 7079 + static size_t ocfs2_xattr_trusted_list(struct dentry *dentry, char *list, 7080 size_t list_size, const char *name, 7081 + size_t name_len, int type) 7082 { 7083 const size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN; 7084 const size_t total_len = prefix_len + name_len + 1; ··· 7091 return total_len; 7092 } 7093 7094 + static int ocfs2_xattr_trusted_get(struct dentry *dentry, const char *name, 7095 + void *buffer, size_t size, int type) 7096 { 7097 if (strcmp(name, "") == 0) 7098 return -EINVAL; 7099 + return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, 7100 + name, buffer, size); 7101 } 7102 7103 + static int ocfs2_xattr_trusted_set(struct dentry *dentry, const char *name, 7104 + const void *value, size_t size, int flags, int type) 7105 { 7106 if (strcmp(name, "") == 0) 7107 return -EINVAL; 7108 7109 + return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_TRUSTED, 7110 + name, value, size, flags); 7111 } 7112 7113 struct xattr_handler ocfs2_xattr_trusted_handler = { ··· 7120 /* 7121 * 'user' attributes support 7122 */ 7123 + static size_t ocfs2_xattr_user_list(struct dentry *dentry, char *list, 7124 size_t list_size, const char *name, 7125 + size_t name_len, int type) 7126 { 7127 const size_t prefix_len = XATTR_USER_PREFIX_LEN; 7128 const size_t total_len = prefix_len + name_len + 1; 7129 + struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 7130 7131 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7132 return 0; ··· 7139 return total_len; 7140 } 7141 7142 + static int ocfs2_xattr_user_get(struct dentry *dentry, const char *name, 7143 + void *buffer, size_t size, int type) 7144 { 7145 + struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 7146 7147 if (strcmp(name, "") == 0) 7148 return -EINVAL; 7149 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7150 return -EOPNOTSUPP; 7151 + return ocfs2_xattr_get(dentry->d_inode, OCFS2_XATTR_INDEX_USER, name, 7152 buffer, size); 7153 } 7154 7155 + static int ocfs2_xattr_user_set(struct dentry *dentry, const char *name, 7156 + const void *value, size_t size, int flags, int type) 7157 { 7158 + struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb); 7159 7160 if (strcmp(name, "") == 0) 7161 return -EINVAL; 7162 if (osb->s_mount_opt & OCFS2_MOUNT_NOUSERXATTR) 7163 return -EOPNOTSUPP; 7164 7165 + return ocfs2_xattr_set(dentry->d_inode, OCFS2_XATTR_INDEX_USER, 7166 + name, value, size, flags); 7167 } 7168 7169 struct xattr_handler ocfs2_xattr_user_handler = {
+4
fs/open.c
··· 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 { ··· 858 if (error) 859 goto cleanup_all; 860 } 861 862 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); 863
··· 30 #include <linux/audit.h> 31 #include <linux/falloc.h> 32 #include <linux/fs_struct.h> 33 + #include <linux/ima.h> 34 + 35 + #include "internal.h" 36 37 int vfs_statfs(struct dentry *dentry, struct kstatfs *buf) 38 { ··· 855 if (error) 856 goto cleanup_all; 857 } 858 + ima_counts_get(f); 859 860 f->f_flags &= ~(O_CREAT | O_EXCL | O_NOCTTY | O_TRUNC); 861
+12 -17
fs/pipe.c
··· 974 int err; 975 struct inode *inode; 976 struct file *f; 977 - struct dentry *dentry; 978 struct qstr name = { .name = "" }; 979 980 err = -ENFILE; ··· 983 goto err; 984 985 err = -ENOMEM; 986 - dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &name); 987 - if (!dentry) 988 goto err_inode; 989 990 - dentry->d_op = &pipefs_dentry_operations; 991 /* 992 * We dont want to publish this dentry into global dentry hash table. 993 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED 994 * This permits a working /proc/$pid/fd/XXX on pipes 995 */ 996 - dentry->d_flags &= ~DCACHE_UNHASHED; 997 - d_instantiate(dentry, inode); 998 999 err = -ENFILE; 1000 - f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipefifo_fops); 1001 if (!f) 1002 goto err_dentry; 1003 f->f_mapping = inode->i_mapping; ··· 1010 1011 err_dentry: 1012 free_pipe_info(inode); 1013 - dput(dentry); 1014 return ERR_PTR(err); 1015 1016 err_inode: ··· 1029 1030 struct file *create_read_pipe(struct file *wrf, int flags) 1031 { 1032 - struct file *f = get_empty_filp(); 1033 if (!f) 1034 return ERR_PTR(-ENFILE); 1035 1036 - /* Grab pipe from the writer */ 1037 - f->f_path = wrf->f_path; 1038 path_get(&wrf->f_path); 1039 - f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping; 1040 - 1041 - f->f_pos = 0; 1042 f->f_flags = O_RDONLY | (flags & O_NONBLOCK); 1043 - f->f_op = &read_pipefifo_fops; 1044 - f->f_mode = FMODE_READ; 1045 - f->f_version = 0; 1046 1047 return f; 1048 }
··· 974 int err; 975 struct inode *inode; 976 struct file *f; 977 + struct path path; 978 struct qstr name = { .name = "" }; 979 980 err = -ENFILE; ··· 983 goto err; 984 985 err = -ENOMEM; 986 + path.dentry = d_alloc(pipe_mnt->mnt_sb->s_root, &name); 987 + if (!path.dentry) 988 goto err_inode; 989 + path.mnt = mntget(pipe_mnt); 990 991 + path.dentry->d_op = &pipefs_dentry_operations; 992 /* 993 * We dont want to publish this dentry into global dentry hash table. 994 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED 995 * This permits a working /proc/$pid/fd/XXX on pipes 996 */ 997 + path.dentry->d_flags &= ~DCACHE_UNHASHED; 998 + d_instantiate(path.dentry, inode); 999 1000 err = -ENFILE; 1001 + f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops); 1002 if (!f) 1003 goto err_dentry; 1004 f->f_mapping = inode->i_mapping; ··· 1009 1010 err_dentry: 1011 free_pipe_info(inode); 1012 + path_put(&path); 1013 return ERR_PTR(err); 1014 1015 err_inode: ··· 1028 1029 struct file *create_read_pipe(struct file *wrf, int flags) 1030 { 1031 + /* Grab pipe from the writer */ 1032 + struct file *f = alloc_file(&wrf->f_path, FMODE_READ, 1033 + &read_pipefifo_fops); 1034 if (!f) 1035 return ERR_PTR(-ENFILE); 1036 1037 path_get(&wrf->f_path); 1038 f->f_flags = O_RDONLY | (flags & O_NONBLOCK); 1039 1040 return f; 1041 }
+18 -18
fs/reiserfs/xattr.c
··· 48 #include <net/checksum.h> 49 #include <linux/stat.h> 50 #include <linux/quotaops.h> 51 52 #define PRIVROOT_NAME ".reiserfs_priv" 53 #define XAROOT_NAME "xattrs" ··· 727 reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, 728 size_t size) 729 { 730 - struct inode *inode = dentry->d_inode; 731 struct xattr_handler *handler; 732 733 - handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); 734 735 - if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) 736 return -EOPNOTSUPP; 737 738 - return handler->get(inode, name, buffer, size); 739 } 740 741 /* ··· 746 reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, 747 size_t size, int flags) 748 { 749 - struct inode *inode = dentry->d_inode; 750 struct xattr_handler *handler; 751 752 - handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); 753 754 - if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) 755 return -EOPNOTSUPP; 756 757 - return handler->set(inode, name, value, size, flags); 758 } 759 760 /* ··· 763 */ 764 int reiserfs_removexattr(struct dentry *dentry, const char *name) 765 { 766 - struct inode *inode = dentry->d_inode; 767 struct xattr_handler *handler; 768 - handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); 769 770 - if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) 771 return -EOPNOTSUPP; 772 773 - return handler->set(inode, name, NULL, 0, XATTR_REPLACE); 774 } 775 776 struct listxattr_buf { 777 size_t size; 778 size_t pos; 779 char *buf; 780 - struct inode *inode; 781 }; 782 783 static int listxattr_filler(void *buf, const char *name, int namelen, ··· 787 if (name[0] != '.' || 788 (namelen != 1 && (name[1] != '.' || namelen != 2))) { 789 struct xattr_handler *handler; 790 - handler = find_xattr_handler_prefix(b->inode->i_sb->s_xattr, 791 name); 792 if (!handler) /* Unsupported xattr name */ 793 return 0; 794 if (b->buf) { 795 - size = handler->list(b->inode, b->buf + b->pos, 796 - b->size, name, namelen); 797 if (size > b->size) 798 return -ERANGE; 799 } else { 800 - size = handler->list(b->inode, NULL, 0, name, namelen); 801 } 802 803 b->pos += size; ··· 820 int err = 0; 821 loff_t pos = 0; 822 struct listxattr_buf buf = { 823 - .inode = dentry->d_inode, 824 .buf = buffer, 825 .size = buffer ? size : 0, 826 };
··· 48 #include <net/checksum.h> 49 #include <linux/stat.h> 50 #include <linux/quotaops.h> 51 + #include <linux/security.h> 52 53 #define PRIVROOT_NAME ".reiserfs_priv" 54 #define XAROOT_NAME "xattrs" ··· 726 reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, 727 size_t size) 728 { 729 struct xattr_handler *handler; 730 731 + handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); 732 733 + if (!handler || get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 734 return -EOPNOTSUPP; 735 736 + return handler->get(dentry, name, buffer, size, handler->flags); 737 } 738 739 /* ··· 746 reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, 747 size_t size, int flags) 748 { 749 struct xattr_handler *handler; 750 751 + handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); 752 753 + if (!handler || get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 754 return -EOPNOTSUPP; 755 756 + return handler->set(dentry, name, value, size, flags, handler->flags); 757 } 758 759 /* ··· 764 */ 765 int reiserfs_removexattr(struct dentry *dentry, const char *name) 766 { 767 struct xattr_handler *handler; 768 + handler = find_xattr_handler_prefix(dentry->d_sb->s_xattr, name); 769 770 + if (!handler || get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) 771 return -EOPNOTSUPP; 772 773 + return handler->set(dentry, name, NULL, 0, XATTR_REPLACE, handler->flags); 774 } 775 776 struct listxattr_buf { 777 size_t size; 778 size_t pos; 779 char *buf; 780 + struct dentry *dentry; 781 }; 782 783 static int listxattr_filler(void *buf, const char *name, int namelen, ··· 789 if (name[0] != '.' || 790 (namelen != 1 && (name[1] != '.' || namelen != 2))) { 791 struct xattr_handler *handler; 792 + handler = find_xattr_handler_prefix(b->dentry->d_sb->s_xattr, 793 name); 794 if (!handler) /* Unsupported xattr name */ 795 return 0; 796 if (b->buf) { 797 + size = handler->list(b->dentry, b->buf + b->pos, 798 + b->size, name, namelen, 799 + handler->flags); 800 if (size > b->size) 801 return -ERANGE; 802 } else { 803 + size = handler->list(b->dentry, NULL, 0, name, 804 + namelen, handler->flags); 805 } 806 807 b->pos += size; ··· 820 int err = 0; 821 loff_t pos = 0; 822 struct listxattr_buf buf = { 823 + .dentry = dentry, 824 .buf = buffer, 825 .size = buffer ? size : 0, 826 };
+19 -50
fs/reiserfs/xattr_acl.c
··· 15 struct posix_acl *acl); 16 17 static int 18 - xattr_set_acl(struct inode *inode, int type, const void *value, size_t size) 19 { 20 struct posix_acl *acl; 21 int error, error2; 22 struct reiserfs_transaction_handle th; ··· 62 } 63 64 static int 65 - xattr_get_acl(struct inode *inode, int type, void *buffer, size_t size) 66 { 67 struct posix_acl *acl; 68 int error; 69 70 - if (!reiserfs_posixacl(inode->i_sb)) 71 return -EOPNOTSUPP; 72 73 - acl = reiserfs_get_acl(inode, type); 74 if (IS_ERR(acl)) 75 return PTR_ERR(acl); 76 if (acl == NULL) ··· 485 return error; 486 } 487 488 - static int 489 - posix_acl_access_get(struct inode *inode, const char *name, 490 - void *buffer, size_t size) 491 - { 492 - if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1) 493 - return -EINVAL; 494 - return xattr_get_acl(inode, ACL_TYPE_ACCESS, buffer, size); 495 - } 496 - 497 - static int 498 - posix_acl_access_set(struct inode *inode, const char *name, 499 - const void *value, size_t size, int flags) 500 - { 501 - if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1) 502 - return -EINVAL; 503 - return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size); 504 - } 505 - 506 - static size_t posix_acl_access_list(struct inode *inode, char *list, 507 size_t list_size, const char *name, 508 - size_t name_len) 509 { 510 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 511 - if (!reiserfs_posixacl(inode->i_sb)) 512 return 0; 513 if (list && size <= list_size) 514 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 499 500 struct xattr_handler reiserfs_posix_acl_access_handler = { 501 .prefix = POSIX_ACL_XATTR_ACCESS, 502 - .get = posix_acl_access_get, 503 - .set = posix_acl_access_set, 504 .list = posix_acl_access_list, 505 }; 506 507 - static int 508 - posix_acl_default_get(struct inode *inode, const char *name, 509 - void *buffer, size_t size) 510 - { 511 - if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1) 512 - return -EINVAL; 513 - return xattr_get_acl(inode, ACL_TYPE_DEFAULT, buffer, size); 514 - } 515 - 516 - static int 517 - posix_acl_default_set(struct inode *inode, const char *name, 518 - const void *value, size_t size, int flags) 519 - { 520 - if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1) 521 - return -EINVAL; 522 - return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size); 523 - } 524 - 525 - static size_t posix_acl_default_list(struct inode *inode, char *list, 526 size_t list_size, const char *name, 527 - size_t name_len) 528 { 529 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 530 - if (!reiserfs_posixacl(inode->i_sb)) 531 return 0; 532 if (list && size <= list_size) 533 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 519 520 struct xattr_handler reiserfs_posix_acl_default_handler = { 521 .prefix = POSIX_ACL_XATTR_DEFAULT, 522 - .get = posix_acl_default_get, 523 - .set = posix_acl_default_set, 524 .list = posix_acl_default_list, 525 };
··· 15 struct posix_acl *acl); 16 17 static int 18 + posix_acl_set(struct dentry *dentry, const char *name, const void *value, 19 + size_t size, int flags, int type) 20 { 21 + struct inode *inode = dentry->d_inode; 22 struct posix_acl *acl; 23 int error, error2; 24 struct reiserfs_transaction_handle th; ··· 60 } 61 62 static int 63 + posix_acl_get(struct dentry *dentry, const char *name, void *buffer, 64 + size_t size, int type) 65 { 66 struct posix_acl *acl; 67 int error; 68 69 + if (!reiserfs_posixacl(dentry->d_sb)) 70 return -EOPNOTSUPP; 71 72 + acl = reiserfs_get_acl(dentry->d_inode, type); 73 if (IS_ERR(acl)) 74 return PTR_ERR(acl); 75 if (acl == NULL) ··· 482 return error; 483 } 484 485 + static size_t posix_acl_access_list(struct dentry *dentry, char *list, 486 size_t list_size, const char *name, 487 + size_t name_len, int type) 488 { 489 const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS); 490 + if (!reiserfs_posixacl(dentry->d_sb)) 491 return 0; 492 if (list && size <= list_size) 493 memcpy(list, POSIX_ACL_XATTR_ACCESS, size); ··· 514 515 struct xattr_handler reiserfs_posix_acl_access_handler = { 516 .prefix = POSIX_ACL_XATTR_ACCESS, 517 + .flags = ACL_TYPE_ACCESS, 518 + .get = posix_acl_get, 519 + .set = posix_acl_set, 520 .list = posix_acl_access_list, 521 }; 522 523 + static size_t posix_acl_default_list(struct dentry *dentry, char *list, 524 size_t list_size, const char *name, 525 + size_t name_len, int type) 526 { 527 const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT); 528 + if (!reiserfs_posixacl(dentry->d_sb)) 529 return 0; 530 if (list && size <= list_size) 531 memcpy(list, POSIX_ACL_XATTR_DEFAULT, size); ··· 551 552 struct xattr_handler reiserfs_posix_acl_default_handler = { 553 .prefix = POSIX_ACL_XATTR_DEFAULT, 554 + .flags = ACL_TYPE_DEFAULT, 555 + .get = posix_acl_get, 556 + .set = posix_acl_set, 557 .list = posix_acl_default_list, 558 };
+11 -10
fs/reiserfs/xattr_security.c
··· 8 #include <asm/uaccess.h> 9 10 static int 11 - security_get(struct inode *inode, const char *name, void *buffer, size_t size) 12 { 13 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 14 return -EINVAL; 15 16 - if (IS_PRIVATE(inode)) 17 return -EPERM; 18 19 - return reiserfs_xattr_get(inode, name, buffer, size); 20 } 21 22 static int 23 - security_set(struct inode *inode, const char *name, const void *buffer, 24 - size_t size, int flags) 25 { 26 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 27 return -EINVAL; 28 29 - if (IS_PRIVATE(inode)) 30 return -EPERM; 31 32 - return reiserfs_xattr_set(inode, name, buffer, size, flags); 33 } 34 35 - static size_t security_list(struct inode *inode, char *list, size_t list_len, 36 - const char *name, size_t namelen) 37 { 38 const size_t len = namelen + 1; 39 40 - if (IS_PRIVATE(inode)) 41 return 0; 42 43 if (list && len <= list_len) {
··· 8 #include <asm/uaccess.h> 9 10 static int 11 + security_get(struct dentry *dentry, const char *name, void *buffer, size_t size, 12 + int handler_flags) 13 { 14 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 15 return -EINVAL; 16 17 + if (IS_PRIVATE(dentry->d_inode)) 18 return -EPERM; 19 20 + return reiserfs_xattr_get(dentry->d_inode, name, buffer, size); 21 } 22 23 static int 24 + security_set(struct dentry *dentry, const char *name, const void *buffer, 25 + size_t size, int flags, int handler_flags) 26 { 27 if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX)) 28 return -EINVAL; 29 30 + if (IS_PRIVATE(dentry->d_inode)) 31 return -EPERM; 32 33 + return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags); 34 } 35 36 + static size_t security_list(struct dentry *dentry, char *list, size_t list_len, 37 + const char *name, size_t namelen, int handler_flags) 38 { 39 const size_t len = namelen + 1; 40 41 + if (IS_PRIVATE(dentry->d_inode)) 42 return 0; 43 44 if (list && len <= list_len) {
+11 -10
fs/reiserfs/xattr_trusted.c
··· 8 #include <asm/uaccess.h> 9 10 static int 11 - trusted_get(struct inode *inode, const char *name, void *buffer, size_t size) 12 { 13 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 14 return -EINVAL; 15 16 - if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)) 17 return -EPERM; 18 19 - return reiserfs_xattr_get(inode, name, buffer, size); 20 } 21 22 static int 23 - trusted_set(struct inode *inode, const char *name, const void *buffer, 24 - size_t size, int flags) 25 { 26 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 27 return -EINVAL; 28 29 - if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)) 30 return -EPERM; 31 32 - return reiserfs_xattr_set(inode, name, buffer, size, flags); 33 } 34 35 - static size_t trusted_list(struct inode *inode, char *list, size_t list_size, 36 - const char *name, size_t name_len) 37 { 38 const size_t len = name_len + 1; 39 40 - if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)) 41 return 0; 42 43 if (list && len <= list_size) {
··· 8 #include <asm/uaccess.h> 9 10 static int 11 + trusted_get(struct dentry *dentry, const char *name, void *buffer, size_t size, 12 + int handler_flags) 13 { 14 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 15 return -EINVAL; 16 17 + if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode)) 18 return -EPERM; 19 20 + return reiserfs_xattr_get(dentry->d_inode, name, buffer, size); 21 } 22 23 static int 24 + trusted_set(struct dentry *dentry, const char *name, const void *buffer, 25 + size_t size, int flags, int handler_flags) 26 { 27 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX)) 28 return -EINVAL; 29 30 + if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode)) 31 return -EPERM; 32 33 + return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags); 34 } 35 36 + static size_t trusted_list(struct dentry *dentry, char *list, size_t list_size, 37 + const char *name, size_t name_len, int handler_flags) 38 { 39 const size_t len = name_len + 1; 40 41 + if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(dentry->d_inode)) 42 return 0; 43 44 if (list && len <= list_size) {
+11 -10
fs/reiserfs/xattr_user.c
··· 7 #include <asm/uaccess.h> 8 9 static int 10 - user_get(struct inode *inode, const char *name, void *buffer, size_t size) 11 { 12 13 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 14 return -EINVAL; 15 - if (!reiserfs_xattrs_user(inode->i_sb)) 16 return -EOPNOTSUPP; 17 - return reiserfs_xattr_get(inode, name, buffer, size); 18 } 19 20 static int 21 - user_set(struct inode *inode, const char *name, const void *buffer, 22 - size_t size, int flags) 23 { 24 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 25 return -EINVAL; 26 27 - if (!reiserfs_xattrs_user(inode->i_sb)) 28 return -EOPNOTSUPP; 29 - return reiserfs_xattr_set(inode, name, buffer, size, flags); 30 } 31 32 - static size_t user_list(struct inode *inode, char *list, size_t list_size, 33 - const char *name, size_t name_len) 34 { 35 const size_t len = name_len + 1; 36 37 - if (!reiserfs_xattrs_user(inode->i_sb)) 38 return 0; 39 if (list && len <= list_size) { 40 memcpy(list, name, name_len);
··· 7 #include <asm/uaccess.h> 8 9 static int 10 + user_get(struct dentry *dentry, const char *name, void *buffer, size_t size, 11 + int handler_flags) 12 { 13 14 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 15 return -EINVAL; 16 + if (!reiserfs_xattrs_user(dentry->d_sb)) 17 return -EOPNOTSUPP; 18 + return reiserfs_xattr_get(dentry->d_inode, name, buffer, size); 19 } 20 21 static int 22 + user_set(struct dentry *dentry, const char *name, const void *buffer, 23 + size_t size, int flags, int handler_flags) 24 { 25 if (strlen(name) < sizeof(XATTR_USER_PREFIX)) 26 return -EINVAL; 27 28 + if (!reiserfs_xattrs_user(dentry->d_sb)) 29 return -EOPNOTSUPP; 30 + return reiserfs_xattr_set(dentry->d_inode, name, buffer, size, flags); 31 } 32 33 + static size_t user_list(struct dentry *dentry, char *list, size_t list_size, 34 + const char *name, size_t name_len, int handler_flags) 35 { 36 const size_t len = name_len + 1; 37 38 + if (!reiserfs_xattrs_user(dentry->d_sb)) 39 return 0; 40 if (list && len <= list_size) { 41 memcpy(list, name, name_len);
+14 -14
fs/xattr.c
··· 615 generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size) 616 { 617 struct xattr_handler *handler; 618 - struct inode *inode = dentry->d_inode; 619 620 - handler = xattr_resolve_name(inode->i_sb->s_xattr, &name); 621 if (!handler) 622 return -EOPNOTSUPP; 623 - return handler->get(inode, name, buffer, size); 624 } 625 626 /* ··· 629 ssize_t 630 generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) 631 { 632 - struct inode *inode = dentry->d_inode; 633 - struct xattr_handler *handler, **handlers = inode->i_sb->s_xattr; 634 unsigned int size = 0; 635 636 if (!buffer) { 637 - for_each_xattr_handler(handlers, handler) 638 - size += handler->list(inode, NULL, 0, NULL, 0); 639 } else { 640 char *buf = buffer; 641 642 for_each_xattr_handler(handlers, handler) { 643 - size = handler->list(inode, buf, buffer_size, NULL, 0); 644 if (size > buffer_size) 645 return -ERANGE; 646 buf += size; ··· 660 generic_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) 661 { 662 struct xattr_handler *handler; 663 - struct inode *inode = dentry->d_inode; 664 665 if (size == 0) 666 value = ""; /* empty EA, do not remove */ 667 - handler = xattr_resolve_name(inode->i_sb->s_xattr, &name); 668 if (!handler) 669 return -EOPNOTSUPP; 670 - return handler->set(inode, name, value, size, flags); 671 } 672 673 /* ··· 677 generic_removexattr(struct dentry *dentry, const char *name) 678 { 679 struct xattr_handler *handler; 680 - struct inode *inode = dentry->d_inode; 681 682 - handler = xattr_resolve_name(inode->i_sb->s_xattr, &name); 683 if (!handler) 684 return -EOPNOTSUPP; 685 - return handler->set(inode, name, NULL, 0, XATTR_REPLACE); 686 } 687 688 EXPORT_SYMBOL(generic_getxattr);
··· 615 generic_getxattr(struct dentry *dentry, const char *name, void *buffer, size_t size) 616 { 617 struct xattr_handler *handler; 618 619 + handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); 620 if (!handler) 621 return -EOPNOTSUPP; 622 + return handler->get(dentry, name, buffer, size, handler->flags); 623 } 624 625 /* ··· 630 ssize_t 631 generic_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size) 632 { 633 + struct xattr_handler *handler, **handlers = dentry->d_sb->s_xattr; 634 unsigned int size = 0; 635 636 if (!buffer) { 637 + for_each_xattr_handler(handlers, handler) { 638 + size += handler->list(dentry, NULL, 0, NULL, 0, 639 + handler->flags); 640 + } 641 } else { 642 char *buf = buffer; 643 644 for_each_xattr_handler(handlers, handler) { 645 + size = handler->list(dentry, buf, buffer_size, 646 + NULL, 0, handler->flags); 647 if (size > buffer_size) 648 return -ERANGE; 649 buf += size; ··· 659 generic_setxattr(struct dentry *dentry, const char *name, const void *value, size_t size, int flags) 660 { 661 struct xattr_handler *handler; 662 663 if (size == 0) 664 value = ""; /* empty EA, do not remove */ 665 + handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); 666 if (!handler) 667 return -EOPNOTSUPP; 668 + return handler->set(dentry, name, value, size, 0, handler->flags); 669 } 670 671 /* ··· 677 generic_removexattr(struct dentry *dentry, const char *name) 678 { 679 struct xattr_handler *handler; 680 681 + handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); 682 if (!handler) 683 return -EOPNOTSUPP; 684 + return handler->set(dentry, name, NULL, 0, 685 + XATTR_REPLACE, handler->flags); 686 } 687 688 EXPORT_SYMBOL(generic_getxattr);
+20 -37
fs/xfs/linux-2.6/xfs_acl.c
··· 354 return error; 355 } 356 357 - /* 358 - * System xattr handlers. 359 - * 360 - * Currently Posix ACLs are the only system namespace extended attribute 361 - * handlers supported by XFS, so we just implement the handlers here. 362 - * If we ever support other system extended attributes this will need 363 - * some refactoring. 364 - */ 365 - 366 static int 367 - xfs_decode_acl(const char *name) 368 - { 369 - if (strcmp(name, "posix_acl_access") == 0) 370 - return ACL_TYPE_ACCESS; 371 - else if (strcmp(name, "posix_acl_default") == 0) 372 - return ACL_TYPE_DEFAULT; 373 - return -EINVAL; 374 - } 375 - 376 - static int 377 - xfs_xattr_system_get(struct inode *inode, const char *name, 378 - void *value, size_t size) 379 { 380 struct posix_acl *acl; 381 - int type, error; 382 383 - type = xfs_decode_acl(name); 384 - if (type < 0) 385 - return type; 386 - 387 - acl = xfs_get_acl(inode, type); 388 if (IS_ERR(acl)) 389 return PTR_ERR(acl); 390 if (acl == NULL) ··· 374 } 375 376 static int 377 - xfs_xattr_system_set(struct inode *inode, const char *name, 378 - const void *value, size_t size, int flags) 379 { 380 struct posix_acl *acl = NULL; 381 - int error = 0, type; 382 383 - type = xfs_decode_acl(name); 384 - if (type < 0) 385 - return type; 386 if (flags & XATTR_CREATE) 387 return -EINVAL; 388 if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) ··· 437 return error; 438 } 439 440 - struct xattr_handler xfs_xattr_system_handler = { 441 - .prefix = XATTR_SYSTEM_PREFIX, 442 - .get = xfs_xattr_system_get, 443 - .set = xfs_xattr_system_set, 444 };
··· 354 return error; 355 } 356 357 static int 358 + xfs_xattr_acl_get(struct dentry *dentry, const char *name, 359 + void *value, size_t size, int type) 360 { 361 struct posix_acl *acl; 362 + int error; 363 364 + acl = xfs_get_acl(dentry->d_inode, type); 365 if (IS_ERR(acl)) 366 return PTR_ERR(acl); 367 if (acl == NULL) ··· 397 } 398 399 static int 400 + xfs_xattr_acl_set(struct dentry *dentry, const char *name, 401 + const void *value, size_t size, int flags, int type) 402 { 403 + struct inode *inode = dentry->d_inode; 404 struct posix_acl *acl = NULL; 405 + int error = 0; 406 407 if (flags & XATTR_CREATE) 408 return -EINVAL; 409 if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode)) ··· 462 return error; 463 } 464 465 + struct xattr_handler xfs_xattr_acl_access_handler = { 466 + .prefix = POSIX_ACL_XATTR_ACCESS, 467 + .flags = ACL_TYPE_ACCESS, 468 + .get = xfs_xattr_acl_get, 469 + .set = xfs_xattr_acl_set, 470 + }; 471 + 472 + struct xattr_handler xfs_xattr_acl_default_handler = { 473 + .prefix = POSIX_ACL_XATTR_DEFAULT, 474 + .flags = ACL_TYPE_DEFAULT, 475 + .get = xfs_xattr_acl_get, 476 + .set = xfs_xattr_acl_set, 477 };
+15 -56
fs/xfs/linux-2.6/xfs_xattr.c
··· 30 31 32 static int 33 - __xfs_xattr_get(struct inode *inode, const char *name, 34 void *value, size_t size, int xflags) 35 { 36 - struct xfs_inode *ip = XFS_I(inode); 37 int error, asize = size; 38 39 if (strcmp(name, "") == 0) ··· 52 } 53 54 static int 55 - __xfs_xattr_set(struct inode *inode, const char *name, const void *value, 56 size_t size, int flags, int xflags) 57 { 58 - struct xfs_inode *ip = XFS_I(inode); 59 60 if (strcmp(name, "") == 0) 61 return -EINVAL; ··· 71 return -xfs_attr_set(ip, name, (void *)value, size, xflags); 72 } 73 74 - static int 75 - xfs_xattr_user_get(struct inode *inode, const char *name, 76 - void *value, size_t size) 77 - { 78 - return __xfs_xattr_get(inode, name, value, size, 0); 79 - } 80 - 81 - static int 82 - xfs_xattr_user_set(struct inode *inode, const char *name, 83 - const void *value, size_t size, int flags) 84 - { 85 - return __xfs_xattr_set(inode, name, value, size, flags, 0); 86 - } 87 - 88 static struct xattr_handler xfs_xattr_user_handler = { 89 .prefix = XATTR_USER_PREFIX, 90 - .get = xfs_xattr_user_get, 91 - .set = xfs_xattr_user_set, 92 }; 93 - 94 - 95 - static int 96 - xfs_xattr_trusted_get(struct inode *inode, const char *name, 97 - void *value, size_t size) 98 - { 99 - return __xfs_xattr_get(inode, name, value, size, ATTR_ROOT); 100 - } 101 - 102 - static int 103 - xfs_xattr_trusted_set(struct inode *inode, const char *name, 104 - const void *value, size_t size, int flags) 105 - { 106 - return __xfs_xattr_set(inode, name, value, size, flags, ATTR_ROOT); 107 - } 108 109 static struct xattr_handler xfs_xattr_trusted_handler = { 110 .prefix = XATTR_TRUSTED_PREFIX, 111 - .get = xfs_xattr_trusted_get, 112 - .set = xfs_xattr_trusted_set, 113 }; 114 - 115 - 116 - static int 117 - xfs_xattr_secure_get(struct inode *inode, const char *name, 118 - void *value, size_t size) 119 - { 120 - return __xfs_xattr_get(inode, name, value, size, ATTR_SECURE); 121 - } 122 - 123 - static int 124 - xfs_xattr_secure_set(struct inode *inode, const char *name, 125 - const void *value, size_t size, int flags) 126 - { 127 - return __xfs_xattr_set(inode, name, value, size, flags, ATTR_SECURE); 128 - } 129 130 static struct xattr_handler xfs_xattr_security_handler = { 131 .prefix = XATTR_SECURITY_PREFIX, 132 - .get = xfs_xattr_secure_get, 133 - .set = xfs_xattr_secure_set, 134 }; 135 - 136 137 struct xattr_handler *xfs_xattr_handlers[] = { 138 &xfs_xattr_user_handler, 139 &xfs_xattr_trusted_handler, 140 &xfs_xattr_security_handler, 141 #ifdef CONFIG_XFS_POSIX_ACL 142 - &xfs_xattr_system_handler, 143 #endif 144 NULL 145 };
··· 30 31 32 static int 33 + xfs_xattr_get(struct dentry *dentry, const char *name, 34 void *value, size_t size, int xflags) 35 { 36 + struct xfs_inode *ip = XFS_I(dentry->d_inode); 37 int error, asize = size; 38 39 if (strcmp(name, "") == 0) ··· 52 } 53 54 static int 55 + xfs_xattr_set(struct dentry *dentry, const char *name, const void *value, 56 size_t size, int flags, int xflags) 57 { 58 + struct xfs_inode *ip = XFS_I(dentry->d_inode); 59 60 if (strcmp(name, "") == 0) 61 return -EINVAL; ··· 71 return -xfs_attr_set(ip, name, (void *)value, size, xflags); 72 } 73 74 static struct xattr_handler xfs_xattr_user_handler = { 75 .prefix = XATTR_USER_PREFIX, 76 + .flags = 0, /* no flags implies user namespace */ 77 + .get = xfs_xattr_get, 78 + .set = xfs_xattr_set, 79 }; 80 81 static struct xattr_handler xfs_xattr_trusted_handler = { 82 .prefix = XATTR_TRUSTED_PREFIX, 83 + .flags = ATTR_ROOT, 84 + .get = xfs_xattr_get, 85 + .set = xfs_xattr_set, 86 }; 87 88 static struct xattr_handler xfs_xattr_security_handler = { 89 .prefix = XATTR_SECURITY_PREFIX, 90 + .flags = ATTR_SECURE, 91 + .get = xfs_xattr_get, 92 + .set = xfs_xattr_set, 93 }; 94 95 struct xattr_handler *xfs_xattr_handlers[] = { 96 &xfs_xattr_user_handler, 97 &xfs_xattr_trusted_handler, 98 &xfs_xattr_security_handler, 99 #ifdef CONFIG_XFS_POSIX_ACL 100 + &xfs_xattr_acl_access_handler, 101 + &xfs_xattr_acl_default_handler, 102 #endif 103 NULL 104 };
+2 -1
fs/xfs/xfs_acl.h
··· 49 extern int posix_acl_access_exists(struct inode *inode); 50 extern int posix_acl_default_exists(struct inode *inode); 51 52 - extern struct xattr_handler xfs_xattr_system_handler; 53 #else 54 # define xfs_check_acl NULL 55 # define xfs_get_acl(inode, type) NULL
··· 49 extern int posix_acl_access_exists(struct inode *inode); 50 extern int posix_acl_default_exists(struct inode *inode); 51 52 + extern struct xattr_handler xfs_xattr_acl_access_handler; 53 + extern struct xattr_handler xfs_xattr_acl_default_handler; 54 #else 55 # define xfs_check_acl NULL 56 # define xfs_get_acl(inode, type) NULL
+3 -5
include/linux/file.h
··· 18 struct file_operations; 19 struct vfsmount; 20 struct dentry; 21 - extern int init_file(struct file *, struct vfsmount *mnt, 22 - struct dentry *dentry, fmode_t mode, 23 - const struct file_operations *fop); 24 - extern struct file *alloc_file(struct vfsmount *, struct dentry *dentry, 25 - fmode_t mode, const struct file_operations *fop); 26 27 static inline void fput_light(struct file *file, int fput_needed) 28 {
··· 18 struct file_operations; 19 struct vfsmount; 20 struct dentry; 21 + struct path; 22 + extern struct file *alloc_file(struct path *, fmode_t mode, 23 + const struct file_operations *fop); 24 25 static inline void fput_light(struct file *file, int fput_needed) 26 {
-1
include/linux/fs.h
··· 2189 __insert_inode_hash(inode, inode->i_ino); 2190 } 2191 2192 - extern struct file * get_empty_filp(void); 2193 extern void file_move(struct file *f, struct list_head *list); 2194 extern void file_kill(struct file *f); 2195 #ifdef CONFIG_BLOCK
··· 2189 __insert_inode_hash(inode, inode->i_ino); 2190 } 2191 2192 extern void file_move(struct file *f, struct list_head *list); 2193 extern void file_kill(struct file *f); 2194 #ifdef CONFIG_BLOCK
+10 -31
include/linux/generic_acl.h
··· 1 - /* 2 - * include/linux/generic_acl.h 3 - * 4 - * (C) 2005 Andreas Gruenbacher <agruen@suse.de> 5 - * 6 - * This file is released under the GPL. 7 - */ 8 9 - #ifndef GENERIC_ACL_H 10 - #define GENERIC_ACL_H 11 12 - #include <linux/posix_acl.h> 13 - #include <linux/posix_acl_xattr.h> 14 15 - /** 16 - * struct generic_acl_operations - filesystem operations 17 - * 18 - * Filesystems must make these operations available to the generic 19 - * operations. 20 - */ 21 - struct generic_acl_operations { 22 - struct posix_acl *(*getacl)(struct inode *, int); 23 - void (*setacl)(struct inode *, int, struct posix_acl *); 24 - }; 25 26 - size_t generic_acl_list(struct inode *, struct generic_acl_operations *, int, 27 - char *, size_t); 28 - int generic_acl_get(struct inode *, struct generic_acl_operations *, int, 29 - void *, size_t); 30 - int generic_acl_set(struct inode *, struct generic_acl_operations *, int, 31 - const void *, size_t); 32 - int generic_acl_init(struct inode *, struct inode *, 33 - struct generic_acl_operations *); 34 - int generic_acl_chmod(struct inode *, struct generic_acl_operations *); 35 36 - #endif
··· 1 + #ifndef LINUX_GENERIC_ACL_H 2 + #define LINUX_GENERIC_ACL_H 3 4 + #include <linux/xattr.h> 5 6 + struct inode; 7 8 + extern struct xattr_handler generic_acl_access_handler; 9 + extern struct xattr_handler generic_acl_default_handler; 10 11 + int generic_acl_init(struct inode *, struct inode *); 12 + int generic_acl_chmod(struct inode *); 13 + int generic_check_acl(struct inode *inode, int mask); 14 15 + #endif /* LINUX_GENERIC_ACL_H */
+2 -10
include/linux/ima.h
··· 13 #include <linux/fs.h> 14 struct linux_binprm; 15 16 - #define IMA_COUNT_UPDATE 1 17 - #define IMA_COUNT_LEAVE 0 18 - 19 #ifdef CONFIG_IMA 20 extern int ima_bprm_check(struct linux_binprm *bprm); 21 extern int ima_inode_alloc(struct inode *inode); 22 extern void ima_inode_free(struct inode *inode); 23 - extern int ima_path_check(struct path *path, int mask, int update_counts); 24 extern void ima_file_free(struct file *file); 25 extern int ima_file_mmap(struct file *file, unsigned long prot); 26 extern void ima_counts_get(struct file *file); 27 - extern void ima_counts_put(struct path *path, int mask); 28 29 #else 30 static inline int ima_bprm_check(struct linux_binprm *bprm) ··· 38 return; 39 } 40 41 - static inline int ima_path_check(struct path *path, int mask, int update_counts) 42 { 43 return 0; 44 } ··· 58 return; 59 } 60 61 - static inline void ima_counts_put(struct path *path, int mask) 62 - { 63 - return; 64 - } 65 #endif /* CONFIG_IMA_H */ 66 #endif /* _LINUX_IMA_H */
··· 13 #include <linux/fs.h> 14 struct linux_binprm; 15 16 #ifdef CONFIG_IMA 17 extern int ima_bprm_check(struct linux_binprm *bprm); 18 extern int ima_inode_alloc(struct inode *inode); 19 extern void ima_inode_free(struct inode *inode); 20 + extern int ima_path_check(struct path *path, int mask); 21 extern void ima_file_free(struct file *file); 22 extern int ima_file_mmap(struct file *file, unsigned long prot); 23 extern void ima_counts_get(struct file *file); 24 25 #else 26 static inline int ima_bprm_check(struct linux_binprm *bprm) ··· 42 return; 43 } 44 45 + static inline int ima_path_check(struct path *path, int mask) 46 { 47 return 0; 48 } ··· 62 return; 63 } 64 65 #endif /* CONFIG_IMA_H */ 66 #endif /* _LINUX_IMA_H */
-1
include/linux/mnt_namespace.h
··· 23 24 struct fs_struct; 25 26 - extern struct mnt_namespace *create_mnt_ns(struct vfsmount *mnt); 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);
··· 23 24 struct fs_struct; 25 26 extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, 27 struct fs_struct *); 28 extern void put_mnt_ns(struct mnt_namespace *ns);
-16
include/linux/shmem_fs.h
··· 41 extern int init_tmpfs(void); 42 extern int shmem_fill_super(struct super_block *sb, void *data, int silent); 43 44 - #ifdef CONFIG_TMPFS_POSIX_ACL 45 - int shmem_check_acl(struct inode *, int); 46 - int shmem_acl_init(struct inode *, struct inode *); 47 - 48 - extern struct xattr_handler shmem_xattr_acl_access_handler; 49 - extern struct xattr_handler shmem_xattr_acl_default_handler; 50 - 51 - extern struct generic_acl_operations shmem_acl_ops; 52 - 53 - #else 54 - static inline int shmem_acl_init(struct inode *inode, struct inode *dir) 55 - { 56 - return 0; 57 - } 58 - #endif /* CONFIG_TMPFS_POSIX_ACL */ 59 - 60 #endif
··· 41 extern int init_tmpfs(void); 42 extern int shmem_fill_super(struct super_block *sb, void *data, int silent); 43 44 #endif
+7 -6
include/linux/xattr.h
··· 38 39 struct xattr_handler { 40 char *prefix; 41 - size_t (*list)(struct inode *inode, char *list, size_t list_size, 42 - const char *name, size_t name_len); 43 - int (*get)(struct inode *inode, const char *name, void *buffer, 44 - size_t size); 45 - int (*set)(struct inode *inode, const char *name, const void *buffer, 46 - size_t size, int flags); 47 }; 48 49 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
··· 38 39 struct xattr_handler { 40 char *prefix; 41 + int flags; /* fs private flags passed back to the handlers */ 42 + size_t (*list)(struct dentry *dentry, char *list, size_t list_size, 43 + const char *name, size_t name_len, int handler_flags); 44 + int (*get)(struct dentry *dentry, const char *name, void *buffer, 45 + size_t size, int handler_flags); 46 + int (*set)(struct dentry *dentry, const char *name, const void *buffer, 47 + size_t size, int flags, int handler_flags); 48 }; 49 50 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
-2
ipc/mqueue.c
··· 32 #include <linux/nsproxy.h> 33 #include <linux/pid.h> 34 #include <linux/ipc_namespace.h> 35 - #include <linux/ima.h> 36 37 #include <net/sock.h> 38 #include "util.h" ··· 733 error = PTR_ERR(filp); 734 goto out_putfd; 735 } 736 - ima_counts_get(filp); 737 738 fd_install(fd, filp); 739 goto out_upsem;
··· 32 #include <linux/nsproxy.h> 33 #include <linux/pid.h> 34 #include <linux/ipc_namespace.h> 35 36 #include <net/sock.h> 37 #include "util.h" ··· 734 error = PTR_ERR(filp); 735 goto out_putfd; 736 } 737 738 fd_install(fd, filp); 739 goto out_upsem;
+5 -7
ipc/shm.c
··· 39 #include <linux/nsproxy.h> 40 #include <linux/mount.h> 41 #include <linux/ipc_namespace.h> 42 - #include <linux/ima.h> 43 44 #include <asm/uaccess.h> 45 ··· 878 if (err) 879 goto out_unlock; 880 881 - path.dentry = dget(shp->shm_file->f_path.dentry); 882 - path.mnt = shp->shm_file->f_path.mnt; 883 shp->shm_nattch++; 884 size = i_size_read(path.dentry->d_inode); 885 shm_unlock(shp); ··· 889 if (!sfd) 890 goto out_put_dentry; 891 892 - file = alloc_file(path.mnt, path.dentry, f_mode, 893 - is_file_hugepages(shp->shm_file) ? 894 &shm_file_operations_huge : 895 &shm_file_operations); 896 if (!file) 897 goto out_free; 898 - ima_counts_get(file); 899 900 file->private_data = sfd; 901 file->f_mapping = shp->shm_file->f_mapping; ··· 949 out_free: 950 kfree(sfd); 951 out_put_dentry: 952 - dput(path.dentry); 953 goto out_nattch; 954 } 955
··· 39 #include <linux/nsproxy.h> 40 #include <linux/mount.h> 41 #include <linux/ipc_namespace.h> 42 43 #include <asm/uaccess.h> 44 ··· 879 if (err) 880 goto out_unlock; 881 882 + path = shp->shm_file->f_path; 883 + path_get(&path); 884 shp->shm_nattch++; 885 size = i_size_read(path.dentry->d_inode); 886 shm_unlock(shp); ··· 890 if (!sfd) 891 goto out_put_dentry; 892 893 + file = alloc_file(&path, f_mode, 894 + is_file_hugepages(shp->shm_file) ? 895 &shm_file_operations_huge : 896 &shm_file_operations); 897 if (!file) 898 goto out_free; 899 900 file->private_data = sfd; 901 file->f_mapping = shp->shm_file->f_mapping; ··· 951 out_free: 952 kfree(sfd); 953 out_put_dentry: 954 + path_put(&path); 955 goto out_nattch; 956 } 957
-1
mm/Makefile
··· 22 obj-$(CONFIG_NUMA) += mempolicy.o 23 obj-$(CONFIG_SPARSEMEM) += sparse.o 24 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o 25 - obj-$(CONFIG_TMPFS_POSIX_ACL) += shmem_acl.o 26 obj-$(CONFIG_SLOB) += slob.o 27 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o 28 obj-$(CONFIG_KSM) += ksm.o
··· 22 obj-$(CONFIG_NUMA) += mempolicy.o 23 obj-$(CONFIG_SPARSEMEM) += sparse.o 24 obj-$(CONFIG_SPARSEMEM_VMEMMAP) += sparse-vmemmap.o 25 obj-$(CONFIG_SLOB) += slob.o 26 obj-$(CONFIG_MMU_NOTIFIER) += mmu_notifier.o 27 obj-$(CONFIG_KSM) += ksm.o
+1 -14
mm/filemap.c
··· 2240 size_t count, ssize_t written) 2241 { 2242 struct file *file = iocb->ki_filp; 2243 - struct address_space *mapping = file->f_mapping; 2244 ssize_t status; 2245 struct iov_iter i; 2246 ··· 2251 *ppos = pos + status; 2252 } 2253 2254 - /* 2255 - * If we get here for O_DIRECT writes then we must have fallen through 2256 - * to buffered writes (block instantiation inside i_size). So we sync 2257 - * the file data here, to try to honour O_DIRECT expectations. 2258 - */ 2259 - if (unlikely(file->f_flags & O_DIRECT) && written) 2260 - status = filemap_write_and_wait_range(mapping, 2261 - pos, pos + written - 1); 2262 - 2263 return written ? written : status; 2264 } 2265 EXPORT_SYMBOL(generic_file_buffered_write); ··· 2349 * semantics. 2350 */ 2351 endbyte = pos + written_buffered - written - 1; 2352 - err = do_sync_mapping_range(file->f_mapping, pos, endbyte, 2353 - SYNC_FILE_RANGE_WAIT_BEFORE| 2354 - SYNC_FILE_RANGE_WRITE| 2355 - SYNC_FILE_RANGE_WAIT_AFTER); 2356 if (err == 0) { 2357 written = written_buffered; 2358 invalidate_mapping_pages(mapping,
··· 2240 size_t count, ssize_t written) 2241 { 2242 struct file *file = iocb->ki_filp; 2243 ssize_t status; 2244 struct iov_iter i; 2245 ··· 2252 *ppos = pos + status; 2253 } 2254 2255 return written ? written : status; 2256 } 2257 EXPORT_SYMBOL(generic_file_buffered_write); ··· 2359 * semantics. 2360 */ 2361 endbyte = pos + written_buffered - written - 1; 2362 + err = filemap_write_and_wait_range(file->f_mapping, pos, endbyte); 2363 if (err == 0) { 2364 written = written_buffered; 2365 invalidate_mapping_pages(mapping,
+36 -35
mm/shmem.c
··· 29 #include <linux/mm.h> 30 #include <linux/module.h> 31 #include <linux/swap.h> 32 - #include <linux/ima.h> 33 34 static struct vfsmount *shm_mnt; 35 ··· 41 42 #include <linux/xattr.h> 43 #include <linux/exportfs.h> 44 #include <linux/generic_acl.h> 45 #include <linux/mman.h> 46 #include <linux/string.h> ··· 810 error = inode_setattr(inode, attr); 811 #ifdef CONFIG_TMPFS_POSIX_ACL 812 if (!error && (attr->ia_valid & ATTR_MODE)) 813 - error = generic_acl_chmod(inode, &shmem_acl_ops); 814 #endif 815 if (page) 816 page_cache_release(page); ··· 1824 return error; 1825 } 1826 } 1827 - error = shmem_acl_init(inode, dir); 1828 if (error) { 1829 iput(inode); 1830 return error; 1831 } 1832 if (dir->i_mode & S_ISGID) { 1833 inode->i_gid = dir->i_gid; 1834 if (S_ISDIR(mode)) ··· 2045 * filesystem level, though. 2046 */ 2047 2048 - static size_t shmem_xattr_security_list(struct inode *inode, char *list, 2049 size_t list_len, const char *name, 2050 - size_t name_len) 2051 { 2052 - return security_inode_listsecurity(inode, list, list_len); 2053 } 2054 2055 - static int shmem_xattr_security_get(struct inode *inode, const char *name, 2056 - void *buffer, size_t size) 2057 { 2058 if (strcmp(name, "") == 0) 2059 return -EINVAL; 2060 - return xattr_getsecurity(inode, name, buffer, size); 2061 } 2062 2063 - static int shmem_xattr_security_set(struct inode *inode, const char *name, 2064 - const void *value, size_t size, int flags) 2065 { 2066 if (strcmp(name, "") == 0) 2067 return -EINVAL; 2068 - return security_inode_setsecurity(inode, name, value, size, flags); 2069 } 2070 2071 static struct xattr_handler shmem_xattr_security_handler = { ··· 2077 }; 2078 2079 static struct xattr_handler *shmem_xattr_handlers[] = { 2080 - &shmem_xattr_acl_access_handler, 2081 - &shmem_xattr_acl_default_handler, 2082 &shmem_xattr_security_handler, 2083 NULL 2084 }; ··· 2457 .getxattr = generic_getxattr, 2458 .listxattr = generic_listxattr, 2459 .removexattr = generic_removexattr, 2460 - .check_acl = shmem_check_acl, 2461 #endif 2462 2463 }; ··· 2480 .getxattr = generic_getxattr, 2481 .listxattr = generic_listxattr, 2482 .removexattr = generic_removexattr, 2483 - .check_acl = shmem_check_acl, 2484 #endif 2485 }; 2486 ··· 2491 .getxattr = generic_getxattr, 2492 .listxattr = generic_listxattr, 2493 .removexattr = generic_removexattr, 2494 - .check_acl = shmem_check_acl, 2495 #endif 2496 }; 2497 ··· 2629 int error; 2630 struct file *file; 2631 struct inode *inode; 2632 - struct dentry *dentry, *root; 2633 struct qstr this; 2634 2635 if (IS_ERR(shm_mnt)) ··· 2647 this.len = strlen(name); 2648 this.hash = 0; /* will go */ 2649 root = shm_mnt->mnt_root; 2650 - dentry = d_alloc(root, &this); 2651 - if (!dentry) 2652 goto put_memory; 2653 - 2654 - error = -ENFILE; 2655 - file = get_empty_filp(); 2656 - if (!file) 2657 - goto put_dentry; 2658 2659 error = -ENOSPC; 2660 inode = shmem_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0, flags); 2661 if (!inode) 2662 - goto close_file; 2663 2664 - d_instantiate(dentry, inode); 2665 inode->i_size = size; 2666 inode->i_nlink = 0; /* It is unlinked */ 2667 - init_file(file, shm_mnt, dentry, FMODE_WRITE | FMODE_READ, 2668 - &shmem_file_operations); 2669 - 2670 #ifndef CONFIG_MMU 2671 error = ramfs_nommu_expand_for_mapping(inode, size); 2672 if (error) 2673 - goto close_file; 2674 #endif 2675 - ima_counts_get(file); 2676 return file; 2677 2678 - close_file: 2679 - put_filp(file); 2680 put_dentry: 2681 - dput(dentry); 2682 put_memory: 2683 shmem_unacct_size(flags, size); 2684 return ERR_PTR(error);
··· 29 #include <linux/mm.h> 30 #include <linux/module.h> 31 #include <linux/swap.h> 32 33 static struct vfsmount *shm_mnt; 34 ··· 42 43 #include <linux/xattr.h> 44 #include <linux/exportfs.h> 45 + #include <linux/posix_acl.h> 46 #include <linux/generic_acl.h> 47 #include <linux/mman.h> 48 #include <linux/string.h> ··· 810 error = inode_setattr(inode, attr); 811 #ifdef CONFIG_TMPFS_POSIX_ACL 812 if (!error && (attr->ia_valid & ATTR_MODE)) 813 + error = generic_acl_chmod(inode); 814 #endif 815 if (page) 816 page_cache_release(page); ··· 1824 return error; 1825 } 1826 } 1827 + #ifdef CONFIG_TMPFS_POSIX_ACL 1828 + error = generic_acl_init(inode, dir); 1829 if (error) { 1830 iput(inode); 1831 return error; 1832 } 1833 + #endif 1834 if (dir->i_mode & S_ISGID) { 1835 inode->i_gid = dir->i_gid; 1836 if (S_ISDIR(mode)) ··· 2043 * filesystem level, though. 2044 */ 2045 2046 + static size_t shmem_xattr_security_list(struct dentry *dentry, char *list, 2047 size_t list_len, const char *name, 2048 + size_t name_len, int handler_flags) 2049 { 2050 + return security_inode_listsecurity(dentry->d_inode, list, list_len); 2051 } 2052 2053 + static int shmem_xattr_security_get(struct dentry *dentry, const char *name, 2054 + void *buffer, size_t size, int handler_flags) 2055 { 2056 if (strcmp(name, "") == 0) 2057 return -EINVAL; 2058 + return xattr_getsecurity(dentry->d_inode, name, buffer, size); 2059 } 2060 2061 + static int shmem_xattr_security_set(struct dentry *dentry, const char *name, 2062 + const void *value, size_t size, int flags, int handler_flags) 2063 { 2064 if (strcmp(name, "") == 0) 2065 return -EINVAL; 2066 + return security_inode_setsecurity(dentry->d_inode, name, value, 2067 + size, flags); 2068 } 2069 2070 static struct xattr_handler shmem_xattr_security_handler = { ··· 2074 }; 2075 2076 static struct xattr_handler *shmem_xattr_handlers[] = { 2077 + &generic_acl_access_handler, 2078 + &generic_acl_default_handler, 2079 &shmem_xattr_security_handler, 2080 NULL 2081 }; ··· 2454 .getxattr = generic_getxattr, 2455 .listxattr = generic_listxattr, 2456 .removexattr = generic_removexattr, 2457 + .check_acl = generic_check_acl, 2458 #endif 2459 2460 }; ··· 2477 .getxattr = generic_getxattr, 2478 .listxattr = generic_listxattr, 2479 .removexattr = generic_removexattr, 2480 + .check_acl = generic_check_acl, 2481 #endif 2482 }; 2483 ··· 2488 .getxattr = generic_getxattr, 2489 .listxattr = generic_listxattr, 2490 .removexattr = generic_removexattr, 2491 + .check_acl = generic_check_acl, 2492 #endif 2493 }; 2494 ··· 2626 int error; 2627 struct file *file; 2628 struct inode *inode; 2629 + struct path path; 2630 + struct dentry *root; 2631 struct qstr this; 2632 2633 if (IS_ERR(shm_mnt)) ··· 2643 this.len = strlen(name); 2644 this.hash = 0; /* will go */ 2645 root = shm_mnt->mnt_root; 2646 + path.dentry = d_alloc(root, &this); 2647 + if (!path.dentry) 2648 goto put_memory; 2649 + path.mnt = mntget(shm_mnt); 2650 2651 error = -ENOSPC; 2652 inode = shmem_get_inode(root->d_sb, S_IFREG | S_IRWXUGO, 0, flags); 2653 if (!inode) 2654 + goto put_dentry; 2655 2656 + d_instantiate(path.dentry, inode); 2657 inode->i_size = size; 2658 inode->i_nlink = 0; /* It is unlinked */ 2659 #ifndef CONFIG_MMU 2660 error = ramfs_nommu_expand_for_mapping(inode, size); 2661 if (error) 2662 + goto put_dentry; 2663 #endif 2664 + 2665 + error = -ENFILE; 2666 + file = alloc_file(&path, FMODE_WRITE | FMODE_READ, 2667 + &shmem_file_operations); 2668 + if (!file) 2669 + goto put_dentry; 2670 + 2671 return file; 2672 2673 put_dentry: 2674 + path_put(&path); 2675 put_memory: 2676 shmem_unacct_size(flags, size); 2677 return ERR_PTR(error);
-171
mm/shmem_acl.c
··· 1 - /* 2 - * mm/shmem_acl.c 3 - * 4 - * (C) 2005 Andreas Gruenbacher <agruen@suse.de> 5 - * 6 - * This file is released under the GPL. 7 - */ 8 - 9 - #include <linux/fs.h> 10 - #include <linux/shmem_fs.h> 11 - #include <linux/xattr.h> 12 - #include <linux/generic_acl.h> 13 - 14 - /** 15 - * shmem_get_acl - generic_acl_operations->getacl() operation 16 - */ 17 - static struct posix_acl * 18 - shmem_get_acl(struct inode *inode, int type) 19 - { 20 - struct posix_acl *acl = NULL; 21 - 22 - spin_lock(&inode->i_lock); 23 - switch(type) { 24 - case ACL_TYPE_ACCESS: 25 - acl = posix_acl_dup(inode->i_acl); 26 - break; 27 - 28 - case ACL_TYPE_DEFAULT: 29 - acl = posix_acl_dup(inode->i_default_acl); 30 - break; 31 - } 32 - spin_unlock(&inode->i_lock); 33 - 34 - return acl; 35 - } 36 - 37 - /** 38 - * shmem_set_acl - generic_acl_operations->setacl() operation 39 - */ 40 - static void 41 - shmem_set_acl(struct inode *inode, int type, struct posix_acl *acl) 42 - { 43 - struct posix_acl *free = NULL; 44 - 45 - spin_lock(&inode->i_lock); 46 - switch(type) { 47 - case ACL_TYPE_ACCESS: 48 - free = inode->i_acl; 49 - inode->i_acl = posix_acl_dup(acl); 50 - break; 51 - 52 - case ACL_TYPE_DEFAULT: 53 - free = inode->i_default_acl; 54 - inode->i_default_acl = posix_acl_dup(acl); 55 - break; 56 - } 57 - spin_unlock(&inode->i_lock); 58 - posix_acl_release(free); 59 - } 60 - 61 - struct generic_acl_operations shmem_acl_ops = { 62 - .getacl = shmem_get_acl, 63 - .setacl = shmem_set_acl, 64 - }; 65 - 66 - /** 67 - * shmem_list_acl_access, shmem_get_acl_access, shmem_set_acl_access, 68 - * shmem_xattr_acl_access_handler - plumbing code to implement the 69 - * system.posix_acl_access xattr using the generic acl functions. 70 - */ 71 - 72 - static size_t 73 - shmem_list_acl_access(struct inode *inode, char *list, size_t list_size, 74 - const char *name, size_t name_len) 75 - { 76 - return generic_acl_list(inode, &shmem_acl_ops, ACL_TYPE_ACCESS, 77 - list, list_size); 78 - } 79 - 80 - static int 81 - shmem_get_acl_access(struct inode *inode, const char *name, void *buffer, 82 - size_t size) 83 - { 84 - if (strcmp(name, "") != 0) 85 - return -EINVAL; 86 - return generic_acl_get(inode, &shmem_acl_ops, ACL_TYPE_ACCESS, buffer, 87 - size); 88 - } 89 - 90 - static int 91 - shmem_set_acl_access(struct inode *inode, const char *name, const void *value, 92 - size_t size, int flags) 93 - { 94 - if (strcmp(name, "") != 0) 95 - return -EINVAL; 96 - return generic_acl_set(inode, &shmem_acl_ops, ACL_TYPE_ACCESS, value, 97 - size); 98 - } 99 - 100 - struct xattr_handler shmem_xattr_acl_access_handler = { 101 - .prefix = POSIX_ACL_XATTR_ACCESS, 102 - .list = shmem_list_acl_access, 103 - .get = shmem_get_acl_access, 104 - .set = shmem_set_acl_access, 105 - }; 106 - 107 - /** 108 - * shmem_list_acl_default, shmem_get_acl_default, shmem_set_acl_default, 109 - * shmem_xattr_acl_default_handler - plumbing code to implement the 110 - * system.posix_acl_default xattr using the generic acl functions. 111 - */ 112 - 113 - static size_t 114 - shmem_list_acl_default(struct inode *inode, char *list, size_t list_size, 115 - const char *name, size_t name_len) 116 - { 117 - return generic_acl_list(inode, &shmem_acl_ops, ACL_TYPE_DEFAULT, 118 - list, list_size); 119 - } 120 - 121 - static int 122 - shmem_get_acl_default(struct inode *inode, const char *name, void *buffer, 123 - size_t size) 124 - { 125 - if (strcmp(name, "") != 0) 126 - return -EINVAL; 127 - return generic_acl_get(inode, &shmem_acl_ops, ACL_TYPE_DEFAULT, buffer, 128 - size); 129 - } 130 - 131 - static int 132 - shmem_set_acl_default(struct inode *inode, const char *name, const void *value, 133 - size_t size, int flags) 134 - { 135 - if (strcmp(name, "") != 0) 136 - return -EINVAL; 137 - return generic_acl_set(inode, &shmem_acl_ops, ACL_TYPE_DEFAULT, value, 138 - size); 139 - } 140 - 141 - struct xattr_handler shmem_xattr_acl_default_handler = { 142 - .prefix = POSIX_ACL_XATTR_DEFAULT, 143 - .list = shmem_list_acl_default, 144 - .get = shmem_get_acl_default, 145 - .set = shmem_set_acl_default, 146 - }; 147 - 148 - /** 149 - * shmem_acl_init - Inizialize the acl(s) of a new inode 150 - */ 151 - int 152 - shmem_acl_init(struct inode *inode, struct inode *dir) 153 - { 154 - return generic_acl_init(inode, dir, &shmem_acl_ops); 155 - } 156 - 157 - /** 158 - * shmem_check_acl - check_acl() callback for generic_permission() 159 - */ 160 - int 161 - shmem_check_acl(struct inode *inode, int mask) 162 - { 163 - struct posix_acl *acl = shmem_get_acl(inode, ACL_TYPE_ACCESS); 164 - 165 - if (acl) { 166 - int error = posix_acl_permission(inode, acl, mask); 167 - posix_acl_release(acl); 168 - return error; 169 - } 170 - return -EAGAIN; 171 - }
···
+46 -66
net/9p/trans_fd.c
··· 42 #include <net/9p/client.h> 43 #include <net/9p/transport.h> 44 45 #define P9_PORT 564 46 #define MAX_SOCK_BUF (64*1024) 47 #define MAXPOLLWADDR 2 ··· 790 791 static int p9_socket_open(struct p9_client *client, struct socket *csocket) 792 { 793 - int fd, ret; 794 795 csocket->sk->sk_allocation = GFP_NOIO; 796 fd = sock_map_fd(csocket, 0); 797 if (fd < 0) { 798 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n"); 799 return fd; 800 } 801 802 - ret = p9_fd_open(client, fd, fd); 803 - if (ret < 0) { 804 - P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to open fd\n"); 805 sockfd_put(csocket); 806 return ret; 807 } 808 - 809 - ((struct p9_trans_fd *)client->trans)->rd->f_flags |= O_NONBLOCK; 810 - 811 return 0; 812 } 813 ··· 902 struct socket *csocket; 903 struct sockaddr_in sin_server; 904 struct p9_fd_opts opts; 905 - struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */ 906 907 err = parse_opts(args, &opts); 908 if (err < 0) ··· 915 sin_server.sin_family = AF_INET; 916 sin_server.sin_addr.s_addr = in_aton(addr); 917 sin_server.sin_port = htons(opts.port); 918 - sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket); 919 920 - if (!csocket) { 921 P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n"); 922 - err = -EIO; 923 - goto error; 924 } 925 926 err = csocket->ops->connect(csocket, ··· 929 P9_EPRINTK(KERN_ERR, 930 "p9_trans_tcp: problem connecting socket to %s\n", 931 addr); 932 - goto error; 933 - } 934 - 935 - err = p9_socket_open(client, csocket); 936 - if (err < 0) 937 - goto error; 938 - 939 - p = (struct p9_trans_fd *) client->trans; 940 - p->conn = p9_conn_create(client); 941 - if (IS_ERR(p->conn)) { 942 - err = PTR_ERR(p->conn); 943 - p->conn = NULL; 944 - goto error; 945 - } 946 - 947 - return 0; 948 - 949 - error: 950 - if (csocket) 951 sock_release(csocket); 952 953 - kfree(p); 954 - 955 - return err; 956 } 957 958 static int ··· 942 int err; 943 struct socket *csocket; 944 struct sockaddr_un sun_server; 945 - struct p9_trans_fd *p = NULL; /* this gets allocated in p9_fd_open */ 946 947 csocket = NULL; 948 949 if (strlen(addr) > UNIX_PATH_MAX) { 950 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", 951 addr); 952 - err = -ENAMETOOLONG; 953 - goto error; 954 } 955 956 sun_server.sun_family = PF_UNIX; 957 strcpy(sun_server.sun_path, addr); 958 - sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket); 959 err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, 960 sizeof(struct sockaddr_un) - 1, 0); 961 if (err < 0) { 962 P9_EPRINTK(KERN_ERR, 963 "p9_trans_unix: problem connecting socket: %s: %d\n", 964 addr, err); 965 - goto error; 966 - } 967 - 968 - err = p9_socket_open(client, csocket); 969 - if (err < 0) 970 - goto error; 971 - 972 - p = (struct p9_trans_fd *) client->trans; 973 - p->conn = p9_conn_create(client); 974 - if (IS_ERR(p->conn)) { 975 - err = PTR_ERR(p->conn); 976 - p->conn = NULL; 977 - goto error; 978 - } 979 - 980 - return 0; 981 - 982 - error: 983 - if (csocket) 984 sock_release(csocket); 985 986 - kfree(p); 987 - return err; 988 } 989 990 static int ··· 976 { 977 int err; 978 struct p9_fd_opts opts; 979 - struct p9_trans_fd *p = NULL; /* this get allocated in p9_fd_open */ 980 981 parse_opts(args, &opts); 982 ··· 987 988 err = p9_fd_open(client, opts.rfd, opts.wfd); 989 if (err < 0) 990 - goto error; 991 992 p = (struct p9_trans_fd *) client->trans; 993 p->conn = p9_conn_create(client); 994 if (IS_ERR(p->conn)) { 995 err = PTR_ERR(p->conn); 996 p->conn = NULL; 997 - goto error; 998 } 999 1000 return 0; 1001 - 1002 - error: 1003 - kfree(p); 1004 - return err; 1005 } 1006 1007 static struct p9_trans_module p9_tcp_trans = {
··· 42 #include <net/9p/client.h> 43 #include <net/9p/transport.h> 44 45 + #include <linux/syscalls.h> /* killme */ 46 + 47 #define P9_PORT 564 48 #define MAX_SOCK_BUF (64*1024) 49 #define MAXPOLLWADDR 2 ··· 788 789 static int p9_socket_open(struct p9_client *client, struct socket *csocket) 790 { 791 + struct p9_trans_fd *p; 792 + int ret, fd; 793 + 794 + p = kmalloc(sizeof(struct p9_trans_fd), GFP_KERNEL); 795 + if (!p) 796 + return -ENOMEM; 797 798 csocket->sk->sk_allocation = GFP_NOIO; 799 fd = sock_map_fd(csocket, 0); 800 if (fd < 0) { 801 P9_EPRINTK(KERN_ERR, "p9_socket_open: failed to map fd\n"); 802 + sock_release(csocket); 803 + kfree(p); 804 return fd; 805 } 806 807 + get_file(csocket->file); 808 + get_file(csocket->file); 809 + p->wr = p->rd = csocket->file; 810 + client->trans = p; 811 + client->status = Connected; 812 + 813 + sys_close(fd); /* still racy */ 814 + 815 + p->rd->f_flags |= O_NONBLOCK; 816 + 817 + p->conn = p9_conn_create(client); 818 + if (IS_ERR(p->conn)) { 819 + ret = PTR_ERR(p->conn); 820 + p->conn = NULL; 821 + kfree(p); 822 + sockfd_put(csocket); 823 sockfd_put(csocket); 824 return ret; 825 } 826 return 0; 827 } 828 ··· 883 struct socket *csocket; 884 struct sockaddr_in sin_server; 885 struct p9_fd_opts opts; 886 887 err = parse_opts(args, &opts); 888 if (err < 0) ··· 897 sin_server.sin_family = AF_INET; 898 sin_server.sin_addr.s_addr = in_aton(addr); 899 sin_server.sin_port = htons(opts.port); 900 + err = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket); 901 902 + if (err) { 903 P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n"); 904 + return err; 905 } 906 907 err = csocket->ops->connect(csocket, ··· 912 P9_EPRINTK(KERN_ERR, 913 "p9_trans_tcp: problem connecting socket to %s\n", 914 addr); 915 sock_release(csocket); 916 + return err; 917 + } 918 919 + return p9_socket_open(client, csocket); 920 } 921 922 static int ··· 944 int err; 945 struct socket *csocket; 946 struct sockaddr_un sun_server; 947 948 csocket = NULL; 949 950 if (strlen(addr) > UNIX_PATH_MAX) { 951 P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", 952 addr); 953 + return -ENAMETOOLONG; 954 } 955 956 sun_server.sun_family = PF_UNIX; 957 strcpy(sun_server.sun_path, addr); 958 + err = sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket); 959 + if (err < 0) { 960 + P9_EPRINTK(KERN_ERR, "p9_trans_unix: problem creating socket\n"); 961 + return err; 962 + } 963 err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, 964 sizeof(struct sockaddr_un) - 1, 0); 965 if (err < 0) { 966 P9_EPRINTK(KERN_ERR, 967 "p9_trans_unix: problem connecting socket: %s: %d\n", 968 addr, err); 969 sock_release(csocket); 970 + return err; 971 + } 972 973 + return p9_socket_open(client, csocket); 974 } 975 976 static int ··· 994 { 995 int err; 996 struct p9_fd_opts opts; 997 + struct p9_trans_fd *p; 998 999 parse_opts(args, &opts); 1000 ··· 1005 1006 err = p9_fd_open(client, opts.rfd, opts.wfd); 1007 if (err < 0) 1008 + return err; 1009 1010 p = (struct p9_trans_fd *) client->trans; 1011 p->conn = p9_conn_create(client); 1012 if (IS_ERR(p->conn)) { 1013 err = PTR_ERR(p->conn); 1014 p->conn = NULL; 1015 + fput(p->rd); 1016 + fput(p->wr); 1017 + return err; 1018 } 1019 1020 return 0; 1021 } 1022 1023 static struct p9_trans_module p9_tcp_trans = {
+36 -72
net/socket.c
··· 355 * but we take care of internal coherence yet. 356 */ 357 358 - static int sock_alloc_fd(struct file **filep, int flags) 359 { 360 int fd; 361 362 fd = get_unused_fd_flags(flags); 363 - if (likely(fd >= 0)) { 364 - struct file *file = get_empty_filp(); 365 366 - *filep = file; 367 - if (unlikely(!file)) { 368 - put_unused_fd(fd); 369 - return -ENFILE; 370 - } 371 - } else 372 - *filep = NULL; 373 - return fd; 374 - } 375 - 376 - static int sock_attach_fd(struct socket *sock, struct file *file, int flags) 377 - { 378 - struct dentry *dentry; 379 - struct qstr name = { .name = "" }; 380 - 381 - dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name); 382 - if (unlikely(!dentry)) 383 return -ENOMEM; 384 385 - dentry->d_op = &sockfs_dentry_operations; 386 /* 387 * We dont want to push this dentry into global dentry hash table. 388 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED 389 * This permits a working /proc/$pid/fd/XXX on sockets 390 */ 391 - dentry->d_flags &= ~DCACHE_UNHASHED; 392 - d_instantiate(dentry, SOCK_INODE(sock)); 393 394 sock->file = file; 395 - init_file(file, sock_mnt, dentry, FMODE_READ | FMODE_WRITE, 396 - &socket_file_ops); 397 - SOCK_INODE(sock)->i_fop = &socket_file_ops; 398 file->f_flags = O_RDWR | (flags & O_NONBLOCK); 399 file->f_pos = 0; 400 file->private_data = sock; 401 402 - return 0; 403 } 404 405 int sock_map_fd(struct socket *sock, int flags) 406 { 407 struct file *newfile; 408 - int fd = sock_alloc_fd(&newfile, flags); 409 410 - if (likely(fd >= 0)) { 411 - int err = sock_attach_fd(sock, newfile, flags); 412 - 413 - if (unlikely(err < 0)) { 414 - put_filp(newfile); 415 - put_unused_fd(fd); 416 - return err; 417 - } 418 fd_install(fd, newfile); 419 - } 420 return fd; 421 } 422 ··· 1383 if (err < 0) 1384 goto out_release_both; 1385 1386 - fd1 = sock_alloc_fd(&newfile1, flags & O_CLOEXEC); 1387 if (unlikely(fd1 < 0)) { 1388 err = fd1; 1389 goto out_release_both; 1390 } 1391 1392 - fd2 = sock_alloc_fd(&newfile2, flags & O_CLOEXEC); 1393 if (unlikely(fd2 < 0)) { 1394 err = fd2; 1395 - put_filp(newfile1); 1396 - put_unused_fd(fd1); 1397 - goto out_release_both; 1398 - } 1399 - 1400 - err = sock_attach_fd(sock1, newfile1, flags & O_NONBLOCK); 1401 - if (unlikely(err < 0)) { 1402 - goto out_fd2; 1403 - } 1404 - 1405 - err = sock_attach_fd(sock2, newfile2, flags & O_NONBLOCK); 1406 - if (unlikely(err < 0)) { 1407 fput(newfile1); 1408 - goto out_fd1; 1409 } 1410 1411 audit_fd_pair(fd1, fd2); ··· 1421 sock_release(sock1); 1422 out: 1423 return err; 1424 - 1425 - out_fd2: 1426 - put_filp(newfile1); 1427 - sock_release(sock1); 1428 - out_fd1: 1429 - put_filp(newfile2); 1430 - sock_release(sock2); 1431 - put_unused_fd(fd1); 1432 - put_unused_fd(fd2); 1433 - goto out; 1434 } 1435 1436 /* ··· 1524 */ 1525 __module_get(newsock->ops->owner); 1526 1527 - newfd = sock_alloc_fd(&newfile, flags & O_CLOEXEC); 1528 if (unlikely(newfd < 0)) { 1529 err = newfd; 1530 sock_release(newsock); 1531 goto out_put; 1532 } 1533 - 1534 - err = sock_attach_fd(newsock, newfile, flags & O_NONBLOCK); 1535 - if (err < 0) 1536 - goto out_fd_simple; 1537 1538 err = security_socket_accept(sock, newsock); 1539 if (err) ··· 1560 fput_light(sock->file, fput_needed); 1561 out: 1562 return err; 1563 - out_fd_simple: 1564 - sock_release(newsock); 1565 - put_filp(newfile); 1566 - put_unused_fd(newfd); 1567 - goto out_put; 1568 out_fd: 1569 fput(newfile); 1570 put_unused_fd(newfd);
··· 355 * but we take care of internal coherence yet. 356 */ 357 358 + static int sock_alloc_file(struct socket *sock, struct file **f, int flags) 359 { 360 + struct qstr name = { .name = "" }; 361 + struct path path; 362 + struct file *file; 363 int fd; 364 365 fd = get_unused_fd_flags(flags); 366 + if (unlikely(fd < 0)) 367 + return fd; 368 369 + path.dentry = d_alloc(sock_mnt->mnt_sb->s_root, &name); 370 + if (unlikely(!path.dentry)) { 371 + put_unused_fd(fd); 372 return -ENOMEM; 373 + } 374 + path.mnt = mntget(sock_mnt); 375 376 + path.dentry->d_op = &sockfs_dentry_operations; 377 /* 378 * We dont want to push this dentry into global dentry hash table. 379 * We pretend dentry is already hashed, by unsetting DCACHE_UNHASHED 380 * This permits a working /proc/$pid/fd/XXX on sockets 381 */ 382 + path.dentry->d_flags &= ~DCACHE_UNHASHED; 383 + d_instantiate(path.dentry, SOCK_INODE(sock)); 384 + SOCK_INODE(sock)->i_fop = &socket_file_ops; 385 + 386 + file = alloc_file(&path, FMODE_READ | FMODE_WRITE, 387 + &socket_file_ops); 388 + if (unlikely(!file)) { 389 + /* drop dentry, keep inode */ 390 + atomic_inc(&path.dentry->d_inode->i_count); 391 + path_put(&path); 392 + put_unused_fd(fd); 393 + return -ENFILE; 394 + } 395 396 sock->file = file; 397 file->f_flags = O_RDWR | (flags & O_NONBLOCK); 398 file->f_pos = 0; 399 file->private_data = sock; 400 401 + *f = file; 402 + return fd; 403 } 404 405 int sock_map_fd(struct socket *sock, int flags) 406 { 407 struct file *newfile; 408 + int fd = sock_alloc_file(sock, &newfile, flags); 409 410 + if (likely(fd >= 0)) 411 fd_install(fd, newfile); 412 + 413 return fd; 414 } 415 ··· 1390 if (err < 0) 1391 goto out_release_both; 1392 1393 + fd1 = sock_alloc_file(sock1, &newfile1, flags); 1394 if (unlikely(fd1 < 0)) { 1395 err = fd1; 1396 goto out_release_both; 1397 } 1398 1399 + fd2 = sock_alloc_file(sock2, &newfile2, flags); 1400 if (unlikely(fd2 < 0)) { 1401 err = fd2; 1402 fput(newfile1); 1403 + put_unused_fd(fd1); 1404 + sock_release(sock2); 1405 + goto out; 1406 } 1407 1408 audit_fd_pair(fd1, fd2); ··· 1438 sock_release(sock1); 1439 out: 1440 return err; 1441 } 1442 1443 /* ··· 1551 */ 1552 __module_get(newsock->ops->owner); 1553 1554 + newfd = sock_alloc_file(newsock, &newfile, flags); 1555 if (unlikely(newfd < 0)) { 1556 err = newfd; 1557 sock_release(newsock); 1558 goto out_put; 1559 } 1560 1561 err = security_socket_accept(sock, newsock); 1562 if (err) ··· 1591 fput_light(sock->file, fput_needed); 1592 out: 1593 return err; 1594 out_fd: 1595 fput(newfile); 1596 put_unused_fd(newfd);
-3
security/integrity/ima/ima.h
··· 97 98 /* iint cache flags */ 99 #define IMA_MEASURED 1 100 - #define IMA_IINT_DUMP_STACK 512 101 102 /* integrity data associated with an inode */ 103 struct ima_iint_cache { ··· 127 */ 128 struct ima_iint_cache *ima_iint_insert(struct inode *inode); 129 struct ima_iint_cache *ima_iint_find_get(struct inode *inode); 130 - struct ima_iint_cache *ima_iint_find_insert_get(struct inode *inode); 131 - void ima_iint_delete(struct inode *inode); 132 void iint_free(struct kref *kref); 133 void iint_rcu_free(struct rcu_head *rcu); 134
··· 97 98 /* iint cache flags */ 99 #define IMA_MEASURED 1 100 101 /* integrity data associated with an inode */ 102 struct ima_iint_cache { ··· 128 */ 129 struct ima_iint_cache *ima_iint_insert(struct inode *inode); 130 struct ima_iint_cache *ima_iint_find_get(struct inode *inode); 131 void iint_free(struct kref *kref); 132 void iint_rcu_free(struct rcu_head *rcu); 133
+13 -68
security/integrity/ima/ima_iint.c
··· 19 #include <linux/radix-tree.h> 20 #include "ima.h" 21 22 - #define ima_iint_delete ima_inode_free 23 - 24 RADIX_TREE(ima_iint_store, GFP_ATOMIC); 25 DEFINE_SPINLOCK(ima_iint_lock); 26 ··· 43 return iint; 44 } 45 46 - /* Allocate memory for the iint associated with the inode 47 - * from the iint_cache slab, initialize the iint, and 48 - * insert it into the radix tree. 49 - * 50 - * On success return a pointer to the iint; on failure return NULL. 51 */ 52 - struct ima_iint_cache *ima_iint_insert(struct inode *inode) 53 { 54 struct ima_iint_cache *iint = NULL; 55 int rc = 0; 56 57 if (!ima_initialized) 58 - return iint; 59 iint = kmem_cache_alloc(iint_cache, GFP_NOFS); 60 if (!iint) 61 - return iint; 62 63 rc = radix_tree_preload(GFP_NOFS); 64 if (rc < 0) ··· 67 rc = radix_tree_insert(&ima_iint_store, (unsigned long)inode, iint); 68 spin_unlock(&ima_iint_lock); 69 out: 70 - if (rc < 0) { 71 kmem_cache_free(iint_cache, iint); 72 - if (rc == -EEXIST) { 73 - spin_lock(&ima_iint_lock); 74 - iint = radix_tree_lookup(&ima_iint_store, 75 - (unsigned long)inode); 76 - spin_unlock(&ima_iint_lock); 77 - } else 78 - iint = NULL; 79 - } 80 radix_tree_preload_end(); 81 - return iint; 82 } 83 - 84 - /** 85 - * ima_inode_alloc - allocate an iint associated with an inode 86 - * @inode: pointer to the inode 87 - * 88 - * Return 0 on success, 1 on failure. 89 - */ 90 - int ima_inode_alloc(struct inode *inode) 91 - { 92 - struct ima_iint_cache *iint; 93 - 94 - if (!ima_initialized) 95 - return 0; 96 - 97 - iint = ima_iint_insert(inode); 98 - if (!iint) 99 - return 1; 100 - return 0; 101 - } 102 - 103 - /* ima_iint_find_insert_get - get the iint associated with an inode 104 - * 105 - * Most insertions are done at inode_alloc, except those allocated 106 - * before late_initcall. When the iint does not exist, allocate it, 107 - * initialize and insert it, and increment the iint refcount. 108 - * 109 - * (Can't initialize at security_initcall before any inodes are 110 - * allocated, got to wait at least until proc_init.) 111 - * 112 - * Return the iint. 113 - */ 114 - struct ima_iint_cache *ima_iint_find_insert_get(struct inode *inode) 115 - { 116 - struct ima_iint_cache *iint = NULL; 117 - 118 - iint = ima_iint_find_get(inode); 119 - if (iint) 120 - return iint; 121 - 122 - iint = ima_iint_insert(inode); 123 - if (iint) 124 - kref_get(&iint->refcount); 125 - 126 - return iint; 127 - } 128 - EXPORT_SYMBOL_GPL(ima_iint_find_insert_get); 129 130 /* iint_free - called when the iint refcount goes to zero */ 131 void iint_free(struct kref *kref) ··· 109 } 110 111 /** 112 - * ima_iint_delete - called on integrity_inode_free 113 * @inode: pointer to the inode 114 * 115 * Free the integrity information(iint) associated with an inode. 116 */ 117 - void ima_iint_delete(struct inode *inode) 118 { 119 struct ima_iint_cache *iint; 120
··· 19 #include <linux/radix-tree.h> 20 #include "ima.h" 21 22 RADIX_TREE(ima_iint_store, GFP_ATOMIC); 23 DEFINE_SPINLOCK(ima_iint_lock); 24 ··· 45 return iint; 46 } 47 48 + /** 49 + * ima_inode_alloc - allocate an iint associated with an inode 50 + * @inode: pointer to the inode 51 */ 52 + int ima_inode_alloc(struct inode *inode) 53 { 54 struct ima_iint_cache *iint = NULL; 55 int rc = 0; 56 57 if (!ima_initialized) 58 + return 0; 59 + 60 iint = kmem_cache_alloc(iint_cache, GFP_NOFS); 61 if (!iint) 62 + return -ENOMEM; 63 64 rc = radix_tree_preload(GFP_NOFS); 65 if (rc < 0) ··· 70 rc = radix_tree_insert(&ima_iint_store, (unsigned long)inode, iint); 71 spin_unlock(&ima_iint_lock); 72 out: 73 + if (rc < 0) 74 kmem_cache_free(iint_cache, iint); 75 + 76 radix_tree_preload_end(); 77 + 78 + return rc; 79 } 80 81 /* iint_free - called when the iint refcount goes to zero */ 82 void iint_free(struct kref *kref) ··· 164 } 165 166 /** 167 + * ima_inode_free - called on security_inode_free 168 * @inode: pointer to the inode 169 * 170 * Free the integrity information(iint) associated with an inode. 171 */ 172 + void ima_inode_free(struct inode *inode) 173 { 174 struct ima_iint_cache *iint; 175
+103 -81
security/integrity/ima/ima_main.c
··· 13 * License. 14 * 15 * File: ima_main.c 16 - * implements the IMA hooks: ima_bprm_check, ima_file_mmap, 17 - * and ima_path_check. 18 */ 19 #include <linux/module.h> 20 #include <linux/file.h> ··· 35 } 36 __setup("ima_hash=", hash_setup); 37 38 /** 39 * ima_file_free - called on __fput() 40 * @file: pointer to file structure being freed ··· 148 return; 149 150 mutex_lock(&iint->mutex); 151 - if (iint->opencount <= 0) { 152 - printk(KERN_INFO 153 - "%s: %s open/free imbalance (r:%ld w:%ld o:%ld f:%ld)\n", 154 - __FUNCTION__, file->f_dentry->d_name.name, 155 - iint->readcount, iint->writecount, 156 - iint->opencount, atomic_long_read(&file->f_count)); 157 - if (!(iint->flags & IMA_IINT_DUMP_STACK)) { 158 - dump_stack(); 159 - iint->flags |= IMA_IINT_DUMP_STACK; 160 - } 161 - } 162 - iint->opencount--; 163 - 164 - if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 165 - iint->readcount--; 166 - 167 - if (file->f_mode & FMODE_WRITE) { 168 - iint->writecount--; 169 - if (iint->writecount == 0) { 170 - if (iint->version != inode->i_version) 171 - iint->flags &= ~IMA_MEASURED; 172 - } 173 - } 174 mutex_unlock(&iint->mutex); 175 kref_put(&iint->refcount, iint_free); 176 } ··· 188 { 189 int rc = 0; 190 191 - iint->opencount++; 192 - iint->readcount++; 193 194 rc = ima_collect_measurement(iint, file); 195 if (!rc) 196 ima_store_measurement(iint, file, filename); 197 return rc; 198 - } 199 - 200 - static void ima_update_counts(struct ima_iint_cache *iint, int mask) 201 - { 202 - iint->opencount++; 203 - if ((mask & MAY_WRITE) || (mask == 0)) 204 - iint->writecount++; 205 - else if (mask & (MAY_READ | MAY_EXEC)) 206 - iint->readcount++; 207 } 208 209 /** ··· 214 * Always return 0 and audit dentry_open failures. 215 * (Return code will be based upon measurement appraisal.) 216 */ 217 - int ima_path_check(struct path *path, int mask, int update_counts) 218 { 219 struct inode *inode = path->dentry->d_inode; 220 struct ima_iint_cache *iint; ··· 223 224 if (!ima_initialized || !S_ISREG(inode->i_mode)) 225 return 0; 226 - iint = ima_iint_find_insert_get(inode); 227 if (!iint) 228 return 0; 229 230 mutex_lock(&iint->mutex); 231 - if (update_counts) 232 - ima_update_counts(iint, mask); 233 234 rc = ima_must_measure(iint, inode, MAY_READ, PATH_CHECK); 235 if (rc < 0) ··· 279 280 if (!ima_initialized || !S_ISREG(inode->i_mode)) 281 return 0; 282 - iint = ima_iint_find_insert_get(inode); 283 if (!iint) 284 return -ENOMEM; 285 ··· 298 } 299 300 /* 301 - * ima_counts_put - decrement file counts 302 - * 303 - * File counts are incremented in ima_path_check. On file open 304 - * error, such as ETXTBSY, decrement the counts to prevent 305 - * unnecessary imbalance messages. 306 - */ 307 - void ima_counts_put(struct path *path, int mask) 308 - { 309 - struct inode *inode = path->dentry->d_inode; 310 - struct ima_iint_cache *iint; 311 - 312 - /* The inode may already have been freed, freeing the iint 313 - * with it. Verify the inode is not NULL before dereferencing 314 - * it. 315 - */ 316 - if (!ima_initialized || !inode || !S_ISREG(inode->i_mode)) 317 - return; 318 - iint = ima_iint_find_insert_get(inode); 319 - if (!iint) 320 - return; 321 - 322 - mutex_lock(&iint->mutex); 323 - iint->opencount--; 324 - if ((mask & MAY_WRITE) || (mask == 0)) 325 - iint->writecount--; 326 - else if (mask & (MAY_READ | MAY_EXEC)) 327 - iint->readcount--; 328 - mutex_unlock(&iint->mutex); 329 - 330 - kref_put(&iint->refcount, iint_free); 331 - } 332 - 333 - /* 334 * ima_counts_get - increment file counts 335 * 336 * - for IPC shm and shmat file. ··· 313 314 if (!ima_initialized || !S_ISREG(inode->i_mode)) 315 return; 316 - iint = ima_iint_find_insert_get(inode); 317 if (!iint) 318 return; 319 mutex_lock(&iint->mutex); 320 - iint->opencount++; 321 - if ((file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 322 - iint->readcount++; 323 - 324 - if (file->f_mode & FMODE_WRITE) 325 - iint->writecount++; 326 mutex_unlock(&iint->mutex); 327 328 kref_put(&iint->refcount, iint_free);
··· 13 * License. 14 * 15 * File: ima_main.c 16 + * implements the IMA hooks: ima_bprm_check, ima_file_mmap, 17 + * and ima_path_check. 18 */ 19 #include <linux/module.h> 20 #include <linux/file.h> ··· 35 } 36 __setup("ima_hash=", hash_setup); 37 38 + struct ima_imbalance { 39 + struct hlist_node node; 40 + unsigned long fsmagic; 41 + }; 42 + 43 + /* 44 + * ima_limit_imbalance - emit one imbalance message per filesystem type 45 + * 46 + * Maintain list of filesystem types that do not measure files properly. 47 + * Return false if unknown, true if known. 48 + */ 49 + static bool ima_limit_imbalance(struct file *file) 50 + { 51 + static DEFINE_SPINLOCK(ima_imbalance_lock); 52 + static HLIST_HEAD(ima_imbalance_list); 53 + 54 + struct super_block *sb = file->f_dentry->d_sb; 55 + struct ima_imbalance *entry; 56 + struct hlist_node *node; 57 + bool found = false; 58 + 59 + rcu_read_lock(); 60 + hlist_for_each_entry_rcu(entry, node, &ima_imbalance_list, node) { 61 + if (entry->fsmagic == sb->s_magic) { 62 + found = true; 63 + break; 64 + } 65 + } 66 + rcu_read_unlock(); 67 + if (found) 68 + goto out; 69 + 70 + entry = kmalloc(sizeof(*entry), GFP_NOFS); 71 + if (!entry) 72 + goto out; 73 + entry->fsmagic = sb->s_magic; 74 + spin_lock(&ima_imbalance_lock); 75 + /* 76 + * we could have raced and something else might have added this fs 77 + * to the list, but we don't really care 78 + */ 79 + hlist_add_head_rcu(&entry->node, &ima_imbalance_list); 80 + spin_unlock(&ima_imbalance_lock); 81 + printk(KERN_INFO "IMA: unmeasured files on fsmagic: %lX\n", 82 + entry->fsmagic); 83 + out: 84 + return found; 85 + } 86 + 87 + /* 88 + * Update the counts given an fmode_t 89 + */ 90 + static void ima_inc_counts(struct ima_iint_cache *iint, fmode_t mode) 91 + { 92 + BUG_ON(!mutex_is_locked(&iint->mutex)); 93 + 94 + iint->opencount++; 95 + if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 96 + iint->readcount++; 97 + if (mode & FMODE_WRITE) 98 + iint->writecount++; 99 + } 100 + 101 + /* 102 + * Decrement ima counts 103 + */ 104 + static void ima_dec_counts(struct ima_iint_cache *iint, struct inode *inode, 105 + struct file *file) 106 + { 107 + mode_t mode = file->f_mode; 108 + BUG_ON(!mutex_is_locked(&iint->mutex)); 109 + 110 + iint->opencount--; 111 + if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) 112 + iint->readcount--; 113 + if (mode & FMODE_WRITE) { 114 + iint->writecount--; 115 + if (iint->writecount == 0) { 116 + if (iint->version != inode->i_version) 117 + iint->flags &= ~IMA_MEASURED; 118 + } 119 + } 120 + 121 + if (((iint->opencount < 0) || 122 + (iint->readcount < 0) || 123 + (iint->writecount < 0)) && 124 + !ima_limit_imbalance(file)) { 125 + printk(KERN_INFO "%s: open/free imbalance (r:%ld w:%ld o:%ld)\n", 126 + __FUNCTION__, iint->readcount, iint->writecount, 127 + iint->opencount); 128 + dump_stack(); 129 + } 130 + } 131 + 132 /** 133 * ima_file_free - called on __fput() 134 * @file: pointer to file structure being freed ··· 54 return; 55 56 mutex_lock(&iint->mutex); 57 + ima_dec_counts(iint, inode, file); 58 mutex_unlock(&iint->mutex); 59 kref_put(&iint->refcount, iint_free); 60 } ··· 116 { 117 int rc = 0; 118 119 + ima_inc_counts(iint, file->f_mode); 120 121 rc = ima_collect_measurement(iint, file); 122 if (!rc) 123 ima_store_measurement(iint, file, filename); 124 return rc; 125 } 126 127 /** ··· 152 * Always return 0 and audit dentry_open failures. 153 * (Return code will be based upon measurement appraisal.) 154 */ 155 + int ima_path_check(struct path *path, int mask) 156 { 157 struct inode *inode = path->dentry->d_inode; 158 struct ima_iint_cache *iint; ··· 161 162 if (!ima_initialized || !S_ISREG(inode->i_mode)) 163 return 0; 164 + iint = ima_iint_find_get(inode); 165 if (!iint) 166 return 0; 167 168 mutex_lock(&iint->mutex); 169 170 rc = ima_must_measure(iint, inode, MAY_READ, PATH_CHECK); 171 if (rc < 0) ··· 219 220 if (!ima_initialized || !S_ISREG(inode->i_mode)) 221 return 0; 222 + iint = ima_iint_find_get(inode); 223 if (!iint) 224 return -ENOMEM; 225 ··· 238 } 239 240 /* 241 * ima_counts_get - increment file counts 242 * 243 * - for IPC shm and shmat file. ··· 286 287 if (!ima_initialized || !S_ISREG(inode->i_mode)) 288 return; 289 + iint = ima_iint_find_get(inode); 290 if (!iint) 291 return; 292 mutex_lock(&iint->mutex); 293 + ima_inc_counts(iint, file->f_mode); 294 mutex_unlock(&iint->mutex); 295 296 kref_put(&iint->refcount, iint_free);