Skip to contentSkip to conversation

fs: introduce file_getattr and file_setattr syscalls

PATCH Superseded Andrey Albershteyn 10 participants 26 messages May 13, 2025 – May 22, 2025

Subsystems (24)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover fs: introduce file_getattr and file_setattr syscalls

This patchset introduced two new syscalls file_getattr() and file_setattr(). These syscalls are similar to FS_IOC_FSSETXATTR ioctl() except they use *at() semantics. Therefore, there's no need to open the file to get a fd.

These syscalls allow userspace to set filesystem inode attributes on special files. One of the usage examples is XFS quota projects.

XFS has project quotas which could be attached to a directory. All new inodes in these directories inherit project ID set on parent directory.

The project is created from userspace by opening and calling FS_IOC_FSSETXATTR on each inode. This is not possible for special files such as FIFO, SOCK, BLK etc. Therefore, some inodes are left with empty project ID. Those inodes then are not shown in the quota accounting but still exist in the directory. This is not critical but in the case when special files are created in the directory with already existing project quota, these new inodes inherit extended attributes. This creates a mix of special files with and without attributes. Moreover, special files with attributes don't have a possibility to become clear or change the attributes. This, in turn, prevents userspace from re-creating quota project on these existing files.

NAME

file_getattr/file_setattr - get/set filesystem inode attributes

SYNOPSIS

	#include <sys/syscall.h>    /* Definition of SYS_* constants */
	#include <unistd.h>

	long syscall(SYS_file_getattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);
	long syscall(SYS_file_setattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);

	Note: glibc doesn't provide for file_getattr()/file_setattr(),
	use syscall(2) instead.

DESCRIPTION

The syscalls take fd and path. If path is absolute, fd is not used. If path is empty, fd can be AT_FDCWD or any valid fd which will be used to get/set attributes on.

This is an alternative to FS_IOC_FSGETXATTR/FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open as we can reference it with a path instead of fd. By having this we can manipulated filesystem inode attributes not only on regular files but also on special ones. This is not possible with FS_IOC_FSSETXATTR ioctl as with special files we can not call ioctl() directly on the filesystem inode using file descriptor.

at_flags can be set to AT_SYMLINK_NOFOLLOW or AT_EMPTY_PATH.

RETURN VALUE

On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error.

ERRORS

EINVAL Invalid at_flag specified (only
AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH is supported).

EINVAL Size was smaller than any known version of
struct fsxattr.

EINVAL Invalid combination of parameters provided in
fsxattr for this type of file.

E2BIG Size of input argument **struct fsxattr** is too
big.

EBADF Invalid file descriptor was provided.

EPERM No permission to change this file.

EOPNOTSUPP Filesystem does not support setting attributes
on this type of inode

HISTORY

Added in Linux 6.15.

EXAMPLE

Create directory and file "mkdir ./dir && touch ./dir/foo" and then execute the following program:

	#include <fcntl.h>
	#include <errno.h>
	#include <string.h>
	#include <linux/fs.h>
	#include <stdio.h>
	#include <sys/syscall.h>
	#include <unistd.h>

	int
	main(int argc, char **argv) {
		int dfd;
		int error;
		struct fsxattr fsx;

		dfd = open("./dir", O_RDONLY);
		if (dfd == -1) {
			printf("can not open ./dir");
			return dfd;
		}

		error = syscall(467, dfd, "./foo", &fsx, 0);
		if (error) {
			printf("can not call 467: %s", strerror(errno));
			return error;
		}

		printf("dir/foo flags: %d\n", fsx.fsx_xflags);

		fsx.fsx_xflags |= FS_XFLAG_NODUMP;
		error = syscall(468, dfd, "./foo", &fsx, 0);
		if (error) {
			printf("can not call 468: %s", strerror(errno));
			return error;
		}

		printf("dir/foo flags: %d\n", fsx.fsx_xflags);

		return error;
	}

SEE ALSO

	ioctl(2), ioctl_iflags(2), ioctl_xfs_fsgetxattr(2)

---
Changes in v5:
- Remove setting of LOOKUP_EMPTY flags which does not have any effect
- Return -ENOSUPP from vfs_fileattr_set()
- Add fsxattr masking (by Amir)
- Fix UAF issue dentry
- Fix getname_maybe_null() issue with NULL path
- Implement file_getattr/file_setattr hooks
- Return LSM return code from file_setattr
- Rename from getfsxattrat/setfsxattrat to file_getattr/file_setattr
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Use getname_maybe_null() for correct handling of dfd + path semantic
- Remove restriction for special files on which flags are allowed
- Utilize copy_struct_from_user() for better future compatibility
- Add draft man page to cover letter
- Convert -ENOIOCTLCMD to -EOPNOSUPP as more appropriate for syscall
- Add missing __user to header declaration of syscalls
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Remove unnecessary "dfd is dir" check as it checked in user_path_at()
- Remove unnecessary "same filesystem" check
- Use CLASS() instead of directly calling fdget/fdput
- Link to v2: https://lore.kernel.org/r/[email protected]

v1:
https://lore.kernel.org/linuxppc-dev/[email protected]/

Previous discussion:
https://lore.kernel.org/linux-xfs/[email protected]/

---
Amir Goldstein (1):
fs: prepare for extending file_get/setattr()

Andrey Albershteyn (6):
fs: split fileattr related helpers into separate file
lsm: introduce new hooks for setting/getting inode fsxattr
selinux: implement inode_file_[g|s]etattr hooks
fs: split fileattr/fsxattr converters into helpers
fs: make vfs_fileattr_[get|set] return -EOPNOSUPP
fs: introduce file_getattr and file_setattr syscalls

 arch/alpha/kernel/syscalls/syscall.tbl      |   2 +
 arch/arm/tools/syscall.tbl                  |   2 +
 arch/arm64/tools/syscall_32.tbl             |   2 +
 arch/m68k/kernel/syscalls/syscall.tbl       |   2 +
 arch/microblaze/kernel/syscalls/syscall.tbl |   2 +
 arch/mips/kernel/syscalls/syscall_n32.tbl   |   2 +
 arch/mips/kernel/syscalls/syscall_n64.tbl   |   2 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   |   2 +
 arch/parisc/kernel/syscalls/syscall.tbl     |   2 +
 arch/powerpc/kernel/syscalls/syscall.tbl    |   2 +
 arch/s390/kernel/syscalls/syscall.tbl       |   2 +
 arch/sh/kernel/syscalls/syscall.tbl         |   2 +
 arch/sparc/kernel/syscalls/syscall.tbl      |   2 +
 arch/x86/entry/syscalls/syscall_32.tbl      |   2 +
 arch/x86/entry/syscalls/syscall_64.tbl      |   2 +
 arch/xtensa/kernel/syscalls/syscall.tbl     |   2 +
 fs/Makefile                                 |   3 +-
 fs/ecryptfs/inode.c                         |   8 +-
 fs/file_attr.c                              | 475 ++++++++++++++++++++++++++++
 fs/ioctl.c                                  | 309 ------------------
 fs/overlayfs/inode.c                        |   2 +-
 include/linux/fileattr.h                    |  26 ++
 include/linux/lsm_hook_defs.h               |   2 +
 include/linux/security.h                    |  16 +
 include/linux/syscalls.h                    |   6 +
 include/uapi/asm-generic/unistd.h           |   8 +-
 include/uapi/linux/fs.h                     |   3 +
 security/security.c                         |  30 ++
 security/selinux/hooks.c                    |  14 +
 29 files changed, 621 insertions(+), 313 deletions(-)

---
base-commit: 0d8d44db295ccad20052d6301ef49ff01fb8ae2d
change-id: 20250114-xattrat-syscall-6a1136d2db59

Best regards,

Signature · 1 line
Andrey Albershteyn <[email protected]>
#1 lore raw

PATCH v5 1/7 fs: split fileattr related helpers into separate file

From: Andrey Albershteyn <[email protected]>

This patch moves function related to file extended attributes manipulations to separate file. Just refactoring.

---
 fs/Makefile              |   3 +-
 fs/file_attr.c           | 318 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/ioctl.c               | 309 ---------------------------------------------
 include/linux/fileattr.h |   4 +
 4 files changed, 324 insertions(+), 310 deletions(-)
fs/Makefile +2 -1
index 77fd7f7b5d02478621f06304e447cc4a387a7167..2f1daaea86da456672234cf4df35e63e39a3e71d 100644
@@ -15,7 +15,8 @@ obj-y :=	open.o read_write.o file_table.o super.o \
 		pnode.o splice.o sync.o utimes.o d_path.o \
 		stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \
 		fs_types.o fs_context.o fs_parser.o fsopen.o init.o \
-		kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o
+		kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \
+		file_attr.o
 
 obj-$(CONFIG_BUFFER_HEAD)	+= buffer.o mpage.o
 obj-$(CONFIG_PROC_FS)		+= proc_namespace.o
fs/file_attr.c new file +318 -0

318 lines not on this page · raw message

fs/ioctl.c +0 -309

315 lines not on this page · raw message

include/linux/fileattr.h +4 -0
index 47c05a9851d0600964b644c9c7218faacfd865f8..6030d0bf7ad32693a0f48a6f28475d97e768bb3e 100644
@@ -55,5 +55,9 @@ static inline bool fileattr_has_fsx(const struct fileattr *fa)
 int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
 int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 		     struct fileattr *fa);
+int ioctl_getflags(struct file *file, unsigned int __user *argp);
+int ioctl_setflags(struct file *file, unsigned int __user *argp);
+int ioctl_fsgetxattr(struct file *file, void __user *argp);
+int ioctl_fssetxattr(struct file *file, void __user *argp);
 
 #endif /* _LINUX_FILEATTR_H */
Signature · 1 line
2.47.2
#2 lore raw

PATCH v5 2/7 lsm: introduce new hooks for setting/getting inode fsxattr

In reply to Andrey Albershteyn

Introduce new hooks for setting and getting filesystem extended attributes on inode (FS_IOC_FSGETXATTR).

---
 fs/file_attr.c                | 19 ++++++++++++++++---
 include/linux/lsm_hook_defs.h |  2 ++
 include/linux/security.h      | 16 ++++++++++++++++
 security/security.c           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 3 deletions(-)
fs/file_attr.c +16 -3
index 2910b7047721df893540ff8a7c992558390eaa3a..be62d97cc444a445deac1c8ac8331f4a3766126a 100644
@@ -76,10 +76,15 @@ EXPORT_SYMBOL(fileattr_fill_flags);
 int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
 {
 	struct inode *inode = d_inode(dentry);
+	int error;
 
 	if (!inode->i_op->fileattr_get)
 		return -ENOIOCTLCMD;
 
+	error = security_inode_file_getattr(dentry, fa);
+	if (error)
+		return error;
+
 	return inode->i_op->fileattr_get(dentry, fa);
 }
 EXPORT_SYMBOL(vfs_fileattr_get);
@@ -242,12 +247,20 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 		} else {
 			fa->flags |= old_ma.flags & ~FS_COMMON_FL;
 		}
+
 		err = fileattr_set_prepare(inode, &old_ma, fa);
-		if (!err)
-			err = inode->i_op->fileattr_set(idmap, dentry, fa);
+		if (err)
+			goto out;
+		err = security_inode_file_setattr(dentry, fa);
+		if (err)
+			goto out;
+		err = inode->i_op->fileattr_set(idmap, dentry, fa);
+		if (err)
+			goto out;
 	}
+
+out:
 	inode_unlock(inode);
-
 	return err;
 }
 EXPORT_SYMBOL(vfs_fileattr_set);
include/linux/lsm_hook_defs.h +2 -0
index bf3bbac4e02a59a67de4ace85b93b1a878131f60..9600a4350e791f47006720765c199e35d3abafd4 100644
@@ -157,6 +157,8 @@ LSM_HOOK(int, 0, inode_removexattr, struct mnt_idmap *idmap,
 	 struct dentry *dentry, const char *name)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_removexattr, struct dentry *dentry,
 	 const char *name)
