virtiofsd: Add support to enable/disable posix acls
v6 cover virtiofsd: Add support to enable/disable posix acls
Hi,
This is V6 of the patches.
Changes since V5:
- Kernel patches for extended setxattr have been merged in 5.13-rc1. These patches have been modified to work with FUSE_SETXATTR_EXT.
Currently posix ACL support does not work well with virtiofs and bunch of tests fail when I run xfstests "./check -g acl".
This patches series fixes the issues with virtiofs posix acl support and provides options to enable/disable posix acl (-o posix_acl/no_posix_acl). By default posix_acls are disabled.
With this patch series applied and virtiofsd running with "-o posix_acl", xfstests "./check -g acl" passes.
Thanks
Vivek
Vivek Goyal (8):
linux-headers: Update linux headers to 5.13.0-rc6
virtiofsd: Fix fuse setxattr() API change issue
virtiofsd: Fix xattr operations overwriting errno
virtiofsd: Add support for extended setxattr
virtiofsd: Add umask to seccom allow list
virtiofsd: Add capability to change/restore umask
virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr
virtiofsd: Add an option to enable/disable posix acls
docs/tools/virtiofsd.rst | 3 + .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.h | 35 - include/standard-headers/drm/drm_fourcc.h | 23 +- include/standard-headers/linux/ethtool.h | 109 ++- include/standard-headers/linux/fuse.h | 17 +- .../linux/input-event-codes.h | 1 + include/standard-headers/linux/input.h | 2 +- include/standard-headers/linux/virtio_ids.h | 2 + .../standard-headers/rdma/vmw_pvrdma-abi.h | 7 + linux-headers/asm-generic/unistd.h | 13 +- linux-headers/asm-mips/unistd_n32.h | 751 +++++++-------- linux-headers/asm-mips/unistd_n64.h | 703 +++++++------- linux-headers/asm-mips/unistd_o32.h | 843 ++++++++--------- linux-headers/asm-powerpc/kvm.h | 2 + linux-headers/asm-powerpc/unistd_32.h | 856 +++++++++--------- linux-headers/asm-powerpc/unistd_64.h | 800 ++++++++-------- linux-headers/asm-s390/unistd_32.h | 4 + linux-headers/asm-s390/unistd_64.h | 4 + linux-headers/asm-x86/kvm.h | 3 + linux-headers/asm-x86/unistd_32.h | 4 + linux-headers/asm-x86/unistd_64.h | 4 + linux-headers/asm-x86/unistd_x32.h | 4 + linux-headers/linux/kvm.h | 131 ++- linux-headers/linux/userfaultfd.h | 36 +- linux-headers/linux/vfio.h | 35 + tools/virtiofsd/fuse_common.h | 10 + tools/virtiofsd/fuse_lowlevel.c | 18 +- tools/virtiofsd/fuse_lowlevel.h | 3 +- tools/virtiofsd/helper.c | 1 + tools/virtiofsd/passthrough_ll.c | 229 ++++- tools/virtiofsd/passthrough_seccomp.c | 1 + 31 files changed, 2592 insertions(+), 2062 deletions(-)
Signature · 1 line
2.25.4
PATCH v6 1/8 linux-headers: Update linux headers to 5.13.0-rc6
Update linux kernel headers for version 5.13.0-rc6
--- .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.h | 35 - include/standard-headers/drm/drm_fourcc.h | 23 +- include/standard-headers/linux/ethtool.h | 109 ++- include/standard-headers/linux/fuse.h | 17 +- .../linux/input-event-codes.h | 1 + include/standard-headers/linux/input.h | 2 +- include/standard-headers/linux/virtio_ids.h | 2 + .../standard-headers/rdma/vmw_pvrdma-abi.h | 7 + linux-headers/asm-generic/unistd.h | 13 +- linux-headers/asm-mips/unistd_n32.h | 751 +++++++-------- linux-headers/asm-mips/unistd_n64.h | 703 +++++++------- linux-headers/asm-mips/unistd_o32.h | 843 ++++++++--------- linux-headers/asm-powerpc/kvm.h | 2 + linux-headers/asm-powerpc/unistd_32.h | 856 +++++++++--------- linux-headers/asm-powerpc/unistd_64.h | 800 ++++++++-------- linux-headers/asm-s390/unistd_32.h | 4 + linux-headers/asm-s390/unistd_64.h | 4 + linux-headers/asm-x86/kvm.h | 3 + linux-headers/asm-x86/unistd_32.h | 4 + linux-headers/asm-x86/unistd_64.h | 4 + linux-headers/asm-x86/unistd_x32.h | 4 + linux-headers/linux/kvm.h | 131 ++- linux-headers/linux/userfaultfd.h | 36 +- linux-headers/linux/vfio.h | 35 + 24 files changed, 2343 insertions(+), 2046 deletions(-)
include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_verbs.h +0 -35
@@ -70,30 +70,6 @@ enum pvrdma_mtu { PVRDMA_MTU_4096 = 5, }; -static inline int pvrdma_mtu_enum_to_int (enum pvrdma_mtu mtu) -{ -switch (mtu) { -case PVRDMA_MTU_256 :return 256 ; -case PVRDMA_MTU_512 :return 512 ; -case PVRDMA_MTU_1024 :return 1024 ; -case PVRDMA_MTU_2048 :return 2048 ; -case PVRDMA_MTU_4096 :return 4096 ; -default :return -1 ; - } -} - -static inline enum pvrdma_mtu pvrdma_mtu_int_to_enum (int mtu) -{ -switch (mtu) { -case 256 :return PVRDMA_MTU_256 ; -case 512 :return PVRDMA_MTU_512 ; -case 1024 :return PVRDMA_MTU_1024 ; -case 2048 :return PVRDMA_MTU_2048 ; -case 4096 : -default :return PVRDMA_MTU_4096 ; - } -} -enum pvrdma_port_state {PVRDMA_PORT_NOP =0 ,PVRDMA_PORT_DOWN =1 ,
@@ -138,17 +114,6 @@ enum pvrdma_port_width { PVRDMA_WIDTH_12X = 8, }; -static inline int pvrdma_width_enum_to_int (enum pvrdma_port_width width) -{ -switch (width) { -case PVRDMA_WIDTH_1X :return 1 ; -case PVRDMA_WIDTH_4X :return 4 ; -case PVRDMA_WIDTH_8X :return 8 ; -case PVRDMA_WIDTH_12X :return 12 ; -default :return -1 ; - } -} -enum pvrdma_port_speed {PVRDMA_SPEED_SDR =1 ,PVRDMA_SPEED_DDR =2 ,
include/standard-headers/drm/drm_fourcc.h +21 -2
@@ -526,6 +526,25 @@ extern "C" {*/ #define I915_FORMAT_MOD_Y_TILED_GEN12_MC_CCS fourcc_mod_code(INTEL, 7) +/* +* Intel Color Control Surface with Clear Color (CCS) for Gen-12 render +* compression. +* +* The main surface is Y-tiled and is at plane index 0 whereas CCS is linear +* and at index 1. The clear color is stored at index 2, and the pitch should +* be ignored. The clear color structure is 256 bits. The first 128 bits +* represents Raw Clear Color Red, Green, Blue and Alpha color each represented +* by 32 bits. The raw clear color is consumed by the 3d engine and generates +* the converted clear color of size 64 bits. The first 32 bits store the Lower +* Converted Clear Color value and the next 32 bits store the Higher Converted +* Clear Color value when applicable. The Converted Clear Color values are +* consumed by the DE. The last 64 bits are used to store Color Discard Enable +* and Depth Clear Value Valid which are ignored by the DE. A CCS cache line +* corresponds to an area of 4x1 tiles in the main surface. The main surface +* pitch is required to be a multiple of 4 tile widths. +*/ +#define I915_FORMAT_MOD_Y_TILED_GEN12_RC_CCS_CC fourcc_mod_code(INTEL, 8) +/* * Tiled, NV12MT, grouped in 64 (pixels) x 32 (lines) -sized macroblocks *
@@ -1035,9 +1054,9 @@ drm_fourcc_canonicalize_nvidia_format_mod(uint64_t modifier)* Not all combinations are valid, and different SoCs may support different * combinations of layout and options. */ -#define __fourcc_mod_amlogic_layout_mask 0xf +#define __fourcc_mod_amlogic_layout_mask 0xff#define __fourcc_mod_amlogic_options_shift 8 -#define __fourcc_mod_amlogic_options_mask 0xf +#define __fourcc_mod_amlogic_options_mask 0xff#define DRM_FORMAT_MOD_AMLOGIC_FBC (__layout, __options) \ fourcc_mod_code(AMLOGIC, \
include/standard-headers/linux/ethtool.h +77 -32
245 lines not on this page · raw message
include/standard-headers/linux/fuse.h +16 -1
@@ -179,6 +179,8 @@* 7.33 * - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID * - add FUSE_OPEN_KILL_SUIDGID +* - extend fuse_setxattr_in, add FUSE_SETXATTR_EXT +* - add FUSE_SETXATTR_ACL_KILL_SGID */ #ifndef _LINUX_FUSE_H
@@ -326,6 +328,7 @@ struct fuse_file_lock {* does not have CAP_FSETID. Additionally upon * write/truncate sgid is killed only if file has group * execute permission. (Same as Linux VFS behavior). +* FUSE_SETXATTR_EXT: Server supports extended struct fuse_setxattr_in */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -356,6 +359,7 @@ struct fuse_file_lock {#define FUSE_MAP_ALIGNMENT (1 << 26)#define FUSE_SUBMOUNTS (1 << 27)#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28) +#define FUSE_SETXATTR_EXT (1 << 29)/** * CUSE INIT request/reply flags
@@ -447,6 +451,12 @@ struct fuse_file_lock {*/ #define FUSE_OPEN_KILL_SUIDGID (1 << 0) +/** +* setxattr flags +* FUSE_SETXATTR_ACL_KILL_SGID: Clear SGID when system.posix_acl_access is set +*/ +#define FUSE_SETXATTR_ACL_KILL_SGID (1 << 0) +enum fuse_opcode {FUSE_LOOKUP =1 ,FUSE_FORGET =2 ,/* no reply */
@@ -677,9 +687,13 @@ struct fuse_fsync_in {uint32_t padding; }; +#define FUSE_COMPAT_SETXATTR_IN_SIZE 8 +struct fuse_setxattr_in {uint32_t size;uint32_t flags; +uint32_t setxattr_flags; +uint32_t padding; };struct fuse_getxattr_in {
@@ -899,7 +913,8 @@ struct fuse_notify_retrieve_in { };/* Device ioctls: */ -#define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t) +#define FUSE_DEV_IOC_MAGIC 229 +#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)struct fuse_lseek_in {uint64_t fh;
include/standard-headers/linux/input-event-codes.h +1 -0
@@ -611,6 +611,7 @@#define KEY_VOICECOMMAND 0x246/* Listening Voice Command */ #define KEY_ASSISTANT 0x247/* AL Context-aware desktop assistant */ #define KEY_KBD_LAYOUT_NEXT 0x248/* AC Next Keyboard Layout Select */ +#define KEY_EMOJI_PICKER 0x249/* Show/hide emoji picker (HUTRR101) */ #define KEY_BRIGHTNESS_MIN 0x250/* Set Brightness to Minimum */ #define KEY_BRIGHTNESS_MAX 0x251/* Set Brightness to Maximum */
include/standard-headers/linux/input.h +1 -1
@@ -81,7 +81,7 @@ struct input_id {* in units per radian. * When INPUT_PROP_ACCELEROMETER is set the resolution changes. * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in -* in units per g (units/g) and in units per degree per second +* units per g (units/g) and in units per degree per second * (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ). */ struct input_absinfo {
include/standard-headers/linux/virtio_ids.h +2 -0
@@ -51,8 +51,10 @@#define VIRTIO_ID_PSTORE 22/* virtio pstore device */ #define VIRTIO_ID_IOMMU 23/* virtio IOMMU */ #define VIRTIO_ID_MEM 24/* virtio mem */ +#define VIRTIO_ID_SOUND 25/* virtio sound */ #define VIRTIO_ID_FS 26/* virtio filesystem */ #define VIRTIO_ID_PMEM 27/* virtio pmem */ #define VIRTIO_ID_MAC80211_HWSIM 29/* virtio mac80211-hwsim */ +#define VIRTIO_ID_BT 40/* virtio bluetooth */ #endif /* _LINUX_VIRTIO_IDS_H */
include/standard-headers/rdma/vmw_pvrdma-abi.h +7 -0
@@ -133,6 +133,13 @@ enum pvrdma_wc_flags { PVRDMA_WC_FLAGS_MAX = PVRDMA_WC_WITH_NETWORK_HDR_TYPE, }; +enum pvrdma_network_type { +PVRDMA_NETWORK_IB , +PVRDMA_NETWORK_ROCE_V1 =PVRDMA_NETWORK_IB , +PVRDMA_NETWORK_IPV4 , +PVRDMA_NETWORK_IPV6 +}; +struct pvrdma_alloc_ucontext_resp {uint32_t qp_tab_size;uint32_t reserved;
linux-headers/asm-generic/unistd.h +12 -1
@@ -861,9 +861,20 @@ __SYSCALL(__NR_faccessat2, sys_faccessat2) __SYSCALL(__NR_process_madvise, sys_process_madvise)#define __NR_epoll_pwait2 441 __SC_COMP(__NR_epoll_pwait2, sys_epoll_pwait2, compat_sys_epoll_pwait2) +#define __NR_mount_setattr 442 +__SYSCALL(__NR_mount_setattr, sys_mount_setattr) +#define __NR_quotactl_path 443 +__SYSCALL(__NR_quotactl_path, sys_quotactl_path) + +#define __NR_landlock_create_ruleset 444 +__SYSCALL(__NR_landlock_create_ruleset, sys_landlock_create_ruleset) +#define __NR_landlock_add_rule 445 +__SYSCALL(__NR_landlock_add_rule, sys_landlock_add_rule) +#define __NR_landlock_restrict_self 446 +__SYSCALL(__NR_landlock_restrict_self, sys_landlock_restrict_self)#undef __NR_syscalls -#define __NR_syscalls 442 +#define __NR_syscalls 447/* * 32 bit systems traditionally used different
linux-headers/asm-mips/unistd_n32.h +377 -374
753 lines not on this page · raw message
linux-headers/asm-mips/unistd_n64.h +353 -350
705 lines not on this page · raw message
linux-headers/asm-mips/unistd_o32.h +423 -420
845 lines not on this page · raw message
linux-headers/asm-powerpc/kvm.h +2 -0
@@ -644,6 +644,8 @@ struct kvm_ppc_cpu_char {#define KVM_REG_PPC_MMCR3 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc1)#define KVM_REG_PPC_SIER2 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc2)#define KVM_REG_PPC_SIER3 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc3) +#define KVM_REG_PPC_DAWR1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc4) +#define KVM_REG_PPC_DAWRX1 (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc5)/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs
linux-headers/asm-powerpc/unistd_32.h +430 -426
246 lines not on this page · raw message
linux-headers/asm-powerpc/unistd_64.h +402 -398
800 lines not on this page · raw message
linux-headers/linux/kvm.h +129 -2
131 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.25.4
Part of the diff is not shown here. View the raw message.
PATCH v6 2/8 virtiofsd: Fix fuse setxattr() API change issue
In reply to Vivek GoyalWith kernel header updates fuse_setxattr_in struct has grown in size. But this new struct size only takes affect if user has opted in for fuse feature FUSE_SETXATTR_EXT otherwise fuse continues to send "fuse_setxattr_in" of older size. Older size is determined by FUSE_COMPAT_SETXATTR_IN_SIZE.
Fix this. If we have not opted in for FUSE_SETXATTR_EXT, then expect that we will get fuse_setxattr_in of size FUSE_COMPAT_SETXATTR_IN_SIZE and not sizeof(struct fuse_sexattr_in).
--- tools/virtiofsd/fuse_common.h | 5 +++++ tools/virtiofsd/fuse_lowlevel.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-)
tools/virtiofsd/fuse_common.h +5 -0
@@ -372,6 +372,11 @@ struct fuse_file_info {*/ #define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 28) +/** +* Indicates that file server supports extended struct fuse_setxattr_in +*/ +#define FUSE_CAP_SETXATTR_EXT (1 << 29) +/** * Ioctl flags *
tools/virtiofsd/fuse_lowlevel.c +6 -1
@@ -1419,8 +1419,13 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid,struct fuse_setxattr_in *arg;const char *name;const char *value; +bool setxattr_ext = req->se->conn.want &FUSE_CAP_SETXATTR_EXT ; + +if (setxattr_ext) + arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); +else + arg =fuse_mbuf_iter_advance (iter,FUSE_COMPAT_SETXATTR_IN_SIZE ); - arg =fuse_mbuf_iter_advance (iter,sizeof (*arg)); name =fuse_mbuf_iter_advance_str (iter);if (!arg || !name) {fuse_reply_err (req,EINVAL );
Signature · 1 line
2.25.4
PATCH v6 3/8 virtiofsd: Fix xattr operations overwriting errno
In reply to Vivek Goyalgetxattr/setxattr/removexattr/listxattr operations handle regualar and non-regular files differently. For the case of non-regular files we do fchdir(/proc/self/fd) and the xattr operation and then revert back to original working directory. After this we are saving errno and that's buggy because fchdir() will overwrite the errno.
FCHDIR_NOFAIL(lo->proc_self_fd);
ret = getxattr(procname, name, value, size);FCHDIR_NOFAIL(lo->root.fd);
if (ret == -1)
saverr = errno
In above example, if getxattr() failed, we will still return 0 to caller as errno must have been written by FCHDIR_NOFAIL(lo->root.fd) call. Fix all such instances and capture "errno" early and save in "saverr" variable.
--- tools/virtiofsd/passthrough_ll.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
tools/virtiofsd/passthrough_ll.c +10 -6
@@ -2791,15 +2791,17 @@ static void lo_getxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, goto out_err; } ret =fgetxattr (fd, name, value, size); + saverr = ret ==-1 ? errno :0 ; }else {/* fchdir should not fail here */ FCHDIR_NOFAIL (lo->proc_self_fd); ret =getxattr (procname, name, value, size); + saverr = ret ==-1 ? errno :0 ;FCHDIR_NOFAIL (lo->root.fd); }if (ret ==-1 ) { - goto out_err; + goto out; }if (size) { saverr =0 ;
@@ -2864,15 +2866,17 @@ static void lo_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) goto out_err; } ret =flistxattr (fd, value, size); + saverr = ret ==-1 ? errno :0 ; }else {/* fchdir should not fail here */ FCHDIR_NOFAIL (lo->proc_self_fd); ret =listxattr (procname, value, size); + saverr = ret ==-1 ? errno :0 ;FCHDIR_NOFAIL (lo->root.fd); }if (ret ==-1 ) { - goto out_err; + goto out; }if (size) { saverr =0 ;
@@ -2998,15 +3002,15 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, goto out; } ret =fsetxattr (fd, name, value, size, flags); + saverr = ret ==-1 ? errno :0 ; }else {/* fchdir should not fail here */ FCHDIR_NOFAIL (lo->proc_self_fd); ret =setxattr (procname, name, value, size, flags); + saverr = ret ==-1 ? errno :0 ;FCHDIR_NOFAIL (lo->root.fd); } - saverr = ret ==-1 ? errno :0 ; - out:if (fd >=0 ) {close (fd);
@@ -3064,15 +3068,15 @@ static void lo_removexattr(fuse_req_t req, fuse_ino_t ino, const char *in_name) goto out; } ret =fremovexattr (fd, name); + saverr = ret ==-1 ? errno :0 ; }else {/* fchdir should not fail here */ FCHDIR_NOFAIL (lo->proc_self_fd); ret =removexattr (procname, name); + saverr = ret ==-1 ? errno :0 ;FCHDIR_NOFAIL (lo->root.fd); } - saverr = ret ==-1 ? errno :0 ; - out:if (fd >=0 ) {close (fd);
Signature · 1 line
2.25.4
PATCH v6 4/8 virtiofsd: Add support for extended setxattr
In reply to Vivek GoyalAdd the bits to enable support for setxattr_ext if fuse offers it. Do not enable it by default yet. Let passthrough_ll opt-in. Enabling it by deafult kind of automatically means that you are taking responsibility of clearing SGID if ACL is set.
--- tools/virtiofsd/fuse_common.h | 5 +++++ tools/virtiofsd/fuse_lowlevel.c | 11 ++++++++++- tools/virtiofsd/fuse_lowlevel.h | 3 ++- tools/virtiofsd/passthrough_ll.c | 3 ++- 4 files changed, 19 insertions(+), 3 deletions(-)
tools/virtiofsd/fuse_common.h +5 -0
@@ -377,6 +377,11 @@ struct fuse_file_info {*/ #define FUSE_CAP_SETXATTR_EXT (1 << 29) +/** +* Indicates that file server supports extended struct fuse_setxattr_in +*/ +#define FUSE_CAP_SETXATTR_EXT (1 << 29) +/** * Ioctl flags *
tools/virtiofsd/fuse_lowlevel.c +10 -1
@@ -1439,7 +1439,9 @@ static void do_setxattr(fuse_req_t req, fuse_ino_t nodeid, }if (req->se->op.setxattr) { - req->se->op.setxattr (req, nodeid, name, value, arg->size, arg->flags); +uint32_t setxattr_flags = setxattr_ext ? arg->setxattr_flags :0 ; + req->se->op.setxattr (req, nodeid, name, value, arg->size, arg->flags, + setxattr_flags); }else {fuse_reply_err (req,ENOSYS ); }
@@ -1986,6 +1988,9 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid,if (arg->flags &FUSE_HANDLE_KILLPRIV_V2 ) { se->conn.capable |=FUSE_CAP_HANDLE_KILLPRIV_V2 ; } +if (arg->flags &FUSE_SETXATTR_EXT ) { + se->conn.capable |=FUSE_CAP_SETXATTR_EXT ; + }#ifdef HAVE_SPLICE #ifdef HAVE_VMSPLICE se->conn.capable |=FUSE_CAP_SPLICE_WRITE |FUSE_CAP_SPLICE_MOVE ;
@@ -2121,6 +2126,10 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, outarg.flags |=FUSE_HANDLE_KILLPRIV_V2 ; } +if (se->conn.want &FUSE_CAP_SETXATTR_EXT ) { + outarg.flags |=FUSE_SETXATTR_EXT ; + } +fuse_log (FUSE_LOG_DEBUG ," INIT: %u.%u\n" , outarg.major, outarg.minor);fuse_log (FUSE_LOG_DEBUG ," flags=0x%08x\n" , outarg.flags);fuse_log (FUSE_LOG_DEBUG ," max_readahead=0x%08x\n" , outarg.max_readahead);
tools/virtiofsd/fuse_lowlevel.h +2 -1
@@ -798,7 +798,8 @@ struct fuse_lowlevel_ops {* fuse_reply_err */ void (*setxattr)(fuse_req_t req,fuse_ino_t ino,const char *name, -const char *value,size_t size,int flags); +const char *value,size_t size,int flags, +uint32_t setxattr_flags);/** * Get an extended attribute
tools/virtiofsd/passthrough_ll.c +2 -1
@@ -2955,7 +2955,8 @@ out: }static void lo_setxattr (fuse_req_t req,fuse_ino_t ino,const char *in_name, -const char *value,size_t size,int flags) +const char *value,size_t size,int flags, +uint32_t extra_flags) {char procname[64 ];const char *name;
Signature · 1 line
2.25.4
PATCH v6 5/8 virtiofsd: Add umask to seccom allow list
In reply to Vivek GoyalPatches in this series are going to make use of "umask" syscall. So allow it.
--- tools/virtiofsd/passthrough_seccomp.c | 1 + 1 file changed, 1 insertion(+)
tools/virtiofsd/passthrough_seccomp.c +1 -0
@@ -114,6 +114,7 @@ static const int syscall_allowlist[] = {SCMP_SYS (utimensat),SCMP_SYS (write),SCMP_SYS (writev), + SCMP_SYS(umask), };/* Syscalls used when --syslog is enabled */
Signature · 1 line
2.25.4
PATCH v6 6/8 virtiofsd: Add capability to change/restore umask
In reply to Vivek GoyalWhen parent directory has default acl and a file is created in that directory, then umask is ignored and final file permissions are determined using default acl instead. (man 2 umask).
Currently, fuse applies the umask and sends modified mode in create request accordingly. fuse server can set FUSE_DONT_MASK and tell fuse client to not apply umask and fuse server will take care of it as needed.
With posix acls enabled, requirement will be that we want umask to determine final file mode if parent directory does not have default acl.
So if posix acls are enabled, opt in for FUSE_DONT_MASK. virtiofsd will set umask of the thread doing file creation. And host kernel should use that umask if parent directory does not have default acls, otherwise umask does not take affect.
Miklos mentioned that we already call unshare(CLONE_FS) for every thread. That means umask has now become property of per thread and it should be ok to manipulate it in file creation path.
This patch only adds capability to change umask and restore it. It does not enable it yet. Next few patches will add capability to enable it based on if user enabled posix_acl or not.
This should fix fstest generic/099.
--- tools/virtiofsd/passthrough_ll.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
tools/virtiofsd/passthrough_ll.c +16 -6
@@ -122,6 +122,7 @@ struct lo_inode {struct lo_cred {uid_t euid;gid_t egid; +mode_t umask; };enum {
@@ -172,6 +173,8 @@ struct lo_data {/* An O_PATH file descriptor to /proc/self/fd/ */ int proc_self_fd;int user_killpriv_v2, killpriv_v2; +/* If set, virtiofsd is responsible for setting umask during creation */ +bool change_umask; };static const struct fuse_opt lo_opts[] = {
@@ -1134,7 +1137,8 @@ static void lo_lookup(fuse_req_t req, fuse_ino_t parent, const char *name)* ownership of caller. * TODO: What about selinux context? */ -static int lo_change_cred (fuse_req_t req,struct lo_cred *old) +static int lo_change_cred (fuse_req_t req,struct lo_cred *old, +bool change_umask) {int res;
@@ -1154,11 +1158,14 @@ static int lo_change_cred(fuse_req_t req, struct lo_cred *old)return errno_save; } +if (change_umask) { + old->umask =umask (req->ctx.umask); + }return 0 ; }/* Regain Privileges */ -static void lo_restore_cred (struct lo_cred *old) +static void lo_restore_cred (struct lo_cred *old,bool restore_umask) {int res;
@@ -1173,6 +1180,9 @@ static void lo_restore_cred(struct lo_cred *old)fuse_log (FUSE_LOG_ERR ,"setegid(%u): %m\n" , old->egid);exit (1 ); } + +if (restore_umask) +umask (old->umask); } static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,
@@ -1202,7 +1212,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent,return ; } - saverr =lo_change_cred (req, &old); + saverr =lo_change_cred (req, &old, lo->change_umask && !S_ISLNK (mode));if (saverr) { goto out; }
@@ -1211,7 +1221,7 @@ static void lo_mknod_symlink(fuse_req_t req, fuse_ino_t parent, saverr = errno; -lo_restore_cred (&old); +lo_restore_cred (&old, lo->change_umask && !S_ISLNK (mode));if (res ==-1 ) { goto out;
@@ -1917,7 +1927,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name,return ; } - err =lo_change_cred (req, &old); + err =lo_change_cred (req, &old, lo->change_umask);if (err) { goto out; }
@@ -1928,7 +1938,7 @@ static void lo_create(fuse_req_t req, fuse_ino_t parent, const char *name, fd =openat (parent_inode->fd, name, fi->flags |O_CREAT |O_EXCL , mode); err = fd ==-1 ? errno :0 ; -lo_restore_cred (&old); +lo_restore_cred (&old, lo->change_umask);/* Ignore the error if file exists and O_EXCL was not given */ if (err && (err !=EEXIST || (fi->flags &O_EXCL ))) {
Signature · 1 line
2.25.4
PATCH v6 7/8 virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr
In reply to Vivek GoyalWhen posix access acls are set on a file, it can lead to adjusting file permissions (mode) as well. If caller does not have CAP_FSETID and it also does not have membership of owner group, this will lead to clearing SGID bit in mode.
Current fuse code is written in such a way that it expects file server to take care of chaning file mode (permission), if there is a need. Right now, host kernel does not clear SGID bit because virtiofsd is running as root and has CAP_FSETID. For host kernel to clear SGID, virtiofsd need to switch to gid of caller in guest and also drop CAP_FSETID (if caller did not have it to begin with).
If SGID needs to be cleared, client will set the flag FUSE_SETXATTR_ACL_KILL_SGID in setxattr request. In that case server should kill sgid.
Currently just switch to uid/gid of the caller and drop CAP_FSETID and that should do it.
This should fix the xfstest generic/375 test case.
We don't have to switch uid for this to work. That could be one optimization that pass a parameter to lo_change_cred() to only switch gid and not uid.
Also this will not work whenever (if ever) we support idmapped mounts. In that case it is possible that uid/gid in request are 0/0 but still we need to clear SGID. So we will have to pick a non-root sgid and switch to that instead. That's an TODO item for future when idmapped mount support is introduced.
This patch only adds the capability to switch creds and drop FSETID when acl xattr is set. This does not take affect yet. It can take affect when next patch adds the capability to enable posix_acl.
--- tools/virtiofsd/passthrough_ll.c | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
tools/virtiofsd/passthrough_ll.c +75 -0
@@ -175,6 +175,7 @@ struct lo_data {int user_killpriv_v2, killpriv_v2;/* If set, virtiofsd is responsible for setting umask during creation */ bool change_umask; +int posix_acl; };static const struct fuse_opt lo_opts[] = {
@@ -1185,6 +1186,51 @@ static void lo_restore_cred(struct lo_cred *old, bool restore_umask)umask (old->umask); } +/* +* A helper to change cred and drop capability. Returns 0 on success and +* errno on error +*/ +static int lo_drop_cap_change_cred (fuse_req_t req,struct lo_cred *old, +bool change_umask,const char *cap_name, +bool *cap_dropped) +{ +int ret; +bool __cap_dropped; + +assert (cap_name); + + ret =drop_effective_cap (cap_name, &__cap_dropped); +if (ret) { +return ret; + } + + ret =lo_change_cred (req, old, change_umask); +if (ret) { +if (__cap_dropped) { +if (gain_effective_cap (cap_name)) { +fuse_log (FUSE_LOG_ERR ,"Failed to gain CAP_%s\n" , cap_name); + } + } + } + +if (cap_dropped) + *cap_dropped = __cap_dropped; + +return ret; +} + +static void lo_restore_cred_gain_cap (struct lo_cred *old,bool restore_umask, +const char *cap_name) +{ +assert (cap_name); + +lo_restore_cred (old, restore_umask); + +if (gain_effective_cap (cap_name)) { +fuse_log (FUSE_LOG_ERR ,"Failed to gain CAP_%s\n" , cap_name); + } +} +static void lo_mknod_symlink (fuse_req_t req,fuse_ino_t parent,const char *name,mode_t mode,dev_t rdev,const char *link)
@@ -2976,6 +3022,9 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name,ssize_t ret;int saverr;int fd =-1 ; +bool switched_creds = false; +bool cap_fsetid_dropped = false; +struct lo_cred old = {}; mapped_name =NULL ; name = in_name;
@@ -3006,6 +3055,26 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, ", name=%s value=%s size=%zd)\n", ino, name, value, size);sprintf (procname,"%i" , inode->fd); +/* +* If we are setting posix access acl and if SGID needs to be +* cleared, then switch to caller's gid and drop CAP_FSETID +* and that should make sure host kernel clears SGID. +* +* This probably will not work when we support idmapped mounts. +* In that case we will need to find a non-root gid and switch +* to it. (Instead of gid in request). Fix it when we support +* idmapped mounts. +*/ +if (lo->posix_acl && !strcmp (name,"system.posix_acl_access" ) + && (extra_flags &FUSE_SETXATTR_ACL_KILL_SGID )) { + ret =lo_drop_cap_change_cred (req, &old, false,"FSETID" , + &cap_fsetid_dropped); +if (ret) { + saverr = ret; + goto out; + } + switched_creds = true; + }if (S_ISREG (inode->filetype) ||S_ISDIR (inode->filetype)) { fd =openat (lo->proc_self_fd, procname,O_RDONLY );if (fd <0 ) {
@@ -3021,6 +3090,12 @@ static void lo_setxattr(fuse_req_t req, fuse_ino_t ino, const char *in_name, saverr = ret ==-1 ? errno :0 ;FCHDIR_NOFAIL (lo->root.fd); } +if (switched_creds) { +if (cap_fsetid_dropped) +lo_restore_cred_gain_cap (&old, false,"FSETID" ); +else +lo_restore_cred (&old, false); + } out:if (fd >=0 ) {
Signature · 1 line
2.25.4
PATCH v6 8/8 virtiofsd: Add an option to enable/disable posix acls
In reply to Vivek Goyalfuse has an option FUSE_POSIX_ACL which needs to be opted in by fuse server to enable posix acls. As of now we are not opting in for this, so posix acls are disabled on virtiofs by default.
Add virtiofsd option "-o posix_acl/no_posix_acl" to let users enable/disable posix acl support. By default it is disabled as of now due to performance concerns with cache=none.
Currently even if file server has not opted in for FUSE_POSIX_ACL, user can still query acl and set acl, and system.posix_acl_access and system.posix_acl_default xattrs show up listxattr response.
Miklos said this is confusing. So he said lets block and filter system.posix_acl_access and system.posix_acl_default xattrs in getxattr/setxattr/listxattr if user has explicitly disabled posix acls using -o no_posix_acl.
As of now continuing to keeping the existing behavior if user did not specify any option to disable acl support due to concerns about backward compatibility.
--- docs/tools/virtiofsd.rst | 3 + tools/virtiofsd/helper.c | 1 + tools/virtiofsd/passthrough_ll.c | 115 ++++++++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 1 deletion(-)
docs/tools/virtiofsd.rst +3 -0
@@ -101,6 +101,9 @@ Options Enable/disable extended attributes (xattr) on files and directories. The default is ``no_xattr``. + * posix_acl|no_posix_acl - + Enable/disable posix acl support. Posix ACLs are disabled by default`. + .. option:: --socket-path=PATH Listen on vhost-user UNIX domain socket at PATH.
tools/virtiofsd/helper.c +1 -0
@@ -186,6 +186,7 @@ void fuse_cmdline_help(void)" to virtiofsd from guest applications.\n" " default: no_allow_direct_io\n" " -o announce_submounts Announce sub-mount points to the guest\n" +" -o posix_acl/no_posix_acl Enable/Disable posix_acl. (default: disabled)\n" ); }
tools/virtiofsd/passthrough_ll.c +114 -1
175 lines not on this page · raw message
Signature · 1 line
2.25.4
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH v6 0/8] virtiofsd: Add support to enable/disable posix acls
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Quoted 1 line
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
c812c39 virtiofsd: Add an option to enable/disable posix acls 62af00e virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr e93c53d virtiofsd: Add capability to change/restore umask
5588053 virtiofsd: Add umask to seccom allow list
dc2337e virtiofsd: Add support for extended setxattr
65fc720 virtiofsd: Fix xattr operations overwriting errno
967e28d virtiofsd: Fix fuse setxattr() API change issue
6c3d050 linux-headers: Update linux headers to 5.13.0-rc6
=== OUTPUT BEGIN ===
1/8 Checking commit 6c3d050bd70f (linux-headers: Update linux headers to 5.13.0-rc6) 2/8 Checking commit 967e28d2e22d (virtiofsd: Fix fuse setxattr() API change issue)
ERROR: braces {} are necessary for all arms of this statement
#50: FILE: tools/virtiofsd/fuse_lowlevel.c:1424:
+ if (setxattr_ext)
[...]
+ else
[...]
total: 1 errors, 0 warnings, 25 lines checked
Patch 2/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
3/8 Checking commit 65fc720e49ac (virtiofsd: Fix xattr operations overwriting errno)
4/8 Checking commit dc2337e643fc (virtiofsd: Add support for extended setxattr)
5/8 Checking commit 5588053fd40b (virtiofsd: Add umask to seccom allow list)
6/8 Checking commit e93c53dabdb7 (virtiofsd: Add capability to change/restore umask)
7/8 Checking commit 62af00ed759e (virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr)
ERROR: suspect code indent for conditional statements (4, 7)
#83: FILE: tools/virtiofsd/passthrough_ll.c:1208:
+ if (ret) {
+ if (__cap_dropped) {
ERROR: suspect code indent for conditional statements (7, 10) #84: FILE: tools/virtiofsd/passthrough_ll.c:1209:
+ if (__cap_dropped) {
+ if (gain_effective_cap(cap_name)) {
ERROR: suspect code indent for conditional statements (10, 14) #85: FILE: tools/virtiofsd/passthrough_ll.c:1210:
+ if (gain_effective_cap(cap_name)) {
+ fuse_log(FUSE_LOG_ERR, "Failed to gain CAP_%s\n", cap_name);
ERROR: braces {} are necessary for all arms of this statement #91: FILE: tools/virtiofsd/passthrough_ll.c:1216:
+ if (cap_dropped)
[...]
total: 4 errors, 0 warnings, 105 lines checked
Patch 7/8 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/8 Checking commit c812c393f36a (virtiofsd: Add an option to enable/disable posix acls) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]