vfs: fix file_getattr hint to request xflags
PATCH 1/1 vfs: fix file_getattr hint to request xflags
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
---
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/[email protected]/T/#t
fs/file_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/file_attr.c +1 -1
@@ -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
Signature · 1 line
2.56.0
Quoted 156 lines · koraynilay
When using a FUSE mount over an underlying filesystem that supports xflags, querying them from userspace with
file_getattr()strips them becausefile_getattrsetsflags_valid= true so FUSE usesFS_IOC_GETFLAGSinstead ofFS_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=0after 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=42Fixes cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get")Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.11Signed-off-by koraynilay <[email protected]>---
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 ext4mount xfs.img xfs
mount ext4.img ext4
touch {xfs,ext4}/filechattr -p 69 xfs/file
chattr -p 42 ext4/filemkdir fuse
./repro_fuse_getattr fuse "$PWD"/xfs/file
./repro_fuse_getattr fuse "$PWD"/ext4/fileumount xfs ext4
where
repro_fuse_getattris 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/[email protected]/T/#t
fs/file_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/file_attr.c +0
-0
fs/file_attr.c SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, · line 389
Quoted 8 lines
fs/file_attr.c +1
-1@@ -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!
Thanks,
Amir.
Quoted 19 lines · koraynilay
When using a FUSE mount over an underlying filesystem that supports xflags, querying them from userspace with
file_getattr()strips them becausefile_getattrsetsflags_valid= true so FUSE usesFS_IOC_GETFLAGSinstead ofFS_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=0after the fix:
Quoted 8 lines
/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=42Fixes cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get")Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.11Signed-off-by koraynilay <[email protected]>
Good catch! Feel free to add:
Honza
Quoted 140 lines
---
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 ext4mount xfs.img xfs
mount ext4.img ext4
touch {xfs,ext4}/filechattr -p 69 xfs/file
chattr -p 42 ext4/filemkdir fuse
./repro_fuse_getattr fuse "$PWD"/xfs/file
./repro_fuse_getattr fuse "$PWD"/ext4/fileumount xfs ext4
where
repro_fuse_getattris 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/[email protected]/T/#t
fs/file_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/file_attr.c +1
-1@@ -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:
3857587d9d6fa44d40d1c73bde6a39f6f7a5216cSignature · 1 line
2.56.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 154 lines · koraynilay
When using a FUSE mount over an underlying filesystem that supports xflags, querying them from userspace with
file_getattr()strips them becausefile_getattrsetsflags_valid= true so FUSE usesFS_IOC_GETFLAGSinstead ofFS_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=0after 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=42Fixes cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get")Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.11Signed-off-by koraynilay <[email protected]>---
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 ext4mount xfs.img xfs
mount ext4.img ext4
touch {xfs,ext4}/filechattr -p 69 xfs/file
chattr -p 42 ext4/filemkdir fuse
./repro_fuse_getattr fuse "$PWD"/xfs/file
./repro_fuse_getattr fuse "$PWD"/ext4/fileumount xfs ext4
where
repro_fuse_getattris 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/[email protected]/T/#t
fs/file_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/file_attr.c +0
-0
fs/file_attr.c SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, · line 386
Quoted 5 lines
fs/file_attr.c +1
-1@@ -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,
Signature · 1 line
Luís
Quoted 9 lines
fs/file_attr.c +0
-0int error;BUILD_BUG_ON (sizeof (struct file_attr ) <FILE_ATTR_SIZE_VER0 );base-commit:
3857587d9d6fa44d40d1c73bde6a39f6f7a5216cSignature · 1 line
2.56.0
Quoted 32 lines · Luis Henriques
Quoted 30 lines · koraynilay
When using a FUSE mount over an underlying filesystem that supports xflags, querying them from userspace with
file_getattr()strips them becausefile_getattrsetsflags_valid= true so FUSE usesFS_IOC_GETFLAGSinstead ofFS_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=0after 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=42Fixes cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get")Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.11Signed-off-by koraynilay <[email protected]>---
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.
[...]
Quoted 19 lines
Quoted 11 lines
[1]: https://lore.kernel.org/all/[email protected]/T/#t
fs/file_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/file_attr.c +0
-0fs/file_attr.c SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, · line 386
Quoted 5 lines
fs/file_attr.c +1
-1@@ -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
Quoted 1 line
cb184dd19154("fs: initflags_validbefore callingvfs_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?).
Quoted 3 lines
Maybe
fuse_fileattr_get()shouldn't be handlingFS_IOC_FSGETXATTRat all, andFS_IOC_FSGETXATTRhandling should be moved intofuse_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
Quoted 1 line
Cheers,
Quoted 53 lines · koraynilay
Quoted 32 lines · Luis Henriques
Quoted 30 lines · koraynilay
When using a FUSE mount over an underlying filesystem that supports xflags, querying them from userspace with
file_getattr()strips them becausefile_getattrsetsflags_valid= true so FUSE usesFS_IOC_GETFLAGSinstead ofFS_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=0after 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=42Fixes cb184dd19154 ("fs: init flags_valid before calling vfs_fileattr_get")Assisted-by Gemini:3.8-flash-high antigravity-cli-1.5.11Signed-off-by koraynilay <[email protected]>---
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.[...]
Quoted 19 lines
Quoted 11 lines
[1]: https://lore.kernel.org/all/[email protected]/T/#t
fs/file_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/file_attr.c +0
-0fs/file_attr.c SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, · line 386
Quoted 5 lines
fs/file_attr.c +1
-1@@ -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
Quoted 5 lines
Quoted 1 line
cb184dd19154("fs: initflags_validbefore callingvfs_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?).
/me facepalms
Sorry for the noise, I totally misread that fix :-(
Cheers,
Signature · 1 line
Luís
Quoted 21 lines
Quoted 3 lines
Maybe
fuse_fileattr_get()shouldn't be handlingFS_IOC_FSGETXATTRat all, andFS_IOC_FSGETXATTRhandling should be moved intofuse_do_ioctl()instead? (Or, more likely, I'm missing something!)The bug being fixed is when using
file_getattrtho, which in the vfs is directly sent toinode->i_op->fileattr_get(dentry, fa), which for FUSE isfuse_fileattr_get().What should probably be done though (well, not in this patch) is switch
fuse_fileattr_get()fromFS_IOC_FSGETXATTRtovfs_fileattr_get(), forfsx_valid.
This is because while right nowFS_IOC_FSGETXATTRis equivalent tofile_getattrVER0, in the [1] above it will be bumped to VER1, makingfile_getattrVER1 a superset offile_getattrVER0.Thanks,
koraynilayQuoted 1 line
Cheers,