Skip to contentSkip to conversation

vfs: add miscattr ops

PATCH Superseded Miklos Szeredi 1 participant 2 messages Mar 3, 2021 – Mar 16, 2021

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vfs: add miscattr ops

Hi Al,

Would you mind taking a look?

Git tree for complete series rebased on v5.12-rc1 can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git#miscattr_v2

Thanks,
Miklos

---
From: Miklos Szeredi <[email protected]>
Date: Tue, 2 Mar 2021 13:38:22 +0100
Subject: vfs: add miscattr ops

There's a substantial amount of boilerplate in filesystems handling FS_IOC_[GS]ETFLAGS/ FS_IOC_FS[GS]ETXATTR ioctls.

Also due to userspace buffers being involved in the ioctl API this is difficult to stack, as shown by overlayfs issues related to these ioctls.

Introduce a new internal API named "miscattr" (fsxattr can be confused with xattr, xflags is inappropriate, since this is more than just flags).

There's significant overlap between flags and xflags and this API handles the conversions automatically, so filesystems may choose which one to use.

In ->miscattr_get() a hint is provided to the filesystem whether flags or xattr are being requested by userspace, but in this series this hint is ignored by all filesystems, since generating all the attributes is cheap.

If a filesystem doesn't implemement the miscattr API, just fall back to f_op->ioctl(). When all filesystems are converted, the fallback can be removed.

32bit compat ioctls are now handled by the generic code as well.

---
 Documentation/filesystems/locking.rst |   5 +
 Documentation/filesystems/vfs.rst     |  15 ++
 fs/ioctl.c                            | 329 ++++++++++++++++++++++++++
 include/linux/fs.h                    |   4 +
 include/linux/miscattr.h              |  53 +++++
 5 files changed, 406 insertions(+)
 create mode 100644 include/linux/miscattr.h
Documentation/filesystems/locking.rst +5 -0
index b7dcc86c92a4..a5aa2046d48f 100644
@@ -80,6 +80,9 @@ prototypes::
 				struct file *, unsigned open_flag,
 				umode_t create_mode);
 	int (*tmpfile) (struct inode *, struct dentry *, umode_t);
+	int (*miscattr_set)(struct user_namespace *mnt_userns,
+			    struct dentry *dentry, struct miscattr *ma);
+	int (*miscattr_get)(struct dentry *dentry, struct miscattr *ma);
 
 locking rules:
 	all may block
@@ -107,6 +110,8 @@ fiemap:		no
 update_time:	no
 atomic_open:	shared (exclusive if O_CREAT is set in open flags)
 tmpfile:	no
+miscattr_get:	no or exclusive
+miscattr_set:	exclusive
 ============	=============================================
 
 
Documentation/filesystems/vfs.rst +15 -0
index 2049bbf5e388..f125ce6c3b47 100644
@@ -441,6 +441,9 @@ As of kernel 2.6.22, the following members are defined:
 				   unsigned open_flag, umode_t create_mode);
 		int (*tmpfile) (struct user_namespace *, struct inode *, struct dentry *, umode_t);
 	        int (*set_acl)(struct user_namespace *, struct inode *, struct posix_acl *, int);
+		int (*miscattr_set)(struct user_namespace *mnt_userns,
+				    struct dentry *dentry, struct miscattr *ma);
+		int (*miscattr_get)(struct dentry *dentry, struct miscattr *ma);
 	};
 
 Again, all methods are called without any locks being held, unless
@@ -588,6 +591,18 @@ otherwise noted.
 	atomically creating, opening and unlinking a file in given
 	directory.
 
+``miscattr_get``
+	called on ioctl(FS_IOC_GETFLAGS) and ioctl(FS_IOC_FSGETXATTR) to
+	retrieve miscellaneous filesystem flags and attributes.  Also
+	called before the relevant SET operation to check what is being
+	changed (in this case with i_rwsem locked exclusive).  If unset,
+	then fall back to f_op->ioctl().
+
+``miscattr_set``
+	called on ioctl(FS_IOC_SETFLAGS) and ioctl(FS_IOC_FSSETXATTR) to
+	change miscellaneous filesystem flags and attributes.  Callers hold
+	i_rwsem exclusive.  If unset, then fall back to f_op->ioctl().
+
 
 The Address Space Object
 ========================
fs/ioctl.c +329 -0

353 lines not on this page · raw message

include/linux/fs.h +4 -0
index ec8f3ddf4a6a..9e7f6a592a70 100644
@@ -70,6 +70,7 @@ struct fsverity_info;
 struct fsverity_operations;
 struct fs_context;
 struct fs_parameter_spec;
+struct miscattr;
 
 extern void __init inode_init(void);
 extern void __init inode_init_early(void);
@@ -1963,6 +1964,9 @@ struct inode_operations {
 			struct dentry *, umode_t);
 	int (*set_acl)(struct user_namespace *, struct inode *,
 		       struct posix_acl *, int);
+	int (*miscattr_set)(struct user_namespace *mnt_userns,
+			    struct dentry *dentry, struct miscattr *ma);
+	int (*miscattr_get)(struct dentry *dentry, struct miscattr *ma);
 } ____cacheline_aligned;
 
 static inline ssize_t call_read_iter(struct file *file, struct kiocb *kio,
include/linux/miscattr.h new file +53 -0

53 lines not on this page · raw message

Signature · 1 line
2.26.2
#1 lore raw
Quoted 33 lines · Miklos Szeredi

Hi Al,

Would you mind taking a look?

Git tree for complete series rebased on v5.12-rc1 can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs.git#miscattr_v2

Thanks,
Miklos

---
From: Miklos Szeredi <[email protected]>
Date: Tue, 2 Mar 2021 13:38:22 +0100
Subject: vfs: add miscattr ops

There's a substantial amount of boilerplate in filesystems handling FS_IOC_[GS]ETFLAGS/ FS_IOC_FS[GS]ETXATTR ioctls.

Also due to userspace buffers being involved in the ioctl API this is difficult to stack, as shown by overlayfs issues related to these ioctls.

Introduce a new internal API named "miscattr" (fsxattr can be confused with xattr, xflags is inappropriate, since this is more than just flags).

There's significant overlap between flags and xflags and this API handles the conversions automatically, so filesystems may choose which one to use.

In ->miscattr_get() a hint is provided to the filesystem whether flags or xattr are being requested by userspace, but in this series this hint is ignored by all filesystems, since generating all the attributes is cheap.

Quoted 7 lines

If a filesystem doesn't implemement the miscattr API, just fall back to f_op->ioctl(). When all filesystems are converted, the fallback can be removed.

32bit compat ioctls are now handled by the generic code as well.

Ping?

Thanks,
Miklos