From: Darrick J. Wong Date: Thu, 4 Sep 2025 01:17:36 +0000 (-0700) Subject: fuse2fs: fix fssetxattr flags updates X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8fbea929d226956acfe491c251a257181a5ff46d;p=thirdparty%2Fe2fsprogs.git fuse2fs: fix fssetxattr flags updates Fix flags setting so that it actually works -- we need to preserve the iflags bits that don't exist in xflags. Cc: # v1.47.3 Fixes: 9b5012c1569d4e ("fuse2fs: support getting and setting via struct fsxattr") Signed-off-by: "Darrick J. Wong" --- diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 868b8899..5e610be2 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -3891,6 +3891,33 @@ static __u32 fsxflags_to_iflags(__u32 xflags) return iflags; } +#define FUSE2FS_MODIFIABLE_XFLAGS (FS_XFLAG_IMMUTABLE | \ + FS_XFLAG_APPEND | \ + FS_XFLAG_SYNC | \ + FS_XFLAG_NOATIME | \ + FS_XFLAG_NODUMP | \ + FS_XFLAG_PROJINHERIT) + +#define FUSE2FS_MODIFIABLE_IXFLAGS (FS_IMMUTABLE_FL | \ + FS_APPEND_FL | \ + FS_SYNC_FL | \ + FS_NOATIME_FL | \ + FS_NODUMP_FL | \ + FS_PROJINHERIT_FL) + +static inline int set_xflags(struct ext2_inode_large *inode, __u32 xflags) +{ + __u32 iflags; + + if (xflags & ~FUSE2FS_MODIFIABLE_XFLAGS) + return -EINVAL; + + iflags = fsxflags_to_iflags(xflags); + inode->i_flags = (inode->i_flags & ~FUSE2FS_MODIFIABLE_IXFLAGS) | + (iflags & FUSE2FS_MODIFIABLE_IXFLAGS); + return 0; +} + static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh, void *data) { @@ -3900,7 +3927,6 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh, int ret; struct fuse_context *ctxt = fuse_get_context(); struct fsxattr *fsx = data; - __u32 flags = fsxflags_to_iflags(fsx->fsx_xflags); unsigned int inode_size; FUSE2FS_CHECK_MAGIC(fs, fh, FUSE2FS_FILE_MAGIC); @@ -3912,7 +3938,7 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh, if (want_check_owner(ff, ctxt) && inode_uid(inode) != ctxt->uid) return -EPERM; - ret = set_iflags(&inode, flags); + ret = set_xflags(&inode, fsx->fsx_xflags); if (ret) return ret;