]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
fs: Move file_kattr initialization to callers
authorChuck Lever <chuck.lever@oracle.com>
Thu, 7 May 2026 08:52:54 +0000 (04:52 -0400)
committerChristian Brauner <brauner@kernel.org>
Mon, 11 May 2026 14:50:27 +0000 (16:50 +0200)
fileattr_fill_xflags() and fileattr_fill_flags() memset the
entire file_kattr struct before populating select fields, so
callers cannot pre-set fields in fa->fsx_xflags without having
their values clobbered. Darrick Wong noted that a function
named "fill_xflags" touching more than xflags forces callers
to know implementation details beyond its apparent scope.

Drop the memset from both fill functions and initialize at the
entry points instead: ioctl_setflags(), ioctl_fssetxattr(),
the file_setattr() syscall, and xfs_ioc_fsgetxattra() now
declare fa with an aggregate initializer. ioctl_getflags(),
ioctl_fsgetxattr(), and the file_getattr() syscall already
aggregate-initialize fa to pass flags_valid/fsx_valid hints
into vfs_fileattr_get().

Subsequent patches rely on this so that ->fileattr_get()
handlers can set case-sensitivity flags (FS_XFLAG_CASEFOLD,
FS_XFLAG_CASENONPRESERVING) in fa->fsx_xflags before the fill
functions run.

Suggested-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Roland Mainz <roland.mainz@nrubsig.org>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Link: https://patch.msgid.link/20260507-case-sensitivity-v14-1-e62cc8200435@oracle.com
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/file_attr.c
fs/xfs/xfs_ioctl.c

index da983e105d7087f0635dc012f63add66edab870d..f429da66a317cce65a7fb660bf90871219f6965b 100644 (file)
  * @fa:                fileattr pointer
  * @xflags:    FS_XFLAG_* flags
  *
- * Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags).  All
- * other fields are zeroed.
+ * Set ->fsx_xflags, ->fsx_valid and ->flags (translated xflags).
  */
 void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags)
 {
-       memset(fa, 0, sizeof(*fa));
        fa->fsx_valid = true;
        fa->fsx_xflags = xflags;
        if (fa->fsx_xflags & FS_XFLAG_IMMUTABLE)
@@ -48,11 +46,9 @@ EXPORT_SYMBOL(fileattr_fill_xflags);
  * @flags:     FS_*_FL flags
  *
  * Set ->flags, ->flags_valid and ->fsx_xflags (translated flags).
- * All other fields are zeroed.
  */
 void fileattr_fill_flags(struct file_kattr *fa, u32 flags)
 {
-       memset(fa, 0, sizeof(*fa));
        fa->flags_valid = true;
        fa->flags = flags;
        if (fa->flags & FS_SYNC_FL)
@@ -325,7 +321,7 @@ int ioctl_setflags(struct file *file, unsigned int __user *argp)
 {
        struct mnt_idmap *idmap = file_mnt_idmap(file);
        struct dentry *dentry = file->f_path.dentry;
-       struct file_kattr fa;
+       struct file_kattr fa = {};
        unsigned int flags;
        int err;
 
@@ -357,7 +353,7 @@ int ioctl_fssetxattr(struct file *file, void __user *argp)
 {
        struct mnt_idmap *idmap = file_mnt_idmap(file);
        struct dentry *dentry = file->f_path.dentry;
-       struct file_kattr fa;
+       struct file_kattr fa = {};
        int err;
 
        err = copy_fsxattr_from_user(&fa, argp);
@@ -431,7 +427,7 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
        struct path filepath __free(path_put) = {};
        unsigned int lookup_flags = 0;
        struct file_attr fattr;
-       struct file_kattr fa;
+       struct file_kattr fa = {};
        int error;
 
        BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
index 46e234863644f036a40f970b7cfe722bbf0fbf3e..ed9b4846c05ff86fcb948932212ff67bc7591cf4 100644 (file)
@@ -517,7 +517,7 @@ xfs_ioc_fsgetxattra(
        xfs_inode_t             *ip,
        void                    __user *arg)
 {
-       struct file_kattr       fa;
+       struct file_kattr       fa = {};
 
        xfs_ilock(ip, XFS_ILOCK_SHARED);
        xfs_fill_fsxattr(ip, XFS_ATTR_FORK, &fa);