The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] vfs: fix file_getattr hint to request xflags
@ 2026-11-24 15:01 koraynilay
  2026-11-24 15:36 ` Amir Goldstein
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: koraynilay @ 2026-11-24 15:01 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner
  Cc: Jan Kara, Edward Adam Davis, Amir Goldstein, Miklos Szeredi,
	linux-kernel, linux-fsdevel, koraynilay

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@gmail.com>
---
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@gmail.com/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);

base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] vfs: fix file_getattr hint to request xflags
  2026-11-24 15:01 [PATCH] vfs: fix file_getattr hint to request xflags koraynilay
@ 2026-11-24 15:36 ` Amir Goldstein
  2026-11-24 16:00 ` Jan Kara
  2026-11-24 16:13 ` Luis Henriques
  2 siblings, 0 replies; 5+ messages in thread
From: Amir Goldstein @ 2026-11-24 15:36 UTC (permalink / raw)
  To: koraynilay
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Edward Adam Davis,
	Miklos Szeredi, linux-kernel, linux-fsdevel

On Tue, Nov 24, 2026 at 4:02 PM koraynilay <koray.fra@gmail.com> 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@gmail.com>
> ---
> 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@gmail.com/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@gmail.com>

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vfs: fix file_getattr hint to request xflags
  2026-11-24 15:01 [PATCH] vfs: fix file_getattr hint to request xflags koraynilay
  2026-11-24 15:36 ` Amir Goldstein
@ 2026-11-24 16:00 ` Jan Kara
  2026-11-24 16:13 ` Luis Henriques
  2 siblings, 0 replies; 5+ messages in thread
From: Jan Kara @ 2026-11-24 16:00 UTC (permalink / raw)
  To: koraynilay
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Edward Adam Davis,
	Amir Goldstein, Miklos Szeredi, linux-kernel, linux-fsdevel

On Tue 24-11-26 16:01:08, koraynilay 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@gmail.com>

Good catch! Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
> 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@gmail.com/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);
> 
> base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c
> -- 
> 2.56.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vfs: fix file_getattr hint to request xflags
  2026-11-24 15:01 [PATCH] vfs: fix file_getattr hint to request xflags koraynilay
  2026-11-24 15:36 ` Amir Goldstein
  2026-11-24 16:00 ` Jan Kara
@ 2026-11-24 16:13 ` Luis Henriques
  2026-11-24 16:36   ` koraynilay
  2 siblings, 1 reply; 5+ messages in thread
From: Luis Henriques @ 2026-11-24 16:13 UTC (permalink / raw)
  To: koraynilay
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Edward Adam Davis,
	Amir Goldstein, Miklos Szeredi, linux-kernel, linux-fsdevel

On Tue, Nov 24 2026, koraynilay 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@gmail.com>
> ---
> 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@gmail.com/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 */

Isn't this reintroducing the bug that was fixed by commit

cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get") ?

Maybe fuse_fileattr_get() shouldn't be handling FS_IOC_FSGETXATTR at all,
and FS_IOC_FSGETXATTR handling should be moved into fuse_do_ioctl()
instead?  (Or, more likely, I'm missing something!)

Cheers,
-- 
Luís

>  	int error;
>  
>  	BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
>
> base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c
> -- 
> 2.56.0
>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] vfs: fix file_getattr hint to request xflags
  2026-11-24 16:13 ` Luis Henriques
@ 2026-11-24 16:36   ` koraynilay
  0 siblings, 0 replies; 5+ messages in thread
From: koraynilay @ 2026-11-24 16:36 UTC (permalink / raw)
  To: Luis Henriques, koraynilay
  Cc: Alexander Viro, Christian Brauner, Jan Kara, Edward Adam Davis,
	Amir Goldstein, Miklos Szeredi, linux-kernel, linux-fsdevel

[-- Attachment #1: Type: text/plain, Size: 3066 bytes --]

On Tue Nov 24, 2026 at 5:13 PM CET, Luis Henriques wrote:
> On Tue, Nov 24 2026, koraynilay 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@gmail.com>
>> ---
>> 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.
[...]
>>
>> [1]: https://lore.kernel.org/all/DN2YMTH77KWE.3IPE9OG8377X0@gmail.com/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 */
>
> Isn't this reintroducing the bug that was fixed by commit
>
> cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get") ?

Hmm, it shouldn't, since that was just an uninitialized bug for the
whole struct, while now it's initialized (unless you meant something
else?).

> Maybe fuse_fileattr_get() shouldn't be handling FS_IOC_FSGETXATTR at all,
> and FS_IOC_FSGETXATTR handling should be moved into fuse_do_ioctl()
> instead?  (Or, more likely, I'm missing something!)

The bug being fixed is when using file_getattr tho, which in the vfs is
directly sent to inode->i_op->fileattr_get(dentry, fa), which for FUSE
is fuse_fileattr_get().

What should probably be done though (well, not in this patch) is switch
fuse_fileattr_get() from FS_IOC_FSGETXATTR to vfs_fileattr_get(), for
fsx_valid.
This is because while right now FS_IOC_FSGETXATTR is equivalent to
file_getattr VER0, in the [1] above it will be bumped to VER1, making
file_getattr VER1 a superset of file_getattr VER0.

Thanks,
koraynilay

> Cheers,



[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-24 16:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 15:01 [PATCH] vfs: fix file_getattr hint to request xflags koraynilay
2026-11-24 15:36 ` Amir Goldstein
2026-11-24 16:00 ` Jan Kara
2026-11-24 16:13 ` Luis Henriques
2026-11-24 16:36   ` koraynilay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox