From: Amir Goldstein <amir73il@gmail.com>
To: Andrey Albershteyn <aalbersh@redhat.com>
Cc: "Pali Rohár" <pali@kernel.org>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>,
linux-fsdevel@vger.kernel.org
Subject: [RFC PATCH 1/2] fs: prepare for extending [gs]etfsxattrat()
Date: Sat, 29 Mar 2025 15:33:11 +0100 [thread overview]
Message-ID: <20250329143312.1350603-2-amir73il@gmail.com> (raw)
In-Reply-To: <20250329143312.1350603-1-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 extention.
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>
---
fs/inode.c | 4 +++-
fs/ioctl.c | 19 +++++++++++++------
include/linux/fileattr.h | 22 +++++++++++++++++++++-
3 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index 3cfcb1b9865ea..6c4d08bd53052 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -3049,7 +3049,9 @@ SYSCALL_DEFINE5(setfsxattrat, int, dfd, const char __user *, filename,
if (error)
return error;
- fsxattr_to_fileattr(&fsx, &fa);
+ error = fsxattr_to_fileattr(&fsx, &fa);
+ if (error)
+ return error;
name = getname_maybe_null(filename, at_flags);
if (!name) {
diff --git a/fs/ioctl.c b/fs/ioctl.c
index 840283d8c4066..b19858db4c432 100644
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -540,8 +540,10 @@ EXPORT_SYMBOL(vfs_fileattr_get);
void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx)
{
+ __u32 mask = FS_XFALGS_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;
@@ -568,13 +570,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_XFALGS_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,
@@ -585,9 +594,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);
}
/*
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 31888fa2edf10..f682bfc7749dd 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_XFALGS_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);
--
2.34.1
next prev parent reply other threads:[~2025-03-29 14:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-29 14:33 [RFC PATCH 0/2] [gs]etfsxattrat() followup patches Amir Goldstein
2025-03-29 14:33 ` Amir Goldstein [this message]
2025-03-31 14:43 ` [RFC PATCH 1/2] fs: prepare for extending [gs]etfsxattrat() Andrey Albershteyn
2025-03-31 15:06 ` Amir Goldstein
2025-03-31 20:58 ` Dave Chinner
2025-03-29 14:33 ` [RFC PATCH 2/2] fs: add support for custom fsx_xflags_mask Amir Goldstein
2025-03-29 14:43 ` Amir Goldstein
2025-03-29 14:44 ` Pali Rohár
2025-03-29 15:23 ` Amir Goldstein
2025-04-01 10:45 ` [RFC PATCH 0/2] [gs]etfsxattrat() followup patches 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=20250329143312.1350603-2-amir73il@gmail.com \
--to=amir73il@gmail.com \
--cc=aalbersh@redhat.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=pali@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).