From: Luis Henriques <luis@igalia.com>
To: koraynilay <koray.fra@gmail.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Edward Adam Davis <eadavis@qq.com>,
Amir Goldstein <amir73il@gmail.com>,
Miklos Szeredi <miklos@szeredi.hu>,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH] vfs: fix file_getattr hint to request xflags
Date: Tue, 24 Nov 2026 16:13:18 +0000 [thread overview]
Message-ID: <87se0qb42p.fsf@igalia.com> (raw)
In-Reply-To: <20261124150108.189282-1-koray.fra@gmail.com>
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
>
>
next prev parent reply other threads:[~2026-11-24 16:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-11-24 16:36 ` koraynilay
2026-11-24 17:04 ` Luis Henriques
2026-12-01 13:07 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87se0qb42p.fsf@igalia.com \
--to=luis@igalia.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=eadavis@qq.com \
--cc=jack@suse.cz \
--cc=koray.fra@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.