+LSM_HOOK(int, 0, inode_file_setattr, struct dentry *dentry, struct fileattr *fa)
+LSM_HOOK(int, 0, inode_file_getattr, struct dentry *dentry, struct fileattr *fa)
 LSM_HOOK(int, 0, inode_set_acl, struct mnt_idmap *idmap,
 	 struct dentry *dentry, const char *acl_name, struct posix_acl *kacl)
 LSM_HOOK(void, LSM_RET_VOID, inode_post_set_acl, struct dentry *dentry,
include/linux/security.h +16 -0
index cc9b54d95d22cd11480c38148005ed778b7af1bd..d2da2f654345b36b20fbe68ce11468ca4a55d8b3 100644
@@ -451,6 +451,10 @@ int security_inode_listxattr(struct dentry *dentry);
 int security_inode_removexattr(struct mnt_idmap *idmap,
 			       struct dentry *dentry, const char *name);
 void security_inode_post_removexattr(struct dentry *dentry, const char *name);
+int security_inode_file_setattr(struct dentry *dentry,
+			      struct fileattr *fa);
+int security_inode_file_getattr(struct dentry *dentry,
+			      struct fileattr *fa);
 int security_inode_need_killpriv(struct dentry *dentry);
 int security_inode_killpriv(struct mnt_idmap *idmap, struct dentry *dentry);
 int security_inode_getsecurity(struct mnt_idmap *idmap,
@@ -1053,6 +1057,18 @@ static inline void security_inode_post_removexattr(struct dentry *dentry,
 						   const char *name)
 { }
 
+static inline int security_inode_file_setattr(struct dentry *dentry,
+					      struct fileattr *fa)
+{
+	return 0;
+}
+
+static inline int security_inode_file_getattr(struct dentry *dentry,
+					      struct fileattr *fa)
+{
+	return 0;
+}
+
 static inline int security_inode_need_killpriv(struct dentry *dentry)
 {
 	return cap_inode_need_killpriv(dentry);
security/security.c +30 -0
index fb57e8fddd911bbb417ed2e7db443979bf611f43..09c891e6027dc1803a3af024b2f676e263da8aec 100644
@@ -2622,6 +2622,36 @@ void security_inode_post_removexattr(struct dentry *dentry, const char *name)
 	call_void_hook(inode_post_removexattr, dentry, name);
 }
 
+/**
+ * security_inode_file_setattr() - check if setting fsxattr is allowed
+ * @dentry: file to set filesystem extended attributes on
+ * @fa: extended attributes to set on the inode
+ *
+ * Called when file_setattr() syscall or FS_IOC_FSSETXATTR ioctl() is called on
+ * inode
+ *
+ * Return: Returns 0 if permission is granted.
+ */
+int security_inode_file_setattr(struct dentry *dentry, struct fileattr *fa)
+{
+	return call_int_hook(inode_file_setattr, dentry, fa);
+}
+
+/**
+ * security_inode_file_getattr() - check if retrieving fsxattr is allowed
+ * @dentry: file to retrieve filesystem extended attributes from
+ * @fa: extended attributes to get
+ *
+ * Called when file_getattr() syscall or FS_IOC_FSGETXATTR ioctl() is called on
+ * inode
+ *
+ * Return: Returns 0 if permission is granted.
+ */
+int security_inode_file_getattr(struct dentry *dentry, struct fileattr *fa)
+{
+	return call_int_hook(inode_file_getattr, dentry, fa);
+}
+
 /**
  * security_inode_need_killpriv() - Check if security_inode_killpriv() required
  * @dentry: associated dentry
Signature · 1 line
2.47.2
maintainer Acked-by on v5 2/7
#3 lore raw

Re: [PATCH v5 2/7] lsm: introduce new hooks for setting/getting inode fsxattr

Quoted 7 lines · On May 13, 2025 Andrey Albershteyn <[email protected]> wrote:

Introduce new hooks for setting and getting filesystem extended attributes on inode (FS_IOC_FSGETXATTR).

Quoted 7 lines
---
 fs/file_attr.c                | 19 ++++++++++++++++---
 include/linux/lsm_hook_defs.h |  2 ++
 include/linux/security.h      | 16 ++++++++++++++++
 security/security.c           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 64 insertions(+), 3 deletions(-)

The only thing that gives me a slight pause is that on a set operation we are going to hit both the get and set LSM hooks, but since the code does call into the getter on a set operation this is arguably the right thing.

--
paul-moore.com

#4 lore raw

PATCH v5 3/7 selinux: implement inode_file_[g|s]etattr hooks

In reply to Andrey Albershteyn

These hooks are called on inode extended attribute retrieval/change.

---
 security/selinux/hooks.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
security/selinux/hooks.c +14 -0
index e7a7dcab81db6a8735877eeb911975e06a9de688..9c6e264b090f9038d6848546760860bfe74b7341 100644
@@ -3366,6 +3366,18 @@ static int selinux_inode_removexattr(struct mnt_idmap *idmap,
 	return -EACCES;
 }
 
+static int selinux_inode_file_setattr(struct dentry *dentry,
+				      struct fileattr *fa)
+{
+	return dentry_has_perm(current_cred(), dentry, FILE__SETATTR);
+}
+
+static int selinux_inode_file_getattr(struct dentry *dentry,
+				      struct fileattr *fa)
+{
+	return dentry_has_perm(current_cred(), dentry, FILE__GETATTR);
+}
+
 static int selinux_path_notify(const struct path *path, u64 mask,
 						unsigned int obj_type)
 {
@@ -7272,6 +7284,8 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
 	LSM_HOOK_INIT(inode_getxattr, selinux_inode_getxattr),
 	LSM_HOOK_INIT(inode_listxattr, selinux_inode_listxattr),
 	LSM_HOOK_INIT(inode_removexattr, selinux_inode_removexattr),
+	LSM_HOOK_INIT(inode_file_getattr, selinux_inode_file_getattr),
+	LSM_HOOK_INIT(inode_file_setattr, selinux_inode_file_setattr),
 	LSM_HOOK_INIT(inode_set_acl, selinux_inode_set_acl),
 	LSM_HOOK_INIT(inode_get_acl, selinux_inode_get_acl),
 	LSM_HOOK_INIT(inode_remove_acl, selinux_inode_remove_acl),
Signature · 1 line
2.47.2
maintainer Acked-by on v5 3/7
#5 lore raw

Re: [PATCH v5 3/7] selinux: implement inode_file_[g|s]etattr hooks

Quoted 10 lines · On May 13, 2025 Andrey Albershteyn <[email protected]> wrote:

These hooks are called on inode extended attribute retrieval/change.

---
 security/selinux/hooks.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

--
paul-moore.com

#6 lore raw

PATCH v5 4/7 fs: split fileattr/fsxattr converters into helpers

In reply to Andrey Albershteyn

This will be helpful for file_get/setattr syscalls to convert between fileattr and fsxattr.

---
 fs/file_attr.c           | 32 +++++++++++++++++++++-----------
 include/linux/fileattr.h |  2 ++
 2 files changed, 23 insertions(+), 11 deletions(-)
fs/file_attr.c +21 -11
index be62d97cc444a445deac1c8ac8331f4a3766126a..d9eab553dc250f84075ac74c1c7d8d6fd6588374 100644
@@ -89,6 +89,16 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
 }
 EXPORT_SYMBOL(vfs_fileattr_get);
 
+void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx)
+{
+	memset(fsx, 0, sizeof(struct fsxattr));
+	fsx->fsx_xflags = fa->fsx_xflags;
+	fsx->fsx_extsize = fa->fsx_extsize;
+	fsx->fsx_nextents = fa->fsx_nextents;
+	fsx->fsx_projid = fa->fsx_projid;
+	fsx->fsx_cowextsize = fa->fsx_cowextsize;
+}
+
 /**
  * copy_fsxattr_to_user - copy fsxattr to userspace.
  * @fa:		fileattr pointer
@@ -100,12 +110,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)
 {
 	struct fsxattr xfa;
 
-	memset(&xfa, 0, sizeof(xfa));
-	xfa.fsx_xflags = fa->fsx_xflags;
-	xfa.fsx_extsize = fa->fsx_extsize;
-	xfa.fsx_nextents = fa->fsx_nextents;
-	xfa.fsx_projid = fa->fsx_projid;
-	xfa.fsx_cowextsize = fa->fsx_cowextsize;
+	fileattr_to_fsxattr(fa, &xfa);
 
 	if (copy_to_user(ufa, &xfa, sizeof(xfa)))
 		return -EFAULT;
@@ -114,6 +119,15 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)
 }
 EXPORT_SYMBOL(copy_fsxattr_to_user);
 
+void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa)
+{
+	fileattr_fill_xflags(fa, fsx->fsx_xflags);
+	fa->fsx_extsize = fsx->fsx_extsize;
+	fa->fsx_nextents = fsx->fsx_nextents;
+	fa->fsx_projid = fsx->fsx_projid;
+	fa->fsx_cowextsize = fsx->fsx_cowextsize;
+}
+
 static int copy_fsxattr_from_user(struct fileattr *fa,
 				  struct fsxattr __user *ufa)
 {
@@ -122,11 +136,7 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
 	if (copy_from_user(&xfa, ufa, sizeof(xfa)))
 		return -EFAULT;
 
-	fileattr_fill_xflags(fa, xfa.fsx_xflags);
-	fa->fsx_extsize = xfa.fsx_extsize;
-	fa->fsx_nextents = xfa.fsx_nextents;
-	fa->fsx_projid = xfa.fsx_projid;
-	fa->fsx_cowextsize = xfa.fsx_cowextsize;
+	fsxattr_to_fileattr(&xfa, fa);
 
 	return 0;
 }
include/linux/fileattr.h +2 -0
index 6030d0bf7ad32693a0f48a6f28475d97e768bb3e..433efa0f47844ef063373eb390672812682b6388 100644
@@ -33,7 +33,9 @@ struct fileattr {
 	bool	fsx_valid:1;
 };
 
+void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx);
 int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa);
+void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa);
 
 void fileattr_fill_xflags(struct fileattr *fa, u32 xflags);
 void fileattr_fill_flags(struct fileattr *fa, u32 flags);
Signature · 1 line
2.47.2
#7 lore raw

PATCH v5 5/7 fs: make vfs_fileattr_[get|set] return -EOPNOSUPP

In reply to Andrey Albershteyn

Future patches will add new syscalls which use these functions. As this interface won't be used for ioctls only the EOPNOSUPP is more appropriate return code.

This patch coverts return code from ENOIOCTLCMD to EOPNOSUPP for vfs_fileattr_get and vfs_fileattr_set. To save old behavior translate EOPNOSUPP back for current users - overlayfs, encryptfs and fs/ioctl.c.

---
 fs/ecryptfs/inode.c  |  8 +++++++-
 fs/file_attr.c       | 12 ++++++++++--
 fs/overlayfs/inode.c |  2 +-
 3 files changed, 18 insertions(+), 4 deletions(-)
fs/ecryptfs/inode.c +7 -1
index 51a5c54eb74026d8b2deec6e0608f3d2b3e9c092..6bf08ff4d7f71c5223b90f4cde57e380b68260fd 100644
@@ -1124,7 +1124,13 @@ static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode,
 
 static int ecryptfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
 {
-	return vfs_fileattr_get(ecryptfs_dentry_to_lower(dentry), fa);
+	int rc;
+
+	rc = vfs_fileattr_get(ecryptfs_dentry_to_lower(dentry), fa);
+	if (rc == -EOPNOTSUPP)
+		rc = -ENOIOCTLCMD;
+
+	return rc;
 }
 
 static int ecryptfs_fileattr_set(struct mnt_idmap *idmap,
fs/file_attr.c +10 -2
index d9eab553dc250f84075ac74c1c7d8d6fd6588374..d696f440fa4ffcba8985cc4bfe22a1c0e612ac7c 100644
@@ -79,7 +79,7 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa)
 	int error;
 
 	if (!inode->i_op->fileattr_get)
-		return -ENOIOCTLCMD;
+		return -EOPNOTSUPP;
 
 	error = security_inode_file_getattr(dentry, fa);
 	if (error)
@@ -239,7 +239,7 @@ int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 	int err;
 
 	if (!inode->i_op->fileattr_set)
-		return -ENOIOCTLCMD;
+		return -EOPNOTSUPP;
 
 	if (!inode_owner_or_capable(idmap, inode))
 		return -EPERM;
@@ -281,6 +281,8 @@ int ioctl_getflags(struct file *file, unsigned int __user *argp)
 	int err;
 
 	err = vfs_fileattr_get(file->f_path.dentry, &fa);
+	if (err == -EOPNOTSUPP)
+		err = -ENOIOCTLCMD;
 	if (!err)
 		err = put_user(fa.flags, argp);
 	return err;
@@ -302,6 +304,8 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)
 			fileattr_fill_flags(&fa, flags);
 			err = vfs_fileattr_set(idmap, dentry, &fa);
 			mnt_drop_write_file(file);
+			if (err == -EOPNOTSUPP)
+				err = -ENOIOCTLCMD;
 		}
 	}
 	return err;
@@ -314,6 +318,8 @@ int ioctl_fsgetxattr(struct file *file, void __user *argp)
 	int err;
 
 	err = vfs_fileattr_get(file->f_path.dentry, &fa);
+	if (err == -EOPNOTSUPP)
+		err = -ENOIOCTLCMD;
 	if (!err)
 		err = copy_fsxattr_to_user(&fa, argp);
 
@@ -334,6 +340,8 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)
 		if (!err) {
 			err = vfs_fileattr_set(idmap, dentry, &fa);
 			mnt_drop_write_file(file);
+			if (err == -EOPNOTSUPP)
+				err = -ENOIOCTLCMD;
 		}
 	}
 	return err;
fs/overlayfs/inode.c +1 -1
index 6f0e15f86c21fc576fe1679e977597bd9f817e36..096d44712bb1130fd3e9673a61747b0fbf877d25 100644
@@ -721,7 +721,7 @@ int ovl_real_fileattr_get(const struct path *realpath, struct fileattr *fa)
 		return err;
 
 	err = vfs_fileattr_get(realpath->dentry, fa);
-	if (err == -ENOIOCTLCMD)
+	if (err == -EOPNOTSUPP)
 		err = -ENOTTY;
 	return err;
 }
Signature · 1 line
2.47.2
#8 lore raw

PATCH v5 6/7 fs: prepare for extending file_get/setattr()

In reply to Andrey Albershteyn

From: Amir Goldstein <[email protected]>

We intend to add support for more xflags to selective filesystems and We cannot rely on copy_struct_from_user() to detect this extension.

In preparation of extending the API, do not allow setting xflags unknown by this kernel version.

Also do not pass the read-only flags and read-only field fsx_nextents to filesystem.

These changes should not affect existing chattr programs that use the ioctl to get fsxattr before setting the new values.

---
 fs/file_attr.c           | 19 +++++++++++++------
 include/linux/fileattr.h | 22 +++++++++++++++++++++-
 2 files changed, 34 insertions(+), 7 deletions(-)
fs/file_attr.c +13 -6
index d696f440fa4ffcba8985cc4bfe22a1c0e612ac7c..6cd1e820f7b108c12c06654df843104f460b94cf 100644
@@ -91,8 +91,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);
 
 void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx)
 {
+	__u32 mask = FS_XFLAGS_MASK;
+
 	memset(fsx, 0, sizeof(struct fsxattr));
-	fsx->fsx_xflags = fa->fsx_xflags;
+	fsx->fsx_xflags = fa->fsx_xflags & mask;
 	fsx->fsx_extsize = fa->fsx_extsize;
 	fsx->fsx_nextents = fa->fsx_nextents;
 	fsx->fsx_projid = fa->fsx_projid;
@@ -119,13 +121,20 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)
 }
 EXPORT_SYMBOL(copy_fsxattr_to_user);
 
-void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa)
+int fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa)
 {
+	__u32 mask = FS_XFLAGS_MASK;
+
+	if (fsx->fsx_xflags & ~mask)
+		return -EINVAL;
+
 	fileattr_fill_xflags(fa, fsx->fsx_xflags);
+	fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK;
 	fa->fsx_extsize = fsx->fsx_extsize;
-	fa->fsx_nextents = fsx->fsx_nextents;
 	fa->fsx_projid = fsx->fsx_projid;
 	fa->fsx_cowextsize = fsx->fsx_cowextsize;
+
+	return 0;
 }
 
 static int copy_fsxattr_from_user(struct fileattr *fa,
@@ -136,9 +145,7 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
 	if (copy_from_user(&xfa, ufa, sizeof(xfa)))
 		return -EFAULT;
 
-	fsxattr_to_fileattr(&xfa, fa);
-
-	return 0;
+	return fsxattr_to_fileattr(&xfa, fa);
 }
 
 /*
include/linux/fileattr.h +21 -1
index 433efa0f47844ef063373eb390672812682b6388..f62a5143eb2dccd5ceedfe72439cc4cab823cb1d 100644
@@ -14,6 +14,26 @@
 	 FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \
 	 FS_XFLAG_PROJINHERIT)
 
+/* Read-only inode flags */
+#define FS_XFLAG_RDONLY_MASK \
+	(FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR)
+
+/* Flags to indicate valid value of fsx_ fields */
+#define FS_XFLAG_VALUES_MASK \
+	(FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE)
+
+/* Flags for directories */
+#define FS_XFLAG_DIRONLY_MASK \
+	(FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT)
+
+/* Misc settable flags */
+#define FS_XFLAG_MISC_MASK \
+	(FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM)
+
+#define FS_XFLAGS_MASK \
+	(FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \
+	 FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK)
+
 /*
  * Merged interface for miscellaneous file attributes.  'flags' originates from
  * ext* and 'fsx_flags' from xfs.  There's some overlap between the two, which
@@ -35,7 +55,7 @@ struct fileattr {
 
 void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx);
 int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa);
-void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa);
+int fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa);
 
 void fileattr_fill_xflags(struct fileattr *fa, u32 xflags);
 void fileattr_fill_flags(struct fileattr *fa, u32 flags);
Signature · 1 line
2.47.2
#9 lore raw

PATCH v5 7/7 fs: introduce file_getattr and file_setattr syscalls

In reply to Andrey Albershteyn

From: Andrey Albershteyn <[email protected]>

Introduce file_getattr and file_setattr syscalls to manipulate inode extended attributes/flags. The syscalls take parent directory fd and path to the child together with struct fsxattr.

This is an alternative to FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open as we can reference it with a path instead of fd. By having this we can manipulated inode extended attributes not only on regular files but also on special ones. This is not possible with FS_IOC_FSSETXATTR ioctl as with special files we can not call ioctl() directly on the filesystem inode using fd.

This patch adds two new syscalls which allows userspace to get/set extended inode attributes on special files by using parent directory and a path - *at() like syscall.

---
 arch/alpha/kernel/syscalls/syscall.tbl      |   2 +
 arch/arm/tools/syscall.tbl                  |   2 +
 arch/arm64/tools/syscall_32.tbl             |   2 +
 arch/m68k/kernel/syscalls/syscall.tbl       |   2 +
 arch/microblaze/kernel/syscalls/syscall.tbl |   2 +
 arch/mips/kernel/syscalls/syscall_n32.tbl   |   2 +
 arch/mips/kernel/syscalls/syscall_n64.tbl   |   2 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   |   2 +
 arch/parisc/kernel/syscalls/syscall.tbl     |   2 +
 arch/powerpc/kernel/syscalls/syscall.tbl    |   2 +
 arch/s390/kernel/syscalls/syscall.tbl       |   2 +
 arch/sh/kernel/syscalls/syscall.tbl         |   2 +
 arch/sparc/kernel/syscalls/syscall.tbl      |   2 +
 arch/x86/entry/syscalls/syscall_32.tbl      |   2 +
 arch/x86/entry/syscalls/syscall_64.tbl      |   2 +
 arch/xtensa/kernel/syscalls/syscall.tbl     |   2 +
 fs/file_attr.c                              | 119 ++++++++++++++++++++++++++++
 include/linux/syscalls.h                    |   6 ++
 include/uapi/asm-generic/unistd.h           |   8 +-
 include/uapi/linux/fs.h                     |   3 +
 20 files changed, 167 insertions(+), 1 deletion(-)
arch/alpha/kernel/syscalls/syscall.tbl +2 -0
index 2dd6340de6b4efddc406f0c235701c15cf02f650..16dca28ebf17e5df2230f640f3686835dc5a1f76 100644
@@ -507,3 +507,5 @@
 575	common	listxattrat			sys_listxattrat
 576	common	removexattrat			sys_removexattrat
 577	common	open_tree_attr			sys_open_tree_attr
+578	common	file_getattr			sys_file_getattr
+579	common	file_setattr			sys_file_setattr
arch/arm/tools/syscall.tbl +2 -0
index 27c1d5ebcd91c8c296dc6676307f66bfdf4ab78d..b07e699aaa3c2840452109c0004529fc68e153ac 100644
@@ -482,3 +482,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/arm64/tools/syscall_32.tbl +2 -0
index 0765b3a8d6d600d7b9f83182d401d9f80c03476c..8d9088bc577df0c6dba6d5d0c227585283789a3f 100644
@@ -479,3 +479,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/m68k/kernel/syscalls/syscall.tbl +2 -0
index 9fe47112c586f152662af38a9a7f90957cb96cf8..f41d38dfbf1382339316f4e3e6e79c75dc2804ec 100644
@@ -467,3 +467,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/microblaze/kernel/syscalls/syscall.tbl +2 -0
index 7b6e97828e552d4da90046ddfcd4a55723e522bb..580af574fe733af29ea69f40ae6e902ad2166ab2 100644
@@ -473,3 +473,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -0
index aa70e371bb54ab5d9c8dd8923b6ecf9693ee914d..d824ffe9a01496a13194710d5278dcc443e40894 100644
@@ -406,3 +406,5 @@
 465	n32	listxattrat			sys_listxattrat
 466	n32	removexattrat			sys_removexattrat
 467	n32	open_tree_attr			sys_open_tree_attr
+468	n32	file_getattr			sys_file_getattr
+469	n32	file_setattr			sys_file_setattr
arch/mips/kernel/syscalls/syscall_n64.tbl +2 -0
index 1e8c44c7b61492eabf00c777831e457a7a6e579c..7a7049c2c307885fe8be33aedb503cfe8afbfb24 100644
@@ -382,3 +382,5 @@
 465	n64	listxattrat			sys_listxattrat
 466	n64	removexattrat			sys_removexattrat
 467	n64	open_tree_attr			sys_open_tree_attr
+468	n64	file_getattr			sys_file_getattr
+469	n64	file_setattr			sys_file_setattr
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -0
index 114a5a1a62302e32dd74d1679ff423a2d57c3c6b..d330274f06010c9f9bf80d55898d0bd38994ef58 100644
@@ -455,3 +455,5 @@
 465	o32	listxattrat			sys_listxattrat
 466	o32	removexattrat			sys_removexattrat
 467	o32	open_tree_attr			sys_open_tree_attr
+468	o32	file_getattr			sys_file_getattr
+469	o32	file_setattr			sys_file_setattr
arch/parisc/kernel/syscalls/syscall.tbl +2 -0
index 94df3cb957e9d547d192e8732c0cf23ef2b5ce5d..88a788a7b18d17967019098b33d2be48a430aed3 100644
@@ -466,3 +466,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/powerpc/kernel/syscalls/syscall.tbl +2 -0
index 9a084bdb892694bc562f514b55212d167cbac12f..b453e80dfc003796a08f022f6bd44cf76a5f82ab 100644
@@ -558,3 +558,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/s390/kernel/syscalls/syscall.tbl +2 -0
index a4569b96ef06c54ce7aa795d039541c90a38284f..8a6744d658db3986f0ac0fd3c90592cdbd27249c 100644
@@ -470,3 +470,5 @@
 465  common	listxattrat		sys_listxattrat			sys_listxattrat
 466  common	removexattrat		sys_removexattrat		sys_removexattrat
 467  common	open_tree_attr		sys_open_tree_attr		sys_open_tree_attr
+468  common	file_getattr		sys_file_getattr		sys_file_getattr
+469  common	file_setattr		sys_file_setattr		sys_file_setattr
arch/sh/kernel/syscalls/syscall.tbl +2 -0
index 52a7652fcff6394b96ace1f3b0ed72250ee5e669..5e9c9eff5539e24113bb757f1e5b51bd7c32864e 100644
@@ -471,3 +471,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/sparc/kernel/syscalls/syscall.tbl +2 -0
index 83e45eb6c095a36baaf749927628e6052fe900e6..ebb7d06d1044fa9b113b0a3fe0316c77f48fc3d0 100644
@@ -513,3 +513,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
index ac007ea00979dc28b0ef7c002a0615ce86dd3101..4877e16da69a50f2225088e556661051dbe3c7a3 100644
@@ -473,3 +473,5 @@
 465	i386	listxattrat		sys_listxattrat
 466	i386	removexattrat		sys_removexattrat
 467	i386	open_tree_attr		sys_open_tree_attr
+468	i386	file_getattr		sys_file_getattr
+469	i386	file_setattr		sys_file_setattr
arch/x86/entry/syscalls/syscall_64.tbl +2 -0
index cfb5ca41e30de1a4e073750096f5b51a2ec137d2..92cf0fe2291eb99b536e4de4201aec16b3472094 100644
@@ -391,6 +391,8 @@
 465	common	listxattrat		sys_listxattrat
 466	common	removexattrat		sys_removexattrat
 467	common	open_tree_attr		sys_open_tree_attr
+468	common	file_getattr		sys_file_getattr
+469	common	file_setattr		sys_file_setattr
 
 #
 # Due to a historical design error, certain syscalls are numbered differently
arch/xtensa/kernel/syscalls/syscall.tbl +2 -0
index f657a77314f8667fa019a01e10c84ea270024adc..374e4cb788d8a6d4e1f3358b949ea8b600013e1c 100644
@@ -438,3 +438,5 @@
 465	common	listxattrat			sys_listxattrat
 466	common	removexattrat			sys_removexattrat
 467	common	open_tree_attr			sys_open_tree_attr
+468	common	file_getattr			sys_file_getattr
+469	common	file_setattr			sys_file_setattr
fs/file_attr.c +119 -0

128 lines not on this page · raw message

include/linux/syscalls.h +6 -0
index e5603cc91963dabb79324d6e9e2274f327311245..f2a747479718f9c93f6a448cdab2e60f7ee87709 100644
@@ -371,6 +371,12 @@ asmlinkage long sys_removexattrat(int dfd, const char __user *path,
 asmlinkage long sys_lremovexattr(const char __user *path,
 				 const char __user *name);
 asmlinkage long sys_fremovexattr(int fd, const char __user *name);
+asmlinkage long sys_file_getattr(int dfd, const char __user *filename,
+				 struct fsxattr __user *ufsx, size_t usize,
+				 unsigned int at_flags);
+asmlinkage long sys_file_setattr(int dfd, const char __user *filename,
+				 struct fsxattr __user *ufsx, size_t usize,
+				 unsigned int at_flags);
 asmlinkage long sys_getcwd(char __user *buf, unsigned long size);
 asmlinkage long sys_eventfd2(unsigned int count, int flags);
 asmlinkage long sys_epoll_create1(int flags);
include/uapi/asm-generic/unistd.h +7 -1
index 2892a45023af6d3eb941623d4fed04841ab07e02..04e0077fb4c97a4d565da86d3d0d1d243f32336e 100644
@@ -852,8 +852,14 @@ __SYSCALL(__NR_removexattrat, sys_removexattrat)
 #define __NR_open_tree_attr 467
 __SYSCALL(__NR_open_tree_attr, sys_open_tree_attr)
 
+/* fs/inode.c */
+#define __NR_file_getattr 468
+__SYSCALL(__NR_file_getattr, sys_file_getattr)
+#define __NR_file_setattr 469
+__SYSCALL(__NR_file_setattr, sys_file_setattr)
+
 #undef __NR_syscalls
-#define __NR_syscalls 468
+#define __NR_syscalls 470
 
 /*
  * 32 bit systems traditionally used different
include/uapi/linux/fs.h +3 -0
index e762e1af650c4bf08766ba7a8ab7a2288e987039..bc1467b44b80e1db3527dd1b70f1a3a3ca7e4484 100644
@@ -148,6 +148,9 @@ struct fsxattr {
 	unsigned char	fsx_pad[8];
 };
 
+#define FSXATTR_SIZE_VER0 28
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0
+
 /*
  * Flags for the fsx_xflags field
  */
Signature · 1 line
2.47.2
#10 lore raw
kernel test robot noticed the following build warnings:

Hi Andrey,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 0d8d44db295ccad20052d6301ef49ff01fb8ae2d]

url:    https://github.com/intel-lab-lkp/linux/commits/Andrey-Albershteyn/fs-split-fileattr-related-helpers-into-separate-file/20250513-172128
base:   0d8d44db295ccad20052d6301ef49ff01fb8ae2d
patch link:    https://lore.kernel.org/r/20250513-xattrat-syscall-v5-7-22bb9c6c767f%40kernel.org
patch subject: [PATCH v5 7/7] fs: introduce file_getattr and file_setattr syscalls
config: openrisc-allnoconfig (https://download.01.org/0day-ci/archive/20250514/[email protected]/config)
compiler: or1k-linux-gcc (GCC) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250514/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> <stdin>:1618:2: warning: #warning syscall file_getattr not implemented [-Wcpp]
>> <stdin>:1621:2: warning: #warning syscall file_setattr not implemented [-Wcpp]
--
>> <stdin>:1618:2: warning: #warning syscall file_getattr not implemented [-Wcpp]
>> <stdin>:1621:2: warning: #warning syscall file_setattr not implemented [-Wcpp]
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#11 lore raw
In reply to Andrey Albershteyn
kernel test robot noticed the following build warnings:

Hi Andrey,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 0d8d44db295ccad20052d6301ef49ff01fb8ae2d]

url:    https://github.com/intel-lab-lkp/linux/commits/Andrey-Albershteyn/fs-split-fileattr-related-helpers-into-separate-file/20250513-172128
base:   0d8d44db295ccad20052d6301ef49ff01fb8ae2d
patch link:    https://lore.kernel.org/r/20250513-xattrat-syscall-v5-7-22bb9c6c767f%40kernel.org
patch subject: [PATCH v5 7/7] fs: introduce file_getattr and file_setattr syscalls
config: s390-randconfig-r112-20250518 (https://download.01.org/0day-ci/archive/20250518/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
reproduce: (https://download.01.org/0day-ci/archive/20250518/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

>> fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer
>> fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer
>> fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer
>> fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer

fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer

vim +362 fs/file_attr.c

361

 > 362	SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,

363 struct fsxattr __user *, ufsx, size_t, usize,
364 unsigned int, at_flags)
365 {
366 struct fileattr fa = {};
367 struct path filepath __free(path_put) = {};
368 int error;
369 unsigned int lookup_flags = 0;
370 struct filename *name;
371 struct fsxattr fsx = {};
372
373 BUILD_BUG_ON(sizeof(struct fsxattr) < FSXATTR_SIZE_VER0);
374 BUILD_BUG_ON(sizeof(struct fsxattr) != FSXATTR_SIZE_LATEST);
375
376 if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
377 return -EINVAL;
378
379 if (!(at_flags & AT_SYMLINK_NOFOLLOW))
380 lookup_flags |= LOOKUP_FOLLOW;
381
382 if (usize > PAGE_SIZE)
383 return -E2BIG;
384
385 if (usize < FSXATTR_SIZE_VER0)
386 return -EINVAL;
387
388 name = getname_maybe_null(filename, at_flags);
389 if (IS_ERR(name))
390 return PTR_ERR(name);
391
392 if (!name && dfd >= 0) {
393 CLASS(fd, f)(dfd);
394
395 filepath = fd_file(f)->f_path;
396 path_get(&filepath);
397 } else {
398 error = filename_lookup(dfd, name, lookup_flags, &filepath,
399 NULL);
400 putname(name);
401 if (error)
402 return error;
403 }
404
405 error = vfs_fileattr_get(filepath.dentry, &fa);
406 if (error)
407 return error;
408
409 fileattr_to_fsxattr(&fa, &fsx);
410 error = copy_struct_to_user(ufsx, usize, &fsx, sizeof(struct fsxattr),
411 NULL);
412
413 return error;
414 }
415

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
maintainer
#12 lore raw
Quoted 29 lines · kernel test robot

Hi Andrey,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 0d8d44db295ccad20052d6301ef49ff01fb8ae2d]

url:    https://github.com/intel-lab-lkp/linux/commits/Andrey-Albershteyn/fs-split-fileattr-related-helpers-into-separate-file/20250513-172128
base:   0d8d44db295ccad20052d6301ef49ff01fb8ae2d
patch link:    https://lore.kernel.org/r/20250513-xattrat-syscall-v5-7-22bb9c6c767f%40kernel.org
patch subject: [PATCH v5 7/7] fs: introduce file_getattr and file_setattr syscalls
config: s390-randconfig-r112-20250518 (https://download.01.org/0day-ci/archive/20250518/[email protected]/config)
compiler: s390-linux-gcc (GCC) 8.5.0
reproduce: (https://download.01.org/0day-ci/archive/20250518/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

sparse warnings: (new ones prefixed by >>)

Quoted 4 lines
Quoted 4 lines

fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:362:1: sparse: sparse: Using plain integer as NULL pointer

fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer fs/file_attr.c:416:1: sparse: sparse: Using plain integer as NULL pointer

Quoted 7 lines

vim +362 fs/file_attr.c

   361	
Quoted 1 line

362 SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,

363 struct fsxattr __user *, ufsx, size_t, usize,
364 unsigned int, at_flags)
365 {

Please ignore the warning. There is nothing to fix; this is a warning which happens only with CONFIG_COMPAT and Al's "SC_DELOUSE" macro, which is used for compat syscalls. Sparse cannot handle that.

maintainer
#13 lore raw
In reply to Andrey Albershteyn
Quoted 5 lines · Andrey Albershteyn
	long syscall(SYS_file_getattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);
	long syscall(SYS_file_setattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

I also find the bit confusing where the argument contains both "ignored but assumed zero" flags, and "required to be zero" flags depending on whether it's in the fsx_pad[] field or after it. This would be fine if it was better documented.

Quoted 2 lines
		fsx.fsx_xflags |= FS_XFLAG_NODUMP;
		error = syscall(468, dfd, "./foo", &fsx, 0);

The example still uses the calling conventions from a previous version.

Arnd

maintainer
#14 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

Quoted 7 lines

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Are you are suggesting that we need to define this variant?:

include/uapi/linux/fs.h +11 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
 
Quoted 5 lines

I also find the bit confusing where the argument contains both "ignored but assumed zero" flags, and "required to be zero" flags depending on whether it's in the fsx_pad[] field or after it. This would be fine if it was better documented.

I think that is an oversight.
The syscall should have required that fsx_pad is zero, same as patch 6/7 requires that unknown xflags are zero.

If we change to:
error = copy_struct_from_user(&fsx, sizeof(struct
fsx_fileattr), ufsx, usize);

It will take care of requiring zero fsx_pad even if user calls the syscall with sizeof(struct fsxattr).

Thanks,
Amir.

#15 lore raw
In reply to Arnd Bergmann
Quoted 21 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn
	long syscall(SYS_file_getattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);
	long syscall(SYS_file_setattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

I also find the bit confusing where the argument contains both "ignored but assumed zero" flags, and "required to be zero" flags depending on whether it's in the fsx_pad[] field or after it. This would be fine if it was better documented.

Quoted 7 lines
Quoted 2 lines
		fsx.fsx_xflags |= FS_XFLAG_NODUMP;
		error = syscall(468, dfd, "./foo", &fsx, 0);

The example still uses the calling conventions from a previous version.

Arnd

Well, ioctls carry the structure size in the ioctl number, so changing the structure size would change the ioctl number with it.

#16 lore raw
In reply to Arnd Bergmann
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn
	long syscall(SYS_file_getattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);
	long syscall(SYS_file_setattr, int dirfd, const char *pathname,
		struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +14 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+
        return -ENOIOCTLCMD;
 }
maintainer
#17 lore raw
Quoted 50 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +4 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 10 lines
fs/ioctl.c +10 -0
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and certainly not
the XFS specific ioctl XFS_IOC_FSGETXATTRA.

This struct is part of XFS uapi:
https://man7.org/linux/man-pages/man2/ioctl_xfs_fsgetxattr.2.html

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +14 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0
+

Right?

Thanks,
Amir.

#18 lore raw
Quoted 59 lines · Amir Goldstein
Quoted 58 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +12 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 2 lines
fs/ioctl.c +2 -0
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and certainly not
the XFS specific ioctl XFS_IOC_FSGETXATTRA.

Sure, I'm just saying this could very likely be handled without the kernel or userspace having to care about the changed structure provided we teach the kernel to use the ioctl number, not the command and only ever copy v1 of the struct for the ioctls in new kernels. But anyway...

Quoted 28 lines

This struct is part of XFS uapi:
https://man7.org/linux/man-pages/man2/ioctl_xfs_fsgetxattr.2.html

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +14 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0
+
Quoted 1 line

Right?

Sure, I don't have a problem with that since I find the current name with "fsxattr" quite problematic anyway.

#19 lore raw
In reply to Amir Goldstein
Quoted 57 lines · Amir Goldstein
Quoted 56 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +10 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 4 lines
fs/ioctl.c +4 -0
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and

There's no need to deprecate anything to rev an ioctl API. We have had to solve this "changing struct size" problem previously in XFS ioctls. See XFS_IOC_FSGEOMETRY and the older XFS_IOC_FSGEOMETRY_V4 and XFS_IOC_FSGEOMETRY_V1 versions of the API/ABI.

If we need to increase the structure size, we can rename the existing ioctl and struct to fix the version in the API, then use the original name for the new ioctl and structure definition.

The only thing we have to make sure of is that the old and new structures have exactly the same overlapping structure. i.e. extension must always be done by appending new varibles, they can't be put in the middle of the structure.

This way applications being rebuild will pick up the new definition automatically when the system asserts that it is suppored, whilst existing binaries will always still be supported by the kernel.

If the application wants/needs to support all possible kernels, then if XFS_IOC_FSGEOMETRY is not supported, call XFS_IOC_FSGEOMETRY_V4, and if that fails (only on really old irix!) or you only need something in that original subset, call XFS_IOC_FSGEOMETRY_V1 which will always succeed....

Quoted 12 lines

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +3 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

	case FSXATTR..._V1:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
	case FSXATTR..._V2:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
	case FSXATTR...:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr));

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#20 lore raw
Quoted 118 lines · Dave Chinner
Quoted 57 lines · Amir Goldstein
Quoted 56 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +10 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 4 lines
fs/ioctl.c +4 -0
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and

There's no need to deprecate anything to rev an ioctl API. We have had to solve this "changing struct size" problem previously in XFS ioctls. See XFS_IOC_FSGEOMETRY and the older XFS_IOC_FSGEOMETRY_V4 and XFS_IOC_FSGEOMETRY_V1 versions of the API/ABI.

If we need to increase the structure size, we can rename the existing ioctl and struct to fix the version in the API, then use the original name for the new ioctl and structure definition.

The only thing we have to make sure of is that the old and new structures have exactly the same overlapping structure. i.e. extension must always be done by appending new varibles, they can't be put in the middle of the structure.

This way applications being rebuild will pick up the new definition automatically when the system asserts that it is suppored, whilst existing binaries will always still be supported by the kernel.

If the application wants/needs to support all possible kernels, then if XFS_IOC_FSGEOMETRY is not supported, call XFS_IOC_FSGEOMETRY_V4, and if that fails (only on really old irix!) or you only need something in that original subset, call XFS_IOC_FSGEOMETRY_V1 which will always succeed....

Quoted 12 lines

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +3 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

Quoted 12 lines
	case FSXATTR..._V1:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
	case FSXATTR..._V2:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
	case FSXATTR...:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr));

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]

