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.

new helper: import_xattr_name()

common logics for marshalling xattr names.

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

Al Viro a10c4c5e 537c7662

+28 -27
+3
fs/internal.h
··· 288 288 int setxattr_copy(const char __user *name, struct kernel_xattr_ctx *ctx); 289 289 int do_setxattr(struct mnt_idmap *idmap, struct dentry *dentry, 290 290 struct kernel_xattr_ctx *ctx); 291 + 292 + int import_xattr_name(struct xattr_name *kname, const char __user *name); 293 + 291 294 int may_write_xattr(struct mnt_idmap *idmap, struct inode *inode); 292 295 293 296 #ifdef CONFIG_FS_POSIX_ACL
+23 -22
fs/xattr.c
··· 586 586 } 587 587 EXPORT_SYMBOL_GPL(vfs_removexattr); 588 588 589 + int import_xattr_name(struct xattr_name *kname, const char __user *name) 590 + { 591 + int error = strncpy_from_user(kname->name, name, 592 + sizeof(kname->name)); 593 + if (error == 0 || error == sizeof(kname->name)) 594 + return -ERANGE; 595 + if (error < 0) 596 + return error; 597 + return 0; 598 + } 599 + 589 600 /* 590 601 * Extended attribute SET operations 591 602 */ ··· 608 597 if (ctx->flags & ~(XATTR_CREATE|XATTR_REPLACE)) 609 598 return -EINVAL; 610 599 611 - error = strncpy_from_user(ctx->kname->name, name, 612 - sizeof(ctx->kname->name)); 613 - if (error == 0 || error == sizeof(ctx->kname->name)) 614 - return -ERANGE; 615 - if (error < 0) 600 + error = import_xattr_name(ctx->kname, name); 601 + if (error) 616 602 return error; 617 603 618 - error = 0; 619 604 if (ctx->size) { 620 605 if (ctx->size > XATTR_SIZE_MAX) 621 606 return -E2BIG; ··· 770 763 .flags = 0, 771 764 }; 772 765 773 - error = strncpy_from_user(kname.name, name, sizeof(kname.name)); 774 - if (error == 0 || error == sizeof(kname.name)) 775 - error = -ERANGE; 776 - if (error < 0) 766 + error = import_xattr_name(&kname, name); 767 + if (error) 777 768 return error; 778 769 779 770 error = do_getxattr(idmap, d, &ctx); ··· 911 906 { 912 907 struct path path; 913 908 int error; 914 - char kname[XATTR_NAME_MAX + 1]; 909 + struct xattr_name kname; 915 910 916 - error = strncpy_from_user(kname, name, sizeof(kname)); 917 - if (error == 0 || error == sizeof(kname)) 918 - error = -ERANGE; 919 - if (error < 0) 911 + error = import_xattr_name(&kname, name); 912 + if (error) 920 913 return error; 921 914 retry: 922 915 error = user_path_at(AT_FDCWD, pathname, lookup_flags, &path); ··· 922 919 return error; 923 920 error = mnt_want_write(path.mnt); 924 921 if (!error) { 925 - error = removexattr(mnt_idmap(path.mnt), path.dentry, kname); 922 + error = removexattr(mnt_idmap(path.mnt), path.dentry, kname.name); 926 923 mnt_drop_write(path.mnt); 927 924 } 928 925 path_put(&path); ··· 948 945 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name) 949 946 { 950 947 CLASS(fd, f)(fd); 951 - char kname[XATTR_NAME_MAX + 1]; 948 + struct xattr_name kname; 952 949 int error; 953 950 954 951 if (fd_empty(f)) 955 952 return -EBADF; 956 953 audit_file(fd_file(f)); 957 954 958 - error = strncpy_from_user(kname, name, sizeof(kname)); 959 - if (error == 0 || error == sizeof(kname)) 960 - error = -ERANGE; 961 - if (error < 0) 955 + error = import_xattr_name(&kname, name); 956 + if (error) 962 957 return error; 963 958 964 959 error = mnt_want_write_file(fd_file(f)); 965 960 if (!error) { 966 961 error = removexattr(file_mnt_idmap(fd_file(f)), 967 - fd_file(f)->f_path.dentry, kname); 962 + fd_file(f)->f_path.dentry, kname.name); 968 963 mnt_drop_write_file(fd_file(f)); 969 964 } 970 965 return error;
+2 -5
io_uring/xattr.c
··· 62 62 if (!ix->ctx.kname) 63 63 return -ENOMEM; 64 64 65 - ret = strncpy_from_user(ix->ctx.kname->name, name, 66 - sizeof(ix->ctx.kname->name)); 67 - if (!ret || ret == sizeof(ix->ctx.kname->name)) 68 - ret = -ERANGE; 69 - if (ret < 0) { 65 + ret = import_xattr_name(ix->ctx.kname, name); 66 + if (ret) { 70 67 kfree(ix->ctx.kname); 71 68 return ret; 72 69 }