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

Configure Feed

Select the types of activity you want to include in your feed.

replace do_getxattr() with saner helpers.

similar to do_setxattr() in the previous commit...

Reviewed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro 0158005a 66d7ac6b

+62 -67
+3 -5
fs/internal.h
··· 280 280 unsigned int flags; 281 281 }; 282 282 283 - 284 - ssize_t do_getxattr(struct mnt_idmap *idmap, 285 - struct dentry *d, 286 - struct kernel_xattr_ctx *ctx); 287 - 283 + ssize_t file_getxattr(struct file *file, struct kernel_xattr_ctx *ctx); 284 + ssize_t filename_getxattr(int dfd, struct filename *filename, 285 + unsigned int lookup_flags, struct kernel_xattr_ctx *ctx); 288 286 int file_setxattr(struct file *file, struct kernel_xattr_ctx *ctx); 289 287 int filename_setxattr(int dfd, struct filename *filename, 290 288 unsigned int lookup_flags, struct kernel_xattr_ctx *ctx);
+52 -38
fs/xattr.c
··· 744 744 /* 745 745 * Extended attribute GET operations 746 746 */ 747 - ssize_t 747 + static ssize_t 748 748 do_getxattr(struct mnt_idmap *idmap, struct dentry *d, 749 749 struct kernel_xattr_ctx *ctx) 750 750 { 751 751 ssize_t error; 752 752 char *kname = ctx->kname->name; 753 + void *kvalue = NULL; 753 754 754 755 if (ctx->size) { 755 756 if (ctx->size > XATTR_SIZE_MAX) 756 757 ctx->size = XATTR_SIZE_MAX; 757 - ctx->kvalue = kvzalloc(ctx->size, GFP_KERNEL); 758 - if (!ctx->kvalue) 758 + kvalue = kvzalloc(ctx->size, GFP_KERNEL); 759 + if (!kvalue) 759 760 return -ENOMEM; 760 761 } 761 762 762 - if (is_posix_acl_xattr(ctx->kname->name)) 763 - error = do_get_acl(idmap, d, kname, ctx->kvalue, ctx->size); 763 + if (is_posix_acl_xattr(kname)) 764 + error = do_get_acl(idmap, d, kname, kvalue, ctx->size); 764 765 else 765 - error = vfs_getxattr(idmap, d, kname, ctx->kvalue, ctx->size); 766 + error = vfs_getxattr(idmap, d, kname, kvalue, ctx->size); 766 767 if (error > 0) { 767 - if (ctx->size && copy_to_user(ctx->value, ctx->kvalue, error)) 768 + if (ctx->size && copy_to_user(ctx->value, kvalue, error)) 768 769 error = -EFAULT; 769 770 } else if (error == -ERANGE && ctx->size >= XATTR_SIZE_MAX) { 770 771 /* The file system tried to returned a value bigger ··· 773 772 error = -E2BIG; 774 773 } 775 774 775 + kvfree(kvalue); 776 776 return error; 777 777 } 778 778 779 - static ssize_t 780 - getxattr(struct mnt_idmap *idmap, struct dentry *d, 781 - const char __user *name, void __user *value, size_t size) 779 + ssize_t file_getxattr(struct file *f, struct kernel_xattr_ctx *ctx) 780 + { 781 + audit_file(f); 782 + return do_getxattr(file_mnt_idmap(f), f->f_path.dentry, ctx); 783 + } 784 + 785 + /* unconditionally consumes filename */ 786 + ssize_t filename_getxattr(int dfd, struct filename *filename, 787 + unsigned int lookup_flags, struct kernel_xattr_ctx *ctx) 788 + { 789 + struct path path; 790 + ssize_t error; 791 + retry: 792 + error = filename_lookup(dfd, filename, lookup_flags, &path, NULL); 793 + if (error) 794 + goto out; 795 + error = do_getxattr(mnt_idmap(path.mnt), path.dentry, ctx); 796 + path_put(&path); 797 + if (retry_estale(error, lookup_flags)) { 798 + lookup_flags |= LOOKUP_REVAL; 799 + goto retry; 800 + } 801 + out: 802 + putname(filename); 803 + return error; 804 + } 805 + 806 + static ssize_t path_getxattr(const char __user *pathname, 807 + const char __user *name, void __user *value, 808 + size_t size, unsigned int lookup_flags) 782 809 { 783 810 ssize_t error; 784 811 struct xattr_name kname; 785 812 struct kernel_xattr_ctx ctx = { 786 813 .value = value, 787 - .kvalue = NULL, 788 814 .size = size, 789 815 .kname = &kname, 790 816 .flags = 0, ··· 820 792 error = import_xattr_name(&kname, name); 821 793 if (error) 822 794 return error; 823 - 824 - error = do_getxattr(idmap, d, &ctx); 825 - 826 - kvfree(ctx.kvalue); 827 - return error; 828 - } 829 - 830 - static ssize_t path_getxattr(const char __user *pathname, 831 - const char __user *name, void __user *value, 832 - size_t size, unsigned int lookup_flags) 833 - { 834 - struct path path; 835 - ssize_t error; 836 - retry: 837 - error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); 838 - if (error) 839 - return error; 840 - error = getxattr(mnt_idmap(path.mnt), path.dentry, name, value, size); 841 - path_put(&path); 842 - if (retry_estale(error, lookup_flags)) { 843 - lookup_flags |= LOOKUP_REVAL; 844 - goto retry; 845 - } 846 - return error; 795 + return filename_getxattr(AT_FDCWD, getname(pathname), lookup_flags, &ctx); 847 796 } 848 797 849 798 SYSCALL_DEFINE4(getxattr, const char __user *, pathname, ··· 838 833 SYSCALL_DEFINE4(fgetxattr, int, fd, const char __user *, name, 839 834 void __user *, value, size_t, size) 840 835 { 836 + ssize_t error; 837 + struct xattr_name kname; 838 + struct kernel_xattr_ctx ctx = { 839 + .value = value, 840 + .size = size, 841 + .kname = &kname, 842 + .flags = 0, 843 + }; 841 844 CLASS(fd, f)(fd); 842 845 843 846 if (fd_empty(f)) 844 847 return -EBADF; 845 - audit_file(fd_file(f)); 846 - return getxattr(file_mnt_idmap(fd_file(f)), fd_file(f)->f_path.dentry, 847 - name, value, size); 848 + error = import_xattr_name(&kname, name); 849 + if (error) 850 + return error; 851 + return file_getxattr(fd_file(f), &ctx); 848 852 } 849 853 850 854 /*
+7 -24
io_uring/xattr.c
··· 51 51 ix->filename = NULL; 52 52 ix->ctx.kvalue = NULL; 53 53 name = u64_to_user_ptr(READ_ONCE(sqe->addr)); 54 - ix->ctx.cvalue = u64_to_user_ptr(READ_ONCE(sqe->addr2)); 54 + ix->ctx.value = u64_to_user_ptr(READ_ONCE(sqe->addr2)); 55 55 ix->ctx.size = READ_ONCE(sqe->len); 56 56 ix->ctx.flags = READ_ONCE(sqe->xattr_flags); 57 57 ··· 94 94 path = u64_to_user_ptr(READ_ONCE(sqe->addr3)); 95 95 96 96 ix->filename = getname(path); 97 - if (IS_ERR(ix->filename)) { 98 - ret = PTR_ERR(ix->filename); 99 - ix->filename = NULL; 100 - } 97 + if (IS_ERR(ix->filename)) 98 + return PTR_ERR(ix->filename); 101 99 102 - return ret; 100 + return 0; 103 101 } 104 102 105 103 int io_fgetxattr(struct io_kiocb *req, unsigned int issue_flags) ··· 107 109 108 110 WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK); 109 111 110 - ret = do_getxattr(file_mnt_idmap(req->file), 111 - req->file->f_path.dentry, 112 - &ix->ctx); 113 - 112 + ret = file_getxattr(req->file, &ix->ctx); 114 113 io_xattr_finish(req, ret); 115 114 return IOU_OK; 116 115 } ··· 115 120 int io_getxattr(struct io_kiocb *req, unsigned int issue_flags) 116 121 { 117 122 struct io_xattr *ix = io_kiocb_to_cmd(req, struct io_xattr); 118 - unsigned int lookup_flags = LOOKUP_FOLLOW; 119 - struct path path; 120 123 int ret; 121 124 122 125 WARN_ON_ONCE(issue_flags & IO_URING_F_NONBLOCK); 123 126 124 - retry: 125 - ret = filename_lookup(AT_FDCWD, ix->filename, lookup_flags, &path, NULL); 126 - if (!ret) { 127 - ret = do_getxattr(mnt_idmap(path.mnt), path.dentry, &ix->ctx); 128 - 129 - path_put(&path); 130 - if (retry_estale(ret, lookup_flags)) { 131 - lookup_flags |= LOOKUP_REVAL; 132 - goto retry; 133 - } 134 - } 135 - 127 + ret = filename_getxattr(AT_FDCWD, ix->filename, LOOKUP_FOLLOW, &ix->ctx); 128 + ix->filename = NULL; 136 129 io_xattr_finish(req, ret); 137 130 return IOU_OK; 138 131 }