So, looks like there's at least two solutions to this concern. Considering also that we have a bit of space in fsxattr, 'fsx_pad[8]', I think it's fine to stick with the current fsxattr for now.

Signature · 1 line
- Andrey
#21 lore raw
Quoted 132 lines · On Wednesday 21 May 2025 10:48:26 Andrey Albershteyn wrote:
Quoted 118 lines · Dave Chinner
Quoted 57 lines · Amir Goldstein
Quoted 56 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +10 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 4 lines
fs/ioctl.c +4 -0
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and

There's no need to deprecate anything to rev an ioctl API. We have had to solve this "changing struct size" problem previously in XFS ioctls. See XFS_IOC_FSGEOMETRY and the older XFS_IOC_FSGEOMETRY_V4 and XFS_IOC_FSGEOMETRY_V1 versions of the API/ABI.

If we need to increase the structure size, we can rename the existing ioctl and struct to fix the version in the API, then use the original name for the new ioctl and structure definition.

The only thing we have to make sure of is that the old and new structures have exactly the same overlapping structure. i.e. extension must always be done by appending new varibles, they can't be put in the middle of the structure.

This way applications being rebuild will pick up the new definition automatically when the system asserts that it is suppored, whilst existing binaries will always still be supported by the kernel.

If the application wants/needs to support all possible kernels, then if XFS_IOC_FSGEOMETRY is not supported, call XFS_IOC_FSGEOMETRY_V4, and if that fails (only on really old irix!) or you only need something in that original subset, call XFS_IOC_FSGEOMETRY_V1 which will always succeed....

