Re: [PATCH] vfs: fix file_getattr hint to request xflags

From: Amir Goldstein

Date: Tue Nov 24 2026 - 10:36:54 EST


On Tue, Nov 24, 2026 at 4:02 PM koraynilay <koray.fra@xxxxxxxxx> wrote:
>
> When using a FUSE mount over an underlying filesystem that supports
> xflags, querying them from userspace with file_getattr() strips them
> because file_getattr sets flags_valid = true so FUSE uses
> FS_IOC_GETFLAGS instead of FS_IOC_FSGETXATTR.
>
> Fix it by setting fsx_valid = true instead.
>
> Output when using a simple FUSE mount that simply forwards the ioctls to
> the underlying fs:
>
> before the fix:
>
> /xfs/file: FS_IOC_FSGETXATTR: ret=0, projid=69
> /xfs/file: file_getattr: ret=0, projid=0
> /ext4/file: FS_IOC_FSGETXATTR: ret=0, projid=42
> /ext4/file: file_getattr: ret=0, projid=0
>
> after the fix:
>
> /xfs/file: FS_IOC_FSGETXATTR: ret=0, projid=69
> /xfs/file: file_getattr: ret=0, projid=69
> /ext4/file: FS_IOC_FSGETXATTR: ret=0, projid=42
> /ext4/file: file_getattr: ret=0, projid=42
>
> Fixes: cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get")
> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11
> Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
> ---
> Hi, I found this issue while working on the v2 of [1], here is the
> reproducer, not in the commit message because of the size.
>
> script:
>
> #!/bin/bash
> truncate -s 100M xfs.img
> truncate -s 100M ext4.img
> mkfs.xfs xfs.img
> mkfs.ext4 -O project ext4.img
> mkdir xfs ext4
>
> mount xfs.img xfs
> mount ext4.img ext4
> touch {xfs,ext4}/file
>
> chattr -p 69 xfs/file
> chattr -p 42 ext4/file
>
> mkdir fuse
> ./repro_fuse_getattr fuse "$PWD"/xfs/file
> ./repro_fuse_getattr fuse "$PWD"/ext4/file
>
> umount xfs ext4
>
> where repro_fuse_getattr is a simple fuse mount, compiled with:
>
> gcc repro_fuse_getattr.c -o repro_fuse_getattr $(pkg-config fuse3 --cflags --libs)
>
> and used like:
>
> ./repro_fuse_getattr <fuse_mount_dir> <full_path_to_real_file>
>
> repro_fuse_getattr.c:
>
> #define _GNU_SOURCE
> #define FUSE_USE_VERSION 35
> #include <fuse3/fuse.h>
> #include <stdio.h>
> #include <string.h>
> #include <errno.h>
> #include <fcntl.h>
> #include <unistd.h>
> #include <sys/syscall.h>
> #include <sys/ioctl.h>
> #include <sys/mount.h>
> #include <linux/fs.h>
>
> /* needed to get the file's file descriptor for the ioctl */
> static int my_getattr(const char *path, struct stat *st, struct fuse_file_info *fi)
> {
> memset(st, 0, sizeof(*st));
> if (!strcmp(path, "/")) {
> st->st_mode = S_IFDIR | 0755;
> st->st_nlink = 2;
> return 0;
> }
> return stat(fuse_get_context()->private_data, st) < 0 ? -errno : 0;
> }
>
> /* pass down the ioctl to the fs */
> static int my_ioctl(const char *path, unsigned int cmd, void *arg,
> struct fuse_file_info *fi, unsigned int flags, void *data)
> {
> int fd = open(fuse_get_context()->private_data, O_RDONLY);
> int ret = ioctl(fd, cmd, data);
> close(fd);
> return ret < 0 ? -errno : 0;
> }
>
> static const struct fuse_operations ops = {
> .getattr = my_getattr,
> .ioctl = my_ioctl,
> };
>
> int main(int argc, char *argv[])
> {
> const char *mnt = argv[1]; /* FUSE mount point */
> const char *real_file = argv[2]; // full path of the file on the
> // underlying fs
>
> /* start FUSE */
> pid_t pid = fork();
> if (pid == 0) {
> char *fuse_argv[] = { "fuse", "-f", (char *)mnt, NULL };
> return fuse_main(3, fuse_argv, &ops, (void *)real_file);
> }
>
> usleep(300000); /* wait for FUSE mount */
>
> /* Query the file attributes through FUSE mount */
> char fuse_file[4096];
> snprintf(fuse_file, sizeof(fuse_file), "%s/file", mnt);
>
> int fd = open(fuse_file, O_RDONLY);
>
> struct fsxattr x = {};
> int ret_fsget = ioctl(fd, FS_IOC_FSGETXATTR, &x);
>
> struct file_attr fa = {};
> long ret_sys = syscall(SYS_file_getattr, -100, fuse_file, &fa, sizeof(fa), 0);
>
> close(fd);
>
> printf("%s: FS_IOC_FSGETXATTR: ret=%d, projid=%u\n",
> real_file, ret_fsget, x.fsx_projid);
> printf("%s: file_getattr: ret=%ld, projid=%llu\n",
> real_file, ret_sys, (unsigned long long)fa.fa_projid);
>
> umount(mnt);
> return 0;
> }
>
> Thanks,
> koraynilay
>
> [1]: https://lore.kernel.org/all/DN2YMTH77KWE.3IPE9OG8377X0@xxxxxxxxx/T/#t
>
> fs/file_attr.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/file_attr.c b/fs/file_attr.c
> index 833e03810b24..3b249a0a6b36 100644
> --- a/fs/file_attr.c
> +++ b/fs/file_attr.c
> @@ -383,7 +383,7 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
> struct path filepath __free(path_put) = {};
> unsigned int lookup_flags = 0;
> struct file_attr fattr;
> - struct file_kattr fa = { .flags_valid = true }; /* hint only */
> + struct file_kattr fa = { .fsx_valid = true }; /* hint only */
> int error;
>
> BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
>

ouch!

Reviewed-by: Amir Goldstein <amir73il@xxxxxxxxx>

Thanks,
Amir.