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

Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull misc vfs cleanups from Al Viro:
"Assorted cleanups and fixes all over the place"

* 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
coredump: only charge written data against RLIMIT_CORE
coredump: get rid of coredump_params->written
ecryptfs_lookup(): try either only encrypted or plaintext name
ecryptfs: avoid multiple aliases for directories
bpf: reject invalid names right in ->lookup()
__d_alloc(): treat NULL name as QSTR("/", 1)
mtd: switch ubi_open_volume_path() to vfs_stat()
mtd: switch open_mtd_by_chdev() to use of vfs_stat()

+69 -112
+3 -2
arch/powerpc/platforms/cell/spufs/coredump.c
··· 137 137 char *name; 138 138 char fullname[80], *buf; 139 139 struct elf_note en; 140 + size_t skip; 140 141 141 142 buf = (void *)get_zeroed_page(GFP_KERNEL); 142 143 if (!buf) ··· 172 171 if (rc < 0) 173 172 goto out; 174 173 175 - if (!dump_skip(cprm, 176 - roundup(cprm->written - total + sz, 4) - cprm->written)) 174 + skip = roundup(cprm->file->f_pos - total + sz, 4) - cprm->file->f_pos; 175 + if (!dump_skip(cprm, skip)) 177 176 goto Eio; 178 177 out: 179 178 free_page((unsigned long)buf);
+5 -8
drivers/mtd/ubi/build.c
··· 1142 1142 */ 1143 1143 static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) 1144 1144 { 1145 - int err, major, minor, mode; 1146 - struct path path; 1145 + struct kstat stat; 1146 + int err, minor; 1147 1147 1148 1148 /* Probably this is an MTD character device node path */ 1149 - err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path); 1149 + err = vfs_stat(mtd_dev, &stat); 1150 1150 if (err) 1151 1151 return ERR_PTR(err); 1152 1152 1153 1153 /* MTD device number is defined by the major / minor numbers */ 1154 - major = imajor(d_backing_inode(path.dentry)); 1155 - minor = iminor(d_backing_inode(path.dentry)); 1156 - mode = d_backing_inode(path.dentry)->i_mode; 1157 - path_put(&path); 1158 - if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode)) 1154 + if (MAJOR(stat.rdev) != MTD_CHAR_MAJOR || !S_ISCHR(stat.mode)) 1159 1155 return ERR_PTR(-EINVAL); 1160 1156 1157 + minor = MINOR(stat.rdev); 1161 1158 if (minor & 1) 1162 1159 /* 1163 1160 * Just do not think the "/dev/mtdrX" devices support is need,
+8 -11
drivers/mtd/ubi/kapi.c
··· 301 301 */ 302 302 struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) 303 303 { 304 - int error, ubi_num, vol_id, mod; 305 - struct inode *inode; 306 - struct path path; 304 + int error, ubi_num, vol_id; 305 + struct kstat stat; 307 306 308 307 dbg_gen("open volume %s, mode %d", pathname, mode); 309 308 310 309 if (!pathname || !*pathname) 311 310 return ERR_PTR(-EINVAL); 312 311 313 - error = kern_path(pathname, LOOKUP_FOLLOW, &path); 312 + error = vfs_stat(pathname, &stat); 314 313 if (error) 315 314 return ERR_PTR(error); 316 315 317 - inode = d_backing_inode(path.dentry); 318 - mod = inode->i_mode; 319 - ubi_num = ubi_major2num(imajor(inode)); 320 - vol_id = iminor(inode) - 1; 321 - path_put(&path); 322 - 323 - if (!S_ISCHR(mod)) 316 + if (!S_ISCHR(stat.mode)) 324 317 return ERR_PTR(-EINVAL); 318 + 319 + ubi_num = ubi_major2num(MAJOR(stat.rdev)); 320 + vol_id = MINOR(stat.rdev) - 1; 321 + 325 322 if (vol_id >= 0 && ubi_num >= 0) 326 323 return ubi_open_volume(ubi_num, vol_id, mode); 327 324 return ERR_PTR(-ENODEV);
+1 -1
fs/binfmt_elf.c
··· 2273 2273 goto end_coredump; 2274 2274 2275 2275 /* Align to page */ 2276 - if (!dump_skip(cprm, dataoff - cprm->written)) 2276 + if (!dump_skip(cprm, dataoff - cprm->file->f_pos)) 2277 2277 goto end_coredump; 2278 2278 2279 2279 for (i = 0, vma = first_vma(current, gate_vma); vma != NULL;
+1 -1
fs/binfmt_elf_fdpic.c
··· 1787 1787 goto end_coredump; 1788 1788 } 1789 1789 1790 - if (!dump_skip(cprm, dataoff - cprm->written)) 1790 + if (!dump_skip(cprm, dataoff - cprm->file->f_pos)) 1791 1791 goto end_coredump; 1792 1792 1793 1793 if (!elf_fdpic_dump_segments(cprm))
+1 -4
fs/coredump.c
··· 803 803 static char zeroes[PAGE_SIZE]; 804 804 struct file *file = cprm->file; 805 805 if (file->f_op->llseek && file->f_op->llseek != no_llseek) { 806 - if (cprm->written + nr > cprm->limit) 807 - return 0; 808 806 if (dump_interrupted() || 809 807 file->f_op->llseek(file, nr, SEEK_CUR) < 0) 810 808 return 0; 811 - cprm->written += nr; 812 809 return 1; 813 810 } else { 814 811 while (nr > PAGE_SIZE) { ··· 820 823 821 824 int dump_align(struct coredump_params *cprm, int align) 822 825 { 823 - unsigned mod = cprm->written & (align - 1); 826 + unsigned mod = cprm->file->f_pos & (align - 1); 824 827 if (align & (align - 1)) 825 828 return 0; 826 829 return mod ? dump_skip(cprm, align - mod) : 1;
+7 -6
fs/dcache.c
··· 1571 1571 * be overwriting an internal NUL character 1572 1572 */ 1573 1573 dentry->d_iname[DNAME_INLINE_LEN-1] = 0; 1574 - if (name->len > DNAME_INLINE_LEN-1) { 1574 + if (unlikely(!name)) { 1575 + static const struct qstr anon = QSTR_INIT("/", 1); 1576 + name = &anon; 1577 + dname = dentry->d_iname; 1578 + } else if (name->len > DNAME_INLINE_LEN-1) { 1575 1579 size_t size = offsetof(struct external_name, name[1]); 1576 1580 struct external_name *p = kmalloc(size + name->len, 1577 1581 GFP_KERNEL_ACCOUNT); ··· 1833 1829 struct dentry *res = NULL; 1834 1830 1835 1831 if (root_inode) { 1836 - static const struct qstr name = QSTR_INIT("/", 1); 1837 - 1838 - res = __d_alloc(root_inode->i_sb, &name); 1832 + res = __d_alloc(root_inode->i_sb, NULL); 1839 1833 if (res) 1840 1834 d_instantiate(res, root_inode); 1841 1835 else ··· 1874 1872 1875 1873 static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected) 1876 1874 { 1877 - static const struct qstr anonstring = QSTR_INIT("/", 1); 1878 1875 struct dentry *tmp; 1879 1876 struct dentry *res; 1880 1877 unsigned add_flags; ··· 1887 1886 if (res) 1888 1887 goto out_iput; 1889 1888 1890 - tmp = __d_alloc(inode->i_sb, &anonstring); 1889 + tmp = __d_alloc(inode->i_sb, NULL); 1891 1890 if (!tmp) { 1892 1891 res = ERR_PTR(-ENOMEM); 1893 1892 goto out_iput;
+35 -50
fs/ecryptfs/inode.c
··· 324 324 /** 325 325 * ecryptfs_lookup_interpose - Dentry interposition for a lookup 326 326 */ 327 - static int ecryptfs_lookup_interpose(struct dentry *dentry, 328 - struct dentry *lower_dentry, 329 - struct inode *dir_inode) 327 + static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry, 328 + struct dentry *lower_dentry) 330 329 { 331 330 struct inode *inode, *lower_inode = d_inode(lower_dentry); 332 331 struct ecryptfs_dentry_info *dentry_info; ··· 338 339 "to allocate ecryptfs_dentry_info struct\n", 339 340 __func__); 340 341 dput(lower_dentry); 341 - return -ENOMEM; 342 + return ERR_PTR(-ENOMEM); 342 343 } 343 344 344 345 lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); 345 - fsstack_copy_attr_atime(dir_inode, d_inode(lower_dentry->d_parent)); 346 + fsstack_copy_attr_atime(d_inode(dentry->d_parent), 347 + d_inode(lower_dentry->d_parent)); 346 348 BUG_ON(!d_count(lower_dentry)); 347 349 348 350 ecryptfs_set_dentry_private(dentry, dentry_info); ··· 353 353 if (d_really_is_negative(lower_dentry)) { 354 354 /* We want to add because we couldn't find in lower */ 355 355 d_add(dentry, NULL); 356 - return 0; 356 + return NULL; 357 357 } 358 - inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb); 358 + inode = __ecryptfs_get_inode(lower_inode, dentry->d_sb); 359 359 if (IS_ERR(inode)) { 360 360 printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n", 361 361 __func__, PTR_ERR(inode)); 362 - return PTR_ERR(inode); 362 + return ERR_CAST(inode); 363 363 } 364 364 if (S_ISREG(inode->i_mode)) { 365 365 rc = ecryptfs_i_size_read(dentry, inode); 366 366 if (rc) { 367 367 make_bad_inode(inode); 368 - return rc; 368 + return ERR_PTR(rc); 369 369 } 370 370 } 371 371 372 372 if (inode->i_state & I_NEW) 373 373 unlock_new_inode(inode); 374 - d_add(dentry, inode); 375 - 376 - return rc; 374 + return d_splice_alias(inode, dentry); 377 375 } 378 376 379 377 /** ··· 388 390 unsigned int flags) 389 391 { 390 392 char *encrypted_and_encoded_name = NULL; 391 - size_t encrypted_and_encoded_name_size; 392 - struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL; 393 + struct ecryptfs_mount_crypt_stat *mount_crypt_stat; 393 394 struct dentry *lower_dir_dentry, *lower_dentry; 395 + const char *name = ecryptfs_dentry->d_name.name; 396 + size_t len = ecryptfs_dentry->d_name.len; 397 + struct dentry *res; 394 398 int rc = 0; 395 399 396 400 lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); 397 - lower_dentry = lookup_one_len_unlocked(ecryptfs_dentry->d_name.name, 398 - lower_dir_dentry, 399 - ecryptfs_dentry->d_name.len); 400 - if (IS_ERR(lower_dentry)) { 401 - rc = PTR_ERR(lower_dentry); 402 - ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " 403 - "[%d] on lower_dentry = [%pd]\n", __func__, rc, 404 - ecryptfs_dentry); 405 - goto out; 406 - } 407 - if (d_really_is_positive(lower_dentry)) 408 - goto interpose; 401 + 409 402 mount_crypt_stat = &ecryptfs_superblock_to_private( 410 403 ecryptfs_dentry->d_sb)->mount_crypt_stat; 411 - if (!(mount_crypt_stat 412 - && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES))) 413 - goto interpose; 414 - dput(lower_dentry); 415 - rc = ecryptfs_encrypt_and_encode_filename( 416 - &encrypted_and_encoded_name, &encrypted_and_encoded_name_size, 417 - mount_crypt_stat, ecryptfs_dentry->d_name.name, 418 - ecryptfs_dentry->d_name.len); 419 - if (rc) { 420 - printk(KERN_ERR "%s: Error attempting to encrypt and encode " 421 - "filename; rc = [%d]\n", __func__, rc); 422 - goto out; 404 + if (mount_crypt_stat 405 + && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)) { 406 + rc = ecryptfs_encrypt_and_encode_filename( 407 + &encrypted_and_encoded_name, &len, 408 + mount_crypt_stat, name, len); 409 + if (rc) { 410 + printk(KERN_ERR "%s: Error attempting to encrypt and encode " 411 + "filename; rc = [%d]\n", __func__, rc); 412 + return ERR_PTR(rc); 413 + } 414 + name = encrypted_and_encoded_name; 423 415 } 424 - lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name, 425 - lower_dir_dentry, 426 - encrypted_and_encoded_name_size); 416 + 417 + lower_dentry = lookup_one_len_unlocked(name, lower_dir_dentry, len); 427 418 if (IS_ERR(lower_dentry)) { 428 - rc = PTR_ERR(lower_dentry); 429 419 ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " 430 - "[%d] on lower_dentry = [%s]\n", __func__, rc, 431 - encrypted_and_encoded_name); 432 - goto out; 420 + "[%ld] on lower_dentry = [%s]\n", __func__, 421 + PTR_ERR(lower_dentry), 422 + name); 423 + res = ERR_CAST(lower_dentry); 424 + } else { 425 + res = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry); 433 426 } 434 - interpose: 435 - rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry, 436 - ecryptfs_dir_inode); 437 - out: 438 427 kfree(encrypted_and_encoded_name); 439 - return ERR_PTR(rc); 428 + return res; 440 429 } 441 430 442 431 static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
+8 -29
kernel/bpf/inode.c
··· 119 119 return 0; 120 120 } 121 121 122 - static bool bpf_dname_reserved(const struct dentry *dentry) 123 - { 124 - return strchr(dentry->d_name.name, '.'); 125 - } 126 - 127 122 static int bpf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 128 123 { 129 124 struct inode *inode; 130 - 131 - if (bpf_dname_reserved(dentry)) 132 - return -EPERM; 133 125 134 126 inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFDIR); 135 127 if (IS_ERR(inode)) ··· 143 151 umode_t mode, const struct inode_operations *iops) 144 152 { 145 153 struct inode *inode; 146 - 147 - if (bpf_dname_reserved(dentry)) 148 - return -EPERM; 149 154 150 155 inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFREG); 151 156 if (IS_ERR(inode)) ··· 176 187 } 177 188 } 178 189 179 - static int bpf_link(struct dentry *old_dentry, struct inode *dir, 180 - struct dentry *new_dentry) 190 + static struct dentry * 191 + bpf_lookup(struct inode *dir, struct dentry *dentry, unsigned flags) 181 192 { 182 - if (bpf_dname_reserved(new_dentry)) 183 - return -EPERM; 184 - 185 - return simple_link(old_dentry, dir, new_dentry); 186 - } 187 - 188 - static int bpf_rename(struct inode *old_dir, struct dentry *old_dentry, 189 - struct inode *new_dir, struct dentry *new_dentry) 190 - { 191 - if (bpf_dname_reserved(new_dentry)) 192 - return -EPERM; 193 - 194 - return simple_rename(old_dir, old_dentry, new_dir, new_dentry); 193 + if (strchr(dentry->d_name.name, '.')) 194 + return ERR_PTR(-EPERM); 195 + return simple_lookup(dir, dentry, flags); 195 196 } 196 197 197 198 static const struct inode_operations bpf_dir_iops = { 198 - .lookup = simple_lookup, 199 + .lookup = bpf_lookup, 199 200 .mknod = bpf_mkobj, 200 201 .mkdir = bpf_mkdir, 201 202 .rmdir = simple_rmdir, 202 - .rename = bpf_rename, 203 - .link = bpf_link, 203 + .rename = simple_rename, 204 + .link = simple_link, 204 205 .unlink = simple_unlink, 205 206 }; 206 207