Quoted 12 lines

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +3 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

Quoted 12 lines
	case FSXATTR..._V1:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
	case FSXATTR..._V2:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
	case FSXATTR...:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr));

-Dave.

Signature · 2 lines
Dave Chinner
[email protected]
Quoted 8 lines

So, looks like there's at least two solutions to this concern. Considering also that we have a bit of space in fsxattr, 'fsx_pad[8]', I think it's fine to stick with the current fsxattr for now.

Signature · 1 line
- Andrey

It is planned to extend this structure for new windows attributes as was discussed. And seem that the current free space would not be enough for everything.

maintainer
#22 lore raw
In reply to Andrey Albershteyn
Quoted 17 lines · Andrey Albershteyn
Quoted 15 lines · Dave Chinner

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

Quoted 6 lines
Quoted 6 lines
	case FSXATTR..._V1:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
	case FSXATTR..._V2:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
	case FSXATTR...:
		return ioctl_fsxattr...(args, sizeof(fsx_fileattr));

I think user space these days, in particular glibc, expects that you can build using new kernel headers and run on older kernels but still get behavior that is compatible with old headers, so redefining FS_IOC_FSGETXATTR would be considered a bug.

I'm fairly sure that in the past it was common to expect userspace to never be built against newer headers and run on older kernels, but the expectation seems to have gradually shifted away from that.

