From: "Darrick J. Wong" <djwong@kernel.org>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: "Amir Goldstein" <amir73il@gmail.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Casey Schaufler" <casey@schaufler-ca.com>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>, "Pali Rohár" <pali@kernel.org>,
"Paul Moore" <paul@paul-moore.com>,
linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-xfs@vger.kernel.org,
selinux@vger.kernel.org,
"Andrey Albershteyn" <aalbersh@kernel.org>
Subject: Re: [PATCH v6 5/6] fs: prepare for extending file_get/setattr()
Date: Tue, 1 Jul 2025 11:31:05 -0700 [thread overview]
Message-ID: <20250701183105.GP10009@frogsfrogsfrogs> (raw)
In-Reply-To: <20250630-xattrat-syscall-v6-5-c4e3bc35227b@kernel.org>
On Mon, Jun 30, 2025 at 06:20:15PM +0200, Andrey Albershteyn wrote:
> From: Amir Goldstein <amir73il@gmail.com>
>
> 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.
>
> Link: https://lore.kernel.org/linux-fsdevel/20250216164029.20673-4-pali@kernel.org/
> Cc: Pali Rohár <pali@kernel.org>
> Cc: Andrey Albershteyn <aalbersh@redhat.com>
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org>
> ---
> fs/file_attr.c | 8 +++++++-
> include/linux/fileattr.h | 20 ++++++++++++++++++++
> 2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/fs/file_attr.c b/fs/file_attr.c
> index 4e85fa00c092..62f08872d4ad 100644
> --- a/fs/file_attr.c
> +++ b/fs/file_attr.c
> @@ -99,9 +99,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);
> int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa)
> {
> struct fsxattr xfa;
> + __u32 mask = FS_XFLAGS_MASK;
>
> memset(&xfa, 0, sizeof(xfa));
> - xfa.fsx_xflags = fa->fsx_xflags;
> + xfa.fsx_xflags = fa->fsx_xflags & mask;
I wonder, should it be an error if a filesystem sets an fsx_xflags bit
outside of FS_XFLAGS_MASK? I guess that's one way to prevent
filesystems from overriding the VFS bits. ;)
Though couldn't that be:
xfa.fsx_xflags = fa->fsx_xflags & FS_XFLAGS_MASK;
instead? And same below?
> xfa.fsx_extsize = fa->fsx_extsize;
> xfa.fsx_nextents = fa->fsx_nextents;
> xfa.fsx_projid = fa->fsx_projid;
> @@ -118,11 +119,16 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
> struct fsxattr __user *ufa)
> {
> struct fsxattr xfa;
> + __u32 mask = FS_XFLAGS_MASK;
>
> if (copy_from_user(&xfa, ufa, sizeof(xfa)))
> return -EFAULT;
>
> + if (xfa.fsx_xflags & ~mask)
> + return -EINVAL;
I wonder if you want EOPNOTSUPP here? We don't know how to support
unknown xflags. OTOH if you all have beaten this to death while I was
out then don't start another round just for me. :P
--D
> +
> fileattr_fill_xflags(fa, xfa.fsx_xflags);
> + fa->fsx_xflags &= ~FS_XFLAG_RDONLY_MASK;
> fa->fsx_extsize = xfa.fsx_extsize;
> fa->fsx_nextents = xfa.fsx_nextents;
> fa->fsx_projid = xfa.fsx_projid;
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index 6030d0bf7ad3..e2a2f4ae242d 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -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
>
> --
> 2.47.2
>
>
next prev parent reply other threads:[~2025-07-01 18:31 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 16:20 [PATCH v6 0/6] fs: introduce file_getattr and file_setattr syscalls Andrey Albershteyn
2025-06-30 16:20 ` [PATCH v6 1/6] fs: split fileattr related helpers into separate file Andrey Albershteyn
2025-07-01 5:39 ` Amir Goldstein
2025-07-01 12:38 ` Jan Kara
2025-07-01 18:13 ` Darrick J. Wong
2025-06-30 16:20 ` [PATCH v6 2/6] lsm: introduce new hooks for setting/getting inode fsxattr Andrey Albershteyn
2025-07-01 12:39 ` Jan Kara
2025-07-01 18:18 ` Darrick J. Wong
2025-07-02 8:47 ` Andrey Albershteyn
2025-06-30 16:20 ` [PATCH v6 3/6] selinux: implement inode_file_[g|s]etattr hooks Andrey Albershteyn
2025-06-30 16:20 ` [PATCH v6 4/6] fs: make vfs_fileattr_[get|set] return -EOPNOSUPP Andrey Albershteyn
2025-06-30 18:05 ` Pali Rohár
2025-07-01 6:05 ` Amir Goldstein
2025-07-01 12:51 ` Jan Kara
2025-07-01 14:16 ` Amir Goldstein
2025-07-01 12:52 ` Jan Kara
2025-07-01 18:18 ` Darrick J. Wong
2025-06-30 16:20 ` [PATCH v6 5/6] fs: prepare for extending file_get/setattr() Andrey Albershteyn
2025-07-01 13:06 ` Jan Kara
2025-07-01 18:31 ` Darrick J. Wong [this message]
2025-07-01 19:27 ` Amir Goldstein
2025-07-01 19:40 ` Darrick J. Wong
2025-07-01 19:54 ` Pali Rohár
2025-07-02 7:03 ` Amir Goldstein
2025-07-02 9:48 ` Amir Goldstein
2025-07-02 12:24 ` Christian Brauner
2025-06-30 16:20 ` [PATCH v6 6/6] fs: introduce file_getattr and file_setattr syscalls Andrey Albershteyn
2025-07-01 12:34 ` Christian Brauner
2025-07-02 9:13 ` Amir Goldstein
2025-07-01 13:24 ` Jan Kara
2025-07-01 18:43 ` Darrick J. Wong
2025-07-01 18:54 ` Pali Rohár
2025-07-01 19:08 ` Darrick J. Wong
2025-07-01 19:17 ` Pali Rohár
2025-07-02 12:40 ` Christian Brauner
2025-07-02 13:43 ` Amir Goldstein
2025-07-02 18:37 ` Darrick J. Wong
2025-07-03 8:28 ` Christian Brauner
2025-07-03 8:42 ` Amir Goldstein
2025-07-03 8:46 ` Christian Brauner
2025-07-03 22:35 ` Darrick J. Wong
2025-07-01 6:11 ` [PATCH v6 0/6] " Amir Goldstein
2025-07-01 12:29 ` Christian Brauner
2025-07-07 12:05 ` Andrey Albershteyn
2025-07-07 12:19 ` Christian Brauner
2025-07-07 12:27 ` Andrey Albershteyn
2025-07-07 12:19 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250701183105.GP10009@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=aalbersh@kernel.org \
--cc=aalbersh@redhat.com \
--cc=amir73il@gmail.com \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=casey@schaufler-ca.com \
--cc=jack@suse.cz \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=pali@kernel.org \
--cc=paul@paul-moore.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).