]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
fuse2fs: fix fssetxattr flags updates
authorDarrick J. Wong <djwong@kernel.org>
Thu, 4 Sep 2025 01:17:36 +0000 (18:17 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 17 Oct 2025 23:34:22 +0000 (16:34 -0700)
Fix flags setting so that it actually works -- we need to preserve the
iflags bits that don't exist in xflags.

Cc: <linux-ext4@vger.kernel.org> # v1.47.3
Fixes: 9b5012c1569d4e ("fuse2fs: support getting and setting via struct fsxattr")
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
misc/fuse2fs.c

index 868b889912857d0813d11d0baa09345074e37575..5e610be2760a5a84ac53134011c40d5dc69861a2 100644 (file)
@@ -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;