Quoted 4 lines

So, looks like there's at least two solutions to this concern. Considering also that we have a bit of space in fsxattr, 'fsx_pad[8]', I think it's fine to stick with the current fsxattr for now.

You still have to document what you expect to happen with the padding fields for both the ioctl and the syscall, as the current behavior of ignoring the padding in the ioctl is not what we expect for a syscall which tends to check unknown fields for zero. I don't see a good solution here if you use the same structure.

Arnd

maintainer
#23 lore raw
In reply to Andrey Albershteyn
Quoted 133 lines · Andrey Albershteyn
Quoted 125 lines · Dave Chinner
Quoted 57 lines · Amir Goldstein
Quoted 56 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +10 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 4 lines
fs/ioctl.c +4 -0
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and

There's no need to deprecate anything to rev an ioctl API. We have had to solve this "changing struct size" problem previously in XFS ioctls. See XFS_IOC_FSGEOMETRY and the older XFS_IOC_FSGEOMETRY_V4 and XFS_IOC_FSGEOMETRY_V1 versions of the API/ABI.

If we need to increase the structure size, we can rename the existing ioctl and struct to fix the version in the API, then use the original name for the new ioctl and structure definition.

The only thing we have to make sure of is that the old and new structures have exactly the same overlapping structure. i.e. extension must always be done by appending new varibles, they can't be put in the middle of the structure.

