virtiofsd: Add support to enable/disable posix acl
v6 cover virtiofsd: Add support to enable/disable posix acl
Hi,
This is V6 of the patches.
Changes since V5:
- If user asked to enable posix acl and if it can't be enabled, give a clear message before failure. (Luis).
- Took care of some coding style issues.
Corresponding kernel patches are posted here.
https://lore.kernel.org/linux-fsdevel/[email protected]/
Thanks
Vivek
Vivek Goyal (5):
virtiofsd: Add umask to seccom allow list
virtiofsd: Add capability to change/restore umask
virtiofsd: Add an option to enable/disable posix acls
virtiofsd: Add support for setxattr_v2
virtiofsd: Switch creds, drop FSETID for system.posix_acl_access xattr
docs/tools/virtiofsd.rst | 3 + include/standard-headers/linux/fuse.h | 19 ++- tools/virtiofsd/fuse_common.h | 6 + tools/virtiofsd/fuse_lowlevel.c | 42 +++++- tools/virtiofsd/fuse_lowlevel.h | 3 +- tools/virtiofsd/helper.c | 1 + tools/virtiofsd/passthrough_ll.c | 177 ++++++++++++++++++++++++-- tools/virtiofsd/passthrough_seccomp.c | 1 + 8 files changed, 241 insertions(+), 11 deletions(-)
Signature · 1 line
2.25.4
PATCH v6 1/5 virtiofsd: Add umask to seccom allow list
Patches 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 2/5 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 patch 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;
@@ -1918,7 +1928,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; }
@@ -1929,7 +1939,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 3/5 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 | 112 ++++++++++++++++++++++++++++++- 3 files changed, 115 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
@@ -183,6 +183,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 +111 -1
178 lines not on this page · raw message
Signature · 1 line
2.25.4
PATCH v6 4/5 virtiofsd: Add support for setxattr_v2
In reply to Vivek GoyalAdd the bits to enable support for setxattr_v2 if fuse offers it.
--- include/standard-headers/linux/fuse.h | 12 +++++++- tools/virtiofsd/fuse_common.h | 6 ++++ tools/virtiofsd/fuse_lowlevel.c | 42 ++++++++++++++++++++++++++- tools/virtiofsd/fuse_lowlevel.h | 3 +- tools/virtiofsd/passthrough_ll.c | 3 +- 5 files changed, 62 insertions(+), 4 deletions(-)
include/standard-headers/linux/fuse.h +11 -1
@@ -179,6 +179,7 @@* 7.33 * - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID * - add FUSE_OPEN_KILL_SUIDGID +* - add FUSE_SETXATTR_V2 */ #ifndef _LINUX_FUSE_H
@@ -210,7 +211,7 @@#define FUSE_KERNEL_VERSION 7/** Minor version number of this interface */ -#define FUSE_KERNEL_MINOR_VERSION 33 +#define FUSE_KERNEL_MINOR_VERSION 34/** The node ID of the root inode */ #define FUSE_ROOT_ID 1
@@ -326,6 +327,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_V2: Does file server support V2 of struct fuse_setxattr_in */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -356,6 +358,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_V2 (1 << 29)/** * CUSE INIT request/reply flags
@@ -682,6 +685,13 @@ struct fuse_setxattr_in {uint32_t flags; }; +struct fuse_setxattr_in_v2 { +uint32_t size; +uint32_t flags; +uint32_t setxattr_flags; +uint32_t padding; +}; +struct fuse_getxattr_in {uint32_t size;uint32_t padding;
tools/virtiofsd/fuse_common.h +6 -0
@@ -372,6 +372,12 @@ struct fuse_file_info {*/ #define FUSE_CAP_HANDLE_KILLPRIV_V2 (1 << 28) +/** +* Indicates that file server will expect "struct fuse_setxattr_in_v2" type +* of struct in setxattr requests +*/ +#define FUSE_CAP_SETXATTR_V2 (1 << 29) +/** * Ioctl flags *
tools/virtiofsd/fuse_lowlevel.c +41 -1
78 lines not on this page · raw message
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
@@ -3053,7 +3053,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/5 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.
--- include/standard-headers/linux/fuse.h | 7 ++++ tools/virtiofsd/passthrough_ll.c | 50 ++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-)
include/standard-headers/linux/fuse.h +7 -0
@@ -180,6 +180,7 @@* - add FUSE_HANDLE_KILLPRIV_V2, FUSE_WRITE_KILL_SUIDGID, FATTR_KILL_SUIDGID * - add FUSE_OPEN_KILL_SUIDGID * - add FUSE_SETXATTR_V2 +* - add FUSE_SETXATTR_ACL_KILL_SGID */ #ifndef _LINUX_FUSE_H
@@ -450,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 */
tools/virtiofsd/passthrough_ll.c +45 -5
80 lines not on this page · raw message
Signature · 1 line
2.25.4