This way applications being rebuild will pick up the new definition automatically when the system asserts that it is suppored, whilst existing binaries will always still be supported by the kernel.

If the application wants/needs to support all possible kernels, then if XFS_IOC_FSGEOMETRY is not supported, call XFS_IOC_FSGEOMETRY_V4, and if that fails (only on really old irix!) or you only need something in that original subset, call XFS_IOC_FSGEOMETRY_V1 which will always succeed....

Quoted 12 lines

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +3 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

      case FSXATTR..._V1:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
      case FSXATTR..._V2:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
      case FSXATTR...:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr));
Quoted 5 lines

-Dave.
--
Dave Chinner
[email protected]

Quoted 4 lines

So, looks like there's at least two solutions to this concern. Considering also that we have a bit of space in fsxattr, 'fsx_pad[8]', I think it's fine to stick with the current fsxattr for now.

Not sure which two solutions you are referring to.

I proposed fsx_fileattr as what I think is the path of least resistance. There are opinions that we may be able to avoid defining this struct, but I don't think there was any objection to adding it.

So unless I am missing an objection that I did not understand define it and get over this hurdle?

Thanks,
Amir.

#24 lore raw
Quoted 134 lines · Amir Goldstein
Quoted 133 lines · Andrey Albershteyn
Quoted 130 lines · Dave Chinner
Quoted 57 lines · Amir Goldstein
Quoted 56 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +10 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 4 lines
fs/ioctl.c +4 -0
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and

There's no need to deprecate anything to rev an ioctl API. We have had to solve this "changing struct size" problem previously in XFS ioctls. See XFS_IOC_FSGEOMETRY and the older XFS_IOC_FSGEOMETRY_V4 and XFS_IOC_FSGEOMETRY_V1 versions of the API/ABI.

If we need to increase the structure size, we can rename the existing ioctl and struct to fix the version in the API, then use the original name for the new ioctl and structure definition.

The only thing we have to make sure of is that the old and new structures have exactly the same overlapping structure. i.e. extension must always be done by appending new varibles, they can't be put in the middle of the structure.

This way applications being rebuild will pick up the new definition automatically when the system asserts that it is suppored, whilst existing binaries will always still be supported by the kernel.

If the application wants/needs to support all possible kernels, then if XFS_IOC_FSGEOMETRY is not supported, call XFS_IOC_FSGEOMETRY_V4, and if that fails (only on really old irix!) or you only need something in that original subset, call XFS_IOC_FSGEOMETRY_V1 which will always succeed....

Quoted 12 lines

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +3 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

      case FSXATTR..._V1:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
      case FSXATTR..._V2:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
      case FSXATTR...:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr));

-Dave.
--
Dave Chinner
[email protected]

Quoted 6 lines
Quoted 4 lines

So, looks like there's at least two solutions to this concern. Considering also that we have a bit of space in fsxattr, 'fsx_pad[8]', I think it's fine to stick with the current fsxattr for now.

Not sure which two solutions you are referring to.

Suggested by Christian and Dave

Quoted 7 lines

I proposed fsx_fileattr as what I think is the path of least resistance. There are opinions that we may be able to avoid defining this struct, but I don't think there was any objection to adding it.

So unless I am missing an objection that I did not understand define it and get over this hurdle?

I see, sure, I misinterpreted the communication :) no problems, I will create 'struct fsx_fileattr' then.

Pali, ah sorry, I forgot that you will extend fsxattr right away

Signature · 1 line
- Andrey
maintainer
#25 lore raw
Quoted 136 lines · Andrey Albershteyn
Quoted 134 lines · Amir Goldstein
Quoted 133 lines · Andrey Albershteyn
Quoted 130 lines · Dave Chinner
Quoted 57 lines · Amir Goldstein
Quoted 56 lines · Christian Brauner
Quoted 11 lines · Arnd Bergmann
Quoted 5 lines · Andrey Albershteyn

long syscall(SYS_file_getattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);
long syscall(SYS_file_setattr, int dirfd, const char *pathname,
struct fsxattr *fsx, size_t size, unsigned int at_flags);

I don't think we can have both the "struct fsxattr" from the uapi headers, and a variable size as an additional argument. I would still prefer not having the extensible structure at all and just

We're not going to add new interfaces that are fixed size unless for the very basic cases. I don't care if we're doing that somewhere else in the kernel but we're not doing that for vfs apis.

Quoted 3 lines

use fsxattr, but if you want to make it extensible in this way, it should use a different structure (name). Otherwise adding fields after fsx_pad[] would break the ioctl interface.

Would that really be a problem? Just along the syscall simply add something like:

fs/ioctl.c +10 -6
index c91fd2b46a77..d3943805c4be 100644
@@ -868,12 +868,6 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
        case FS_IOC_SETFLAGS:
                return ioctl_setflags(filp, argp);
 
-       case FS_IOC_FSGETXATTR:
-               return ioctl_fsgetxattr(filp, argp);
-
-       case FS_IOC_FSSETXATTR:
-               return ioctl_fssetxattr(filp, argp);
-
        case FS_IOC_GETFSUUID:
                return ioctl_getfsuuid(filp, argp);
 
@@ -886,6 +880,20 @@ static int do_vfs_ioctl(struct file *filp, unsigned int fd,
                break;
        }
 
+       switch (_IOC_NR(cmd)) {
+       case _IOC_NR(FS_IOC_FSGETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FS_IOC_FSGETXATTR)))
+                       return SOMETHING_SOMETHING;
+               /* Only handle original size. */
+               return ioctl_fsgetxattr(filp, argp);
+
+       case _IOC_NR(FFS_IOC_FSSETXATTR):
+               if (WARN_ON_ONCE(_IOC_TYPE(cmd) != _IOC_TYPE(FFS_IOC_FSSETXATTR)))
+                       return SOMETHING_SOMETHING;
Quoted 8 lines

fs/ioctl.c static int do_vfs_ioctl(struct file *filp, unsigned int fd, · line 896

Quoted 4 lines
fs/ioctl.c +4 -0
+               /* Only handle original size. */
+               return ioctl_fssetxattr(filp, argp);
+       }
+

I think what Arnd means is that we will not be able to change struct sfxattr in uapi
going forward, because we are not going to deprecate the ioctls and

There's no need to deprecate anything to rev an ioctl API. We have had to solve this "changing struct size" problem previously in XFS ioctls. See XFS_IOC_FSGEOMETRY and the older XFS_IOC_FSGEOMETRY_V4 and XFS_IOC_FSGEOMETRY_V1 versions of the API/ABI.

If we need to increase the structure size, we can rename the existing ioctl and struct to fix the version in the API, then use the original name for the new ioctl and structure definition.

The only thing we have to make sure of is that the old and new structures have exactly the same overlapping structure. i.e. extension must always be done by appending new varibles, they can't be put in the middle of the structure.

This way applications being rebuild will pick up the new definition automatically when the system asserts that it is suppored, whilst existing binaries will always still be supported by the kernel.

If the application wants/needs to support all possible kernels, then if XFS_IOC_FSGEOMETRY is not supported, call XFS_IOC_FSGEOMETRY_V4, and if that fails (only on really old irix!) or you only need something in that original subset, call XFS_IOC_FSGEOMETRY_V1 which will always succeed....

Quoted 12 lines

Should we will need to depart from this struct definition and we might as well do it for the initial release of the syscall rather than later on, e.g.:

include/uapi/linux/fs.h +3 -0
@@ -148,6 +148,17 @@ struct fsxattr {
        unsigned char   fsx_pad[8];
 };
 
+/*
+ * Variable size structure for file_[sg]et_attr().
+ */

include/uapi/linux/fs.h struct fsxattr { · line 163

Quoted 10 lines
include/uapi/linux/fs.h +10 -0
+struct fsx_fileattr {
+       __u32           fsx_xflags;     /* xflags field value (get/set) */
+       __u32           fsx_extsize;    /* extsize field value (get/set)*/
+       __u32           fsx_nextents;   /* nextents field value (get)   */
+       __u32           fsx_projid;     /* project identifier (get/set) */
+       __u32           fsx_cowextsize; /* CoW extsize field value (get/set)*/
+};
+
+#define FSXATTR_SIZE_VER0 20
+#define FSXATTR_SIZE_LATEST FSXATTR_SIZE_VER0

If all the structures overlap the same, all that is needed in the code is to define the structure size that should be copied in and parsed. i.e:

      case FSXATTR..._V1:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v1));
      case FSXATTR..._V2:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr_v2));
      case FSXATTR...:
              return ioctl_fsxattr...(args, sizeof(fsx_fileattr));

-Dave.
--
Dave Chinner
[email protected]

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

So, looks like there's at least two solutions to this concern. Considering also that we have a bit of space in fsxattr, 'fsx_pad[8]', I think it's fine to stick with the current fsxattr for now.

Not sure which two solutions you are referring to.

Suggested by Christian and Dave

IIUC, those are suggestions of how we could cope with changing struct fsxattr in the future, but it is easier not to have to do that.

Quoted 5 lines
Quoted 5 lines

I proposed fsx_fileattr as what I think is the path of least resistance. There are opinions that we may be able to avoid defining this struct, but I don't think there was any objection to adding it.

Quoted 8 lines
Quoted 2 lines

So unless I am missing an objection that I did not understand define it and get over this hurdle?

I see, sure, I misinterpreted the communication :) no problems, I will create 'struct fsx_fileattr' then.

Pali, ah sorry, I forgot that you will extend fsxattr right away

Much less problems could be caused if fsxattr remain frozen in time along with the ioctls as we continue to extend the syscalls.

Thanks,
Amir.

P.S. your CC list is a bit much.
I wouldn't trust get_maintainer.pl output when it provides such a huge list it has some emails that bounce - not nice.

When you are at v5 you should be able to have figured out who is participating in the review and for the rest, the public lists linux-fsdevel, linux-api and linux-xfs should be enough.