VFS: Introduce filesystem context [ver #9]
Subsystems (89)
David Howells
maintainercover VFS: Introduce filesystem context [ver #9]
Hi Al,
Can you update your tree with this?
Here are a set of patches to create a filesystem context prior to setting up a new mount, populating it with the parsed options/binary data, creating the superblock and then effecting the mount. This is also used for remount since much of the parsing stuff is common in many filesystems.
This allows namespaces and other information to be conveyed through the mount procedure.
This also allows Miklós Szeredi's idea of doing:
fd = fsopen("nfs");
write(fd, "option=val", ...);
mfd = fsmount(fd, MS_NODEV);
move_mount(mfd, "", AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH);that he presented at LSF-2017 to be implemented (see the relevant patches in the series).
I didn't use netlink as that would make the core kernel depend on CONFIG_NET and CONFIG_NETLINK and would introduce network namespacing issues.
I've implemented filesystem context handling for procfs, nfs, mqueue, cpuset, kernfs, sysfs, cgroup and afs filesystems.
Unconverted filesystems are handled by a legacy filesystem wrapper.
Significant changes:
ver #9:
(*) Dropped the fd cookie stuff and the FMODE_*/O_* split stuff.
(*) Al added an open_tree() system call to allow a mount tree to be picked
referenced or cloned into an O_PATH-style fd. This can then be used with sys_move_mount(). Dropped the O_CLONE_MOUNT and O_NON_RECURSIVE open() flags.
(*) Brought error logging back in, though only in the fs_context and not
in the task_struct.
(*) Separated MS_REMOUNT|MS_BIND handling from MS_REMOUNT handling.
(*) Used anon_inodes for the fd returned by fsopen() and fspick(). This
requires making it unconditional.
(*) Fixed lots of bugs. Especial thanks to Al and Eric Biggers for
finding them and providing patches.
(*) Wrote manual pages, which I'll post separately.
ver #8:
(*) Changed the way fsmount() mounts into the namespace according to some
of Al's ideas.
(*) Put better typing on the fd cookie obtained from __fdget() & co..
(*) Stored the fd cookie in struct nameidata rather than the dfd number.
(*) Changed sys_fsmount() to return an O_PATH-style fd rather than
actually mounting into the mount namespace.
(*) Separated internal FMODE_* handling from O_* handling to free up
certain O_* flag numbers.
(*) Added two new open flags (O_CLONE_MOUNT and O_NON_RECURSIVE) for use
with open(O_PATH) to copy a mount or mount-subtree to an O_PATH fd.
(*) Added a new syscall, sys_move_mount(), to move a mount from an
dfd+path source to a dfd+path destination.
(*) Added a file->f_mode flag (FMODE_NEED_UNMOUNT) that indicates that the
vfsmount attached to file->f_path needs 'unmounting' if set.
(*) Made sys_move_mount() clear FMODE_NEED_UNMOUNT if successful.
[!] This doesn't work quite right.
(*) Added a new syscall, fsinfo(), to query information about a
filesystem. The idea being that this will, in future, work with the fd from fsopen() too and permit querying of the parameters and metadata before fsmount() is called.
ver #7:
(*) Undo an incorrect MS_* -> SB_* conversion.
(*) Pass the mount data buffer size to all the mount-related functions that
take the data pointer. This fixes a problem where someone (say SELinux) tries to copy the mount data, assuming it to be a page in size, and overruns the buffer - thereby incurring an oops by hitting a guard page.
(*) Made the AFS filesystem use them as an example. This is a much easier to
deal with than with NFS or Ext4 as there are very few mount options.
ver #6:
(*) Dropped the supplementary error string facility for the moment.
(*) Dropped the NFS patches for the moment.
(*) Dropped the reserved file descriptor argument from fsopen() and
replaced it with three reserved pointers that must be NULL.
ver #5:
(*) Renamed sb_config -> fs_context and adjusted variable names.
(*) Differentiated the flags in sb->s_flags (now named SB_*) from those
passed to mount(2) (named MS_*).
(*) Renamed __vfs_new_fs_context() to vfs_new_fs_context() and made the
caller always provide a struct file_system_type pointer and the parameters required.
(*) Got rid of vfs_submount_fc() in favour of passing
FS_CONTEXT_FOR_SUBMOUNT to vfs_new_fs_context(). The purpose is now used more.
(*) Call ->validate() on the remount path.
(*) Got rid of the inode locking in sys_fsmount().
(*) Call security_sb_mountpoint() in the mount(2) path.
ver #4:
(*) Split the sb_config patch up somewhat.
(*) Made the supplementary error string facility something attached to the
task_struct rather than the sb_config so that error messages can be obtained from NFS doing a mount-root-and-pathwalk inside the nfs_get_tree() operation.
Further, made this managed and read by prctl rather than through the mount fd so that it's more generally available.
ver #3:
(*) Rebased on 4.12-rc1.
(*) Split the NFS patch up somewhat.
ver #2:
(*) Removed the ->fill_super() from sb_config_operations and passed it in
directly to functions that want to call it. NFS now calls nfs_fill_super() directly rather than jumping through a pointer to it since there's only the one option at the moment.
(*) Removed ->mnt_ns and ->sb from sb_config and moved ->pid_ns into
proc_sb_config.
(*) Renamed create_super -> get_tree.
(*) Renamed struct mount_context to struct sb_config and amended various
variable names.
(*) sys_fsmount() acquired AT_* flags and MS_* flags (for MNT_* flags)
arguments.
ver #1:
(*) Split the sb_config stuff out into its own header.
(*) Support non-context aware filesystems through a special set of
sb_config operations.
(*) Stored the created superblock and root dentry into the sb_config after
creation rather than directly into a vfsmount. This allows some arguments to be removed to various NFS functions.
(*) Added an explicit superblock-creation step. This allows a created
superblock to then be mounted multiple times.
(*) Added a flag to say that the sb_config is degraded and cannot have
another go at having a superblock creation whilst getting rid of the one that says it's already mounted.
Possible further developments:
(*) Implement sb reconfiguration (for now it returns ENOANO).
(*) Implement mount context support in more filesystems, ext4 being next
on my list.
(*) Move the walk-from-root stuff that nfs has to generic code so that you
can do something akin to:
mount /dev/sda1:/foo/bar /mnt
See nfs_follow_remote_path() and mount_subtree(). This is slightly tricky in NFS as we have to prevent referral loops.
(*) Work out how to get at the error message incurred by submounts
encountered during nfs_follow_remote_path().
Should the error message be moved to task_struct and made more general, perhaps retrieved with a prctl() function?
(*) Clean up/consolidate the security functions. Possibly add a
validation hook to be called at the same time as the mount context validate op.
The patches can be found here also:
https://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs.git/tag/?h=mount-api-20180710-2
on branch:
mount-context
David
---
Al Viro (2):
vfs: syscall: Add open_tree(2) to reference or clone a mount teach move_mount(2) to work with OPEN_TREE_CLONE
David Howells (30):
vfs: syscall: Add move_mount(2) to move mounts around
vfs: Suppress MS_* flag defs within the kernel unless explicitly enabled
vfs: Introduce the basic header for the new mount API's filesystem context
vfs: Add LSM hooks for the new mount API
selinux: Implement the new mount API LSM hooks
smack: Implement filesystem context security hooks
apparmor: Implement security hooks for the new mount API
tomoyo: Implement security hooks for the new mount API
vfs: Require specification of size of mount data for internal mounts
vfs: Separate changing mount flags full remount
vfs: Implement a filesystem superblock creation/configuration context
vfs: Remove unused code after filesystem context changes
procfs: Move proc_fill_super() to fs/proc/root.c
proc: Add fs_context support to procfs
ipc: Convert mqueue fs to fs_context
cpuset: Use fs_context
kernfs, sysfs, cgroup, intel_rdt: Support fs_context
hugetlbfs: Convert to fs_context
vfs: Remove kern_mount_data()
vfs: Provide documentation for new mount API
Make anon_inodes unconditional
vfs: syscall: Add fsopen() to prepare for superblock creation
vfs: syscall: Add fsmount() to create a mount for a superblock
vfs: syscall: Add fspick() to select a superblock for reconfiguration
vfs: Implement logging through fs_context
vfs: Add some logging to the core users of the fs_context log
afs: Add fs_context support
afs: Use fs_context to pass parameters over automount
vfs: syscall: Add fsinfo() to query filesystem information
afs: Add fsinfo support
Documentation/filesystems/mount_api.txt | 439 +++++++++++++++ arch/arc/kernel/setup.c | 1 arch/arm/kernel/atags_parse.c | 1 arch/ia64/kernel/perfmon.c | 3 arch/powerpc/platforms/cell/spufs/inode.c | 6 arch/s390/hypfs/inode.c | 7 arch/sh/kernel/setup.c | 1 arch/sparc/kernel/setup_32.c | 1 arch/sparc/kernel/setup_64.c | 1 arch/x86/entry/syscalls/syscall_32.tbl | 6 arch/x86/entry/syscalls/syscall_64.tbl | 6 arch/x86/kernel/cpu/intel_rdt.h | 15 arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 149 +++-- arch/x86/kernel/setup.c | 1 drivers/base/devtmpfs.c | 7 drivers/dax/super.c | 2 drivers/gpu/drm/drm_drv.c | 3 drivers/gpu/drm/i915/i915_gemfs.c | 2 drivers/infiniband/hw/qib/qib_fs.c | 7 drivers/misc/cxl/api.c | 3 drivers/misc/ibmasm/ibmasmfs.c | 11 drivers/mtd/mtdsuper.c | 26 - drivers/oprofile/oprofilefs.c | 8 drivers/scsi/cxlflash/ocxl_hw.c | 2 drivers/usb/gadget/function/f_fs.c | 7 drivers/usb/gadget/legacy/inode.c | 7 drivers/virtio/virtio_balloon.c | 2 drivers/xen/xenfs/super.c | 7 fs/9p/vfs_super.c | 2 fs/Makefile | 5 fs/adfs/super.c | 9 fs/affs/super.c | 13 fs/afs/internal.h | 9 fs/afs/mntpt.c | 147 ++--- fs/afs/super.c | 536 +++++++++++------- fs/afs/volume.c | 4 fs/aio.c | 3 fs/anon_inodes.c | 3 fs/autofs/autofs_i.h | 2 fs/autofs/init.c | 4 fs/autofs/inode.c | 3 fs/befs/linuxvfs.c | 11 fs/bfs/inode.c | 8 fs/binfmt_misc.c | 7 fs/block_dev.c | 2 fs/btrfs/super.c | 30 + fs/btrfs/tests/btrfs-tests.c | 2 fs/ceph/super.c | 3 fs/cifs/cifs_dfs_ref.c | 3 fs/cifs/cifsfs.c | 18 - fs/coda/inode.c | 11 fs/configfs/mount.c | 7 fs/cramfs/inode.c | 17 - fs/debugfs/inode.c | 14 fs/devpts/inode.c | 10 fs/ecryptfs/main.c | 2 fs/efivarfs/super.c | 9 fs/efs/super.c | 14 fs/exofs/super.c | 7 fs/ext2/super.c | 14 fs/ext4/super.c | 16 - fs/f2fs/super.c | 13 fs/fat/inode.c | 3 fs/fat/namei_msdos.c | 8 fs/fat/namei_vfat.c | 8 fs/file_table.c | 9 fs/freevxfs/vxfs_super.c | 12 fs/fs_context.c | 721 ++++++++++++++++++++++++ fs/fsopen.c | 335 +++++++++++ fs/fuse/control.c | 9 fs/fuse/inode.c | 16 - fs/gfs2/ops_fstype.c | 6 fs/gfs2/super.c | 4 fs/hfs/super.c | 12 fs/hfsplus/super.c | 12 fs/hostfs/hostfs_kern.c | 7 fs/hpfs/super.c | 11 fs/hugetlbfs/inode.c | 339 +++++++---- fs/internal.h | 6 fs/isofs/inode.c | 11 fs/jffs2/super.c | 10 fs/jfs/super.c | 11 fs/kernfs/mount.c | 88 +-- fs/libfs.c | 19 + fs/minix/inode.c | 14 fs/namespace.c | 877 ++++++++++++++++++++++------- fs/nfs/internal.h | 4 fs/nfs/namespace.c | 3 fs/nfs/nfs4namespace.c | 3 fs/nfs/nfs4super.c | 27 - fs/nfs/super.c | 22 - fs/nfsd/nfsctl.c | 8 fs/nilfs2/super.c | 10 fs/nsfs.c | 3 fs/ntfs/super.c | 13 fs/ocfs2/dlmfs/dlmfs.c | 5 fs/ocfs2/super.c | 14 fs/omfs/inode.c | 9 fs/openpromfs/inode.c | 11 fs/orangefs/orangefs-kernel.h | 2 fs/orangefs/super.c | 5 fs/overlayfs/super.c | 11 fs/pipe.c | 3 fs/pnode.c | 1 fs/proc/inode.c | 50 -- fs/proc/internal.h | 6 fs/proc/root.c | 212 +++++-- fs/pstore/inode.c | 10 fs/qnx4/inode.c | 14 fs/qnx6/inode.c | 14 fs/ramfs/inode.c | 6 fs/reiserfs/super.c | 14 fs/romfs/super.c | 13 fs/squashfs/super.c | 12 fs/statfs.c | 470 ++++++++++++++++ fs/super.c | 394 ++++++++++--- fs/sysfs/mount.c | 67 ++ fs/sysv/inode.c | 3 fs/sysv/super.c | 16 - fs/tracefs/inode.c | 10 fs/ubifs/super.c | 5 fs/udf/super.c | 16 - fs/ufs/super.c | 11 fs/xfs/xfs_super.c | 10 include/linux/cgroup.h | 3 include/linux/debugfs.h | 8 include/linux/fs.h | 47 +- include/linux/fs_context.h | 178 ++++++ include/linux/fsinfo.h | 40 + include/linux/kernfs.h | 39 + include/linux/lsm_hooks.h | 88 +++ include/linux/module.h | 6 include/linux/mount.h | 10 include/linux/mtd/super.h | 4 include/linux/ramfs.h | 4 include/linux/security.h | 74 ++ include/linux/shmem_fs.h | 3 include/linux/syscalls.h | 11 include/uapi/linux/fcntl.h | 2 include/uapi/linux/fs.h | 68 +- include/uapi/linux/fsinfo.h | 237 ++++++++ include/uapi/linux/mount.h | 75 ++ init/Kconfig | 10 init/do_mounts.c | 5 init/do_mounts_initrd.c | 1 ipc/mqueue.c | 120 +++- kernel/bpf/inode.c | 7 kernel/cgroup/cgroup-internal.h | 49 +- kernel/cgroup/cgroup-v1.c | 302 +++++----- kernel/cgroup/cgroup.c | 226 ++++--- kernel/cgroup/cpuset.c | 67 ++ kernel/trace/trace.c | 7 mm/shmem.c | 10 mm/zsmalloc.c | 3 net/socket.c | 3 net/sunrpc/rpc_pipe.c | 7 samples/statx/Makefile | 5 samples/statx/test-fsinfo.c | 539 ++++++++++++++++++ security/apparmor/apparmorfs.c | 8 security/apparmor/include/mount.h | 11 security/apparmor/lsm.c | 84 +++ security/apparmor/mount.c | 47 ++ security/inode.c | 7 security/security.c | 70 ++ security/selinux/hooks.c | 294 +++++++++- security/selinux/selinuxfs.c | 8 security/smack/smack_lsm.c | 344 ++++++++++- security/smack/smackfs.c | 9 security/tomoyo/common.h | 3 security/tomoyo/mount.c | 46 ++ security/tomoyo/tomoyo.c | 19 + 171 files changed, 7147 insertions(+), 1805 deletions(-) create mode 100644 Documentation/filesystems/mount_api.txt create mode 100644 fs/fs_context.c create mode 100644 fs/fsopen.c create mode 100644 include/linux/fs_context.h create mode 100644 include/linux/fsinfo.h create mode 100644 include/uapi/linux/fsinfo.h create mode 100644 include/uapi/linux/mount.h create mode 100644 samples/statx/test-fsinfo.c
David Howells
maintainerPATCH 1/32 vfs: syscall: Add open_tree(2) to reference or clone a mount [ver #9]
From: Al Viro <[email protected]>
open_tree(dfd, pathname, flags)
Returns an O_PATH-opened file descriptor or an error.
dfd and pathname specify the location to open, in usual fashion (see e.g. fstatat(2)). flags should be an OR of some of the following:
* AT_PATH_EMPTY, AT_NO_AUTOMOUNT, AT_SYMLINK_NOFOLLOW -
same meanings as usual
* OPEN_TREE_CLOEXEC - make the resulting descriptor
close-on-exec
* OPEN_TREE_CLONE or OPEN_TREE_CLONE | AT_RECURSIVE -
instead of opening the location in question, create a detached mount tree matching the subtree rooted at location specified by dfd/pathname. With AT_RECURSIVE the entire subtree is cloned, without it - only the part within in the mount containing the location in question. In other words, the same as mount --rbind or mount --bind would've taken. The detached tree will be dissolved on the final close of obtained file. Creation of such detached trees requires the same capabilities as doing mount --bind.
---
arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 fs/file_table.c | 9 +- fs/internal.h | 1 fs/namespace.c | 132 +++++++++++++++++++++++++++----- include/linux/fs.h | 3 + include/linux/syscalls.h | 1 include/uapi/linux/fcntl.h | 2 include/uapi/linux/mount.h | 10 ++ 9 files changed, 135 insertions(+), 25 deletions(-) create mode 100644 include/uapi/linux/mount.h
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -398,3 +398,4 @@ 384 i386 arch_prctl sys_arch_prctl __ia32_compat_sys_arch_prctl 385 i386 io_pgetevents sys_io_pgetevents __ia32_compat_sys_io_pgetevents 386 i386 rseq sys_rseq __ia32_sys_rseq +387 i386 open_tree sys_open_tree __ia32_sys_open_tree
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -343,6 +343,7 @@ 332 common statx __x64_sys_statx 333 common io_pgetevents __x64_sys_io_pgetevents 334 common rseq __x64_sys_rseq +335 common open_tree __x64_sys_open_tree # # x32-specific system call numbers start at 512 to avoid cache impact
fs/file_table.c +6 -3
@@ -189,6 +189,7 @@ static void __fput(struct file *file)struct dentry *dentry = file->f_path.dentry;struct vfsmount *mnt = file->f_path.mnt;struct inode *inode = file->f_inode; +fmode_t mode = file->f_mode;might_sleep ();
@@ -209,14 +210,14 @@ static void __fput(struct file *file) file->f_op->release (inode, file);security_file_free (file);if (unlikely (S_ISCHR (inode->i_mode) && inode->i_cdev !=NULL && - !(file->f_mode &FMODE_PATH ))) { + !(mode &FMODE_PATH ))) {cdev_put (inode->i_cdev); }fops_put (file->f_op);put_pid (file->f_owner.pid); -if ((file->f_mode & (FMODE_READ |FMODE_WRITE )) ==FMODE_READ ) +if ((mode & (FMODE_READ |FMODE_WRITE )) ==FMODE_READ )i_readcount_dec (inode); -if (file->f_mode &FMODE_WRITER ) { +if (mode &FMODE_WRITER ) {put_write_access (inode);__mnt_drop_write (mnt); }
@@ -224,6 +225,8 @@ static void __fput(struct file *file) file->f_path.mnt =NULL ; file->f_inode =NULL ;file_free (file); +if (unlikely (mode &FMODE_NEED_UNMOUNT )) +dissolve_on_fput (mnt);dput (dentry);mntput (mnt); }
fs/internal.h +1 -0
@@ -85,6 +85,7 @@ extern void __mnt_drop_write(struct vfsmount *);extern void __mnt_drop_write_file (struct file *);extern void mnt_drop_write_file_path (struct file *); +extern void dissolve_on_fput (struct vfsmount *);/* * fs_struct.c */
fs/namespace.c +110 -22
185 lines not on this page · raw message
include/linux/fs.h +3 -0
@@ -154,6 +154,9 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,/* File is capable of returning -EAGAIN if I/O will block */ #define FMODE_NOWAIT ((__force fmode_t)0x8000000) +/* File represents mount that needs unmounting */ +#define FMODE_NEED_UNMOUNT ((__force fmode_t)0x10000000) +/* * Flag for rw_copy_check_uvector and compat_rw_copy_check_uvector * that indicates that they should check the contents of the iovec are
include/linux/syscalls.h +1 -0
@@ -900,6 +900,7 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, unsigned mask, struct statx __user *buffer);asmlinkage long sys_rseq (struct rseq __user *rseq,uint32_t rseq_len,int flags,uint32_t sig); +asmlinkage long sys_open_tree (int dfd,const char __user *path,unsigned flags);/* * Architecture-specific system calls
include/uapi/linux/fcntl.h +2 -0
@@ -90,5 +90,7 @@#define AT_STATX_FORCE_SYNC 0x2000/* - Force the attributes to be sync'd with the server */ #define AT_STATX_DONT_SYNC 0x4000/* - Don't sync attributes with the server */ +#define AT_RECURSIVE 0x8000/* Apply to the entire subtree */ +#endif /* _UAPI_LINUX_FCNTL_H */
include/uapi/linux/mount.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _UAPI_LINUX_MOUNT_H +#define _UAPI_LINUX_MOUNT_H + +/* +* open_tree() flags. +*/ +#define OPEN_TREE_CLONE 1/* Clone the target tree and attach the clone */ +#define OPEN_TREE_CLOEXEC O_CLOEXEC/* Close the file on execve() */ + +#endif /* _UAPI_LINUX_MOUNT_H */
David Howells
maintainerPATCH 1/1 Add manpages for move_mount(2) and open_tree(2)
Add manual pages to document the move_mount and open_tree() system calls.
---
man2/move_mount.2 | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++ man2/open_tree.2 | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 534 insertions(+) create mode 100644 man2/move_mount.2 create mode 100644 man2/open_tree.2
man2/move_mount.2 new file +274 -0
@@ -0,0 +1,274 @@ +'\" t +.\" Copyright (c) 2018 David Howells <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.TH MOVE_MOUNT 2 2018-06-08 "Linux" "Linux Programmer's Manual" +.SH NAME +move_mount \- Move mount objects around the filesystem topology +.SH SYNOPSIS +.nf +.B #include <sys/types.h> +.br +.B #include <sys/mount.h> +.br +.B #include <unistd.h> +.br +.BR "#include <fcntl.h> " "/* Definition of AT_* constants */" +.PP +.BI "int move_mount(int " from_dirfd ", const char *" from_pathname "," +.BI " int " to_dirfd ", const char *" to_pathname "," +.BI " unsigned int " flags ); +.fi +.PP +.IR Note : +There are no glibc wrappers for these system calls. +.SH DESCRIPTION +The +.BR move_mount () +call moves a mount from one place to another; it can also be used to attach an +unattached mount created by +.BR fsmount "() or " open_tree "() with " OPEN_TREE_CLONE . +.PP +If +.BR move_mount () +is called repeatedly with a file descriptor that refers to a mount object, +then the object will be attached/moved the first time and then moved again and +again and again, detaching it from the previous mountpoint each time. +.PP +To access the source mount object or the destination mountpoint, no +permissions are required on the object itself, but if either pathname is +supplied, execute (search) permission is required on all of the directories +specified in +.IR from_pathname " or " to_pathname . +.PP +The caller does, however, require the appropriate capabilities or permission +to effect a mount. +.PP +.BR move_mount () +uses +.IR from_pathname ", " from_dirfd " and some " flags +to locate the mount object to be moved and +.IR to_pathname ", " to_dirfd " and some other " flags +to locate the destination mountpoint. Each lookup can be done in one of a +variety of ways: +.TP +[*] By absolute path. +The pathname points to an absolute path and the dirfd is ignored. The file is +looked up by name, starting from the root of the filesystem as seen by the +calling process. +.TP +[*] By cwd-relative path. +The pathname points to a relative path and the dirfd is +.IR AT_FDCWD . +The file is looked up by name, starting from the current working directory. +.TP +[*] By dir-relative path. +The pathname points to relative path and the dirfd indicates a file descriptor +pointing to a directory. The file is looked up by name, starting from the +directory specified by +.IR dirfd . +.TP +[*] By file descriptor. +The pathname points to "", the dirfd points directly to the mount object to +move or the destination mount point and the appropriate +.B *_EMPTY_PATH +flag is set. +.PP +.I flags +can be used to influence a path-based lookup. A value for +.I flags +is constructed by OR'ing together zero or more of the following constants: +.TP +.BR MOVE_MOUNT_F_EMPTY_PATH +.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d +If +.I from_pathname +is an empty string, operate on the file referred to by +.IR from_dirfd +(which may have been obtained using the +.BR open (2) +.B O_PATH +flag or +.BR open_tree ()) +If +.I from_dirfd +is +.BR AT_FDCWD , +the call operates on the current working directory. +In this case, +.I from_dirfd +can refer to any type of file, not just a directory. +This flag is Linux-specific; define +.B _GNU_SOURCE +.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed +to obtain its definition. +.TP +.B MOVE_MOUNT_T_EMPTY_PATH +As above, but operating on +.IR to_pathname " and " to_dirfd . +.TP +.B MOVE_MOUNT_F_NO_AUTOMOUNT +Don't automount the terminal ("basename") component of +.I from_pathname +if it is a directory that is an automount point. This allows a mount object +that has an automount point at its root to be moved and prevents unintended +triggering of an automount point. +The +.B MOVE_MOUNT_F_NO_AUTOMOUNT +flag has no effect if the automount point has already been mounted over. This +flag is Linux-specific; define +.B _GNU_SOURCE +.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed +to obtain its definition. +.TP +.B MOVE_MOUNT_T_NO_AUTOMOUNT +As above, but operating on +.IR to_pathname " and " to_dirfd . +This allows an automount point to be manually mounted over. +.TP +.B MOVE_MOUNT_F_SYMLINKS +If +.I from_pathname +is a symbolic link, then dereference it. The default for +.BR move_mount () +is to not follow symlinks. +.TP +.B MOVE_MOUNT_T_SYMLINKS +As above, but operating on +.IR to_pathname " and " to_dirfd . + +.SH EXAMPLES +The +.BR move_mount () +function can be used like the following: +.PP +.RS +.nf +move_mount(AT_FDCWD, "/a", AT_FDCWD, "/b", 0); +.fi +.RE +.PP +This would move the object mounted on "/a" to "/b". It can also be used in +conjunction with +.BR open_tree "(2) or " open "(2) with " O_PATH : +.PP +.RS +.nf +fd = open_tree(AT_FDCWD, "/mnt", 0); +move_mount(fd, "", AT_FDCWD, "/mnt2", MOVE_MOUNT_F_EMPTY_PATH); +move_mount(fd, "", AT_FDCWD, "/mnt3", MOVE_MOUNT_F_EMPTY_PATH); +move_mount(fd, "", AT_FDCWD, "/mnt4", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.RE +.PP +This would attach the path point for "/mnt" to fd, then it would move the +mount to "/mnt2", then move it to "/mnt3" and finally to "/mnt4". +.PP +It can also be used to attach new mounts: +.PP +.RS +.nf +sfd = fsopen("ext4", FSOPEN_CLOEXEC); +write(sfd, "s /dev/sda1"); +write(sfd, "o user_xattr"); +mfd = fsmount(sfd, FSMOUNT_CLOEXEC, MS_NODEV); +move_mount(mfd, "", AT_FDCWD, "/home", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.RE +.PP +Which would open the Ext4 filesystem mounted on "/dev/sda1", turn on user +extended attribute support and create a mount object for it. Finally, the new +mount object would be attached with +.BR move_mount () +to "/home". + + +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.SH RETURN VALUE +On success, 0 is returned. On error, \-1 is returned, and +.I errno +is set appropriately. +.SH ERRORS +.TP +.B EACCES +Search permission is denied for one of the directories +in the path prefix of +.IR pathname . +(See also +.BR path_resolution (7).) +.TP +.B EBADF +.IR from_dirfd " or " to_dirfd +is not a valid open file descriptor. +.TP +.B EFAULT +.IR from_pathname " or " to_pathname +is NULL or either one point to a location outside the process's accessible +address space. +.TP +.B EINVAL +Reserved flag specified in +.IR flags . +.TP +.B ELOOP +Too many symbolic links encountered while traversing the pathname. +.TP +.B ENAMETOOLONG +.IR from_pathname " or " to_pathname +is too long. +.TP +.B ENOENT +A component of +.IR from_pathname " or " to_pathname +does not exist, or one is an empty string and the appropriate +.B *_EMPTY_PATH +was not specified in +.IR flags . +.TP +.B ENOMEM +Out of memory (i.e., kernel memory). +.TP +.B ENOTDIR +A component of the path prefix of +.IR from_pathname " or " to_pathname +is not a directory or one or the other is relative and the appropriate +.I *_dirfd +is a file descriptor referring to a file other than a directory. +.SH VERSIONS +.BR move_mount () +was added to Linux in kernel 4.18. +.SH CONFORMING TO +.BR move_mount () +is Linux-specific. +.SH NOTES +Glibc does not (yet) provide a wrapper for the +.BR move_mount () +system call; call it using +.BR syscall (2). +.SH SEE ALSO +.BR fsmount (2), +.BR fsopen (2), +.BR open_tree (2)
man2/open_tree.2 new file +260 -0
260 lines not on this page · raw message
Re: [MANPAGE PATCH] Add manpages for move_mount(2) and open_tree(2)
Hello David,
Your wrote a series of manual pages patches (of which the mail below is one) for the new mount API about a year before the code patches were actually released in the kernel.
I'd like to check that these man-pages patches are up to date before merging them. I think they may not be, since there is one patch for fsinfo(2) which does not exist in the kernel, and no manual page for fsconfig(2). I imagine that details may also have changed in the system calls that were ultimately merged.
Could you write a manual page for fsconfig(2) please?
With respect to the patch below, would you be willing to:
* split it into two pieces, one for each page.
* review the content to see if it accurately reflects what was merged into the kernel and then resubmit please?
Thanks,
Michael
Quoted 558 lines · David Howells
Add manual pages to document the
move_mountandopen_tree()system calls.Signed-off-by David Howells <[email protected]>---
man2/move_mount.2 | 274 +++++++++++++++++++++++++++++++++++++++++++++++++++++ man2/open_tree.2 | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 534 insertions(+) create mode 100644 man2/move_mount.2 create mode 100644 man2/open_tree.2man2/move_mount.2 new file +274
-0@@ -0,0 +1,274 @@ +'\" t +.\" Copyright (c) 2018 David Howells <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.TH MOVE_MOUNT 2 2018-06-08 "Linux" "Linux Programmer's Manual" +.SH NAME +move_mount \- Move mount objects around the filesystem topology +.SH SYNOPSIS +.nf +.B #include <sys/types.h> +.br +.B #include <sys/mount.h> +.br +.B #include <unistd.h> +.br +.BR "#include <fcntl.h> " "/* Definition of AT_* constants */" +.PP +.BI "int move_mount(int " from_dirfd ", const char *" from_pathname "," +.BI " int " to_dirfd ", const char *" to_pathname "," +.BI " unsigned int " flags ); +.fi +.PP +.IR Note : +There are no glibc wrappers for these system calls. +.SH DESCRIPTION +The +.BR move_mount () +call moves a mount from one place to another; it can also be used to attach an +unattached mount created by +.BR fsmount "() or " open_tree "() with " OPEN_TREE_CLONE . +.PP +If +.BR move_mount () +is called repeatedly with a file descriptor that refers to a mount object, +then the object will be attached/moved the first time and then moved again and +again and again, detaching it from the previous mountpoint each time. +.PP +To access the source mount object or the destination mountpoint, no +permissions are required on the object itself, but if either pathname is +supplied, execute (search) permission is required on all of the directories +specified in +.IR from_pathname " or " to_pathname . +.PP +The caller does, however, require the appropriate capabilities or permission +to effect a mount. +.PP +.BR move_mount () +uses +.IR from_pathname ", " from_dirfd " and some " flags +to locate the mount object to be moved and +.IR to_pathname ", " to_dirfd " and some other " flags +to locate the destination mountpoint. Each lookup can be done in one of a +variety of ways: +.TP +[*] By absolute path. +The pathname points to an absolute path and the dirfd is ignored. The file is +looked up by name, starting from the root of the filesystem as seen by the +calling process. +.TP +[*] By cwd-relative path. +The pathname points to a relative path and the dirfd is +.IR AT_FDCWD . +The file is looked up by name, starting from the current working directory. +.TP +[*] By dir-relative path. +The pathname points to relative path and the dirfd indicates a file descriptor +pointing to a directory. The file is looked up by name, starting from the +directory specified by +.IR dirfd . +.TP +[*] By file descriptor. +The pathname points to "", the dirfd points directly to the mount object to +move or the destination mount point and the appropriate +.B *_EMPTY_PATH +flag is set. +.PP +.I flags +can be used to influence a path-based lookup. A value for +.I flags +is constructed by OR'ing together zero or more of the following constants: +.TP +.BR MOVE_MOUNT_F_EMPTY_PATH +.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d +If +.I from_pathname +is an empty string, operate on the file referred to by +.IR from_dirfd +(which may have been obtained using the +.BR open (2) +.B O_PATH +flag or +.BR open_tree ()) +If +.I from_dirfd +is +.BR AT_FDCWD , +the call operates on the current working directory. +In this case, +.I from_dirfd +can refer to any type of file, not just a directory. +This flag is Linux-specific; define +.B _GNU_SOURCE +.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed +to obtain its definition. +.TP +.B MOVE_MOUNT_T_EMPTY_PATH +As above, but operating on +.IR to_pathname " and " to_dirfd . +.TP +.B MOVE_MOUNT_F_NO_AUTOMOUNT +Don't automount the terminal ("basename") component of +.I from_pathname +if it is a directory that is an automount point. This allows a mount object +that has an automount point at its root to be moved and prevents unintended +triggering of an automount point. +The +.B MOVE_MOUNT_F_NO_AUTOMOUNT +flag has no effect if the automount point has already been mounted over. This +flag is Linux-specific; define +.B _GNU_SOURCE +.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed +to obtain its definition. +.TP +.B MOVE_MOUNT_T_NO_AUTOMOUNT +As above, but operating on +.IR to_pathname " and " to_dirfd . +This allows an automount point to be manually mounted over. +.TP +.B MOVE_MOUNT_F_SYMLINKS +If +.I from_pathname +is a symbolic link, then dereference it. The default for +.BR move_mount () +is to not follow symlinks. +.TP +.B MOVE_MOUNT_T_SYMLINKS +As above, but operating on +.IR to_pathname " and " to_dirfd . + +.SH EXAMPLES +The +.BR move_mount () +function can be used like the following: +.PP +.RS +.nf +move_mount(AT_FDCWD, "/a", AT_FDCWD, "/b", 0); +.fi +.RE +.PP +This would move the object mounted on "/a" to "/b". It can also be used in +conjunction with +.BR open_tree "(2) or " open "(2) with " O_PATH : +.PP +.RS +.nf +fd = open_tree(AT_FDCWD, "/mnt", 0); +move_mount(fd, "", AT_FDCWD, "/mnt2", MOVE_MOUNT_F_EMPTY_PATH); +move_mount(fd, "", AT_FDCWD, "/mnt3", MOVE_MOUNT_F_EMPTY_PATH); +move_mount(fd, "", AT_FDCWD, "/mnt4", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.RE +.PP +This would attach the path point for "/mnt" to fd, then it would move the +mount to "/mnt2", then move it to "/mnt3" and finally to "/mnt4". +.PP +It can also be used to attach new mounts: +.PP +.RS +.nf +sfd = fsopen("ext4", FSOPEN_CLOEXEC); +write(sfd, "s /dev/sda1"); +write(sfd, "o user_xattr"); +mfd = fsmount(sfd, FSMOUNT_CLOEXEC, MS_NODEV); +move_mount(mfd, "", AT_FDCWD, "/home", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.RE +.PP +Which would open the Ext4 filesystem mounted on "/dev/sda1", turn on user +extended attribute support and create a mount object for it. Finally, the new +mount object would be attached with +.BR move_mount () +to "/home". + + +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.SH RETURN VALUE +On success, 0 is returned. On error, \-1 is returned, and +.I errno +is set appropriately. +.SH ERRORS +.TP +.B EACCES +Search permission is denied for one of the directories +in the path prefix of +.IR pathname . +(See also +.BR path_resolution (7).) +.TP +.B EBADF +.IR from_dirfd " or " to_dirfd +is not a valid open file descriptor. +.TP +.B EFAULT +.IR from_pathname " or " to_pathname +is NULL or either one point to a location outside the process's accessible +address space. +.TP +.B EINVAL +Reserved flag specified in +.IR flags . +.TP +.B ELOOP +Too many symbolic links encountered while traversing the pathname. +.TP +.B ENAMETOOLONG +.IR from_pathname " or " to_pathname +is too long. +.TP +.B ENOENT +A component of +.IR from_pathname " or " to_pathname +does not exist, or one is an empty string and the appropriate +.B *_EMPTY_PATH +was not specified in +.IR flags . +.TP +.B ENOMEM +Out of memory (i.e., kernel memory). +.TP +.B ENOTDIR +A component of the path prefix of +.IR from_pathname " or " to_pathname +is not a directory or one or the other is relative and the appropriate +.I *_dirfd +is a file descriptor referring to a file other than a directory. +.SH VERSIONS +.BR move_mount () +was added to Linux in kernel 4.18. +.SH CONFORMING TO +.BR move_mount () +is Linux-specific. +.SH NOTES +Glibc does not (yet) provide a wrapper for the +.BR move_mount () +system call; call it using +.BR syscall (2). +.SH SEE ALSO +.BR fsmount (2), +.BR fsopen (2), +.BR open_tree (2)man2/open_tree.2 new file +260
-0@@ -0,0 +1,260 @@ +'\" t +.\" Copyright (c) 2018 David Howells <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.TH OPEN_TREE 2 2018-06-08 "Linux" "Linux Programmer's Manual" +.SH NAME +open_tree \- Pick or clone mount object and attach to fd +.SH SYNOPSIS +.nf +.B #include <sys/types.h> +.br +.B #include <sys/mount.h> +.br +.B #include <unistd.h> +.br +.BR "#include <fcntl.h> " "/* Definition of AT_* constants */" +.PP +.BI "int open_tree(int " dirfd ", const char *" pathname ", unsigned int " flags ); +.fi +.PP +.IR Note : +There are no glibc wrappers for these system calls. +.SH DESCRIPTION +.BR open_tree () +picks the mount object specified by the pathname and attaches it to a new file +descriptor or clones it and attaches the clone to the file descriptor. The +resultant file descriptor is indistinguishable from one produced by +.BR open "(2) with " O_PATH . +.PP +In the case that the mount object is cloned, the clone will be "unmounted" and +destroyed when the file descriptor is closed if it is not otherwise mounted +somewhere by calling +.BR move_mount (2). +.PP +To select a mount object, no permissions are required on the object referred +to by the path, but execute (search) permission is required on all of the +directories in +.I pathname +that lead to the object. +.PP +To clone an object, however, the caller must have mount capabilities and +permissions. +.PP +.BR open_tree () +uses +.IR pathname ", " dirfd " and " flags +to locate the target object in one of a variety of ways: +.TP +[*] By absolute path. +.I pathname +points to an absolute path and +.I dirfd +is ignored. The object is looked up by name, starting from the root of the +filesystem as seen by the calling process. +.TP +[*] By cwd-relative path. +.I pathname +points to a relative path and +.IR dirfd " is " AT_FDCWD . +The object is looked up by name, starting from the current working directory. +.TP +[*] By dir-relative path. +.I pathname +points to relative path and +.I dirfd +indicates a file descriptor pointing to a directory. The object is looked up +by name, starting from the directory specified by +.IR dirfd . +.TP +[*] By file descriptor. +.I pathname +is "", +.I dirfd +indicates a file descriptor and +.B AT_EMPTY_PATH +is set in +.IR flags . +The mount attached to the file descriptor is queried directly. The file +descriptor may point to any type of file, not just a directory. + +.\"______________________________________________________________ +.PP +.I flags +can be used to control the operation of the function and to influence a +path-based lookup. A value for +.I flags +is constructed by OR'ing together zero or more of the following constants: +.TP +.BR AT_EMPTY_PATH +.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d +If +.I pathname +is an empty string, operate on the file referred to by +.IR dirfd +(which may have been obtained from +.BR open "(2) with" +.BR O_PATH ", from " fsmount (2) +or from another +.BR open_tree ()). +If +.I dirfd +is +.BR AT_FDCWD , +the call operates on the current working directory. +In this case, +.I dirfd +can refer to any type of file, not just a directory. +This flag is Linux-specific; define +.B _GNU_SOURCE +.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed +to obtain its definition. +.TP +.BR AT_NO_AUTOMOUNT +Don't automount the terminal ("basename") component of +.I pathname +if it is a directory that is an automount point. This flag allows the +automount point itself to be picked up or a mount cloned that is rooted on the +automount point. The +.B AT_NO_AUTOMOUNT +flag has no effect if the mount point has already been mounted over. +This flag is Linux-specific; define +.B _GNU_SOURCE +.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed +to obtain its definition. +.TP +.B AT_SYMLINK_NOFOLLOW +If +.I pathname +is a symbolic link, do not dereference it: instead pick up or clone a mount +rooted on the link itself. +.TP +.B OPEN_TREE_CLOEXEC +Set the close-on-exec flag for the new file descriptor. This will cause the +file descriptor to be closed automatically when a process exec's. +.TP +.B OPEN_TREE_CLONE +Rather than directly attaching the selected object to the file descriptor, +clone the object, set the root of the new mount object to that point and +attach the clone to the file descriptor. +.TP +.B AT_RECURSIVE +This is only permitted in conjunction with OPEN_TREE_CLONE. It causes the +entire mount subtree rooted at the selected spot to be cloned rather than just +that one mount object. + + +.SH EXAMPLE +The +.BR open_tree () +function can be used like the following: +.PP +.RS +.nf +fd1 = open_tree(AT_FDCWD, "/mnt", 0); +fd2 = open_tree(fd1, "", + AT_EMPTY_PATH | OPEN_TREE_CLONE | AT_RECURSIVE); +move_mount(fd2, "", AT_FDCWD, "/mnt2", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.RE +.PP +This would attach the path point for "/mnt" to fd1, then it would copy the +entire subtree at the point referred to by fd1 and attach that to fd2; lastly, +it would attach the clone to "/mnt2". + + +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.SH RETURN VALUE +On success, the new file descriptor is returned. On error, \-1 is returned, +and +.I errno +is set appropriately. +.SH ERRORS +.TP +.B EACCES +Search permission is denied for one of the directories +in the path prefix of +.IR pathname . +(See also +.BR path_resolution (7).) +.TP +.B EBADF +.I dirfd +is not a valid open file descriptor. +.TP +.B EFAULT +.I pathname +is NULL or +.IR pathname +point to a location outside the process's accessible address space. +.TP +.B EINVAL +Reserved flag specified in +.IR flags . +.TP +.B ELOOP +Too many symbolic links encountered while traversing the pathname. +.TP +.B ENAMETOOLONG +.I pathname +is too long. +.TP +.B ENOENT +A component of +.I pathname +does not exist, or +.I pathname +is an empty string and +.B AT_EMPTY_PATH +was not specified in +.IR flags . +.TP +.B ENOMEM +Out of memory (i.e., kernel memory). +.TP +.B ENOTDIR +A component of the path prefix of +.I pathname +is not a directory or +.I pathname +is relative and +.I dirfd +is a file descriptor referring to a file other than a directory. +.SH VERSIONS +.BR open_tree () +was added to Linux in kernel 4.18. +.SH CONFORMING TO +.BR open_tree () +is Linux-specific. +.SH NOTES +Glibc does not (yet) provide a wrapper for the +.BR open_tree () +system call; call it using +.BR syscall (2). +.SH SEE ALSO +.BR fsmount (2), +.BR move_mount (2), +.BR open (2)
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
David Howells
maintainerPATCH 2/32 vfs: syscall: Add move_mount(2) to move mounts around [ver #9]
In reply to David HowellsAdd a move_mount() system call that will move a mount from one place to another and, in the next commit, allow to attach an unattached mount tree.
The new system call looks like the following:
int move_mount(int from_dfd, const char *from_path,
int to_dfd, const char *to_path, unsigned int flags);
---
arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 fs/namespace.c | 102 ++++++++++++++++++++++++++------ include/linux/lsm_hooks.h | 6 ++ include/linux/security.h | 7 ++ include/linux/syscalls.h | 3 + include/uapi/linux/mount.h | 11 +++ security/security.c | 5 ++ 8 files changed, 118 insertions(+), 18 deletions(-)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -399,3 +399,4 @@ 385 i386 io_pgetevents sys_io_pgetevents __ia32_compat_sys_io_pgetevents 386 i386 rseq sys_rseq __ia32_sys_rseq 387 i386 open_tree sys_open_tree __ia32_sys_open_tree +388 i386 move_mount sys_move_mount __ia32_sys_move_mount
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -344,6 +344,7 @@ 333 common io_pgetevents __x64_sys_io_pgetevents 334 common rseq __x64_sys_rseq 335 common open_tree __x64_sys_open_tree +336 common move_mount __x64_sys_move_mount # # x32-specific system call numbers start at 512 to avoid cache impact
fs/namespace.c +84 -18
153 lines not on this page · raw message
include/linux/lsm_hooks.h +6 -0
@@ -144,6 +144,10 @@* Parse a string of security data filling in the opts structure * @options string containing all mount options known by the LSM * @opts binary data structure usable by the LSM +* @move_mount: +* Check permission before a mount is moved. +* @from_path indicates the mount that is going to be moved. +* @to_path indicates the mountpoint that will be mounted upon. * @dentry_init_security: * Compute a context for a dentry as the inode is not yet available * since NFSv4 has no label backed by an EA anyway.
@@ -1475,6 +1479,7 @@ union security_list_options {unsigned long kern_flags, unsigned long *set_kern_flags);int (*sb_parse_opts_str)(char *options,struct security_mnt_opts *opts); +int (*move_mount)(const struct path *from_path,const struct path *to_path);int (*dentry_init_security)(struct dentry *dentry,int mode,const struct qstr *name,void **ctx,u32 *ctxlen);
@@ -1806,6 +1811,7 @@ struct security_hook_heads {struct hlist_head sb_set_mnt_opts;struct hlist_head sb_clone_mnt_opts;struct hlist_head sb_parse_opts_str; +struct hlist_head move_mount;struct hlist_head dentry_init_security;struct hlist_head dentry_create_files_as;#ifdef CONFIG_SECURITY_PATH
include/linux/security.h +7 -0
@@ -245,6 +245,7 @@ int security_sb_clone_mnt_opts(const struct super_block *oldsb,unsigned long kern_flags, unsigned long *set_kern_flags);int security_sb_parse_opts_str (char *options,struct security_mnt_opts *opts); +int security_move_mount (const struct path *from_path,const struct path *to_path);int security_dentry_init_security (struct dentry *dentry,int mode,const struct qstr *name,void **ctx,u32 *ctxlen);
@@ -598,6 +599,12 @@ static inline int security_sb_parse_opts_str(char *options, struct security_mnt_return 0 ; } +static inline int security_move_mount (const struct path *from_path, +const struct path *to_path) +{ +return 0 ; +} +static inline int security_inode_alloc (struct inode *inode) {return 0 ;
include/linux/syscalls.h +3 -0
@@ -901,6 +901,9 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,asmlinkage long sys_rseq (struct rseq __user *rseq,uint32_t rseq_len,int flags,uint32_t sig);asmlinkage long sys_open_tree (int dfd,const char __user *path,unsigned flags); +asmlinkage long sys_move_mount (int from_dfd,const char __user *from_path, +int to_dfd,const char __user *to_path, +unsigned int ms_flags);/* * Architecture-specific system calls
include/uapi/linux/mount.h +11 -0
@@ -7,4 +7,15 @@#define OPEN_TREE_CLONE 1/* Clone the target tree and attach the clone */ #define OPEN_TREE_CLOEXEC O_CLOEXEC/* Close the file on execve() */ +/* +* move_mount() flags. +*/ +#define MOVE_MOUNT_F_SYMLINKS 0x00000001/* Follow symlinks on from path */ +#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002/* Follow automounts on from path */ +#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004/* Empty from path permitted */ +#define MOVE_MOUNT_T_SYMLINKS 0x00000010/* Follow symlinks on to path */ +#define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020/* Follow automounts on to path */ +#define MOVE_MOUNT_T_EMPTY_PATH 0x00000040/* Empty to path permitted */ +#define MOVE_MOUNT__MASK 0x00000077 +#endif /* _UAPI_LINUX_MOUNT_H */
security/security.c +5 -0
@@ -437,6 +437,11 @@ int security_sb_parse_opts_str(char *options, struct security_mnt_opts *opts) }EXPORT_SYMBOL (security_sb_parse_opts_str); +int security_move_mount (const struct path *from_path,const struct path *to_path) +{ +return call_int_hook (move_mount,0 , from_path, to_path); +} +int security_inode_alloc (struct inode *inode) { inode->i_security =NULL ;
David Howells
maintainerPATCH 3/32 teach move_mount(2) to work with OPEN_TREE_CLONE [ver #9]
In reply to David HowellsFrom: Al Viro <[email protected]>
Allow a detached tree created by open_tree(..., OPEN_TREE_CLONE) to be attached by move_mount(2).
If by the time of final fput() of OPEN_TREE_CLONE-opened file its tree is not detached anymore, it won't be dissolved. move_mount(2) is adjusted to handle detached source.
That gives us equivalents of mount --bind and mount --rbind.
---
fs/namespace.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
fs/namespace.c +20 -6
@@ -1845,8 +1845,10 @@ void dissolve_on_fput(struct vfsmount *mnt) {namespace_lock ();lock_mount_hash (); -mntget (mnt); -umount_tree (real_mount (mnt),UMOUNT_SYNC ); +if (!real_mount (mnt)->mnt_ns) { +mntget (mnt); +umount_tree (real_mount (mnt),UMOUNT_SYNC ); + }unlock_mount_hash ();namespace_unlock (); }
@@ -2453,6 +2455,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path)struct mount *old;struct mountpoint *mp;int err; +bool attached; mp =lock_mount (new_path); err =PTR_ERR (mp);
@@ -2463,10 +2466,19 @@ static int do_move_mount(struct path *old_path, struct path *new_path) p =real_mount (new_path->mnt); err = -EINVAL ; -if (!check_mnt (p) || !check_mnt (old)) +/* The mountpoint must be in our namespace. */ +if (!check_mnt (p)) + goto out1; +/* The thing moved should be either ours or completely unattached. */ +if (old->mnt_ns && !check_mnt (old)) goto out1; -if (!mnt_has_parent (old)) + attached =mnt_has_parent (old); +/* +* We need to allow open_tree(OPEN_TREE_CLONE) followed by +* move_mount(), but mustn't allow "/" to be moved. +*/ +if (old->mnt_ns && !attached) goto out1;if (old->mnt.mnt_flags &MNT_LOCKED )
@@ -2481,7 +2493,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path)/* * Don't move a mount residing in a shared parent. */ -if (IS_MNT_SHARED (old->mnt_parent)) +if (attached &&IS_MNT_SHARED (old->mnt_parent)) goto out1;/* * Don't move a mount tree containing unbindable mounts to a destination
@@ -2495,7 +2507,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path) goto out1; err =attach_recursive_mnt (old,real_mount (new_path->mnt), mp, - &parent_path); + attached ? &parent_path :NULL );if (err) goto out1;
@@ -3179,6 +3191,8 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,/* * Move a mount from one place to another. +* In combination with open_tree(OPEN_TREE_CLONE [| AT_RECURSIVE]) it can be +* used to copy a mount subtree. * * Note the flags value is a combination of MOVE_MOUNT_* flags. */
David Howells
maintainerPATCH 4/32 vfs: Suppress MS_* flag defs within the kernel unless explicitly enabled [ver #9]
In reply to David HowellsOnly the mount namespace code that implements mount(2) should be using the MS_* flags. Suppress them inside the kernel unless uapi/linux/mount.h is included.
---
arch/arc/kernel/setup.c | 1 + arch/arm/kernel/atags_parse.c | 1 + arch/sh/kernel/setup.c | 1 + arch/sparc/kernel/setup_32.c | 1 + arch/sparc/kernel/setup_64.c | 1 + arch/x86/kernel/setup.c | 1 + drivers/base/devtmpfs.c | 1 + fs/f2fs/super.c | 2 + fs/pnode.c | 1 + fs/super.c | 1 + include/uapi/linux/fs.h | 56 ++++------------------------------------- include/uapi/linux/mount.h | 54 ++++++++++++++++++++++++++++++++++++++++ init/do_mounts.c | 1 + init/do_mounts_initrd.c | 1 + security/apparmor/lsm.c | 1 + security/apparmor/mount.c | 1 + security/selinux/hooks.c | 1 + security/tomoyo/mount.c | 1 + 18 files changed, 75 insertions(+), 52 deletions(-)
arch/arc/kernel/setup.c +1 -0
@@ -19,6 +19,7 @@#include <linux/of_fdt.h> #include <linux/of.h> #include <linux/cache.h> +#include <uapi/linux/mount.h> #include <asm/sections.h> #include <asm/arcregs.h> #include <asm/tlb.h>
arch/arm/kernel/atags_parse.c +1 -0
@@ -24,6 +24,7 @@#include <linux/root_dev.h> #include <linux/screen_info.h> #include <linux/memblock.h> +#include <uapi/linux/mount.h> #include <asm/setup.h> #include <asm/system_info.h>
arch/sh/kernel/setup.c +1 -0
@@ -32,6 +32,7 @@#include <linux/of.h> #include <linux/of_fdt.h> #include <linux/uaccess.h> +#include <uapi/linux/mount.h> #include <asm/io.h> #include <asm/page.h> #include <asm/elf.h>
arch/sparc/kernel/setup_32.c +1 -0
@@ -34,6 +34,7 @@#include <linux/kdebug.h> #include <linux/export.h> #include <linux/start_kernel.h> +#include <uapi/linux/mount.h> #include <asm/io.h> #include <asm/processor.h>
arch/sparc/kernel/setup_64.c +1 -0
@@ -33,6 +33,7 @@#include <linux/module.h> #include <linux/start_kernel.h> #include <linux/bootmem.h> +#include <uapi/linux/mount.h> #include <asm/io.h> #include <asm/processor.h>
arch/x86/kernel/setup.c +1 -0
@@ -51,6 +51,7 @@#include <linux/kvm_para.h> #include <linux/dma-contiguous.h> #include <xen/xen.h> +#include <uapi/linux/mount.h> #include <linux/errno.h> #include <linux/kernel.h>
drivers/base/devtmpfs.c +1 -0
@@ -25,6 +25,7 @@#include <linux/sched.h> #include <linux/slab.h> #include <linux/kthread.h> +#include <uapi/linux/mount.h> #include "base.h" static struct task_struct *thread;
fs/f2fs/super.c +1 -1
@@ -1453,7 +1453,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) err =dquot_suspend (sb,-1 );if (err <0 ) goto restore_opts; - }else if (f2fs_readonly (sb) && !(*flags &MS_RDONLY )) { + }else if (f2fs_readonly (sb) && !(*flags &SB_RDONLY )) {/* dquot_resume needs RW */ sb->s_flags &= ~SB_RDONLY ;if (sb_any_quota_suspended (sb)) {
fs/pnode.c +1 -0
@@ -10,6 +10,7 @@#include <linux/mount.h> #include <linux/fs.h> #include <linux/nsproxy.h> +#include <uapi/linux/mount.h> #include "internal.h" #include "pnode.h"
fs/super.c +1 -0
@@ -35,6 +35,7 @@#include <linux/fsnotify.h> #include <linux/lockdep.h> #include <linux/user_namespace.h> +#include <uapi/linux/mount.h> #include "internal.h" static int thaw_super_locked (struct super_block *sb);
include/uapi/linux/fs.h +5 -51
68 lines not on this page · raw message
include/uapi/linux/mount.h +54 -0
60 lines not on this page · raw message
init/do_mounts.c +1 -0
@@ -32,6 +32,7 @@#include <linux/nfs_fs.h> #include <linux/nfs_fs_sb.h> #include <linux/nfs_mount.h> +#include <uapi/linux/mount.h> #include "do_mounts.h"
init/do_mounts_initrd.c +1 -0
@@ -18,6 +18,7 @@#include <linux/sched.h> #include <linux/freezer.h> #include <linux/kmod.h> +#include <uapi/linux/mount.h> #include "do_mounts.h"
security/apparmor/lsm.c +1 -0
@@ -24,6 +24,7 @@#include <linux/audit.h> #include <linux/user_namespace.h> #include <net/sock.h> +#include <uapi/linux/mount.h> #include "include/apparmor.h" #include "include/apparmorfs.h"
security/apparmor/mount.c +1 -0
@@ -15,6 +15,7 @@#include <linux/fs.h> #include <linux/mount.h> #include <linux/namei.h> +#include <uapi/linux/mount.h> #include "include/apparmor.h" #include "include/audit.h"
security/selinux/hooks.c +1 -0
@@ -88,6 +88,7 @@#include <linux/msg.h> #include <linux/shm.h> #include <linux/bpf.h> +#include <uapi/linux/mount.h> #include "avc.h" #include "objsec.h"
security/tomoyo/mount.c +1 -0
@@ -6,6 +6,7 @@*/ #include <linux/slab.h> +#include <uapi/linux/mount.h> #include "common.h" /* String table for special mount operations. */
David Howells
maintainerPATCH 5/32 vfs: Introduce the basic header for the new mount API's filesystem context [ver #9]
In reply to David HowellsIntroduce a filesystem context concept to be used during superblock creation for mount and superblock reconfiguration for remount. This is allocated at the beginning of the mount procedure and into it is placed:
(1) Filesystem type.
(2) Namespaces.
(3) Source/Device names (there may be multiple).
(4) Superblock flags (SB_*).
(5) Security details.
(6) Filesystem-specific data, as set by the mount options.
---
include/linux/fs_context.h | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 include/linux/fs_context.h
include/linux/fs_context.h new file +73 -0
@@ -0,0 +1,73 @@ +/* Filesystem superblock creation and reconfiguration context. +* +* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#ifndef _LINUX_FS_CONTEXT_H +#define _LINUX_FS_CONTEXT_H + +#include <linux/kernel.h> +#include <linux/errno.h> + +struct cred ; +struct dentry ; +struct file_operations ; +struct file_system_type ; +struct mnt_namespace ; +struct net ; +struct pid_namespace ; +struct super_block ; +struct user_namespace ; +struct vfsmount ; + +enum fs_context_purpose { +FS_CONTEXT_FOR_USER_MOUNT ,/* New superblock for user-specified mount */ +FS_CONTEXT_FOR_KERNEL_MOUNT ,/* New superblock for kernel-internal mount */ +FS_CONTEXT_FOR_SUBMOUNT ,/* New superblock for automatic submount */ +FS_CONTEXT_FOR_RECONFIGURE ,/* Superblock reconfiguration (remount) */ +}; + +/* +* Filesystem context for holding the parameters used in the creation or +* reconfiguration of a superblock. +* +* Superblock creation fills in ->root whereas reconfiguration begins with this +* already set. +* +* See Documentation/filesystems/mounting.txt +*/ +struct fs_context { +const struct fs_context_operations *ops; +struct file_system_type *fs_type; +void *fs_private;/* The filesystem's context */ +struct dentry *root;/* The root and superblock */ +struct user_namespace *user_ns;/* The user namespace for this mount */ +struct net *net_ns;/* The network namespace for this mount */ +const struct cred *cred;/* The mounter's credentials */ +char *source;/* The source name (eg. dev path) */ +char *subtype;/* The subtype to set on the superblock */ +void *security;/* The LSM context */ +void *s_fs_info;/* Proposed s_fs_info */ +unsigned int sb_flags;/* Proposed superblock flags (SB_*) */ +enum fs_context_purpose purpose:8 ; +bool sloppy:1 ;/* T if unrecognised options are okay */ +bool silent:1 ;/* T if "o silent" specified */ +}; + +struct fs_context_operations { +void (*free)(struct fs_context *fc); +int (*dup)(struct fs_context *fc,struct fs_context *src_fc); +int (*parse_source)(struct fs_context *fc,char *source); +int (*parse_option)(struct fs_context *fc,char *opt,size_t len); +int (*parse_monolithic)(struct fs_context *fc,void *data); +int (*validate)(struct fs_context *fc); +int (*get_tree)(struct fs_context *fc); +}; + +#endif /* _LINUX_FS_CONTEXT_H */
David Howells
maintainerPATCH 6/32 vfs: Add LSM hooks for the new mount API [ver #9]
In reply to David HowellsAdd LSM hooks for use by the new mount API and filesystem context code. This includes:
(1) Hooks to handle allocation, duplication and freeing of the security record attached to a filesystem context.
(2) A hook to snoop source specifications. There may be multiple of these if the filesystem supports it. They will to be local files/devices if fs_context::source_is_dev is true and will be something else, possibly remote server specifications, if false.
(3) A hook to snoop superblock configuration options in key[=val] form. If the LSM decides it wants to handle it, it can suppress the option being passed to the filesystem. Note that 'val' may include commas and binary data with the fsopen patch.
(4) A hook to perform validation and allocation after the configuration has been done but before the superblock is allocated and set up.
(5) A hook to transfer the security from the context to a newly created superblock.
(6) A hook to rule on whether a path point can be used as a mountpoint.
These are intended to replace:
security_sb_copy_data
security_sb_kern_mount
security_sb_mount
security_sb_set_mnt_opts
security_sb_clone_mnt_opts
security_sb_parse_opts_str
---
include/linux/lsm_hooks.h | 70 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/security.h | 49 ++++++++++++++++++++++++++++++++ security/security.c | 46 ++++++++++++++++++++++++++++++ 3 files changed, 165 insertions(+)
include/linux/lsm_hooks.h +70 -0
@@ -76,6 +76,56 @@* changes on the process such as clearing out non-inheritable signal * state. This is called immediately after commit_creds(). * +* Security hooks for mount using fs_context. +* [See also Documentation/filesystems/mounting.txt] +* +* @fs_context_alloc: +* Allocate and attach a security structure to sc->security. This pointer +* is initialised to NULL by the caller. +* @fc indicates the new filesystem context. +* @reference indicates the source dentry of a submount or start of reconfig. +* @fs_context_dup: +* Allocate and attach a security structure to sc->security. This pointer +* is initialised to NULL by the caller. +* @fc indicates the new filesystem context. +* @src_fc indicates the original filesystem context. +* @fs_context_free: +* Clean up a filesystem context. +* @fc indicates the filesystem context. +* @fs_context_parse_source: +* Check a source for the superblock (multiple sources may be provided). +* The LSM may reject it with an error; otherwise it should return 0. +* @fc indicates the filesystem context. +* @src indicates the source name. It is NUL-terminated, +* @fs_context_parse_option: +* Userspace provided an option to configure a superblock. The LSM may +* reject it with an error and may use it for itself, in which case it +* should return 1; otherwise it should return 0 to pass it on to the +* filesystem. +* @fc indicates the filesystem context. +* @opt indicates the option in "key[=val]" form. It is NUL-terminated, +* but val may be binary data. +* @len indicates the size of the option. +* @fs_context_validate: +* Validate the filesystem context preparatory to applying it. This is +* done after all the options have been parsed. +* @fc indicates the filesystem context. +* @sb_get_tree: +* Assign the security to a newly created superblock. +* @fc indicates the filesystem context. +* @fc->root indicates the root that will be mounted. +* @fc->root->d_sb points to the superblock. +* @sb_reconfigure: +* Apply reconfiguration to the security on a superblock. +* @fc indicates the filesystem context. +* @fc->root indicates a dentry in the mount. +* @fc->root->d_sb points to the superblock. +* @sb_mountpoint: +* Equivalent of sb_mount, but with an fs_context. +* @fc indicates the filesystem context. +* @mountpoint indicates the path on which the mount will take place. +* @mnt_flags indicates the MNT_* flags specified. +* * Security hooks for filesystem operations. * * @sb_alloc_security:
@@ -1459,6 +1509,17 @@ union security_list_options {void (*bprm_committing_creds)(struct linux_binprm *bprm);void (*bprm_committed_creds)(struct linux_binprm *bprm); +int (*fs_context_alloc)(struct fs_context *fc,struct dentry *reference); +int (*fs_context_dup)(struct fs_context *fc,struct fs_context *src_sc); +void (*fs_context_free)(struct fs_context *fc); +int (*fs_context_parse_source)(struct fs_context *fc,char *src); +int (*fs_context_parse_option)(struct fs_context *fc,char *opt,size_t len); +int (*fs_context_validate)(struct fs_context *fc); +int (*sb_get_tree)(struct fs_context *fc); +void (*sb_reconfigure)(struct fs_context *fc); +int (*sb_mountpoint)(struct fs_context *fc,struct path *mountpoint, +unsigned int mnt_flags); +int (*sb_alloc_security)(struct super_block *sb);void (*sb_free_security)(struct super_block *sb);int (*sb_copy_data)(char *orig,char *copy);
@@ -1798,6 +1859,15 @@ struct security_hook_heads {struct hlist_head bprm_check_security;struct hlist_head bprm_committing_creds;struct hlist_head bprm_committed_creds; +struct hlist_head fs_context_alloc; +struct hlist_head fs_context_dup; +struct hlist_head fs_context_free; +struct hlist_head fs_context_parse_source; +struct hlist_head fs_context_parse_option; +struct hlist_head fs_context_validate; +struct hlist_head sb_get_tree; +struct hlist_head sb_reconfigure; +struct hlist_head sb_mountpoint;struct hlist_head sb_alloc_security;struct hlist_head sb_free_security;struct hlist_head sb_copy_data;
include/linux/security.h +49 -0
67 lines not on this page · raw message
security/security.c +46 -0
52 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Howells
maintainerPATCH 7/32 selinux: Implement the new mount API LSM hooks [ver #9]
In reply to David HowellsImplement the new mount API LSM hooks for SELinux. At some point the old hooks will need to be removed.
Question: Should the ->fs_context_parse_source() hook be implemented to check the labels on any source devices specified?
---
security/selinux/hooks.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+)
security/selinux/hooks.c +264 -0
@@ -48,6 +48,7 @@#include <linux/fdtable.h> #include <linux/namei.h> #include <linux/mount.h> +#include <linux/fs_context.h> #include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv6.h> #include <linux/tty.h>
@@ -2973,6 +2974,261 @@ static int selinux_umount(struct vfsmount *mnt, int flags) FILESYSTEM__UNMOUNT, NULL); } +/* fsopen mount context operations */ + +static int selinux_fs_context_alloc (struct fs_context *fc, +struct dentry *reference) +{ +struct security_mnt_opts *opts; + + opts =kzalloc (sizeof (*opts),GFP_KERNEL ); +if (!opts) +return -ENOMEM ; + + fc->security = opts; +return 0 ; +} + +static int selinux_fs_context_dup (struct fs_context *fc, +struct fs_context *src_fc) +{ +const struct security_mnt_opts *src = src_fc->security; +struct security_mnt_opts *opts; +int i, n; + + opts =kzalloc (sizeof (*opts),GFP_KERNEL ); +if (!opts) +return -ENOMEM ; + fc->security = opts; + +if (!src || !src->num_mnt_opts) +return 0 ; + n = opts->num_mnt_opts = src->num_mnt_opts; + +if (src->mnt_opts) { + opts->mnt_opts =kcalloc (n,sizeof (char *),GFP_KERNEL ); +if (!opts->mnt_opts) +return -ENOMEM ; + +for (i =0 ; i < n; i++) { +if (src->mnt_opts[i]) { + opts->mnt_opts[i] =kstrdup (src->mnt_opts[i], +GFP_KERNEL ); +if (!opts->mnt_opts[i]) +return -ENOMEM ; + } + } + } + +if (src->mnt_opts_flags) { + opts->mnt_opts_flags =kmemdup (src->mnt_opts_flags, + n *sizeof (int ),GFP_KERNEL ); +if (!opts->mnt_opts_flags) +return -ENOMEM ; + } + +return 0 ; +} + +static void selinux_fs_context_free (struct fs_context *fc) +{ +struct security_mnt_opts *opts = fc->security; + +if (opts) { +security_free_mnt_opts (opts); + fc->security =NULL ; + } +} + +static int selinux_fs_context_parse_option (struct fs_context *fc,char *opt,size_t len) +{ +struct security_mnt_opts *opts = fc->security; +substring_t args[MAX_OPT_ARGS ]; +unsigned int have; +char *c, **oo; +int token, ctx, i, *of; + + token =match_token (opt, tokens, args); +if (token == Opt_error) +return 0 ;/* Doesn't belong to us. */ + + have =0 ; +for (i =0 ; i < opts->num_mnt_opts; i++) + have |=1 << opts->mnt_opts_flags[i]; +if (have & (1 << token)) +return -EINVAL ; + +switch (token) { +case Opt_context: +if (have & (1 << Opt_defcontext)) + goto incompatible; + ctx =CONTEXT_MNT ; + goto copy_context_string; + +case Opt_fscontext: + ctx =FSCONTEXT_MNT ; + goto copy_context_string; + +case Opt_rootcontext: + ctx =ROOTCONTEXT_MNT ; + goto copy_context_string; + +case Opt_defcontext: +if (have & (1 << Opt_context)) + goto incompatible; + ctx =DEFCONTEXT_MNT ; + goto copy_context_string; + +case Opt_labelsupport: +return 1 ; + +default : +return -EINVAL ; + } + +copy_context_string: +if (opts->num_mnt_opts >3 ) +return -EINVAL ; + + of =krealloc (opts->mnt_opts_flags, + (opts->num_mnt_opts +1 ) *sizeof (int ),GFP_KERNEL ); +if (!of) +return -ENOMEM ; + of[opts->num_mnt_opts] =0 ; + opts->mnt_opts_flags = of; + + oo =krealloc (opts->mnt_opts, + (opts->num_mnt_opts +1 ) *sizeof (char *),GFP_KERNEL ); +if (!oo) +return -ENOMEM ; + oo[opts->num_mnt_opts] =NULL ; + opts->mnt_opts = oo; + + c =match_strdup (&args[0 ]); +if (!c) +return -ENOMEM ; + opts->mnt_opts[opts->num_mnt_opts] = c; + opts->mnt_opts_flags[opts->num_mnt_opts] = ctx; + opts->num_mnt_opts++; +return 1 ; + +incompatible: +return -EINVAL ; +} + +/* +* Validate the security parameters supplied for a reconfiguration/remount +* event. +*/ +static int selinux_validate_for_sb_reconfigure (struct fs_context *fc) +{ +struct super_block *sb = fc->root->d_sb; +struct superblock_security_struct *sbsec = sb->s_security; +struct security_mnt_opts *opts = fc->security; +int rc, i, *flags; +char **mount_options; + +if (!(sbsec->flags &SE_SBINITIALIZED )) +return 0 ; + + mount_options = opts->mnt_opts; + flags = opts->mnt_opts_flags; + +for (i =0 ; i < opts->num_mnt_opts; i++) { +u32 sid; + +if (flags[i] ==SBLABEL_MNT ) +continue ; + + rc =security_context_str_to_sid (&selinux_state, mount_options[i], + &sid,GFP_KERNEL ); +if (rc) { +pr_warn ("SELinux: security_context_str_to_sid" +"(%s) failed for (dev %s, type %s) errno=%d\n" , + mount_options[i], sb->s_id, sb->s_type->name, rc); + goto inval; + } + +switch (flags[i]) { +case FSCONTEXT_MNT : +if (bad_option (sbsec,FSCONTEXT_MNT , sbsec->sid, sid)) + goto bad_option; +break ; +case CONTEXT_MNT : +if (bad_option (sbsec,CONTEXT_MNT , sbsec->mntpoint_sid, sid)) + goto bad_option; +break ; +case ROOTCONTEXT_MNT : { +struct inode_security_struct *root_isec; + root_isec =backing_inode_security (sb->s_root); + +if (bad_option (sbsec,ROOTCONTEXT_MNT , root_isec->sid, sid)) + goto bad_option; +break ; + } +case DEFCONTEXT_MNT : +if (bad_option (sbsec,DEFCONTEXT_MNT , sbsec->def_sid, sid)) + goto bad_option; +break ; +default : + goto inval; + } + } + + rc =0 ; +out: +return rc; + +bad_option: +pr_warn ("SELinux: unable to change security options " +"during remount (dev %s, type=%s)\n" , + sb->s_id, sb->s_type->name); +inval: + rc = -EINVAL ; + goto out; +} + +/* +* Validate the security context assembled from the option data supplied to +* mount. +*/ +static int selinux_fs_context_validate (struct fs_context *fc) +{ +if (fc->purpose ==FS_CONTEXT_FOR_RECONFIGURE ) +return selinux_validate_for_sb_reconfigure (fc); +return 0 ; +} + +/* +* Set the security context on a superblock. +*/ +static int selinux_sb_get_tree (struct fs_context *fc) +{ +const struct cred *cred =current_cred (); +struct common_audit_data ad; +int rc; + + rc =selinux_set_mnt_opts (fc->root->d_sb, fc->security,0 ,NULL ); +if (rc) +return rc; + +/* Allow all mounts performed by the kernel */ +if (fc->purpose ==FS_CONTEXT_FOR_KERNEL_MOUNT ) +return 0 ; + + ad.type =LSM_AUDIT_DATA_DENTRY ; + ad.u.dentry = fc->root; +return superblock_has_perm (cred, fc->root->d_sb,FILESYSTEM__MOUNT , &ad); +} + +static int selinux_sb_mountpoint (struct fs_context *fc,struct path *mountpoint, +unsigned int mnt_flags) +{ +const struct cred *cred =current_cred (); + +return path_has_perm (cred, mountpoint,FILE__MOUNTON ); +} +/* inode security operations */ static int selinux_inode_alloc_security (struct inode *inode)
@@ -6905,6 +7161,14 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (bprm_committing_creds, selinux_bprm_committing_creds),LSM_HOOK_INIT (bprm_committed_creds, selinux_bprm_committed_creds), +LSM_HOOK_INIT (fs_context_alloc, selinux_fs_context_alloc), +LSM_HOOK_INIT (fs_context_dup, selinux_fs_context_dup), +LSM_HOOK_INIT (fs_context_free, selinux_fs_context_free), +LSM_HOOK_INIT (fs_context_parse_option, selinux_fs_context_parse_option), +LSM_HOOK_INIT (fs_context_validate, selinux_fs_context_validate), +LSM_HOOK_INIT (sb_get_tree, selinux_sb_get_tree), +LSM_HOOK_INIT (sb_mountpoint, selinux_sb_mountpoint), +LSM_HOOK_INIT (sb_alloc_security, selinux_sb_alloc_security),LSM_HOOK_INIT (sb_free_security, selinux_sb_free_security), LSM_HOOK_INIT(sb_copy_data, selinux_sb_copy_data),
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 07/32] selinux: Implement the new mount API LSM hooks [ver #9]
Quoted 5 lines · David Howells
Implement the new mount API LSM hooks for SELinux. At some point the old hooks will need to be removed.
Question: Should the ->fs_context_parse_source() hook be implemented to check the labels on any source devices specified?
The hook interface doesn't appear to lend itself to such validation, since you are just passing a string, not an inode. Looking up the inode within the security module could easily yield a different object than what is ultimately used for the actual mount.
Quoted 301 lines
Signed-off-by David Howells <[email protected]>cc Paul Moore <[email protected]>cc Stephen Smalley <[email protected]>---
security/selinux/hooks.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 264 insertions(+)security/selinux/hooks.c +264
-0@@ -48,6 +48,7 @@#include <linux/fdtable.h> #include <linux/namei.h> #include <linux/mount.h> +#include <linux/fs_context.h> #include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv6.h> #include <linux/tty.h> @@ -2973,6 +2974,261 @@ static int selinux_umount(struct vfsmount *mnt, int flags) FILESYSTEM__UNMOUNT, NULL); } +/* fsopen mount context operations */ + +static int selinux_fs_context_alloc (struct fs_context *fc, +struct dentry *reference) +{ +struct security_mnt_opts *opts; + + opts =kzalloc (sizeof (*opts),GFP_KERNEL ); +if (!opts) +return -ENOMEM ; + + fc->security = opts; +return 0 ; +} + +static int selinux_fs_context_dup (struct fs_context *fc, +struct fs_context *src_fc) +{ +const struct security_mnt_opts *src = src_fc->security; +struct security_mnt_opts *opts; +int i, n; + + opts =kzalloc (sizeof (*opts),GFP_KERNEL ); +if (!opts) +return -ENOMEM ; + fc->security = opts; + +if (!src || !src->num_mnt_opts) +return 0 ; + n = opts->num_mnt_opts = src->num_mnt_opts; + +if (src->mnt_opts) { + opts->mnt_opts =kcalloc (n,sizeof (char *),GFP_KERNEL ); +if (!opts->mnt_opts) +return -ENOMEM ; + +for (i =0 ; i < n; i++) { +if (src->mnt_opts[i]) { + opts->mnt_opts[i] =kstrdup (src->mnt_opts[i], +GFP_KERNEL ); +if (!opts->mnt_opts[i]) +return -ENOMEM ; + } + } + } + +if (src->mnt_opts_flags) { + opts->mnt_opts_flags =kmemdup (src->mnt_opts_flags, + n *sizeof (int ),GFP_KERNEL ); +if (!opts->mnt_opts_flags) +return -ENOMEM ; + } + +return 0 ; +} + +static void selinux_fs_context_free (struct fs_context *fc) +{ +struct security_mnt_opts *opts = fc->security; + +if (opts) { +security_free_mnt_opts (opts); + fc->security =NULL ; + } +} + +static int selinux_fs_context_parse_option (struct fs_context *fc,char *opt,size_t len) +{ +struct security_mnt_opts *opts = fc->security; +substring_t args[MAX_OPT_ARGS ]; +unsigned int have; +char *c, **oo; +int token, ctx, i, *of; + + token =match_token (opt, tokens, args); +if (token == Opt_error) +return 0 ;/* Doesn't belong to us. */ + + have =0 ; +for (i =0 ; i < opts->num_mnt_opts; i++) + have |=1 << opts->mnt_opts_flags[i]; +if (have & (1 << token)) +return -EINVAL ; + +switch (token) { +case Opt_context: +if (have & (1 << Opt_defcontext)) + goto incompatible; + ctx =CONTEXT_MNT ; + goto copy_context_string; + +case Opt_fscontext: + ctx =FSCONTEXT_MNT ; + goto copy_context_string; + +case Opt_rootcontext: + ctx =ROOTCONTEXT_MNT ; + goto copy_context_string; + +case Opt_defcontext: +if (have & (1 << Opt_context)) + goto incompatible; + ctx =DEFCONTEXT_MNT ; + goto copy_context_string; + +case Opt_labelsupport: +return 1 ; + +default : +return -EINVAL ; + } + +copy_context_string: +if (opts->num_mnt_opts >3 ) +return -EINVAL ; + + of =krealloc (opts->mnt_opts_flags, + (opts->num_mnt_opts +1 ) *sizeof (int ),GFP_KERNEL ); +if (!of) +return -ENOMEM ; + of[opts->num_mnt_opts] =0 ; + opts->mnt_opts_flags = of; + + oo =krealloc (opts->mnt_opts, + (opts->num_mnt_opts +1 ) *sizeof (char *),GFP_KERNEL ); +if (!oo) +return -ENOMEM ; + oo[opts->num_mnt_opts] =NULL ; + opts->mnt_opts = oo; + + c =match_strdup (&args[0 ]); +if (!c) +return -ENOMEM ; + opts->mnt_opts[opts->num_mnt_opts] = c; + opts->mnt_opts_flags[opts->num_mnt_opts] = ctx; + opts->num_mnt_opts++; +return 1 ; + +incompatible: +return -EINVAL ; +} + +/* +* Validate the security parameters supplied for a reconfiguration/remount +* event. +*/ +static int selinux_validate_for_sb_reconfigure (struct fs_context *fc) +{ +struct super_block *sb = fc->root->d_sb; +struct superblock_security_struct *sbsec = sb->s_security; +struct security_mnt_opts *opts = fc->security; +int rc, i, *flags; +char **mount_options; + +if (!(sbsec->flags &SE_SBINITIALIZED )) +return 0 ; + + mount_options = opts->mnt_opts; + flags = opts->mnt_opts_flags; + +for (i =0 ; i < opts->num_mnt_opts; i++) { +u32 sid; + +if (flags[i] ==SBLABEL_MNT ) +continue ; + + rc =security_context_str_to_sid (&selinux_state, mount_options[i], + &sid,GFP_KERNEL ); +if (rc) { +pr_warn ("SELinux: security_context_str_to_sid" +"(%s) failed for (dev %s, type %s) errno=%d\n" , + mount_options[i], sb->s_id, sb->s_type->name, rc); + goto inval; + } + +switch (flags[i]) { +case FSCONTEXT_MNT : +if (bad_option (sbsec,FSCONTEXT_MNT , sbsec->sid, sid)) + goto bad_option; +break ; +case CONTEXT_MNT : +if (bad_option (sbsec,CONTEXT_MNT , sbsec->mntpoint_sid, sid)) + goto bad_option; +break ; +case ROOTCONTEXT_MNT : { +struct inode_security_struct *root_isec; + root_isec =backing_inode_security (sb->s_root); + +if (bad_option (sbsec,ROOTCONTEXT_MNT , root_isec->sid, sid)) + goto bad_option; +break ; + } +case DEFCONTEXT_MNT : +if (bad_option (sbsec,DEFCONTEXT_MNT , sbsec->def_sid, sid)) + goto bad_option; +break ; +default : + goto inval; + } + } + + rc =0 ; +out: +return rc; + +bad_option: +pr_warn ("SELinux: unable to change security options " +"during remount (dev %s, type=%s)\n" , + sb->s_id, sb->s_type->name); +inval: + rc = -EINVAL ; + goto out; +} + +/* +* Validate the security context assembled from the option data supplied to +* mount. +*/ +static int selinux_fs_context_validate (struct fs_context *fc) +{ +if (fc->purpose ==FS_CONTEXT_FOR_RECONFIGURE ) +return selinux_validate_for_sb_reconfigure (fc); +return 0 ; +} + +/* +* Set the security context on a superblock. +*/ +static int selinux_sb_get_tree (struct fs_context *fc) +{ +const struct cred *cred =current_cred (); +struct common_audit_data ad; +int rc; + + rc =selinux_set_mnt_opts (fc->root->d_sb, fc->security,0 ,NULL ); +if (rc) +return rc; + +/* Allow all mounts performed by the kernel */ +if (fc->purpose ==FS_CONTEXT_FOR_KERNEL_MOUNT ) +return 0 ; + + ad.type =LSM_AUDIT_DATA_DENTRY ; + ad.u.dentry = fc->root; +return superblock_has_perm (cred, fc->root->d_sb,FILESYSTEM__MOUNT , &ad); +} + +static int selinux_sb_mountpoint (struct fs_context *fc,struct path *mountpoint, +unsigned int mnt_flags) +{ +const struct cred *cred =current_cred (); + +return path_has_perm (cred, mountpoint,FILE__MOUNTON ); +} +/* inode security operations */ static int selinux_inode_alloc_security (struct inode *inode)@@ -6905,6 +7161,14 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (bprm_committing_creds, selinux_bprm_committing_creds),LSM_HOOK_INIT (bprm_committed_creds, selinux_bprm_committed_creds), +LSM_HOOK_INIT (fs_context_alloc, selinux_fs_context_alloc), +LSM_HOOK_INIT (fs_context_dup, selinux_fs_context_dup), +LSM_HOOK_INIT (fs_context_free, selinux_fs_context_free), +LSM_HOOK_INIT (fs_context_parse_option, selinux_fs_context_parse_option), +LSM_HOOK_INIT (fs_context_validate, selinux_fs_context_validate), +LSM_HOOK_INIT (sb_get_tree, selinux_sb_get_tree), +LSM_HOOK_INIT (sb_mountpoint, selinux_sb_mountpoint), +LSM_HOOK_INIT (sb_alloc_security, selinux_sb_alloc_security),LSM_HOOK_INIT (sb_free_security, selinux_sb_free_security), LSM_HOOK_INIT(sb_copy_data, selinux_sb_copy_data),
David Howells
maintainerPATCH 8/32 smack: Implement filesystem context security hooks [ver #9]
In reply to David HowellsImplement filesystem context security hooks for the smack LSM.
Question: Should the ->fs_context_parse_source() hook be implemented to check the labels on any source devices specified?
---
security/smack/smack_lsm.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 309 insertions(+)
security/smack/smack_lsm.c +309 -0
@@ -42,6 +42,7 @@#include <linux/shm.h> #include <linux/binfmts.h> #include <linux/parser.h> +#include <linux/fs_context.h> #include "smack.h" #define TRANS_TRUE "TRUE"
@@ -521,6 +522,307 @@ static int smack_syslog(int typefrom_file)return rc; } +/* +* Mount context operations +*/ + +struct smack_fs_context { +union { +struct { +char *fsdefault; +char *fsfloor; +char *fshat; +char *fsroot; +char *fstransmute; + }; +char *ptrs[5 ]; + + }; +struct superblock_smack *sbsp; +struct inode_smack *isp; +bool transmute; +}; + +/** +* smack_fs_context_free - Free the security data from a filesystem context +* @fc: The filesystem context to be cleaned up. +*/ +static void smack_fs_context_free (struct fs_context *fc) +{ +struct smack_fs_context *ctx = fc->security; +int i; + +if (ctx) { +for (i =0 ; i <ARRAY_SIZE (ctx->ptrs); i++) +kfree (ctx->ptrs[i]); +kfree (ctx->isp); +kfree (ctx->sbsp); +kfree (ctx); + fc->security =NULL ; + } +} + +/** +* smack_fs_context_alloc - Allocate security data for a filesystem context +* @fc: The filesystem context. +* @reference: Reference dentry (automount/reconfigure) or NULL +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_alloc (struct fs_context *fc, +struct dentry *reference) +{ +struct smack_fs_context *ctx; +struct superblock_smack *sbsp; +struct inode_smack *isp; +struct smack_known *skp; + + ctx =kzalloc (sizeof (struct smack_fs_context ),GFP_KERNEL ); +if (!ctx) + goto nomem; + fc->security = ctx; + + sbsp =kzalloc (sizeof (struct superblock_smack ),GFP_KERNEL ); +if (!sbsp) + goto nomem_free; + ctx->sbsp = sbsp; + + isp =new_inode_smack (NULL ); +if (!isp) + goto nomem_free; + ctx->isp = isp; + +if (reference) { +if (reference->d_sb->s_security) +memcpy (sbsp, reference->d_sb->s_security,sizeof (*sbsp)); + }else if (!smack_privileged (CAP_MAC_ADMIN )) { +/* Unprivileged mounts get root and default from the caller. */ + skp =smk_of_current (); + sbsp->smk_root = skp; + sbsp->smk_default = skp; + }else { + sbsp->smk_root = &smack_known_floor; + sbsp->smk_default = &smack_known_floor; + sbsp->smk_floor = &smack_known_floor; + sbsp->smk_hat = &smack_known_hat; +/* SMK_SB_INITIALIZED will be zero from kzalloc. */ + } + +return 0 ; + +nomem_free: +smack_fs_context_free (fc); +nomem: +return -ENOMEM ; +} + +/** +* smack_fs_context_dup - Duplicate the security data on fs_context duplication +* @fc: The new filesystem context. +* @src_fc: The source filesystem context being duplicated. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_dup (struct fs_context *fc, +struct fs_context *src_fc) +{ +struct smack_fs_context *dst, *src = src_fc->security; +int i; + + dst =kzalloc (sizeof (struct smack_fs_context ),GFP_KERNEL ); +if (!dst) + goto nomem; + fc->security = dst; + + dst->sbsp =kmemdup (src->sbsp,sizeof (struct superblock_smack ), +GFP_KERNEL ); +if (!dst->sbsp) + goto nomem_free; + +for (i =0 ; i <ARRAY_SIZE (dst->ptrs); i++) { +if (src->ptrs[i]) { + dst->ptrs[i] =kstrdup (src->ptrs[i],GFP_KERNEL ); +if (!dst->ptrs[i]) + goto nomem_free; + } + } + +return 0 ; + +nomem_free: +smack_fs_context_free (fc); +nomem: +return -ENOMEM ; +} + +/** +* smack_fs_context_parse_option - Parse a single mount option +* @fc: The new filesystem context being constructed. +* @opt: The option text buffer. +* @len: The length of the text. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_parse_option (struct fs_context *fc,char *p,size_t len) +{ +struct smack_fs_context *ctx = fc->security; +substring_t args[MAX_OPT_ARGS ]; +int rc = -ENOMEM ; +int token; + +/* Unprivileged mounts don't get to specify Smack values. */ +if (!smack_privileged (CAP_MAC_ADMIN )) +return -EPERM ; + + token =match_token (p, smk_mount_tokens, args); +switch (token) { +case Opt_fsdefault: +if (ctx->fsdefault) + goto error_dup; + ctx->fsdefault =match_strdup (&args[0 ]); +if (!ctx->fsdefault) + goto error; +break ; +case Opt_fsfloor: +if (ctx->fsfloor) + goto error_dup; + ctx->fsfloor =match_strdup (&args[0 ]); +if (!ctx->fsfloor) + goto error; +break ; +case Opt_fshat: +if (ctx->fshat) + goto error_dup; + ctx->fshat =match_strdup (&args[0 ]); +if (!ctx->fshat) + goto error; +break ; +case Opt_fsroot: +if (ctx->fsroot) + goto error_dup; + ctx->fsroot =match_strdup (&args[0 ]); +if (!ctx->fsroot) + goto error; +break ; +case Opt_fstransmute: +if (ctx->fstransmute) + goto error_dup; + ctx->fstransmute =match_strdup (&args[0 ]); +if (!ctx->fstransmute) + goto error; +break ; +default : +pr_warn ("Smack: unknown mount option\n" ); + goto error_inval; + } + +return 0 ; + +error_dup: +pr_warn ("Smack: duplicate mount option\n" ); +error_inval: + rc = -EINVAL ; +error: +return rc; +} + +/** +* smack_fs_context_validate - Validate the filesystem context security data +* @fc: The filesystem context. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_validate (struct fs_context *fc) +{ +struct smack_fs_context *ctx = fc->security; +struct superblock_smack *sbsp = ctx->sbsp; +struct inode_smack *isp = ctx->isp; +struct smack_known *skp; + +if (ctx->fsdefault) { + skp =smk_import_entry (ctx->fsdefault,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_default = skp; + } + +if (ctx->fsfloor) { + skp =smk_import_entry (ctx->fsfloor,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_floor = skp; + } + +if (ctx->fshat) { + skp =smk_import_entry (ctx->fshat,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_hat = skp; + } + +if (ctx->fsroot || ctx->fstransmute) { + skp =smk_import_entry (ctx->fstransmute ?: ctx->fsroot,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_root = skp; + ctx->transmute = !!ctx->fstransmute; + } + + isp->smk_inode = sbsp->smk_root; +return 0 ; +} + +/** +* smack_sb_get_tree - Assign the context to a newly created superblock +* @fc: The new filesystem context. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_sb_get_tree (struct fs_context *fc) +{ +struct smack_fs_context *ctx = fc->security; +struct superblock_smack *sbsp = ctx->sbsp; +struct dentry *root = fc->root; +struct inode *inode =d_backing_inode (root); +struct super_block *sb = root->d_sb; +struct inode_smack *isp; +bool transmute = ctx->transmute; + +if (sb->s_security) +return 0 ; + +if (!smack_privileged (CAP_MAC_ADMIN )) { +/* +* For a handful of fs types with no user-controlled +* backing store it's okay to trust security labels +* in the filesystem. The rest are untrusted. +*/ +if (fc->user_ns != &init_user_ns && + sb->s_magic !=SYSFS_MAGIC && sb->s_magic !=TMPFS_MAGIC && + sb->s_magic !=RAMFS_MAGIC ) { + transmute = true; + sbsp->smk_flags |=SMK_SB_UNTRUSTED ; + } + } + + sbsp->smk_flags |=SMK_SB_INITIALIZED ; + sb->s_security = sbsp; + ctx->sbsp =NULL ; + +/* Initialize the root inode. */ + isp = inode->i_security; +if (isp ==NULL ) { + isp = ctx->isp; + ctx->isp =NULL ; + inode->i_security = isp; + }else + isp->smk_inode = sbsp->smk_root; + +if (transmute) + isp->smk_flags |=SMK_INODE_TRANSMUTE ; + +return 0 ; +}/* * Superblock Hooks.
@@ -4647,6 +4949,13 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (ptrace_traceme, smack_ptrace_traceme),LSM_HOOK_INIT (syslog, smack_syslog), +LSM_HOOK_INIT (fs_context_alloc, smack_fs_context_alloc), +LSM_HOOK_INIT (fs_context_dup, smack_fs_context_dup), +LSM_HOOK_INIT (fs_context_free, smack_fs_context_free), +LSM_HOOK_INIT (fs_context_parse_option, smack_fs_context_parse_option), +LSM_HOOK_INIT (fs_context_validate, smack_fs_context_validate), +LSM_HOOK_INIT (sb_get_tree, smack_sb_get_tree), +LSM_HOOK_INIT (sb_alloc_security, smack_sb_alloc_security),LSM_HOOK_INIT (sb_free_security, smack_sb_free_security), LSM_HOOK_INIT(sb_copy_data, smack_sb_copy_data),
Casey Schaufler
maintainerRe: [PATCH 08/32] smack: Implement filesystem context security hooks [ver #9]
Quoted 4 lines · David Howells
Implement filesystem context security hooks for the smack LSM.
Question: Should the ->fs_context_parse_source() hook be implemented to check the labels on any source devices specified?
Checking the label on a block device when doing a mount is just going to end in tears. If you're remounting from an already mounted filesystem it might make sense to check that the new mount doesn't provide greater access than the existing mount. If the original mount has smackfsdefault="_" I could see prohibiting the additional mount having smackfsdefault="*" on a filesystem that doesn't support xattrs. But that requires that a (hopefully) privileged process be involved, and we expect them to have a clue. So no, I don't see it necessary.
Quoted 345 lines
Signed-off-by David Howells <[email protected]>cc Casey Schaufler <[email protected]>---
security/smack/smack_lsm.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 309 insertions(+)security/smack/smack_lsm.c +309
-0@@ -42,6 +42,7 @@#include <linux/shm.h> #include <linux/binfmts.h> #include <linux/parser.h> +#include <linux/fs_context.h> #include "smack.h" #define TRANS_TRUE "TRUE"@@ -521,6 +522,307 @@ static int smack_syslog(int typefrom_file)return rc; } +/* +* Mount context operations +*/ + +struct smack_fs_context { +union { +struct { +char *fsdefault; +char *fsfloor; +char *fshat; +char *fsroot; +char *fstransmute; + }; +char *ptrs[5 ]; + + }; +struct superblock_smack *sbsp; +struct inode_smack *isp; +bool transmute; +}; + +/** +* smack_fs_context_free - Free the security data from a filesystem context +* @fc: The filesystem context to be cleaned up. +*/ +static void smack_fs_context_free (struct fs_context *fc) +{ +struct smack_fs_context *ctx = fc->security; +int i; + +if (ctx) { +for (i =0 ; i <ARRAY_SIZE (ctx->ptrs); i++) +kfree (ctx->ptrs[i]); +kfree (ctx->isp); +kfree (ctx->sbsp); +kfree (ctx); + fc->security =NULL ; + } +} + +/** +* smack_fs_context_alloc - Allocate security data for a filesystem context +* @fc: The filesystem context. +* @reference: Reference dentry (automount/reconfigure) or NULL +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_alloc (struct fs_context *fc, +struct dentry *reference) +{ +struct smack_fs_context *ctx; +struct superblock_smack *sbsp; +struct inode_smack *isp; +struct smack_known *skp; + + ctx =kzalloc (sizeof (struct smack_fs_context ),GFP_KERNEL ); +if (!ctx) + goto nomem; + fc->security = ctx; + + sbsp =kzalloc (sizeof (struct superblock_smack ),GFP_KERNEL ); +if (!sbsp) + goto nomem_free; + ctx->sbsp = sbsp; + + isp =new_inode_smack (NULL ); +if (!isp) + goto nomem_free; + ctx->isp = isp; + +if (reference) { +if (reference->d_sb->s_security) +memcpy (sbsp, reference->d_sb->s_security,sizeof (*sbsp)); + }else if (!smack_privileged (CAP_MAC_ADMIN )) { +/* Unprivileged mounts get root and default from the caller. */ + skp =smk_of_current (); + sbsp->smk_root = skp; + sbsp->smk_default = skp; + }else { + sbsp->smk_root = &smack_known_floor; + sbsp->smk_default = &smack_known_floor; + sbsp->smk_floor = &smack_known_floor; + sbsp->smk_hat = &smack_known_hat; +/* SMK_SB_INITIALIZED will be zero from kzalloc. */ + } + +return 0 ; + +nomem_free: +smack_fs_context_free (fc); +nomem: +return -ENOMEM ; +} + +/** +* smack_fs_context_dup - Duplicate the security data on fs_context duplication +* @fc: The new filesystem context. +* @src_fc: The source filesystem context being duplicated. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_dup (struct fs_context *fc, +struct fs_context *src_fc) +{ +struct smack_fs_context *dst, *src = src_fc->security; +int i; + + dst =kzalloc (sizeof (struct smack_fs_context ),GFP_KERNEL ); +if (!dst) + goto nomem; + fc->security = dst; + + dst->sbsp =kmemdup (src->sbsp,sizeof (struct superblock_smack ), +GFP_KERNEL ); +if (!dst->sbsp) + goto nomem_free; + +for (i =0 ; i <ARRAY_SIZE (dst->ptrs); i++) { +if (src->ptrs[i]) { + dst->ptrs[i] =kstrdup (src->ptrs[i],GFP_KERNEL ); +if (!dst->ptrs[i]) + goto nomem_free; + } + } + +return 0 ; + +nomem_free: +smack_fs_context_free (fc); +nomem: +return -ENOMEM ; +} + +/** +* smack_fs_context_parse_option - Parse a single mount option +* @fc: The new filesystem context being constructed. +* @opt: The option text buffer. +* @len: The length of the text. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_parse_option (struct fs_context *fc,char *p,size_t len) +{ +struct smack_fs_context *ctx = fc->security; +substring_t args[MAX_OPT_ARGS ]; +int rc = -ENOMEM ; +int token; + +/* Unprivileged mounts don't get to specify Smack values. */ +if (!smack_privileged (CAP_MAC_ADMIN )) +return -EPERM ; + + token =match_token (p, smk_mount_tokens, args); +switch (token) { +case Opt_fsdefault: +if (ctx->fsdefault) + goto error_dup; + ctx->fsdefault =match_strdup (&args[0 ]); +if (!ctx->fsdefault) + goto error; +break ; +case Opt_fsfloor: +if (ctx->fsfloor) + goto error_dup; + ctx->fsfloor =match_strdup (&args[0 ]); +if (!ctx->fsfloor) + goto error; +break ; +case Opt_fshat: +if (ctx->fshat) + goto error_dup; + ctx->fshat =match_strdup (&args[0 ]); +if (!ctx->fshat) + goto error; +break ; +case Opt_fsroot: +if (ctx->fsroot) + goto error_dup; + ctx->fsroot =match_strdup (&args[0 ]); +if (!ctx->fsroot) + goto error; +break ; +case Opt_fstransmute: +if (ctx->fstransmute) + goto error_dup; + ctx->fstransmute =match_strdup (&args[0 ]); +if (!ctx->fstransmute) + goto error; +break ; +default : +pr_warn ("Smack: unknown mount option\n" ); + goto error_inval; + } + +return 0 ; + +error_dup: +pr_warn ("Smack: duplicate mount option\n" ); +error_inval: + rc = -EINVAL ; +error: +return rc; +} + +/** +* smack_fs_context_validate - Validate the filesystem context security data +* @fc: The filesystem context. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_fs_context_validate (struct fs_context *fc) +{ +struct smack_fs_context *ctx = fc->security; +struct superblock_smack *sbsp = ctx->sbsp; +struct inode_smack *isp = ctx->isp; +struct smack_known *skp; + +if (ctx->fsdefault) { + skp =smk_import_entry (ctx->fsdefault,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_default = skp; + } + +if (ctx->fsfloor) { + skp =smk_import_entry (ctx->fsfloor,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_floor = skp; + } + +if (ctx->fshat) { + skp =smk_import_entry (ctx->fshat,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_hat = skp; + } + +if (ctx->fsroot || ctx->fstransmute) { + skp =smk_import_entry (ctx->fstransmute ?: ctx->fsroot,0 ); +if (IS_ERR (skp)) +return PTR_ERR (skp); + sbsp->smk_root = skp; + ctx->transmute = !!ctx->fstransmute; + } + + isp->smk_inode = sbsp->smk_root; +return 0 ; +} + +/** +* smack_sb_get_tree - Assign the context to a newly created superblock +* @fc: The new filesystem context. +* +* Returns 0 on success or -ENOMEM on error. +*/ +static int smack_sb_get_tree (struct fs_context *fc) +{ +struct smack_fs_context *ctx = fc->security; +struct superblock_smack *sbsp = ctx->sbsp; +struct dentry *root = fc->root; +struct inode *inode =d_backing_inode (root); +struct super_block *sb = root->d_sb; +struct inode_smack *isp; +bool transmute = ctx->transmute; + +if (sb->s_security) +return 0 ; + +if (!smack_privileged (CAP_MAC_ADMIN )) { +/* +* For a handful of fs types with no user-controlled +* backing store it's okay to trust security labels +* in the filesystem. The rest are untrusted. +*/ +if (fc->user_ns != &init_user_ns && + sb->s_magic !=SYSFS_MAGIC && sb->s_magic !=TMPFS_MAGIC && + sb->s_magic !=RAMFS_MAGIC ) { + transmute = true; + sbsp->smk_flags |=SMK_SB_UNTRUSTED ; + } + } + + sbsp->smk_flags |=SMK_SB_INITIALIZED ; + sb->s_security = sbsp; + ctx->sbsp =NULL ; + +/* Initialize the root inode. */ + isp = inode->i_security; +if (isp ==NULL ) { + isp = ctx->isp; + ctx->isp =NULL ; + inode->i_security = isp; + }else + isp->smk_inode = sbsp->smk_root; + +if (transmute) + isp->smk_flags |=SMK_INODE_TRANSMUTE ; + +return 0 ; +}/* * Superblock Hooks. @@ -4647,6 +4949,13 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (ptrace_traceme, smack_ptrace_traceme),LSM_HOOK_INIT (syslog, smack_syslog), +LSM_HOOK_INIT (fs_context_alloc, smack_fs_context_alloc), +LSM_HOOK_INIT (fs_context_dup, smack_fs_context_dup), +LSM_HOOK_INIT (fs_context_free, smack_fs_context_free), +LSM_HOOK_INIT (fs_context_parse_option, smack_fs_context_parse_option), +LSM_HOOK_INIT (fs_context_validate, smack_fs_context_validate), +LSM_HOOK_INIT (sb_get_tree, smack_sb_get_tree), +LSM_HOOK_INIT (sb_alloc_security, smack_sb_alloc_security),LSM_HOOK_INIT (sb_free_security, smack_sb_free_security), LSM_HOOK_INIT(sb_copy_data, smack_sb_copy_data),
David Howells
maintainerRe: [PATCH 08/32] smack: Implement filesystem context security hooks [ver #9]
Quoted 5 lines · Casey Schaufler
Quoted 4 lines
Implement filesystem context security hooks for the smack LSM.
Question: Should the ->fs_context_parse_source() hook be implemented to check the labels on any source devices specified?
Quoted 10 lines
Checking the label on a block device when doing a mount is just going to end in tears. If you're remounting from an already mounted filesystem it might make sense to check that the new mount doesn't provide greater access than the existing mount. If the original mount has smackfsdefault="_" I could see prohibiting the additional mount having smackfsdefault="*" on a filesystem that doesn't support xattrs. But that requires that a (hopefully) privileged process be involved, and we expect them to have a clue. So no, I don't see it necessary.
I think I may have meant the device file rather than the actual device content.
David
Casey Schaufler
maintainerRe: [PATCH 08/32] smack: Implement filesystem context security hooks [ver #9]
Quoted 16 lines · David Howells
Quoted 4 lines · Casey Schaufler
Quoted 4 lines
Implement filesystem context security hooks for the smack LSM.
Question: Should the ->fs_context_parse_source() hook be implemented to check the labels on any source devices specified?
Quoted 10 lines
Checking the label on a block device when doing a mount is just going to end in tears. If you're remounting from an already mounted filesystem it might make sense to check that the new mount doesn't provide greater access than the existing mount. If the original mount has smackfsdefault="_" I could see prohibiting the additional mount having smackfsdefault="*" on a filesystem that doesn't support xattrs. But that requires that a (hopefully) privileged process be involved, and we expect them to have a clue. So no, I don't see it necessary.
Quoted 2 lines
I think I may have meant the device file rather than the actual device content.
You may have! I see no reason to look at the label on /dev/sdb1 when mounting it. There's already sufficient privilege required to protect that in my mind.
Quoted 7 lines
David
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Howells
maintainerPATCH 9/32 apparmor: Implement security hooks for the new mount API [ver #9]
In reply to David HowellsImplement hooks to check the creation of new mountpoints for AppArmor.
Unfortunately, the DFA evaluation puts the option data in last, after the details of the mountpoint, so we have to cache the mount options in the fs_context using those hooks till we get to the new mountpoint hook.
---
security/apparmor/include/mount.h | 11 +++++ security/apparmor/lsm.c | 80 +++++++++++++++++++++++++++++++++++++ security/apparmor/mount.c | 46 +++++++++++++++++++++ 3 files changed, 135 insertions(+), 2 deletions(-)
security/apparmor/include/mount.h +10 -1
@@ -16,6 +16,7 @@#include <linux/fs.h> #include <linux/path.h> +#include <linux/fs_context.h> #include "domain.h" #include "policy.h"
@@ -27,7 +28,13 @@#define AA_AUDIT_DATA 0x40#define AA_MNT_CONT_MATCH 0x40 -#define AA_MS_IGNORE_MASK (MS_KERNMOUNT | MS_NOSEC | MS_ACTIVE | MS_BORN) +#define AA_SB_IGNORE_MASK (SB_KERNMOUNT | SB_NOSEC | SB_ACTIVE | SB_BORN) + +struct apparmor_fs_context { +struct fs_context fc; +char *saved_options; +size_t saved_size; +};int aa_remount (struct aa_label *label,const struct path *path,unsigned long flags,void *data);
@@ -45,6 +52,8 @@ int aa_move_mount(struct aa_label *label, const struct path *path,int aa_new_mount (struct aa_label *label,const char *dev_name,const struct path *path,const char *type,unsigned long flags,void *data); +int aa_new_mount_fc (struct aa_label *label,struct fs_context *fc, +const struct path *mountpoint);int aa_umount (struct aa_label *label,struct vfsmount *mnt,int flags);
security/apparmor/lsm.c +79 -1
98 lines not on this page · raw message
security/apparmor/mount.c +46 -0
52 lines not on this page · raw message
David Howells
maintainerPATCH 10/32 tomoyo: Implement security hooks for the new mount API [ver #9]
In reply to David HowellsImplement the security hook to check the creation of a new mountpoint for Tomoyo.
As far as I can tell, Tomoyo doesn't make use of the mount data or parse any mount options, so I haven't implemented any of the fs_context hooks for it.
---
security/tomoyo/common.h | 3 +++ security/tomoyo/mount.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ security/tomoyo/tomoyo.c | 15 +++++++++++++++ 3 files changed, 63 insertions(+)
security/tomoyo/common.h +3 -0
@@ -971,6 +971,9 @@ int tomoyo_init_request_info(struct tomoyo_request_info *r, const u8 index);int tomoyo_mkdev_perm (const u8 operation,const struct path *path,const unsigned int mode,unsigned int dev); +int tomoyo_mount_permission_fc (struct fs_context *fc, +const struct path *mountpoint, +unsigned int mnt_flags);int tomoyo_mount_permission (const char *dev_name,const struct path *path,const char *type,unsigned long flags,void *data_page);
security/tomoyo/mount.c +45 -0
54 lines not on this page · raw message
security/tomoyo/tomoyo.c +15 -0
@@ -391,6 +391,20 @@ static int tomoyo_path_chroot(const struct path *path)return tomoyo_path_perm (TOMOYO_TYPE_CHROOT , path,NULL ); } +/** +* tomoyo_sb_mount - Target for security_sb_mountpoint(). +* @fc: Context describing the object to be mounted. +* @mountpoint: The target object to mount on. +* @mnt_flags: Mountpoint specific options (as MNT_* flags). +* +* Returns 0 on success, negative value otherwise. +*/ +static int tomoyo_sb_mountpoint (struct fs_context *fc,struct path *mountpoint, +unsigned int mnt_flags) +{ +return tomoyo_mount_permission_fc (fc, mountpoint, mnt_flags); +} +/** * tomoyo_sb_mount - Target for security_sb_mount(). *
@@ -519,6 +533,7 @@ static struct security_hook_list tomoyo_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (path_chmod, tomoyo_path_chmod),LSM_HOOK_INIT (path_chown, tomoyo_path_chown),LSM_HOOK_INIT (path_chroot, tomoyo_path_chroot), +LSM_HOOK_INIT (sb_mountpoint, tomoyo_sb_mountpoint),LSM_HOOK_INIT (sb_mount, tomoyo_sb_mount),LSM_HOOK_INIT (sb_umount, tomoyo_sb_umount), LSM_HOOK_INIT(sb_pivotroot, tomoyo_sb_pivotroot),
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Tetsuo Handa
maintainerRe: [PATCH 10/32] tomoyo: Implement security hooks for the new mount API [ver #9]
Quoted 12 lines · David Howells
Implement the security hook to check the creation of a new mountpoint for Tomoyo.
As far as I can tell, Tomoyo doesn't make use of the mount data or parse any mount options, so I haven't implemented any of the
fs_contexthooks for it.Signed-off-by David Howells <[email protected]>cc Tetsuo Handa <[email protected]>cc tomoyo-dev-en at lists.sourceforge.jpcc linux-security-module at vger.kernel.org
Would you provide examples of each possible combination as a C program? For example, if one mount point from multiple sources with different options are possible, please describe such pattern using syscall so that LSM modules can run it to see whether they are working as expected.
--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
David Howells
maintainerPATCH 11/32 vfs: Require specification of size of mount data for internal mounts [ver #9]
In reply to David HowellsRequire specification of the size of the mount data passed to the VFS mounting functions by internal mounts. The problem is that the legacy handling for the upcoming mount-context patches has to copy an entire page as that's how big the buffer is defined as being, but some of the internal calls pass in a short bit of stack space, with the result that the stack guard page may get hit.
---
arch/ia64/kernel/perfmon.c | 3 +- arch/powerpc/platforms/cell/spufs/inode.c | 6 ++-- arch/s390/hypfs/inode.c | 7 +++-- arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 2 + drivers/base/devtmpfs.c | 6 ++-- drivers/dax/super.c | 2 + drivers/gpu/drm/drm_drv.c | 3 +- drivers/gpu/drm/i915/i915_gemfs.c | 2 + drivers/infiniband/hw/qib/qib_fs.c | 7 +++-- drivers/misc/cxl/api.c | 3 +- drivers/misc/ibmasm/ibmasmfs.c | 11 +++++-- drivers/mtd/mtdsuper.c | 26 ++++++++++------- drivers/oprofile/oprofilefs.c | 8 +++-- drivers/scsi/cxlflash/ocxl_hw.c | 2 + drivers/usb/gadget/function/f_fs.c | 7 +++-- drivers/usb/gadget/legacy/inode.c | 7 +++-- drivers/virtio/virtio_balloon.c | 2 + drivers/xen/xenfs/super.c | 7 +++-- fs/9p/vfs_super.c | 2 + fs/adfs/super.c | 9 +++--- fs/affs/super.c | 13 +++++---- fs/afs/mntpt.c | 3 +- fs/afs/super.c | 6 +++- fs/aio.c | 3 +- fs/anon_inodes.c | 3 +- fs/autofs/autofs_i.h | 2 + fs/autofs/init.c | 4 +-- fs/autofs/inode.c | 3 +- fs/befs/linuxvfs.c | 11 ++++--- fs/bfs/inode.c | 8 +++-- fs/binfmt_misc.c | 7 +++-- fs/block_dev.c | 2 + fs/btrfs/super.c | 30 ++++++++++++-------- fs/btrfs/tests/btrfs-tests.c | 2 + fs/ceph/super.c | 3 +- fs/cifs/cifs_dfs_ref.c | 3 +- fs/cifs/cifsfs.c | 18 +++++++----- fs/coda/inode.c | 11 +++++-- fs/configfs/mount.c | 7 +++-- fs/cramfs/inode.c | 17 +++++++---- fs/debugfs/inode.c | 14 +++++---- fs/devpts/inode.c | 10 ++++--- fs/ecryptfs/main.c | 2 + fs/efivarfs/super.c | 9 ++++-- fs/efs/super.c | 14 ++++++--- fs/exofs/super.c | 7 +++-- fs/ext2/super.c | 14 ++++++--- fs/ext4/super.c | 16 +++++++---- fs/f2fs/super.c | 11 +++++-- fs/fat/inode.c | 3 +- fs/fat/namei_msdos.c | 8 +++-- fs/fat/namei_vfat.c | 8 +++-- fs/freevxfs/vxfs_super.c | 12 +++++--- fs/fuse/control.c | 9 ++++-- fs/fuse/inode.c | 16 +++++++---- fs/gfs2/ops_fstype.c | 6 +++- fs/gfs2/super.c | 4 ++- fs/hfs/super.c | 12 +++++--- fs/hfsplus/super.c | 12 +++++--- fs/hostfs/hostfs_kern.c | 7 +++-- fs/hpfs/super.c | 11 +++++-- fs/hugetlbfs/inode.c | 13 +++++---- fs/internal.h | 4 +-- fs/isofs/inode.c | 11 +++++-- fs/jffs2/super.c | 10 ++++--- fs/jfs/super.c | 11 +++++-- fs/kernfs/mount.c | 3 +- fs/libfs.c | 2 + fs/minix/inode.c | 14 ++++++--- fs/namespace.c | 38 ++++++++++++++----------- fs/nfs/internal.h | 4 +-- fs/nfs/namespace.c | 3 +- fs/nfs/nfs4namespace.c | 3 +- fs/nfs/nfs4super.c | 27 ++++++++++-------- fs/nfs/super.c | 22 ++++++++------- fs/nfsd/nfsctl.c | 8 +++-- fs/nilfs2/super.c | 10 ++++--- fs/nsfs.c | 3 +- fs/ntfs/super.c | 13 ++++++--- fs/ocfs2/dlmfs/dlmfs.c | 5 ++- fs/ocfs2/super.c | 14 ++++++--- fs/omfs/inode.c | 9 ++++-- fs/openpromfs/inode.c | 11 +++++-- fs/orangefs/orangefs-kernel.h | 2 + fs/orangefs/super.c | 5 ++- fs/overlayfs/super.c | 11 +++++-- fs/pipe.c | 3 +- fs/proc/inode.c | 3 +- fs/proc/internal.h | 4 +-- fs/proc/root.c | 11 +++++-- fs/pstore/inode.c | 10 ++++--- fs/qnx4/inode.c | 14 ++++++--- fs/qnx6/inode.c | 14 ++++++--- fs/ramfs/inode.c | 6 ++-- fs/reiserfs/super.c | 14 ++++++--- fs/romfs/super.c | 13 +++++---- fs/squashfs/super.c | 12 +++++--- fs/super.c | 44 ++++++++++++++++------------- fs/sysfs/mount.c | 2 + fs/sysv/inode.c | 3 +- fs/sysv/super.c | 16 +++++++---- fs/tracefs/inode.c | 10 ++++--- fs/ubifs/super.c | 5 ++- fs/udf/super.c | 16 +++++++---- fs/ufs/super.c | 11 +++++-- fs/xfs/xfs_super.c | 10 +++++-- include/linux/debugfs.h | 8 +++-- include/linux/fs.h | 29 ++++++++++--------- include/linux/lsm_hooks.h | 13 ++++++--- include/linux/mount.h | 5 ++- include/linux/mtd/super.h | 4 +-- include/linux/ramfs.h | 4 +-- include/linux/security.h | 17 ++++++----- include/linux/shmem_fs.h | 3 +- init/do_mounts.c | 4 +-- ipc/mqueue.c | 9 +++--- kernel/bpf/inode.c | 7 +++-- kernel/cgroup/cgroup.c | 2 + kernel/cgroup/cpuset.c | 7 +++-- kernel/trace/trace.c | 7 +++-- mm/shmem.c | 10 ++++--- mm/zsmalloc.c | 3 +- net/socket.c | 3 +- net/sunrpc/rpc_pipe.c | 7 +++-- security/apparmor/apparmorfs.c | 8 +++-- security/apparmor/lsm.c | 3 +- security/inode.c | 7 +++-- security/security.c | 18 +++++++----- security/selinux/hooks.c | 11 ++++--- security/selinux/selinuxfs.c | 8 +++-- security/smack/smack_lsm.c | 6 +++- security/smack/smackfs.c | 9 ++++-- security/tomoyo/tomoyo.c | 4 ++- 133 files changed, 708 insertions(+), 468 deletions(-)
arch/ia64/kernel/perfmon.c +2 -1
@@ -611,7 +611,8 @@ pfm_unprotect_ctx_ctxsw(pfm_context_t *x, unsigned long f)static const struct dentry_operations pfmfs_dentry_operations;static struct dentry * -pfmfs_mount (struct file_system_type *fs_type,int flags,const char *dev_name,void *data) +pfmfs_mount (struct file_system_type *fs_type,int flags,const char *dev_name, +void *data,size_t data_size) {return mount_pseudo (fs_type,"pfm:" ,NULL , &pfmfs_dentry_operations,PFMFS_MAGIC );
arch/powerpc/platforms/cell/spufs/inode.c +3 -3
@@ -734,7 +734,7 @@ spufs_create_root(struct super_block *sb, void *data) }static int -spufs_fill_super (struct super_block *sb,void *data,int silent) +spufs_fill_super (struct super_block *sb,void *data,size_t data_size,int silent) {struct spufs_sb_info *info;static const struct super_operations s_ops = {
@@ -761,9 +761,9 @@ spufs_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *spufs_mount (struct file_system_type *fstype,int flags, -const char *name,void *data) +const char *name,void *data,size_t data_size) { -return mount_single (fstype, flags, data, spufs_fill_super); +return mount_single (fstype, flags, data, data_size, spufs_fill_super); }static struct file_system_type spufs_type = {
arch/s390/hypfs/inode.c +4 -3
@@ -266,7 +266,8 @@ static int hypfs_show_options(struct seq_file *s, struct dentry *root)return 0 ; } -static int hypfs_fill_super (struct super_block *sb,void *data,int silent) +static int hypfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct inode *root_inode;struct dentry *root_dentry;
@@ -309,9 +310,9 @@ static int hypfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *hypfs_mount (struct file_system_type *fst,int flags, -const char *devname,void *data) +const char *devname,void *data,size_t data_size) { -return mount_single (fst, flags, data, hypfs_fill_super); +return mount_single (fst, flags, data, data_size, hypfs_fill_super); }static void hypfs_kill_super (struct super_block *sb)
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +1 -1
@@ -1238,7 +1238,7 @@ static int mkdir_mondata_all(struct kernfs_node *parent_kn,static struct dentry *rdt_mount (struct file_system_type *fs_type,int flags,const char *unused_dev_name, -void *data) +void *data,size_t data_size) {struct rdt_domain *dom;struct rdt_resource *r;
drivers/base/devtmpfs.c +3 -3
@@ -57,12 +57,12 @@ static int __init mount_param(char *str)__setup ("devtmpfs.mount=" , mount_param);static struct dentry *dev_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) {#ifdef CONFIG_TMPFS -return mount_single (fs_type, flags, data, shmem_fill_super); +return mount_single (fs_type, flags, data, data_size, shmem_fill_super);#else -return mount_single (fs_type, flags, data, ramfs_fill_super); +return mount_single (fs_type, flags, data, data_size, ramfs_fill_super);#endif }
drivers/dax/super.c +1 -1
@@ -411,7 +411,7 @@ static const struct super_operations dax_sops = { };static struct dentry *dax_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) {return mount_pseudo (fs_type,"dax:" , &dax_sops,NULL ,DAXFS_MAGIC ); }
drivers/gpu/drm/drm_drv.c +2 -1
@@ -417,7 +417,8 @@ static const struct super_operations drm_fs_sops = { };static struct dentry *drm_fs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name, +void *data,size_t data_size) { return mount_pseudo(fs_type, "drm:",
drivers/gpu/drm/i915/i915_gemfs.c +1 -1
@@ -57,7 +57,7 @@ int i915_gemfs_init(struct drm_i915_private *i915)int flags =0 ;int err; - err = sb->s_op->remount_fs (sb, &flags, options); + err = sb->s_op->remount_fs (sb, &flags, options,sizeof (options));if (err) {kern_unmount (gemfs);return err;
drivers/infiniband/hw/qib/qib_fs.c +4 -3
@@ -506,7 +506,8 @@ static int remove_device_files(struct super_block *sb,* after device init. The direct add_cntr_files() call handles adding * them from the init code, when the fs is already mounted. */ -static int qibfs_fill_super (struct super_block *sb,void *data,int silent) +static int qibfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct qib_devdata *dd, *tmp;unsigned long flags;
@@ -541,11 +542,11 @@ static int qibfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *qibfs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) {struct dentry *ret; - ret =mount_single (fs_type, flags, data, qibfs_fill_super); + ret =mount_single (fs_type, flags, data, data_size, qibfs_fill_super);if (!IS_ERR (ret)) qib_super = ret->d_sb;return ret;
drivers/misc/cxl/api.c +2 -1
@@ -43,7 +43,8 @@ static const struct dentry_operations cxl_fs_dops = { };static struct dentry *cxl_fs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name, +void *data,size_t data_len) {return mount_pseudo (fs_type,"cxl:" ,NULL , &cxl_fs_dops,CXL_PSEUDO_FS_MAGIC );
drivers/misc/ibmasm/ibmasmfs.c +7 -4
@@ -88,13 +88,15 @@ static LIST_HEAD(service_processors);static struct inode *ibmasmfs_make_inode (struct super_block *sb,int mode);static void ibmasmfs_create_files (struct super_block *sb); -static int ibmasmfs_fill_super (struct super_block *sb,void *data,int silent); +static int ibmasmfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent);static struct dentry *ibmasmfs_mount (struct file_system_type *fst, -int flags,const char *name,void *data) +int flags,const char *name, +void *data,size_t data_size) { -return mount_single (fst, flags, data, ibmasmfs_fill_super); +return mount_single (fst, flags, data, data_size, ibmasmfs_fill_super); }static const struct super_operations ibmasmfs_s_ops = {
@@ -112,7 +114,8 @@ static struct file_system_type ibmasmfs_type = { };MODULE_ALIAS_FS ("ibmasmfs" ); -static int ibmasmfs_fill_super (struct super_block *sb,void *data,int silent) +static int ibmasmfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct inode *root;
drivers/mtd/mtdsuper.c +15 -11
@@ -61,9 +61,9 @@ static int get_sb_mtd_set(struct super_block *sb, void *_mtd)* get a superblock on an MTD-backed filesystem */ static struct dentry *mount_mtd_aux (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data, +const char *dev_name,void *data,size_t data_size,struct mtd_info *mtd, -int (*fill_super)(struct super_block *,void *,int )) +int (*fill_super)(struct super_block *,void *,size_t ,int )) {struct super_block *sb;int ret;
@@ -79,7 +79,7 @@ static struct dentry *mount_mtd_aux(struct file_system_type *fs_type, int flags,pr_debug ("MTDSB: New superblock for device %d (\"%s\")\n" , mtd->index, mtd->name); - ret =fill_super (sb, data, flags &SB_SILENT ?1 :0 ); + ret =fill_super (sb, data, data_size, flags &SB_SILENT ?1 :0 );if (ret <0 ) {deactivate_locked_super (sb);return ERR_PTR (ret);
@@ -105,8 +105,10 @@ static struct dentry *mount_mtd_aux(struct file_system_type *fs_type, int flags,* get a superblock on an MTD-backed filesystem by MTD device number */ static struct dentry *mount_mtd_nr (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data,int mtdnr, -int (*fill_super)(struct super_block *,void *,int )) +const char *dev_name, +void *data,size_t data_size,int mtdnr, +int (*fill_super)(struct super_block *,void *, +size_t ,int )) {struct mtd_info *mtd;
@@ -116,15 +118,16 @@ static struct dentry *mount_mtd_nr(struct file_system_type *fs_type, int flags,return ERR_CAST (mtd); } -return mount_mtd_aux (fs_type, flags, dev_name, data, mtd, fill_super); +return mount_mtd_aux (fs_type, flags, dev_name, data, data_size, mtd, + fill_super); }/* * set up an MTD-based superblock */ struct dentry *mount_mtd (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data, -int (*fill_super)(struct super_block *,void *,int )) +const char *dev_name,void *data,size_t data_size, +int (*fill_super)(struct super_block *,void *,size_t ,int )) {#ifdef CONFIG_BLOCK struct block_device *bdev;
@@ -153,7 +156,7 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,if (!IS_ERR (mtd))return mount_mtd_aux ( fs_type, flags, - dev_name, data, mtd, + dev_name, data, data_size, mtd, fill_super); printk(KERN_NOTICE "MTD:"
@@ -170,7 +173,7 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,pr_debug ("MTDSB: mtd%%d, mtdnr %d\n" , mtdnr);return mount_mtd_nr (fs_type, flags, - dev_name, data, + dev_name, data, data_size, mtdnr, fill_super); } }
@@ -197,7 +200,8 @@ struct dentry *mount_mtd(struct file_system_type *fs_type, int flags,if (major !=MTD_BLOCK_MAJOR ) goto not_an_MTD_device; -return mount_mtd_nr (fs_type, flags, dev_name, data, mtdnr, fill_super); +return mount_mtd_nr (fs_type, flags, dev_name, data, data_size, mtdnr, + fill_super); not_an_MTD_device:#endif /* CONFIG_BLOCK */
drivers/oprofile/oprofilefs.c +5 -3
@@ -238,7 +238,8 @@ struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name) } -static int oprofilefs_fill_super (struct super_block *sb,void *data,int silent) +static int oprofilefs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct inode *root_inode;
@@ -265,9 +266,10 @@ static int oprofilefs_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *oprofilefs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_single (fs_type, flags, data, oprofilefs_fill_super); +return mount_single (fs_type, flags, data, data_size, + oprofilefs_fill_super); }
drivers/scsi/cxlflash/ocxl_hw.c +1 -1
@@ -50,7 +50,7 @@ static const struct dentry_operations ocxlflash_fs_dops = {*/ static struct dentry *ocxlflash_fs_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) {return mount_pseudo (fs_type,"ocxlflash:" ,NULL , &ocxlflash_fs_dops,OCXLFLASH_FS_MAGIC );
drivers/usb/gadget/function/f_fs.c +4 -3
@@ -1366,7 +1366,8 @@ struct ffs_sb_fill_data {struct ffs_data *ffs_data; }; -static int ffs_sb_fill (struct super_block *sb,void *_data,int silent) +static int ffs_sb_fill (struct super_block *sb,void *_data,size_t data_size, +int silent) {struct ffs_sb_fill_data *data = _data;struct inode *inode;
@@ -1494,7 +1495,7 @@ static int ffs_fs_parse_opts(struct ffs_sb_fill_data *data, char *opts)static struct dentry *ffs_fs_mount (struct file_system_type *t,int flags, -const char *dev_name,void *opts) +const char *dev_name,void *opts,size_t data_size) {struct ffs_sb_fill_data data = { .perms = {
@@ -1536,7 +1537,7 @@ ffs_fs_mount(struct file_system_type *t, int flags, ffs->private_data = ffs_dev; data.ffs_data = ffs; - rv =mount_nodev (t, flags, &data, ffs_sb_fill); + rv =mount_nodev (t, flags, &data,sizeof (data), ffs_sb_fill);if (IS_ERR (rv) && data.ffs_data) {ffs_release_dev (data.ffs_data);ffs_data_put (data.ffs_data);
drivers/usb/gadget/legacy/inode.c +4 -3
@@ -1990,7 +1990,8 @@ static const struct super_operations gadget_fs_operations = { };static int -gadgetfs_fill_super (struct super_block *sb,void *opts,int silent) +gadgetfs_fill_super (struct super_block *sb,void *opts,size_t data_size, +int silent) {struct inode *inode;struct dev_data *dev;
@@ -2046,9 +2047,9 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent)/* "mount -t gadgetfs path /dev/gadget" ends up here */ static struct dentry *gadgetfs_mount (struct file_system_type *t,int flags, -const char *path,void *opts) +const char *path,void *opts,size_t data_size) { -return mount_single (t, flags, opts, gadgetfs_fill_super); +return mount_single (t, flags, opts, data_size, gadgetfs_fill_super); } static void
drivers/virtio/virtio_balloon.c +1 -1
@@ -526,7 +526,7 @@ static int virtballoon_migratepage(struct balloon_dev_info *vb_dev_info, }static struct dentry *balloon_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) {static const struct dentry_operations ops = { .d_dname = simple_dname,
drivers/xen/xenfs/super.c +4 -3
@@ -42,7 +42,8 @@ static const struct file_operations capabilities_file_ops = { .llseek = default_llseek, }; -static int xenfs_fill_super (struct super_block *sb,void *data,int silent) +static int xenfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {static const struct tree_descr xenfs_files[] = { [2 ] = {"xenbus" , &xen_xenbus_fops,S_IRUSR |S_IWUSR },
@@ -69,9 +70,9 @@ static int xenfs_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *xenfs_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_single (fs_type, flags, data, xenfs_fill_super); +return mount_single (fs_type, flags, data, data_size, xenfs_fill_super); }static struct file_system_type xenfs_type = {
fs/9p/vfs_super.c +1 -1
@@ -116,7 +116,7 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,*/ static struct dentry *v9fs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) {struct super_block *sb =NULL ;struct inode *inode =NULL ;
fs/adfs/super.c +5 -4
@@ -210,7 +210,7 @@ static int parse_options(struct super_block *sb, char *options)return 0 ; } -static int adfs_remount (struct super_block *sb,int *flags,char *data) +static int adfs_remount (struct super_block *sb,int *flags,char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_NODIRATIME ;
@@ -362,7 +362,8 @@ static inline unsigned long adfs_discsize(struct adfs_discrecord *dr, int block_return discsize; } -static int adfs_fill_super (struct super_block *sb,void *data,int silent) +static int adfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct adfs_discrecord *dr;struct buffer_head *bh;
@@ -522,9 +523,9 @@ static int adfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *adfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, adfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, adfs_fill_super); }static struct file_system_type adfs_fs_type = {
fs/affs/super.c +8 -5
@@ -26,7 +26,8 @@static int affs_statfs (struct dentry *dentry,struct kstatfs *buf);static int affs_show_options (struct seq_file *m,struct dentry *root); -static int affs_remount (struct super_block *sb,int *flags,char *data); +static int affs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);static void affs_commit_super (struct super_block *sb,int wait)
@@ -335,7 +336,8 @@ static int affs_show_options(struct seq_file *m, struct dentry *root)* hopefully have the guts to do so. Until then: sorry for the mess. */ -static int affs_fill_super (struct super_block *sb,void *data,int silent) +static int affs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct affs_sb_info *sbi;struct buffer_head *root_bh =NULL ;
@@ -550,7 +552,7 @@ static int affs_fill_super(struct super_block *sb, void *data, int silent) }static int -affs_remount (struct super_block *sb,int *flags,char *data) +affs_remount (struct super_block *sb,int *flags,char *data,size_t data_size) {struct affs_sb_info *sbi =AFFS_SB (sb);int blocksize;
@@ -633,9 +635,10 @@ affs_statfs(struct dentry *dentry, struct kstatfs *buf) }static struct dentry *affs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, affs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + affs_fill_super); }static void affs_kill_sb (struct super_block *sb)
fs/afs/mntpt.c +2 -1
@@ -152,7 +152,8 @@ static struct vfsmount *afs_mntpt_do_automount(struct dentry *mntpt)/* try and do the mount */ _debug ("--- attempting mount %s -o %s ---" , devname, options); - mnt =vfs_submount (mntpt, &afs_fs_type, devname, options); + mnt =vfs_submount (mntpt, &afs_fs_type, devname, + options,strlen (options) +1 );_debug ("--- mount result %p ---" , mnt);free_page ((unsigned long ) devname);
fs/afs/super.c +4 -2
@@ -31,7 +31,8 @@static void afs_i_init_once (void *foo);static struct dentry *afs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data); +int flags,const char *dev_name, +void *data,size_t data_size);static void afs_kill_super (struct super_block *sb);static struct inode *afs_alloc_inode (struct super_block *sb);static void afs_destroy_inode (struct inode *inode);
@@ -490,7 +491,8 @@ static void afs_kill_super(struct super_block *sb)* get an AFS superblock */ static struct dentry *afs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *options) +int flags,const char *dev_name, +void *options,size_t data_size) {struct afs_mount_params params;struct super_block *sb;
fs/aio.c +2 -1
@@ -245,7 +245,8 @@ static struct file *aio_private_file(struct kioctx *ctx, loff_t nr_pages) }static struct dentry *aio_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {static const struct dentry_operations ops = { .d_dname = simple_dname,
fs/anon_inodes.c +2 -1
@@ -39,7 +39,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = { };static struct dentry *anon_inodefs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {return mount_pseudo (fs_type,"anon_inode:" ,NULL , &anon_inodefs_dentry_operations,ANON_INODE_FS_MAGIC );
fs/autofs/autofs_i.h +1 -1
@@ -201,7 +201,7 @@ static inline void managed_dentry_clear_managed(struct dentry *dentry)/* Initializing function */ -int autofs_fill_super (struct super_block *,void *,int ); +int autofs_fill_super (struct super_block *,void *,size_t ,int );struct autofs_info *autofs_new_ino (struct autofs_sb_info *);void autofs_clean_ino (struct autofs_info *);
fs/autofs/init.c +2 -2
@@ -11,9 +11,9 @@#include "autofs_i.h" static struct dentry *autofs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_nodev (fs_type, flags, data, autofs_fill_super); +return mount_nodev (fs_type, flags, data, data_size, autofs_fill_super); }static struct file_system_type autofs_fs_type = {
fs/autofs/inode.c +2 -1
@@ -202,7 +202,8 @@ static int parse_options(char *options, int *pipefd, kuid_t *uid, kgid_t *gid,return (*pipefd <0 ); } -int autofs_fill_super (struct super_block *s,void *data,int silent) +int autofs_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct inode *root_inode;struct dentry *root;
fs/befs/linuxvfs.c +6 -5
@@ -52,7 +52,7 @@ static int befs_utf2nls(struct super_block *sb, const char *in, int in_len,static int befs_nls2utf (struct super_block *sb,const char *in,int in_len,char **out,int *out_len);static void befs_put_super (struct super_block *); -static int befs_remount (struct super_block *,int *,char *); +static int befs_remount (struct super_block *,int *,char *,size_t );static int befs_statfs (struct dentry *,struct kstatfs *);static int befs_show_options (struct seq_file *,struct dentry *);static int parse_options (char *,struct befs_mount_options *);
@@ -810,7 +810,7 @@ befs_put_super(struct super_block *sb)* Load a set of NLS translations if needed. */ static int -befs_fill_super (struct super_block *sb,void *data,int silent) +befs_fill_super (struct super_block *sb,void *data,size_t data_size,int silent) {struct buffer_head *bh;struct befs_sb_info *befs_sb;
@@ -942,7 +942,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent) }static int -befs_remount (struct super_block *sb,int *flags,char *data) +befs_remount (struct super_block *sb,int *flags,char *data,size_t data_size) {sync_filesystem (sb);if (!(*flags &SB_RDONLY ))
@@ -976,9 +976,10 @@ befs_statfs(struct dentry *dentry, struct kstatfs *buf)static struct dentry *befs_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, befs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + befs_fill_super); }static struct file_system_type befs_fs_type = {
fs/bfs/inode.c +5 -3
@@ -317,7 +317,8 @@ void bfs_dump_imap(const char *prefix, struct super_block *s)#endif } -static int bfs_fill_super (struct super_block *s,void *data,int silent) +static int bfs_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct buffer_head *bh, *sbh;struct bfs_super_block *bfs_sb;
@@ -460,9 +461,10 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent) }static struct dentry *bfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, bfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + bfs_fill_super); }static struct file_system_type bfs_fs_type = {
fs/binfmt_misc.c +4 -3
@@ -820,7 +820,8 @@ static const struct super_operations s_ops = { .evict_inode = bm_evict_inode, }; -static int bm_fill_super (struct super_block *sb,void *data,int silent) +static int bm_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {int err;static const struct tree_descr bm_files[] = {
@@ -836,9 +837,9 @@ static int bm_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *bm_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_single (fs_type, flags, data, bm_fill_super); +return mount_single (fs_type, flags, data, data_size, bm_fill_super); }static struct linux_binfmt misc_format = {
fs/block_dev.c +1 -1
@@ -786,7 +786,7 @@ static const struct super_operations bdev_sops = { };static struct dentry *bd_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) {struct dentry *dent; dent =mount_pseudo (fs_type,"bdev:" , &bdev_sops,NULL ,BDEVFS_MAGIC );
fs/btrfs/super.c +18 -12
@@ -64,7 +64,8 @@ static const struct super_operations btrfs_super_ops;static struct file_system_type btrfs_fs_type;static struct file_system_type btrfs_root_fs_type; -static int btrfs_remount (struct super_block *sb,int *flags,char *data); +static int btrfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);const char *btrfs_decode_error (int errno) {
@@ -1456,7 +1457,7 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,return root; } -static int parse_security_options (char *orig_opts, +static int parse_security_options (char *orig_opts,size_t data_size,struct security_mnt_opts *sec_opts) {char *secdata =NULL ;
@@ -1465,7 +1466,7 @@ static int parse_security_options(char *orig_opts, secdata =alloc_secdata ();if (!secdata)return -ENOMEM ; - ret =security_sb_copy_data (orig_opts, secdata); + ret =security_sb_copy_data (orig_opts, data_size, secdata);if (ret) {free_secdata (secdata);return ret;
@@ -1513,7 +1514,8 @@ static int setup_security_options(struct btrfs_fs_info *fs_info,* for multiple device setup. Make sure to keep it in sync. */ static struct dentry *btrfs_mount_root (struct file_system_type *fs_type, -int flags,const char *device_name,void *data) +int flags,const char *device_name, +void *data,size_t data_size) {struct block_device *bdev =NULL ;struct super_block *s;
@@ -1534,7 +1536,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,security_init_mnt_opts (&new_sec_opts);if (data) { - error =parse_security_options (data, &new_sec_opts); + error =parse_security_options (data, data_size, &new_sec_opts);if (error)return ERR_PTR (error); }
@@ -1638,7 +1640,7 @@ static struct dentry *btrfs_mount_root(struct file_system_type *fs_type,* "btrfs subvolume set-default", mount_subvol() is called always. */ static struct dentry *btrfs_mount (struct file_system_type *fs_type,int flags, -const char *device_name,void *data) +const char *device_name,void *data,size_t data_size) {struct vfsmount *mnt_root;struct dentry *root;
@@ -1658,21 +1660,24 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, }/* mount device's root (/) */ - mnt_root =vfs_kern_mount (&btrfs_root_fs_type, flags, device_name, data); + mnt_root =vfs_kern_mount (&btrfs_root_fs_type, flags, device_name, + data, data_size);if (PTR_ERR_OR_ZERO (mnt_root) == -EBUSY ) {if (flags &SB_RDONLY ) { mnt_root =vfs_kern_mount (&btrfs_root_fs_type, - flags & ~SB_RDONLY , device_name, data); + flags & ~SB_RDONLY , device_name, + data, data_size); }else { mnt_root =vfs_kern_mount (&btrfs_root_fs_type, - flags |SB_RDONLY , device_name, data); + flags |SB_RDONLY , device_name, + data, data_size);if (IS_ERR (mnt_root)) { root =ERR_CAST (mnt_root); goto out; }down_write (&mnt_root->mnt_sb->s_umount); - error =btrfs_remount (mnt_root->mnt_sb, &flags,NULL ); + error =btrfs_remount (mnt_root->mnt_sb, &flags,NULL ,0 );up_write (&mnt_root->mnt_sb->s_umount);if (error <0 ) { root =ERR_PTR (error);
@@ -1754,7 +1759,8 @@ static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,clear_bit (BTRFS_FS_STATE_REMOUNTING , &fs_info->fs_state); } -static int btrfs_remount (struct super_block *sb,int *flags,char *data) +static int btrfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct btrfs_fs_info *fs_info =btrfs_sb (sb);struct btrfs_root *root = fs_info->tree_root;
@@ -1773,7 +1779,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)struct security_mnt_opts new_sec_opts;security_init_mnt_opts (&new_sec_opts); - ret =parse_security_options (data, &new_sec_opts); + ret =parse_security_options (data, data_size, &new_sec_opts);if (ret) goto restore; ret = setup_security_options(fs_info, sb,
fs/btrfs/tests/btrfs-tests.c +1 -1
@@ -24,7 +24,7 @@ static const struct super_operations btrfs_test_super_ops = {static struct dentry *btrfs_test_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) {return mount_pseudo (fs_type,"btrfs_test:" , &btrfs_test_super_ops,NULL ,BTRFS_TEST_MAGIC );
fs/ceph/super.c +2 -1
@@ -1017,7 +1017,8 @@ static int ceph_setup_bdi(struct super_block *sb, struct ceph_fs_client *fsc) }static struct dentry *ceph_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {struct super_block *sb;struct ceph_fs_client *fsc;
fs/cifs/cifs_dfs_ref.c +2 -1
@@ -260,7 +260,8 @@ static struct vfsmount *cifs_dfs_do_refmount(struct dentry *mntpt,if (IS_ERR (mountdata))return (struct vfsmount *)mountdata; - mnt =vfs_submount (mntpt, &cifs_fs_type, devname, mountdata); + mnt =vfs_submount (mntpt, &cifs_fs_type, devname, + mountdata,strlen (mountdata) +1 );kfree (mountdata);kfree (devname);return mnt;
fs/cifs/cifsfs.c +11 -7
@@ -596,7 +596,8 @@ static int cifs_show_stats(struct seq_file *s, struct dentry *root) }#endif -static int cifs_remount (struct super_block *sb,int *flags,char *data) +static int cifs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_NODIRATIME ;
@@ -699,7 +700,8 @@ static int cifs_set_super(struct super_block *sb, void *data)static struct dentry *cifs_smb3_do_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data,bool is_smb3) +int flags,const char *dev_name,void *data,size_t data_size, +bool is_smb3) {int rc;struct super_block *sb;
@@ -720,7 +722,7 @@ cifs_smb3_do_mount(struct file_system_type *fs_type, goto out_nls; } - cifs_sb->mountdata =kstrndup (data,PAGE_SIZE ,GFP_KERNEL ); + cifs_sb->mountdata =kstrndup (data, data_size,GFP_KERNEL );if (cifs_sb->mountdata ==NULL ) { root =ERR_PTR (-ENOMEM ); goto out_free;
@@ -792,16 +794,18 @@ cifs_smb3_do_mount(struct file_system_type *fs_type,static struct dentry *smb3_do_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return cifs_smb3_do_mount (fs_type, flags, dev_name, data, true); +return cifs_smb3_do_mount (fs_type, flags, dev_name, data, data_size, + true); }static struct dentry *cifs_do_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return cifs_smb3_do_mount (fs_type, flags, dev_name, data, false); +return cifs_smb3_do_mount (fs_type, flags, dev_name, data, data_size, + false); } static ssize_t
fs/coda/inode.c +7 -4
@@ -93,7 +93,8 @@ void coda_destroy_inodecache(void)kmem_cache_destroy (coda_inode_cachep); } -static int coda_remount (struct super_block *sb,int *flags,char *data) +static int coda_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_NOATIME ;
@@ -150,7 +151,8 @@ static int get_device_index(struct coda_mount_data *data)return -1 ; } -static int coda_fill_super (struct super_block *sb,void *data,int silent) +static int coda_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct inode *root =NULL ;struct venus_comm *vc;
@@ -316,9 +318,10 @@ static int coda_statfs(struct dentry *dentry, struct kstatfs *buf)/* init_coda: used by filesystems.c to register coda */ static struct dentry *coda_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_nodev (fs_type, flags, data, coda_fill_super); +return mount_nodev (fs_type, flags, data, data_size, coda_fill_super); }struct file_system_type coda_fs_type = {
fs/configfs/mount.c +4 -3
@@ -66,7 +66,8 @@ static struct configfs_dirent configfs_root = { .s_iattr = NULL, }; -static int configfs_fill_super (struct super_block *sb,void *data,int silent) +static int configfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct inode *inode;struct dentry *root;
@@ -103,9 +104,9 @@ static int configfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *configfs_do_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_single (fs_type, flags, data, configfs_fill_super); +return mount_single (fs_type, flags, data, data_size, configfs_fill_super); }static struct file_system_type configfs_fs_type = {
fs/cramfs/inode.c +10 -7
@@ -502,7 +502,8 @@ static void cramfs_kill_sb(struct super_block *sb)kfree (sbi); } -static int cramfs_remount (struct super_block *sb,int *flags,char *data) +static int cramfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_RDONLY ;
@@ -603,7 +604,8 @@ static int cramfs_finalize_super(struct super_block *sb,return 0 ; } -static int cramfs_blkdev_fill_super (struct super_block *sb,void *data, +static int cramfs_blkdev_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct cramfs_sb_info *sbi;
@@ -625,8 +627,8 @@ static int cramfs_blkdev_fill_super(struct super_block *sb, void *data,return cramfs_finalize_super (sb, &super.root); } -static int cramfs_mtd_fill_super (struct super_block *sb,void *data, -int silent) +static int cramfs_mtd_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct cramfs_sb_info *sbi;struct cramfs_super super;
@@ -948,18 +950,19 @@ static const struct super_operations cramfs_ops = { };static struct dentry *cramfs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name, +void *data,size_t data_size) {struct dentry *ret =ERR_PTR (-ENOPROTOOPT );if (IS_ENABLED (CONFIG_CRAMFS_MTD )) { - ret =mount_mtd (fs_type, flags, dev_name, data, + ret =mount_mtd (fs_type, flags, dev_name, data, data_size, cramfs_mtd_fill_super);if (!IS_ERR (ret))return ret; }if (IS_ENABLED (CONFIG_CRAMFS_BLOCKDEV )) { - ret =mount_bdev (fs_type, flags, dev_name, data, + ret =mount_bdev (fs_type, flags, dev_name, data, data_size, cramfs_blkdev_fill_super); }return ret;
fs/debugfs/inode.c +8 -6
@@ -130,7 +130,8 @@ static int debugfs_apply_options(struct super_block *sb)return 0 ; } -static int debugfs_remount (struct super_block *sb,int *flags,char *data) +static int debugfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {int err;struct debugfs_fs_info *fsi = sb->s_fs_info;
@@ -190,7 +191,7 @@ static struct vfsmount *debugfs_automount(struct path *path) {debugfs_automount_t f; f = (debugfs_automount_t )path->dentry->d_fsdata; -return f (path->dentry,d_inode (path->dentry)->i_private); +return f (path->dentry,d_inode (path->dentry)->i_private,0 ); }static const struct dentry_operations debugfs_dops = {
@@ -199,7 +200,8 @@ static const struct dentry_operations debugfs_dops = { .d_automount = debugfs_automount, }; -static int debug_fill_super (struct super_block *sb,void *data,int silent) +static int debug_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {static const struct tree_descr debug_files[] = {{"" }};struct debugfs_fs_info *fsi;
@@ -235,9 +237,9 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *debug_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_single (fs_type, flags, data, debug_fill_super); +return mount_single (fs_type, flags, data, data_size, debug_fill_super); }static struct file_system_type debug_fs_type = {
@@ -539,7 +541,7 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir);struct dentry *debugfs_create_automount (const char *name,struct dentry *parent,debugfs_automount_t f, -void *data) +void *data,size_t data_size) {struct dentry *dentry =start_creating (name, parent);struct inode *inode;
fs/devpts/inode.c +6 -4
@@ -386,7 +386,8 @@ static void update_ptmx_mode(struct pts_fs_info *fsi) } } -static int devpts_remount (struct super_block *sb,int *flags,char *data) +static int devpts_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {int err;struct pts_fs_info *fsi =DEVPTS_SB (sb);
@@ -447,7 +448,8 @@ static void *new_pts_fs_info(struct super_block *sb) }static int -devpts_fill_super (struct super_block *s,void *data,int silent) +devpts_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct inode *inode;int error;
@@ -504,9 +506,9 @@ devpts_fill_super(struct super_block *s, void *data, int silent)* instance are independent of the PTYs in other devpts instances. */ static struct dentry *devpts_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_nodev (fs_type, flags, data, devpts_fill_super); +return mount_nodev (fs_type, flags, data, data_size, devpts_fill_super); }static void devpts_kill_sb (struct super_block *sb)
fs/ecryptfs/main.c +1 -1
@@ -488,7 +488,7 @@ static struct file_system_type ecryptfs_fs_type;* @raw_data: The options passed into the kernel */ static struct dentry *ecryptfs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *raw_data) +const char *dev_name,void *raw_data,size_t data_size) {struct super_block *s;struct ecryptfs_sb_info *sbi;
fs/efivarfs/super.c +6 -3
@@ -191,7 +191,8 @@ static int efivarfs_destroy(struct efivar_entry *entry, void *data)return 0 ; } -static int efivarfs_fill_super (struct super_block *sb,void *data,int silent) +static int efivarfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct inode *inode =NULL ;struct dentry *root;
@@ -227,9 +228,11 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *efivarfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_single (fs_type, flags, data, efivarfs_fill_super); +return mount_single (fs_type, flags, data, data_size, + efivarfs_fill_super); }static void efivarfs_kill_sb (struct super_block *sb)
fs/efs/super.c +9 -5
@@ -19,12 +19,14 @@#include <linux/efs_fs_sb.h> static int efs_statfs (struct dentry *dentry,struct kstatfs *buf); -static int efs_fill_super (struct super_block *s,void *d,int silent); +static int efs_fill_super (struct super_block *s,void *d,size_t data_size, +int silent);static struct dentry *efs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, efs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + efs_fill_super); }static void efs_kill_sb (struct super_block *s)
@@ -113,7 +115,8 @@ static void destroy_inodecache(void)kmem_cache_destroy (efs_inode_cachep); } -static int efs_remount (struct super_block *sb,int *flags,char *data) +static int efs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_RDONLY ;
@@ -253,7 +256,8 @@ static int efs_validate_super(struct efs_sb_info *sb, struct efs_super *super) {return 0 ; } -static int efs_fill_super (struct super_block *s,void *d,int silent) +static int efs_fill_super (struct super_block *s,void *d,size_t data_size, +int silent) {struct efs_sb_info *sb;struct buffer_head *bh;
fs/exofs/super.c +4 -3
@@ -704,7 +704,8 @@ static int exofs_read_lookup_dev_table(struct exofs_sb_info *sbi,/* * Read the superblock from the OSD and fill in the fields */ -static int exofs_fill_super (struct super_block *sb,void *data,int silent) +static int exofs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct inode *root;struct exofs_mountopt *opts = data;
@@ -860,7 +861,7 @@ static int exofs_fill_super(struct super_block *sb, void *data, int silent)*/ static struct dentry *exofs_mount (struct file_system_type *type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) {struct exofs_mountopt opts;int ret;
@@ -871,7 +872,7 @@ static struct dentry *exofs_mount(struct file_system_type *type,if (!opts.dev_name) opts.dev_name = dev_name; -return mount_nodev (type, flags, &opts, exofs_fill_super); +return mount_nodev (type, flags, &opts,0 , exofs_fill_super); }/*
fs/ext2/super.c +9 -5
@@ -39,7 +39,8 @@#include "acl.h" static void ext2_write_super (struct super_block *sb); -static int ext2_remount (struct super_block * sb,int * flags,char * data); +static int ext2_remount (struct super_block * sb,int * flags, +char * data,size_t data_size);static int ext2_statfs (struct dentry * dentry,struct kstatfs * buf);static int ext2_sync_fs (struct super_block *sb,int wait);static int ext2_freeze (struct super_block *sb);
@@ -815,7 +816,8 @@ static unsigned long descriptor_loc(struct super_block *sb,return ext2_group_first_block_no (sb, bg) + has_super; } -static int ext2_fill_super (struct super_block *sb,void *data,int silent) +static int ext2_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct dax_device *dax_dev =fs_dax_get_by_bdev (sb->s_bdev);struct buffer_head * bh;
@@ -1320,7 +1322,8 @@ static void ext2_write_super(struct super_block *sb)ext2_sync_fs (sb,1 ); } -static int ext2_remount (struct super_block * sb,int * flags,char * data) +static int ext2_remount (struct super_block * sb,int * flags, +char *data,size_t data_size) {struct ext2_sb_info * sbi =EXT2_SB (sb);struct ext2_super_block * es;
@@ -1474,9 +1477,10 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf) }static struct dentry *ext2_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, ext2_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + ext2_fill_super); }#ifdef CONFIG_QUOTA
fs/ext4/super.c +10 -6
@@ -70,12 +70,13 @@ static void ext4_mark_recovery_complete(struct super_block *sb,static void ext4_clear_journal_err (struct super_block *sb,struct ext4_super_block *es);static int ext4_sync_fs (struct super_block *sb,int wait); -static int ext4_remount (struct super_block *sb,int *flags,char *data); +static int ext4_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);static int ext4_statfs (struct dentry *dentry,struct kstatfs *buf);static int ext4_unfreeze (struct super_block *sb);static int ext4_freeze (struct super_block *sb);static struct dentry *ext4_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data); +const char *dev_name,void *data,size_t data_size);static inline int ext2_feature_set_ok (struct super_block *sb);static inline int ext3_feature_set_ok (struct super_block *sb);static int ext4_feature_set_ok (struct super_block *sb,int readonly);
@@ -3429,7 +3430,8 @@ static void ext4_set_resv_clusters(struct super_block *sb)atomic64_set (&sbi->s_resv_clusters, resv_clusters); } -static int ext4_fill_super (struct super_block *sb,void *data,int silent) +static int ext4_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct dax_device *dax_dev =fs_dax_get_by_bdev (sb->s_bdev);char *orig_data =kstrdup (data,GFP_KERNEL );
@@ -4999,7 +5001,8 @@ struct ext4_mount_options {#endif }; -static int ext4_remount (struct super_block *sb,int *flags,char *data) +static int ext4_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct ext4_super_block *es;struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -5766,9 +5769,10 @@ static int ext4_get_next_id(struct super_block *sb, struct kqid *qid)#endif static struct dentry *ext4_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, ext4_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + ext4_fill_super); }#if !defined(CONFIG_EXT2_FS ) && !defined(CONFIG_EXT2_FS_MODULE ) && defined(CONFIG_EXT4_USE_FOR_EXT2 )
fs/f2fs/super.c +7 -4
@@ -1387,7 +1387,8 @@ static void default_options(struct f2fs_sb_info *sbi)#ifdef CONFIG_QUOTA static int f2fs_enable_quotas (struct super_block *sb);#endif -static int f2fs_remount (struct super_block *sb,int *flags,char *data) +static int f2fs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct f2fs_sb_info *sbi =F2FS_SB (sb);struct f2fs_mount_info org_mount_opt;
@@ -2653,7 +2654,8 @@ static void f2fs_tuning_parameters(struct f2fs_sb_info *sbi) } } -static int f2fs_fill_super (struct super_block *sb,void *data,int silent) +static int f2fs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct f2fs_sb_info *sbi;struct f2fs_super_block *raw_super;
@@ -3081,9 +3083,10 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *f2fs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, f2fs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + f2fs_fill_super); }static void kill_f2fs_super (struct super_block *sb)
fs/fat/inode.c +2 -1
@@ -788,7 +788,8 @@ static void __exit fat_destroy_inodecache(void)kmem_cache_destroy (fat_inode_cachep); } -static int fat_remount (struct super_block *sb,int *flags,char *data) +static int fat_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {bool new_rdonly;struct msdos_sb_info *sbi =MSDOS_SB (sb);
fs/fat/namei_msdos.c +5 -3
@@ -651,16 +651,18 @@ static void setup(struct super_block *sb) sb->s_flags |=SB_NOATIME ; } -static int msdos_fill_super (struct super_block *sb,void *data,int silent) +static int msdos_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {return fat_fill_super (sb, data, silent,0 , setup); }static struct dentry *msdos_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, msdos_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + msdos_fill_super); }static struct file_system_type msdos_fs_type = {
fs/fat/namei_vfat.c +5 -3
@@ -1049,16 +1049,18 @@ static void setup(struct super_block *sb) sb->s_d_op = &vfat_dentry_ops; } -static int vfat_fill_super (struct super_block *sb,void *data,int silent) +static int vfat_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {return fat_fill_super (sb, data, silent,1 , setup); }static struct dentry *vfat_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, vfat_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + vfat_fill_super); }static struct file_system_type vfat_fs_type = {
fs/freevxfs/vxfs_super.c +8 -4
@@ -113,7 +113,8 @@ vxfs_statfs(struct dentry *dentry, struct kstatfs *bufp)return 0 ; } -static int vxfs_remount (struct super_block *sb,int *flags,char *data) +static int vxfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_RDONLY ;
@@ -199,6 +200,7 @@ static int vxfs_try_sb_magic(struct super_block *sbp, int silent,* vxfs_read_super - read superblock into memory and initialize filesystem * @sbp: VFS superblock (to fill) * @dp: fs private mount data +* @data_size: size of mount data * @silent: do not complain loudly when sth is wrong * * Description:
@@ -211,7 +213,8 @@ static int vxfs_try_sb_magic(struct super_block *sbp, int silent,* Locking: * We are under @sbp->s_lock. */ -static int vxfs_fill_super (struct super_block *sbp,void *dp,int silent) +static int vxfs_fill_super (struct super_block *sbp,void *dp,size_t data_size, +int silent) {struct vxfs_sb_info *infp;struct vxfs_sb *rsbp;
@@ -312,9 +315,10 @@ static int vxfs_fill_super(struct super_block *sbp, void *dp, int silent)* The usual module blurb. */ static struct dentry *vxfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, vxfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + vxfs_fill_super); }static struct file_system_type vxfs_fs_type = {
fs/fuse/control.c +6 -3
@@ -297,7 +297,8 @@ void fuse_ctl_remove_conn(struct fuse_conn *fc)drop_nlink (d_inode (fuse_control_sb->s_root)); } -static int fuse_ctl_fill_super (struct super_block *sb,void *data,int silent) +static int fuse_ctl_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {static const struct tree_descr empty_descr = {"" };struct fuse_conn *fc;
@@ -324,9 +325,11 @@ static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *fuse_ctl_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data) +int flags,const char *dev_name, +void *raw_data,size_t data_size) { -return mount_single (fs_type, flags, raw_data, fuse_ctl_fill_super); +return mount_single (fs_type, flags, raw_data, data_size, + fuse_ctl_fill_super); }static void fuse_ctl_kill_sb (struct super_block *sb)
fs/fuse/inode.c +10 -6
@@ -138,7 +138,8 @@ static void fuse_evict_inode(struct inode *inode) } } -static int fuse_remount_fs (struct super_block *sb,int *flags,char *data) +static int fuse_remount_fs (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb);if (*flags &SB_MANDLOCK )
@@ -1049,7 +1050,8 @@ void fuse_dev_free(struct fuse_dev *fud) }EXPORT_SYMBOL_GPL (fuse_dev_free); -static int fuse_fill_super (struct super_block *sb,void *data,int silent) +static int fuse_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct fuse_dev *fud;struct fuse_conn *fc;
@@ -1205,9 +1207,10 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *fuse_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *raw_data) +void *raw_data,size_t data_size) { -return mount_nodev (fs_type, flags, raw_data, fuse_fill_super); +return mount_nodev (fs_type, flags, raw_data, data_size, + fuse_fill_super); }static void fuse_kill_sb_anon (struct super_block *sb)
@@ -1235,9 +1238,10 @@ MODULE_ALIAS_FS("fuse");#ifdef CONFIG_BLOCK static struct dentry *fuse_mount_blk (struct file_system_type *fs_type,int flags,const char *dev_name, -void *raw_data) +void *raw_data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, raw_data, fuse_fill_super); +return mount_bdev (fs_type, flags, dev_name, raw_data, data_size, + fuse_fill_super); }static void fuse_kill_sb_blk (struct super_block *sb)
fs/gfs2/ops_fstype.c +4 -2
@@ -1220,6 +1220,7 @@ static int test_gfs2_super(struct super_block *s, void *ptr)* @flags: Mount flags * @dev_name: The name of the device * @data: The mount arguments +* @data_size: The size of the mount arguments * * Q. Why not use get_sb_bdev() ? * A. We need to select one of two root directories to mount, independent
@@ -1229,7 +1230,7 @@ static int test_gfs2_super(struct super_block *s, void *ptr)*/ static struct dentry *gfs2_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) {struct block_device *bdev;struct super_block *s;
@@ -1326,7 +1327,8 @@ static int set_meta_super(struct super_block *s, void *ptr) }static struct dentry *gfs2_mount_meta (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {struct super_block *s;struct gfs2_sbd *sdp;
fs/gfs2/super.c +3 -1
@@ -1228,11 +1228,13 @@ static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)* @sb: the filesystem * @flags: the remount flags * @data: extra data passed in (not used right now) +* @data_size: size of the extra data * * Returns: errno */ -static int gfs2_remount_fs (struct super_block *sb,int *flags,char *data) +static int gfs2_remount_fs (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct gfs2_sbd *sdp = sb->s_fs_info;struct gfs2_args args = sdp->sd_args;/* Default to current settings */
fs/hfs/super.c +8 -4
@@ -111,7 +111,8 @@ static int hfs_statfs(struct dentry *dentry, struct kstatfs *buf)return 0 ; } -static int hfs_remount (struct super_block *sb,int *flags,char *data) +static int hfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_NODIRATIME ;
@@ -382,7 +383,8 @@ static int parse_options(char *options, struct hfs_sb_info *hsb)* hfs_btree_init() to get the necessary data about the extents and * catalog B-trees and, finally, reading the root inode into memory. */ -static int hfs_fill_super (struct super_block *sb,void *data,int silent) +static int hfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct hfs_sb_info *sbi;struct hfs_find_data fd;
@@ -458,9 +460,11 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *hfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, hfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + hfs_fill_super); }static struct file_system_type hfs_fs_type = {
fs/hfsplus/super.c +8 -4
@@ -326,7 +326,8 @@ static int hfsplus_statfs(struct dentry *dentry, struct kstatfs *buf)return 0 ; } -static int hfsplus_remount (struct super_block *sb,int *flags,char *data) +static int hfsplus_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb);if ((bool )(*flags &SB_RDONLY ) ==sb_rdonly (sb))
@@ -371,7 +372,8 @@ static const struct super_operations hfsplus_sops = { .show_options = hfsplus_show_options, }; -static int hfsplus_fill_super (struct super_block *sb,void *data,int silent) +static int hfsplus_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct hfsplus_vh *vhdr;struct hfsplus_sb_info *sbi;
@@ -641,9 +643,11 @@ static void hfsplus_destroy_inode(struct inode *inode)#define HFSPLUS_INODE_SIZE sizeof(struct hfsplus_inode_info)static struct dentry *hfsplus_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, hfsplus_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + hfsplus_fill_super); }static struct file_system_type hfsplus_fs_type = {
fs/hostfs/hostfs_kern.c +4 -3
@@ -923,7 +923,8 @@ static const struct inode_operations hostfs_link_iops = { .get_link = hostfs_get_link, }; -static int hostfs_fill_sb_common (struct super_block *sb,void *d,int silent) +static int hostfs_fill_sb_common (struct super_block *sb, +void *d,size_t data_size,int silent) {struct inode *root_inode;char *host_root_path, *req_root = d;
@@ -983,9 +984,9 @@ static int hostfs_fill_sb_common(struct super_block *sb, void *d, int silent)static struct dentry *hostfs_read_sb (struct file_system_type *type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_nodev (type, flags, data, hostfs_fill_sb_common); +return mount_nodev (type, flags, data, data_size, hostfs_fill_sb_common); }static void hostfs_kill_sb (struct super_block *s)
fs/hpfs/super.c +7 -4
@@ -445,7 +445,8 @@ HPFS filesystem options:\n\ \n"); } -static int hpfs_remount_fs (struct super_block *s,int *flags,char *data) +static int hpfs_remount_fs (struct super_block *s,int *flags, +char *data,size_t data_size) {kuid_t uid;kgid_t gid;
@@ -540,7 +541,8 @@ static const struct super_operations hpfs_sops = .show_options = hpfs_show_options, }; -static int hpfs_fill_super (struct super_block *s,void *options,int silent) +static int hpfs_fill_super (struct super_block *s, +void *options,size_t data_size,int silent) {struct buffer_head *bh0, *bh1, *bh2;struct hpfs_boot_block *bootblock;
@@ -757,9 +759,10 @@ bail2: brelse(bh0); }static struct dentry *hpfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, hpfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + hpfs_fill_super); }static struct file_system_type hpfs_fs_type = {
fs/hugetlbfs/inode.c +8 -5
@@ -1220,7 +1220,8 @@ hugetlbfs_parse_options(char *options, struct hugetlbfs_config *pconfig) }static int -hugetlbfs_fill_super (struct super_block *sb,void *data,int silent) +hugetlbfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {int ret;struct hugetlbfs_config config;
@@ -1279,9 +1280,10 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *hugetlbfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_nodev (fs_type, flags, data, hugetlbfs_fill_super); +return mount_nodev (fs_type, flags, data, data_size, + hugetlbfs_fill_super); }static struct file_system_type hugetlbfs_fs_type = {
@@ -1420,10 +1422,11 @@ static int __init init_hugetlbfs_fs(void)for_each_hstate (h) {char buf[50 ];unsigned ps_kb =1U << (h->order +PAGE_SHIFT -10 ); +int n; -snprintf (buf,sizeof (buf),"pagesize=%uK" , ps_kb); + n =snprintf (buf,sizeof (buf),"pagesize=%uK" , ps_kb); hugetlbfs_vfsmount[i] =kern_mount_data (&hugetlbfs_fs_type, - buf); + buf, n +1 );if (IS_ERR (hugetlbfs_vfsmount[i])) { pr_err("Cannot mount internal hugetlbfs for "
fs/internal.h +2 -2
@@ -99,10 +99,10 @@ extern struct file *get_empty_filp(void);/* * super.c */ -extern int do_remount_sb (struct super_block *,int ,void *,int ); +extern int do_remount_sb (struct super_block *,int ,void *,size_t ,int );extern bool trylock_super (struct super_block *sb);extern struct dentry *mount_fs (struct file_system_type *, -int ,const char *,void *); +int ,const char *,void *,size_t );extern struct super_block *user_get_super (dev_t );/*
fs/isofs/inode.c +7 -4
@@ -111,7 +111,8 @@ static void destroy_inodecache(void)kmem_cache_destroy (isofs_inode_cachep); } -static int isofs_remount (struct super_block *sb,int *flags,char *data) +static int isofs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb);if (!(*flags &SB_RDONLY ))
@@ -619,7 +620,8 @@ static bool rootdir_empty(struct super_block *sb, unsigned long block)* Note: a check_disk_change() has been done immediately prior * to this call, so we don't need to check again. */ -static int isofs_fill_super (struct super_block *s,void *data,int silent) +static int isofs_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct buffer_head *bh =NULL , *pri_bh =NULL ;struct hs_primary_descriptor *h_pri =NULL ;
@@ -1558,9 +1560,10 @@ struct inode *__isofs_iget(struct super_block *sb, }static struct dentry *isofs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, isofs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + isofs_fill_super); }static struct file_system_type iso9660_fs_type = {
fs/jffs2/super.c +6 -4
@@ -238,7 +238,8 @@ static int jffs2_parse_options(struct jffs2_sb_info *c, char *data)return 0 ; } -static int jffs2_remount_fs (struct super_block *sb,int *flags,char *data) +static int jffs2_remount_fs (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct jffs2_sb_info *c =JFFS2_SB_INFO (sb);int err;
@@ -267,7 +268,8 @@ static const struct super_operations jffs2_super_operations =/* * fill in the superblock */ -static int jffs2_fill_super (struct super_block *sb,void *data,int silent) +static int jffs2_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct jffs2_sb_info *c;int ret;
@@ -312,9 +314,9 @@ static int jffs2_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *jffs2_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_mtd (fs_type, flags, dev_name, data, jffs2_fill_super); +return mount_mtd (fs_type, flags, dev_name, data, data_size, jffs2_fill_super); }static void jffs2_put_super (struct super_block *sb)
fs/jfs/super.c +7 -4
@@ -456,7 +456,8 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,return 0 ; } -static int jfs_remount (struct super_block *sb,int *flags,char *data) +static int jfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {s64 newLVSize =0 ;int rc =0 ;
@@ -516,7 +517,8 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data)return 0 ; } -static int jfs_fill_super (struct super_block *sb,void *data,int silent) +static int jfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct jfs_sb_info *sbi;struct inode *inode;
@@ -698,9 +700,10 @@ static int jfs_unfreeze(struct super_block *sb) }static struct dentry *jfs_do_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, jfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + jfs_fill_super); }static int jfs_sync_fs (struct super_block *sb,int wait)
fs/kernfs/mount.c +2 -1
@@ -22,7 +22,8 @@struct kmem_cache *kernfs_node_cache; -static int kernfs_sop_remount_fs (struct super_block *sb,int *flags,char *data) +static int kernfs_sop_remount_fs (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct kernfs_root *root =kernfs_info (sb)->root;struct kernfs_syscall_ops *scops = root->syscall_ops;
fs/libfs.c +1 -1
@@ -578,7 +578,7 @@ int simple_pin_fs(struct file_system_type *type, struct vfsmount **mount, int *cspin_lock (&pin_fs_lock);if (unlikely (!*mount)) {spin_unlock (&pin_fs_lock); - mnt =vfs_kern_mount (type,SB_KERNMOUNT , type->name,NULL ); + mnt =vfs_kern_mount (type,SB_KERNMOUNT , type->name,NULL ,0 );if (IS_ERR (mnt))return PTR_ERR (mnt);spin_lock (&pin_fs_lock);
fs/minix/inode.c +9 -5
@@ -22,7 +22,8 @@static int minix_write_inode (struct inode *inode,struct writeback_control *wbc);static int minix_statfs (struct dentry *dentry,struct kstatfs *buf); -static int minix_remount (struct super_block * sb,int * flags,char * data); +static int minix_remount (struct super_block * sb,int * flags, +char * data,size_t data_size);static void minix_evict_inode (struct inode *inode) {
@@ -118,7 +119,8 @@ static const struct super_operations minix_sops = { .remount_fs = minix_remount, }; -static int minix_remount (struct super_block * sb,int * flags,char * data) +static int minix_remount (struct super_block * sb,int * flags, +char * data,size_t data_size) {struct minix_sb_info * sbi =minix_sb (sb);struct minix_super_block * ms;
@@ -155,7 +157,8 @@ static int minix_remount (struct super_block * sb, int * flags, char * data)return 0 ; } -static int minix_fill_super (struct super_block *s,void *data,int silent) +static int minix_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct buffer_head *bh;struct buffer_head **map;
@@ -651,9 +654,10 @@ void minix_truncate(struct inode * inode) }static struct dentry *minix_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, minix_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + minix_fill_super); }static struct file_system_type minix_fs_type = {
fs/namespace.c +21 -17
@@ -1021,7 +1021,8 @@ static struct mount *skip_mnt_tree(struct mount *p) }struct vfsmount * -vfs_kern_mount (struct file_system_type *type,int flags,const char *name,void *data) +vfs_kern_mount (struct file_system_type *type,int flags,const char *name, +void *data,size_t data_size) {struct mount *mnt;struct dentry *root;
@@ -1036,7 +1037,7 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, voidif (flags &SB_KERNMOUNT ) mnt->mnt.mnt_flags =MNT_INTERNAL ; - root =mount_fs (type, flags, name, data); + root =mount_fs (type, flags, name, data, data_size);if (IS_ERR (root)) {mnt_free_id (mnt);free_vfsmnt (mnt);
@@ -1056,7 +1057,7 @@ EXPORT_SYMBOL_GPL(vfs_kern_mount);struct vfsmount *vfs_submount (const struct dentry *mountpoint,struct file_system_type *type, -const char *name,void *data) +const char *name,void *data,size_t data_size) {/* Until it is worked out how to pass the user namespace * through from the parent mount to the submount don't support
@@ -1065,7 +1066,7 @@ vfs_submount(const struct dentry *mountpoint, struct file_system_type *type,if (mountpoint->d_sb->s_user_ns != &init_user_ns)return ERR_PTR (-EPERM ); -return vfs_kern_mount (type,SB_SUBMOUNT , name, data); +return vfs_kern_mount (type,SB_SUBMOUNT , name, data, data_size); }EXPORT_SYMBOL_GPL (vfs_submount);
@@ -1596,7 +1597,7 @@ static int do_umount(struct mount *mnt, int flags)return -EPERM ;down_write (&sb->s_umount);if (!sb_rdonly (sb)) - retval =do_remount_sb (sb,SB_RDONLY ,NULL ,0 ); + retval =do_remount_sb (sb,SB_RDONLY ,NULL ,0 ,0 );up_write (&sb->s_umount);return retval; }
@@ -2377,7 +2378,7 @@ static int change_mount_flags(struct vfsmount *mnt, int ms_flags)* on it - tough luck. */ static int do_remount (struct path *path,int ms_flags,int sb_flags, -int mnt_flags,void *data) +int mnt_flags,void *data,size_t data_size) {int err;struct super_block *sb = path->mnt->mnt_sb;
@@ -2416,7 +2417,7 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,return -EPERM ; } - err =security_sb_remount (sb, data); + err =security_sb_remount (sb, data, data_size);if (err)return err;
@@ -2426,7 +2427,7 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,else if (!ns_capable (sb->s_user_ns,CAP_SYS_ADMIN )) err = -EPERM ;else - err =do_remount_sb (sb, sb_flags, data,0 ); + err =do_remount_sb (sb, sb_flags, data, data_size,0 );if (!err) {lock_mount_hash (); mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK ;
@@ -2613,7 +2614,8 @@ static bool mount_too_revealing(struct vfsmount *mnt, int *new_mnt_flags);* namespace's tree */ static int do_new_mount (struct path *path,const char *fstype,int sb_flags, -int mnt_flags,const char *name,void *data) +int mnt_flags,const char *name, +void *data,size_t data_size) {struct file_system_type *type;struct vfsmount *mnt;
@@ -2626,7 +2628,7 @@ static int do_new_mount(struct path *path, const char *fstype, int sb_flags,if (!type)return -ENODEV ; - mnt =vfs_kern_mount (type, sb_flags, name, data); + mnt =vfs_kern_mount (type, sb_flags, name, data, data_size);if (!IS_ERR (mnt) && (type->fs_flags &FS_HAS_SUBTYPE ) && !mnt->mnt_sb->s_subtype) mnt =fs_set_subtype (mnt, fstype);
@@ -2882,6 +2884,7 @@ long do_mount(const char *dev_name, const char __user *dir_name, {struct path path;unsigned int mnt_flags =0 , sb_flags; +size_t data_size = data_page ?PAGE_SIZE :0 ;int retval =0 ;/* Discard magic */
@@ -2900,8 +2903,8 @@ long do_mount(const char *dev_name, const char __user *dir_name,if (retval)return retval; - retval =security_sb_mount (dev_name, &path, - type_page, flags, data_page); + retval =security_sb_mount (dev_name, &path, type_page, flags, + data_page, data_size);if (!retval && !may_mount ()) retval = -EPERM ;if (!retval && (flags &SB_MANDLOCK ) && !may_mandlock ())
@@ -2948,7 +2951,7 @@ long do_mount(const char *dev_name, const char __user *dir_name,if (flags &MS_REMOUNT ) retval =do_remount (&path, flags, sb_flags, mnt_flags, - data_page); + data_page, data_size);else if (flags &MS_BIND ) retval =do_loopback (&path, dev_name, flags &MS_REC );else if (flags & (MS_SHARED |MS_PRIVATE |MS_SLAVE |MS_UNBINDABLE ))
@@ -2957,7 +2960,7 @@ long do_mount(const char *dev_name, const char __user *dir_name, retval =do_move_mount_old (&path, dev_name); else retval =do_new_mount (&path, type_page, sb_flags, mnt_flags, - dev_name, data_page); + dev_name, data_page, data_size); dput_out:path_put (&path);return retval;
@@ -3404,7 +3407,7 @@ static void __init init_mount_tree(void) type =get_fs_type ("rootfs" );if (!type)panic ("Can't find rootfs type" ); - mnt =vfs_kern_mount (type,0 ,"rootfs" ,NULL ); + mnt =vfs_kern_mount (type,0 ,"rootfs" ,NULL ,0 );put_filesystem (type);if (IS_ERR (mnt))panic ("Can't create rootfs" );
@@ -3466,10 +3469,11 @@ void put_mnt_ns(struct mnt_namespace *ns)free_mnt_ns (ns); } -struct vfsmount *kern_mount_data (struct file_system_type *type,void *data) +struct vfsmount *kern_mount_data (struct file_system_type *type, +void *data,size_t data_size) {struct vfsmount *mnt; - mnt =vfs_kern_mount (type,SB_KERNMOUNT , type->name, data); + mnt =vfs_kern_mount (type,SB_KERNMOUNT , type->name, data, data_size);if (!IS_ERR (mnt)) {/* * it is a longterm mount, don't release mnt until
fs/nfs/internal.h +2 -2
@@ -405,7 +405,7 @@ int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_int nfs_clone_sb_security (struct super_block *,struct dentry *,struct nfs_mount_info *);struct dentry *nfs_fs_mount_common (struct nfs_server *,int ,const char *,struct nfs_mount_info *,struct nfs_subversion *); -struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *); +struct dentry *nfs_fs_mount (struct file_system_type *,int ,const char *,void *,size_t );struct dentry *nfs_xdev_mount_common (struct file_system_type *,int ,const char *,struct nfs_mount_info *);void nfs_kill_super (struct super_block *);
@@ -466,7 +466,7 @@ int nfs_show_options(struct seq_file *, struct dentry *);int nfs_show_devname (struct seq_file *,struct dentry *);int nfs_show_path (struct seq_file *,struct dentry *);int nfs_show_stats (struct seq_file *,struct dentry *); -int nfs_remount (struct super_block *sb,int *flags,char *raw_data); +int nfs_remount (struct super_block *sb,int *flags,char *raw_data,size_t data_size);/* write.c */ extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
fs/nfs/namespace.c +2 -1
@@ -216,7 +216,8 @@ static struct vfsmount *nfs_do_clone_mount(struct nfs_server *server,const char *devname, struct nfs_clone_mount *mountdata) { - return vfs_submount(mountdata->dentry, &nfs_xdev_fs_type, devname, mountdata); + return vfs_submount(mountdata->dentry, &nfs_xdev_fs_type, devname, + mountdata, 0); }/**
fs/nfs/nfs4namespace.c +2 -1
@@ -278,7 +278,8 @@ static struct vfsmount *try_location(struct nfs_clone_mount *mountdata, mountdata->hostname, mountdata->mnt_path); - mnt =vfs_submount (mountdata->dentry, &nfs4_referral_fs_type, page, mountdata); + mnt =vfs_submount (mountdata->dentry, &nfs4_referral_fs_type, page, + mountdata,0 );if (!IS_ERR (mnt))break ; }
fs/nfs/nfs4super.c +15 -12
@@ -18,11 +18,11 @@static int nfs4_write_inode (struct inode *inode,struct writeback_control *wbc);static void nfs4_evict_inode (struct inode *inode);static struct dentry *nfs4_remote_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data); +int flags,const char *dev_name,void *raw_data,size_t data_size);static struct dentry *nfs4_referral_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data); +int flags,const char *dev_name,void *raw_data,size_t data_size);static struct dentry *nfs4_remote_referral_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data); +int flags,const char *dev_name,void *raw_data,size_t data_size);static struct file_system_type nfs4_remote_fs_type = { .owner =THIS_MODULE ,
@@ -105,7 +105,7 @@ static void nfs4_evict_inode(struct inode *inode)*/ static struct dentry *nfs4_remote_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *info) +const char *dev_name,void *info,size_t data_size) {struct nfs_mount_info *mount_info = info;struct nfs_server *server;
@@ -127,7 +127,7 @@ nfs4_remote_mount(struct file_system_type *fs_type, int flags, }static struct vfsmount *nfs_do_root_mount (struct file_system_type *fs_type, -int flags,void *data,const char *hostname) +int flags,void *data,size_t data_size,const char *hostname) {struct vfsmount *root_mnt;char *root_devname;
@@ -142,7 +142,8 @@ static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,snprintf (root_devname, len,"[%s]:/" , hostname); else snprintf(root_devname, len, "%s:/", hostname); - root_mnt =vfs_kern_mount (fs_type, flags, root_devname, data); + root_mnt =vfs_kern_mount (fs_type, flags, root_devname, + data, data_size);kfree (root_devname);return root_mnt; }
@@ -247,8 +248,8 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name, export_path = data->nfs_server.export_path; data->nfs_server.export_path ="/" ; - root_mnt =nfs_do_root_mount (&nfs4_remote_fs_type, flags, mount_info, - data->nfs_server.hostname); + root_mnt =nfs_do_root_mount (&nfs4_remote_fs_type, flags, mount_info,0 , + data->nfs_server.hostname); data->nfs_server.export_path = export_path; res =nfs_follow_remote_path (root_mnt, export_path);
@@ -261,7 +262,8 @@ struct dentry *nfs4_try_mount(int flags, const char *dev_name,static struct dentry *nfs4_remote_referral_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *raw_data) +const char *dev_name, +void *raw_data,size_t data_size) {struct nfs_mount_info mount_info = { .fill_super = nfs_fill_super,
@@ -294,7 +296,8 @@ nfs4_remote_referral_mount(struct file_system_type *fs_type, int flags,* Create an NFS4 server record on referral traversal */ static struct dentry *nfs4_referral_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data) +int flags,const char *dev_name, +void *raw_data,size_t data_size) {struct nfs_clone_mount *data = raw_data;char *export_path;
@@ -306,8 +309,8 @@ static struct dentry *nfs4_referral_mount(struct file_system_type *fs_type, export_path = data->mnt_path; data->mnt_path ="/" ; - root_mnt =nfs_do_root_mount (&nfs4_remote_referral_fs_type, - flags, data, data->hostname); + root_mnt =nfs_do_root_mount (&nfs4_remote_referral_fs_type, flags, + data,0 , data->hostname); data->mnt_path = export_path; res =nfs_follow_remote_path (root_mnt, export_path);
fs/nfs/super.c +12 -10
@@ -287,7 +287,8 @@ static match_table_t nfs_vers_tokens = { };static struct dentry *nfs_xdev_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data); +int flags,const char *dev_name, +void *raw_data,size_t data_size);struct file_system_type nfs_fs_type = { .owner =THIS_MODULE ,
@@ -1203,7 +1204,7 @@ static int nfs_get_option_ul_bound(substring_t args[], unsigned long *option,* skipped as they are encountered. If there were no errors, return 1; * otherwise return 0 (zero). */ -static int nfs_parse_mount_options (char *raw, +static int nfs_parse_mount_options (char *raw,size_t raw_size,struct nfs_parsed_mount_data *mnt) {char *p, *string, *secdata;
@@ -1221,7 +1222,7 @@ static int nfs_parse_mount_options(char *raw,if (!secdata) goto out_nomem; - rc =security_sb_copy_data (raw, secdata); + rc =security_sb_copy_data (raw, raw_size, secdata);if (rc) goto out_security_failure;
@@ -2151,7 +2152,7 @@ static int nfs_validate_mount_data(struct file_system_type *fs_type, }#endif -static int nfs_validate_text_mount_data (void *options, +static int nfs_validate_text_mount_data (void *options,size_t data_size,struct nfs_parsed_mount_data *args,const char *dev_name) {
@@ -2160,7 +2161,7 @@ static int nfs_validate_text_mount_data(void *options,int max_pathlen =NFS_MAXPATHLEN ;struct sockaddr *sap = (struct sockaddr *)&args->nfs_server.address; -if (nfs_parse_mount_options ((char *)options, args) ==0 ) +if (nfs_parse_mount_options ((char *)options, data_size, args) ==0 )return -EINVAL ;if (!nfs_verify_server_address (sap))
@@ -2243,7 +2244,7 @@ nfs_compare_remount_data(struct nfs_server *nfss, }int -nfs_remount (struct super_block *sb,int *flags,char *raw_data) +nfs_remount (struct super_block *sb,int *flags,char *raw_data,size_t data_size) {int error;struct nfs_server *nfss = sb->s_fs_info;
@@ -2290,7 +2291,7 @@ nfs_remount(struct super_block *sb, int *flags, char *raw_data)/* overwrite those values with any that were specified */ error = -EINVAL ; -if (!nfs_parse_mount_options ((char *)options, data)) +if (!nfs_parse_mount_options ((char *)options, data_size, data)) goto out;/*
@@ -2662,7 +2663,7 @@ struct dentry *nfs_fs_mount_common(struct nfs_server *server,EXPORT_SYMBOL_GPL (nfs_fs_mount_common);struct dentry *nfs_fs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *raw_data) +int flags,const char *dev_name,void *raw_data,size_t data_size) {struct nfs_mount_info mount_info = { .fill_super = nfs_fill_super,
@@ -2680,7 +2681,8 @@ struct dentry *nfs_fs_mount(struct file_system_type *fs_type,/* Validate the mount data */ error =nfs_validate_mount_data (fs_type, raw_data, mount_info.parsed, mount_info.mntfh, dev_name);if (error ==NFS_TEXT_DATA ) - error =nfs_validate_text_mount_data (raw_data, mount_info.parsed, dev_name); + error =nfs_validate_text_mount_data (raw_data, data_size, + mount_info.parsed, dev_name);if (error <0 ) { mntroot =ERR_PTR (error); goto out;
@@ -2724,7 +2726,7 @@ EXPORT_SYMBOL_GPL(nfs_kill_super);*/ static struct dentry *nfs_xdev_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *raw_data) +const char *dev_name,void *raw_data,size_t data_size) {struct nfs_clone_mount *data = raw_data;struct nfs_mount_info mount_info = {
fs/nfsd/nfsctl.c +5 -3
@@ -1144,7 +1144,8 @@ static ssize_t write_v4_end_grace(struct file *file, char *buf, size_t size)* populating the filesystem. */ -static int nfsd_fill_super (struct super_block * sb,void * data,int silent) +static int nfsd_fill_super (struct super_block * sb, +void * data,size_t data_size,int silent) {static const struct tree_descr nfsd_files[] = { [NFSD_List] = {"exports" , &exports_nfsd_operations,S_IRUGO },
@@ -1179,10 +1180,11 @@ static int nfsd_fill_super(struct super_block * sb, void * data, int silent) }static struct dentry *nfsd_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) {struct net *net = current->nsproxy->net_ns; -return mount_ns (fs_type, flags, data, net, net->user_ns, nfsd_fill_super); +return mount_ns (fs_type, flags, data, data_size, + net, net->user_ns, nfsd_fill_super); }static void nfsd_umount (struct super_block *sb)
fs/nilfs2/super.c +6 -4
@@ -69,7 +69,8 @@ struct kmem_cache *nilfs_segbuf_cachep;struct kmem_cache *nilfs_btree_path_cache;static int nilfs_setup_super (struct super_block *sb,int is_mount); -static int nilfs_remount (struct super_block *sb,int *flags,char *data); +static int nilfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);void __nilfs_msg (struct super_block *sb,const char *level,const char *fmt, ...)
@@ -1118,7 +1119,8 @@ nilfs_fill_super(struct super_block *sb, void *data, int silent)return err; } -static int nilfs_remount (struct super_block *sb,int *flags,char *data) +static int nilfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct the_nilfs *nilfs = sb->s_fs_info;unsigned long old_sb_flags;
@@ -1278,7 +1280,7 @@ static int nilfs_test_bdev_super(struct super_block *s, void *data)static struct dentry *nilfs_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data) +const char *dev_name,void *data,size_t data_size) {struct nilfs_super_data sd;struct super_block *s;
@@ -1346,7 +1348,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,* Try remount to setup mount states if the current * tree is not mounted and only snapshots use this sb. */ - err =nilfs_remount (s, &flags, data); + err =nilfs_remount (s, &flags, data, data_size);if (err) goto failed_super; }
fs/nsfs.c +2 -1
@@ -263,7 +263,8 @@ static const struct super_operations nsfs_ops = { .show_path = nsfs_show_path, };static struct dentry *nsfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {return mount_pseudo (fs_type,"nsfs:" , &nsfs_ops, &ns_dentry_operations,NSFS_MAGIC );
fs/ntfs/super.c +9 -4
@@ -456,6 +456,7 @@ static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)* @sb: superblock of mounted ntfs filesystem * @flags: remount flags * @opt: remount options string +* @data_size: size of the options string * * Change the mount options of an already mounted ntfs filesystem. *
@@ -463,7 +464,8 @@ static inline int ntfs_clear_volume_flags(ntfs_volume *vol, VOLUME_FLAGS flags)* ntfs_remount() returns successfully (i.e. returns 0). Otherwise, * @sb->s_flags are not changed. */ -static int ntfs_remount (struct super_block *sb,int *flags,char *opt) +static int ntfs_remount (struct super_block *sb,int *flags, +char *opt,size_t data_size) {ntfs_volume *vol =NTFS_SB (sb);
@@ -2694,6 +2696,7 @@ static const struct super_operations ntfs_sops = {* ntfs_fill_super - mount an ntfs filesystem * @sb: super block of ntfs filesystem to mount * @opt: string containing the mount options +* @data_size: size of the mount options string * @silent: silence error output * * ntfs_fill_super() is called by the VFS to mount the device described by @sb
@@ -2708,7 +2711,8 @@ static const struct super_operations ntfs_sops = {* * NOTE: @sb->s_flags contains the mount options flags. */ -static int ntfs_fill_super (struct super_block *sb,void *opt,const int silent) +static int ntfs_fill_super (struct super_block *sb,void *opt,size_t data_size, +const int silent) {ntfs_volume *vol;struct buffer_head *bh;
@@ -3060,9 +3064,10 @@ struct kmem_cache *ntfs_index_ctx_cache;DEFINE_MUTEX (ntfs_lock);static struct dentry *ntfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, ntfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + ntfs_fill_super); }static struct file_system_type ntfs_fs_type = {
fs/ocfs2/dlmfs/dlmfs.c +3 -2
@@ -568,6 +568,7 @@ static int dlmfs_unlink(struct inode *dir,static int dlmfs_fill_super (struct super_block * sb,void * data, +size_t data_size,int silent) { sb->s_maxbytes =MAX_LFS_FILESIZE ;
@@ -617,9 +618,9 @@ static const struct inode_operations dlmfs_file_inode_operations = { };static struct dentry *dlmfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_nodev (fs_type, flags, data, dlmfs_fill_super); +return mount_nodev (fs_type, flags, data, data_size, dlmfs_fill_super); }static struct file_system_type dlmfs_fs_type = {
fs/ocfs2/super.c +9 -5
@@ -107,7 +107,8 @@ static int ocfs2_check_set_options(struct super_block *sb,static int ocfs2_show_options (struct seq_file *s,struct dentry *root);static void ocfs2_put_super (struct super_block *sb);static int ocfs2_mount_volume (struct super_block *sb); -static int ocfs2_remount (struct super_block *sb,int *flags,char *data); +static int ocfs2_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);static void ocfs2_dismount_volume (struct super_block *sb,int mnt_err);static int ocfs2_initialize_mem_caches (void );static void ocfs2_free_mem_caches (void );
@@ -633,7 +634,8 @@ static unsigned long long ocfs2_max_file_offset(unsigned int bbits,return (((unsigned long long )bytes) << bitshift) - trim; } -static int ocfs2_remount (struct super_block *sb,int *flags,char *data) +static int ocfs2_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {int incompat_features;int ret =0 ;
@@ -999,7 +1001,8 @@ static void ocfs2_disable_quotas(struct ocfs2_super *osb) } } -static int ocfs2_fill_super (struct super_block *sb,void *data,int silent) +static int ocfs2_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct dentry *root;int status, sector_size;
@@ -1236,9 +1239,10 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *ocfs2_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, ocfs2_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + ocfs2_fill_super); }static struct file_system_type ocfs2_fs_type = {
fs/omfs/inode.c +6 -3
@@ -454,7 +454,8 @@ static int parse_options(char *options, struct omfs_sb_info *sbi)return 1 ; } -static int omfs_fill_super (struct super_block *sb,void *data,int silent) +static int omfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct buffer_head *bh, *bh2;struct omfs_super_block *omfs_sb;
@@ -596,9 +597,11 @@ static int omfs_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *omfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, omfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + omfs_fill_super); }static struct file_system_type omfs_fs_type = {
fs/openpromfs/inode.c +7 -4
@@ -365,7 +365,8 @@ static struct inode *openprom_iget(struct super_block *sb, ino_t ino)return inode; } -static int openprom_remount (struct super_block *sb,int *flags,char *data) +static int openprom_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_NOATIME ;
@@ -379,7 +380,8 @@ static const struct super_operations openprom_sops = { .remount_fs = openprom_remount, }; -static int openprom_fill_super (struct super_block *s,void *data,int silent) +static int openprom_fill_super (struct super_block *s, +void *data,size_t data_size,int silent) {struct inode *root_inode;struct op_inode_info *oi;
@@ -414,9 +416,10 @@ static int openprom_fill_super(struct super_block *s, void *data, int silent) }static struct dentry *openprom_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_single (fs_type, flags, data, openprom_fill_super); +return mount_single (fs_type, flags, data, data_size, + openprom_fill_super); }static struct file_system_type openprom_fs_type = {
fs/orangefs/orangefs-kernel.h +1 -1
@@ -318,7 +318,7 @@ extern uint64_t orangefs_features;struct dentry *orangefs_mount (struct file_system_type *fst,int flags,const char *devname, -void *data); +void *data,size_t data_size);void orangefs_kill_sb (struct super_block *sb);int orangefs_remount (struct orangefs_sb_info_s *);
fs/orangefs/super.c +3 -2
@@ -207,7 +207,8 @@ static int orangefs_statfs(struct dentry *dentry, struct kstatfs *buf)* Remount as initiated by VFS layer. We just need to reparse the mount * options, no need to signal pvfs2-client-core about it. */ -static int orangefs_remount_fs (struct super_block *sb,int *flags,char *data) +static int orangefs_remount_fs (struct super_block *sb,int *flags, +char *data,size_t data_size) {gossip_debug (GOSSIP_SUPER_DEBUG ,"orangefs_remount_fs: called\n" );return parse_mount_options (sb, data,1 );
@@ -457,7 +458,7 @@ static int orangefs_fill_sb(struct super_block *sb,struct dentry *orangefs_mount (struct file_system_type *fst,int flags,const char *devname, -void *data) +void *data,size_t data_size) {int ret = -EINVAL ;struct super_block *sb =ERR_PTR (-EINVAL );
fs/overlayfs/super.c +7 -4
@@ -379,7 +379,8 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)return 0 ; } -static int ovl_remount (struct super_block *sb,int *flags,char *data) +static int ovl_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct ovl_fs *ofs = sb->s_fs_info;
@@ -1354,7 +1355,8 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, goto out; } -static int ovl_fill_super (struct super_block *sb,void *data,int silent) +static int ovl_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct path upperpath = { };struct dentry *root_dentry;
@@ -1492,9 +1494,10 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *ovl_mount (struct file_system_type *fs_type,int flags, -const char *dev_name,void *raw_data) +const char *dev_name, +void *raw_data,size_t data_size) { -return mount_nodev (fs_type, flags, raw_data, ovl_fill_super); +return mount_nodev (fs_type, flags, raw_data, data_size, ovl_fill_super); }static struct file_system_type ovl_fs_type = {
fs/pipe.c +2 -1
@@ -1183,7 +1183,8 @@ static const struct super_operations pipefs_ops = {* d_name - pipe: will go nicely and kill the special-casing in procfs. */ static struct dentry *pipefs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {return mount_pseudo (fs_type,"pipe:" , &pipefs_ops, &pipefs_dentry_operations,PIPEFS_MAGIC );
fs/proc/inode.c +2 -1
@@ -489,7 +489,8 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)return inode; } -int proc_fill_super (struct super_block *s,void *data,int silent) +int proc_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct pid_namespace *ns =get_pid_ns (s->s_fs_info);struct inode *root_inode;
fs/proc/internal.h +2 -2
@@ -214,7 +214,7 @@ extern const struct inode_operations proc_pid_link_inode_operations;void proc_init_kmemcache (void );void set_proc_pid_nlink (void );extern struct inode *proc_get_inode (struct super_block *,struct proc_dir_entry *); -extern int proc_fill_super (struct super_block *,void *data,int flags); +extern int proc_fill_super (struct super_block *,void *,size_t ,int );extern void proc_entry_rundown (struct proc_dir_entry *);/*
@@ -275,7 +275,7 @@ extern struct proc_dir_entry proc_root;extern int proc_parse_options (char *options,struct pid_namespace *pid);extern void proc_self_init (void ); -extern int proc_remount (struct super_block *,int *,char *); +extern int proc_remount (struct super_block *,int *,char *,size_t );/* * task_[no]mmu.c
fs/proc/root.c +7 -4
@@ -78,7 +78,8 @@ int proc_parse_options(char *options, struct pid_namespace *pid)return 1 ; } -int proc_remount (struct super_block *sb,int *flags,char *data) +int proc_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct pid_namespace *pid = sb->s_fs_info;
@@ -87,7 +88,8 @@ int proc_remount(struct super_block *sb, int *flags, char *data) }static struct dentry *proc_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) {struct pid_namespace *ns;
@@ -98,7 +100,8 @@ static struct dentry *proc_mount(struct file_system_type *fs_type, ns =task_active_pid_ns (current); } -return mount_ns (fs_type, flags, data, ns, ns->user_ns, proc_fill_super); +return mount_ns (fs_type, flags, data, data_size, ns, ns->user_ns, + proc_fill_super); }static void proc_kill_sb (struct super_block *sb)
@@ -211,7 +214,7 @@ int pid_ns_prepare_proc(struct pid_namespace *ns) {struct vfsmount *mnt; - mnt =kern_mount_data (&proc_fs_type, ns); + mnt =kern_mount_data (&proc_fs_type, ns,0 );if (IS_ERR (mnt))return PTR_ERR (mnt);
fs/pstore/inode.c +6 -4
@@ -271,7 +271,8 @@ static int pstore_show_options(struct seq_file *m, struct dentry *root)return 0 ; } -static int pstore_remount (struct super_block *sb,int *flags,char *data) +static int pstore_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb);parse_options (data);
@@ -432,7 +433,8 @@ void pstore_get_records(int quiet)inode_unlock (d_inode (root)); } -static int pstore_fill_super (struct super_block *sb,void *data,int silent) +static int pstore_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct inode *inode;
@@ -464,9 +466,9 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) }static struct dentry *pstore_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_single (fs_type, flags, data, pstore_fill_super); +return mount_single (fs_type, flags, data, data_size, pstore_fill_super); }static void pstore_kill_sb (struct super_block *sb)
fs/qnx4/inode.c +9 -5
@@ -29,7 +29,8 @@ static const struct super_operations qnx4_sops;static struct inode *qnx4_alloc_inode (struct super_block *sb);static void qnx4_destroy_inode (struct inode *inode); -static int qnx4_remount (struct super_block *sb,int *flags,char *data); +static int qnx4_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);static int qnx4_statfs (struct dentry *,struct kstatfs *); static const struct super_operations qnx4_sops =
@@ -40,7 +41,8 @@ static const struct super_operations qnx4_sops = .remount_fs = qnx4_remount, }; -static int qnx4_remount (struct super_block *sb,int *flags,char *data) +static int qnx4_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct qnx4_sb_info *qs;
@@ -183,7 +185,8 @@ static const char *qnx4_checkroot(struct super_block *sb,return "bitmap file not found." ; } -static int qnx4_fill_super (struct super_block *s,void *data,int silent) +static int qnx4_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct buffer_head *bh;struct inode *root;
@@ -383,9 +386,10 @@ static void destroy_inodecache(void) }static struct dentry *qnx4_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, qnx4_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + qnx4_fill_super); }static struct file_system_type qnx4_fs_type = {
fs/qnx6/inode.c +9 -5
@@ -30,7 +30,8 @@ static const struct super_operations qnx6_sops;static void qnx6_put_super (struct super_block *sb);static struct inode *qnx6_alloc_inode (struct super_block *sb);static void qnx6_destroy_inode (struct inode *inode); -static int qnx6_remount (struct super_block *sb,int *flags,char *data); +static int qnx6_remount (struct super_block *sb,int *flags, +char *data,size_t data_size);static int qnx6_statfs (struct dentry *dentry,struct kstatfs *buf);static int qnx6_show_options (struct seq_file *seq,struct dentry *root);
@@ -53,7 +54,8 @@ static int qnx6_show_options(struct seq_file *seq, struct dentry *root)return 0 ; } -static int qnx6_remount (struct super_block *sb,int *flags,char *data) +static int qnx6_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_RDONLY ;
@@ -294,7 +296,8 @@ static struct buffer_head *qnx6_check_first_superblock(struct super_block *s,static struct inode *qnx6_private_inode (struct super_block *s,struct qnx6_root_node *p); -static int qnx6_fill_super (struct super_block *s,void *data,int silent) +static int qnx6_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct buffer_head *bh1 =NULL , *bh2 =NULL ;struct qnx6_super_block *sb1 =NULL , *sb2 =NULL ;
@@ -643,9 +646,10 @@ static void destroy_inodecache(void) }static struct dentry *qnx6_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, qnx6_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + qnx6_fill_super); }static struct file_system_type qnx6_fs_type = {
fs/ramfs/inode.c +3 -3
@@ -217,7 +217,7 @@ static int ramfs_parse_options(char *data, struct ramfs_mount_opts *opts)return 0 ; } -int ramfs_fill_super (struct super_block *sb,void *data,int silent) +int ramfs_fill_super (struct super_block *sb,void *data,size_t data_size,int silent) {struct ramfs_fs_info *fsi;struct inode *inode;
@@ -248,9 +248,9 @@ int ramfs_fill_super(struct super_block *sb, void *data, int silent) }struct dentry *ramfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_nodev (fs_type, flags, data, ramfs_fill_super); +return mount_nodev (fs_type, flags, data, data_size, ramfs_fill_super); }static void ramfs_kill_sb (struct super_block *sb)
fs/reiserfs/super.c +9 -5
@@ -61,7 +61,8 @@ static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs) is_reiserfs_jr(rs)); } -static int reiserfs_remount (struct super_block *s,int *flags,char *data); +static int reiserfs_remount (struct super_block *s,int *flags, +char *data,size_t data_size);static int reiserfs_statfs (struct dentry *dentry,struct kstatfs *buf);static int reiserfs_sync_fs (struct super_block *s,int wait)
@@ -1433,7 +1434,8 @@ static void handle_quota_files(struct super_block *s, char **qf_names, }#endif -static int reiserfs_remount (struct super_block *s,int *mount_flags,char *arg) +static int reiserfs_remount (struct super_block *s,int *mount_flags, +char *arg,size_t data_size) {struct reiserfs_super_block *rs;struct reiserfs_transaction_handle th;
@@ -1898,7 +1900,8 @@ static int function2code(hashf_t func)if (!(silent)) \ reiserfs_warning(s, id, __VA_ARGS__) -static int reiserfs_fill_super (struct super_block *s,void *data,int silent) +static int reiserfs_fill_super (struct super_block *s,void *data,size_t data_size, +int silent) {struct inode *root_inode;struct reiserfs_transaction_handle th;
@@ -2600,9 +2603,10 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,static struct dentry *get_super_block (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, reiserfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + reiserfs_fill_super); }static int __init init_reiserfs_fs (void )
fs/romfs/super.c +8 -5
@@ -430,7 +430,8 @@ static int romfs_statfs(struct dentry *dentry, struct kstatfs *buf)/* * remounting must involve read-only */ -static int romfs_remount (struct super_block *sb,int *flags,char *data) +static int romfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_RDONLY ;
@@ -464,7 +465,8 @@ static __u32 romfs_checksum(const void *data, int size)/* * fill in the superblock */ -static int romfs_fill_super (struct super_block *sb,void *data,int silent) +static int romfs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct romfs_super_block *rsb;struct inode *root;
@@ -557,16 +559,17 @@ static int romfs_fill_super(struct super_block *sb, void *data, int silent)*/ static struct dentry *romfs_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) {struct dentry *ret =ERR_PTR (-EINVAL );#ifdef CONFIG_ROMFS_ON_MTD - ret =mount_mtd (fs_type, flags, dev_name, data, romfs_fill_super); + ret =mount_mtd (fs_type, flags, dev_name, data, data_size, + romfs_fill_super);#endif #ifdef CONFIG_ROMFS_ON_BLOCK if (ret ==ERR_PTR (-EINVAL )) - ret =mount_bdev (fs_type, flags, dev_name, data, + ret =mount_bdev (fs_type, flags, dev_name, data, data_size, romfs_fill_super);#endif return ret;
fs/squashfs/super.c +8 -4
@@ -76,7 +76,8 @@ static const struct squashfs_decompressor *supported_squashfs_filesystem(short } -static int squashfs_fill_super (struct super_block *sb,void *data,int silent) +static int squashfs_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {struct squashfs_sb_info *msblk;struct squashfs_super_block *sblk =NULL ;
@@ -370,7 +371,8 @@ static int squashfs_statfs(struct dentry *dentry, struct kstatfs *buf) } -static int squashfs_remount (struct super_block *sb,int *flags,char *data) +static int squashfs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {sync_filesystem (sb); *flags |=SB_RDONLY ;
@@ -398,9 +400,11 @@ static void squashfs_put_super(struct super_block *sb)static struct dentry *squashfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, squashfs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + squashfs_fill_super); }
fs/super.c +24 -20
142 lines not on this page · raw message
fs/sysfs/mount.c +1 -1
@@ -21,7 +21,7 @@ static struct kernfs_root *sysfs_root;struct kernfs_node *sysfs_root_kn;static struct dentry *sysfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) {struct dentry *root;void *ns;
fs/sysv/inode.c +2 -1
@@ -57,7 +57,8 @@ static int sysv_sync_fs(struct super_block *sb, int wait)return 0 ; } -static int sysv_remount (struct super_block *sb,int *flags,char *data) +static int sysv_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {struct sysv_sb_info *sbi =SYSV_SB (sb);
fs/sysv/super.c +10 -6
@@ -349,7 +349,8 @@ static int complete_read_super(struct super_block *sb, int silent, int size)return 1 ; } -static int sysv_fill_super (struct super_block *sb,void *data,int silent) +static int sysv_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct buffer_head *bh1, *bh =NULL ;struct sysv_sb_info *sbi;
@@ -470,7 +471,8 @@ static int v7_sanity_check(struct super_block *sb, struct buffer_head *bh)return 1 ; } -static int v7_fill_super (struct super_block *sb,void *data,int silent) +static int v7_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct sysv_sb_info *sbi;struct buffer_head *bh;
@@ -528,15 +530,17 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)/* Every kernel module contains stuff like this. */ static struct dentry *sysv_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, sysv_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + sysv_fill_super); }static struct dentry *v7_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, v7_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + v7_fill_super); }static struct file_system_type sysv_fs_type = {
fs/tracefs/inode.c +6 -4
@@ -225,7 +225,8 @@ static int tracefs_apply_options(struct super_block *sb)return 0 ; } -static int tracefs_remount (struct super_block *sb,int *flags,char *data) +static int tracefs_remount (struct super_block *sb,int *flags, +char *data,size_t data_size) {int err;struct tracefs_fs_info *fsi = sb->s_fs_info;
@@ -264,7 +265,8 @@ static const struct super_operations tracefs_super_operations = { .show_options = tracefs_show_options, }; -static int trace_fill_super (struct super_block *sb,void *data,int silent) +static int trace_fill_super (struct super_block *sb, +void *data,size_t data_size,int silent) {static const struct tree_descr trace_files[] = {{"" }};struct tracefs_fs_info *fsi;
@@ -299,9 +301,9 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent)static struct dentry *trace_mount (struct file_system_type *fs_type,int flags,const char *dev_name, -void *data) +void *data,size_t data_size) { -return mount_single (fs_type, flags, data, trace_fill_super); +return mount_single (fs_type, flags, data, data_size, trace_fill_super); }static struct file_system_type trace_fs_type = {
fs/ubifs/super.c +3 -2
@@ -1843,7 +1843,8 @@ static void ubifs_put_super(struct super_block *sb)mutex_unlock (&c->umount_mutex); } -static int ubifs_remount_fs (struct super_block *sb,int *flags,char *data) +static int ubifs_remount_fs (struct super_block *sb,int *flags, +char *data,size_t data_size) {int err;struct ubifs_info *c = sb->s_fs_info;
@@ -2106,7 +2107,7 @@ static int sb_set(struct super_block *sb, void *data) }static struct dentry *ubifs_mount (struct file_system_type *fs_type,int flags, -const char *name,void *data) +const char *name,void *data,size_t data_size) {struct ubi_volume_desc *ubi;struct ubifs_info *c;
fs/udf/super.c +10 -6
@@ -87,10 +87,10 @@ enum {enum {UDF_MAX_LINKS =0xffff };/* These are the "meat" - everything else is stuffing */ -static int udf_fill_super (struct super_block *,void *,int ); +static int udf_fill_super (struct super_block *,void *,size_t ,int );static void udf_put_super (struct super_block *);static int udf_sync_fs (struct super_block *,int ); -static int udf_remount_fs (struct super_block *,int *,char *); +static int udf_remount_fs (struct super_block *,int *,char *,size_t );static void udf_load_logicalvolint (struct super_block *,struct kernel_extent_ad );static int udf_find_fileset (struct super_block *,struct kernel_lb_addr *,struct kernel_lb_addr *);
@@ -126,9 +126,11 @@ struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct super_block *sb)/* UDF filesystem type */ static struct dentry *udf_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name, +void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, udf_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + udf_fill_super); }static struct file_system_type udf_fstype = {
@@ -608,7 +610,8 @@ static int udf_parse_options(char *options, struct udf_options *uopt,return 1 ; } -static int udf_remount_fs (struct super_block *sb,int *flags,char *options) +static int udf_remount_fs (struct super_block *sb,int *flags, +char *options,size_t data_size) {struct udf_options uopt;struct udf_sb_info *sbi =UDF_SB (sb);
@@ -2085,7 +2088,8 @@ u64 lvid_get_unique_id(struct super_block *sb)return ret; } -static int udf_fill_super (struct super_block *sb,void *options,int silent) +static int udf_fill_super (struct super_block *sb, +void *options,size_t data_size,int silent) {int ret = -EINVAL ;struct inode *inode =NULL ;
fs/ufs/super.c +7 -4
@@ -774,7 +774,8 @@ static u64 ufs_max_bytes(struct super_block *sb)return res << uspi->s_bshift; } -static int ufs_fill_super (struct super_block *sb,void *data,int silent) +static int ufs_fill_super (struct super_block *sb,void *data,size_t data_size, +int silent) {struct ufs_sb_info * sbi;struct ufs_sb_private_info * uspi;
@@ -1297,7 +1298,8 @@ static int ufs_fill_super(struct super_block *sb, void *data, int silent)return -ENOMEM ; } -static int ufs_remount (struct super_block *sb,int *mount_flags,char *data) +static int ufs_remount (struct super_block *sb,int *mount_flags, +char *data,size_t data_size) {struct ufs_sb_private_info * uspi;struct ufs_super_block_first * usb1;
@@ -1505,9 +1507,10 @@ static const struct super_operations ufs_super_ops = { };static struct dentry *ufs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data) +int flags,const char *dev_name,void *data,size_t data_size) { -return mount_bdev (fs_type, flags, dev_name, data, ufs_fill_super); +return mount_bdev (fs_type, flags, dev_name, data, data_size, + ufs_fill_super); }static struct file_system_type ufs_fs_type = {
fs/xfs/xfs_super.c +7 -3
@@ -1256,7 +1256,8 @@ STATIC intxfs_fs_remount ( struct super_block *sb, int *flags, - char *options) + char *options, + size_t data_size) { struct xfs_mount *mp = XFS_M(sb);xfs_sb_t *sbp = &mp->m_sb;
@@ -1595,6 +1596,7 @@ STATIC intxfs_fs_fill_super ( struct super_block *sb, void *data, + size_t data_size, int silent) { struct inode *root;
@@ -1808,9 +1810,11 @@ xfs_fs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, - void *data) + void *data, + size_t data_size) { - return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super); + return mount_bdev(fs_type, flags, dev_name, data, data_size, +xfs_fs_fill_super ); } static long
include/linux/debugfs.h +4 -4
@@ -75,11 +75,11 @@ struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);struct dentry *debugfs_create_symlink (const char *name,struct dentry *parent,const char *dest); -typedef struct vfsmount *(*debugfs_automount_t )(struct dentry *,void *); +typedef struct vfsmount *(*debugfs_automount_t )(struct dentry *,void *,size_t );struct dentry *debugfs_create_automount (const char *name,struct dentry *parent,debugfs_automount_t f, -void *data); +void *data,size_t data_size);void debugfs_remove (struct dentry *dentry);void debugfs_remove_recursive (struct dentry *dentry);
@@ -204,8 +204,8 @@ static inline struct dentry *debugfs_create_symlink(const char *name,static inline struct dentry *debugfs_create_automount (const char *name,struct dentry *parent, -struct vfsmount *(*f)(void *), -void *data) +struct vfsmount *(*f)(void *,size_t ), +void *data,size_t data_size) {return ERR_PTR (-ENODEV ); }
include/linux/fs.h +15 -14
@@ -1841,7 +1841,7 @@ struct super_operations {int (*thaw_super) (struct super_block *);int (*unfreeze_fs) (struct super_block *);int (*statfs) (struct dentry *,struct kstatfs *); -int (*remount_fs) (struct super_block *,int *,char *); +int (*remount_fs) (struct super_block *,int *,char *,size_t );void (*umount_begin) (struct super_block *);int (*show_options)(struct seq_file *,struct dentry *);
@@ -2099,7 +2099,7 @@ struct file_system_type {#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ struct dentry *(*mount) (struct file_system_type *,int , -const char *,void *); +const char *,void *,size_t );void (*kill_sb) (struct super_block *);struct module *owner;struct file_system_type * next;
@@ -2118,26 +2118,27 @@ struct file_system_type {#define MODULE_ALIAS_FS (NAME ) MODULE_ALIAS("fs-" NAME)extern struct dentry *mount_ns (struct file_system_type *fs_type, -int flags,void *data,void *ns,struct user_namespace *user_ns, -int (*fill_super)(struct super_block *,void *,int )); +int flags,void *data,size_t data_size, +void *ns,struct user_namespace *user_ns, +int (*fill_super)(struct super_block *,void *,size_t ,int ));#ifdef CONFIG_BLOCK extern struct dentry *mount_bdev (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data, -int (*fill_super)(struct super_block *,void *,int )); +int flags,const char *dev_name,void *data,size_t data_size, +int (*fill_super)(struct super_block *,void *,size_t ,int ));#else static inline struct dentry *mount_bdev (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data, -int (*fill_super)(struct super_block *,void *,int )) +int flags,const char *dev_name,void *data,size_t data_size, +int (*fill_super)(struct super_block *,void *,size_t ,int )) {return ERR_PTR (-ENODEV ); }#endif extern struct dentry *mount_single (struct file_system_type *fs_type, -int flags,void *data, -int (*fill_super)(struct super_block *,void *,int )); +int flags,void *data,size_t data_size, +int (*fill_super)(struct super_block *,void *,size_t ,int ));extern struct dentry *mount_nodev (struct file_system_type *fs_type, -int flags,void *data, -int (*fill_super)(struct super_block *,void *,int )); +int flags,void *data,size_t data_size, +int (*fill_super)(struct super_block *,void *,size_t ,int ));extern struct dentry *mount_subtree (struct vfsmount *mnt,const char *path);void generic_shutdown_super (struct super_block *sb);#ifdef CONFIG_BLOCK
@@ -2197,8 +2198,8 @@ mount_pseudo(struct file_system_type *fs_type, char *name,extern int register_filesystem (struct file_system_type *);extern int unregister_filesystem (struct file_system_type *); -extern struct vfsmount *kern_mount_data (struct file_system_type *,void *data); -#define kern_mount (type) kern_mount_data(type, NULL) +extern struct vfsmount *kern_mount_data (struct file_system_type *,void *,size_t ); +#define kern_mount (type) kern_mount_data(type, NULL, 0)extern void kern_unmount (struct vfsmount *mnt);extern int may_umount_tree (struct vfsmount *);extern int may_umount (struct vfsmount *);
include/linux/lsm_hooks.h +9 -4
@@ -154,6 +154,7 @@* @type contains the filesystem type. * @flags contains the mount flags. * @data contains the filesystem-specific data. +* @data_size contains the size of the data. * Return 0 if permission is granted. * @sb_copy_data: * Allow mount option data to be copied prior to parsing by the filesystem,
@@ -163,6 +164,7 @@* specific options to avoid having to make filesystems aware of them. * @type the type of filesystem being mounted. * @orig the original mount data copied from userspace. +* @orig_data is the size of the original data * @copy copied data which will be passed to the security module. * Returns 0 if the copy was successful. * @sb_remount:
@@ -170,6 +172,7 @@* are being made to those options. * @sb superblock being remounted * @data contains the filesystem-specific data. +* @data_size contains the size of the data. * Return 0 if permission is granted. * @sb_umount: * Check permission before the @mnt file system is unmounted.
@@ -1522,13 +1525,15 @@ union security_list_options {int (*sb_alloc_security)(struct super_block *sb);void (*sb_free_security)(struct super_block *sb); -int (*sb_copy_data)(char *orig,char *copy); -int (*sb_remount)(struct super_block *sb,void *data); -int (*sb_kern_mount)(struct super_block *sb,int flags,void *data); +int (*sb_copy_data)(char *orig,size_t orig_size,char *copy); +int (*sb_remount)(struct super_block *sb,void *data,size_t data_size); +int (*sb_kern_mount)(struct super_block *sb,int flags, +void *data,size_t data_size);int (*sb_show_options)(struct seq_file *m,struct super_block *sb);int (*sb_statfs)(struct dentry *dentry);int (*sb_mount)(const char *dev_name,const struct path *path, -const char *type,unsigned long flags,void *data); +const char *type,unsigned long flags, +void *data,size_t data_size);int (*sb_umount)(struct vfsmount *mnt,int flags);int (*sb_pivotroot)(const struct path *old_path,const struct path *new_path); int (*sb_set_mnt_opts)(struct super_block *sb,
include/linux/mount.h +3 -2
@@ -90,10 +90,11 @@ extern struct vfsmount *clone_private_mount(const struct path *path);struct file_system_type ;extern struct vfsmount *vfs_kern_mount (struct file_system_type *type,int flags,const char *name, -void *data); +void *data,size_t data_size);extern struct vfsmount *vfs_submount (const struct dentry *mountpoint,struct file_system_type *type, -const char *name,void *data); +const char *name, +void *data,size_t data_size);extern void mnt_set_expiry (struct vfsmount *mnt,struct list_head *expiry_list);extern void mark_mounts_for_expiry (struct list_head *mounts);
include/linux/mtd/super.h +2 -2
@@ -19,8 +19,8 @@#include <linux/mount.h> extern struct dentry *mount_mtd (struct file_system_type *fs_type,int flags, -const char *dev_name,void *data, -int (*fill_super)(struct super_block *,void *,int )); +const char *dev_name,void *data,size_t data_size, +int (*fill_super)(struct super_block *,void *,size_t ,int ));
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Re: [PATCH 11/32] vfs: Require specification of size of mount data for internal mounts [ver #9]
Quoted 3 lines · David Howells
Require specification of the size of the mount data passed to the VFS mounting functions by internal mounts.
This should not be patch 11/32 in some big and complex series with new user API's etc.
This should be a prerequisite patch that stands on its own.
Linus
David Howells
maintainerPATCH 12/32 vfs: Separate changing mount flags full remount [ver #9]
In reply to David HowellsSeparate just the changing of mount flags (MS_REMOUNT|MS_BIND) from full remount because the mount data will get parsed with the new fs_context stuff prior to doing a remount - and this causes the syscall to fail under some circumstances.
To quote Eric's explanation:
[...] mount(..., MS_REMOUNT|MS_BIND, ...) now validates the mount options string, which breaks systemd unit files with ProtectControlGroups=yes (e.g. systemd-networkd.service) when systemd does the following to change a cgroup (v1) mount to read-only:
mount(NULL, "/run/systemd/unit-root/sys/fs/cgroup/systemd", NULL,
MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_REMOUNT|MS_BIND, NULL)
... when the kernel has CONFIG_CGROUPS=y but no cgroup subsystems enabled, since in that case the error "cgroup1: Need name or subsystem set" is hit when the mount options string is empty.
Probably it doesn't make sense to validate the mount options string at all in the MS_REMOUNT|MS_BIND case, though maybe you had something else in mind.
This is also worthwhile doing because we will need to add a mount_setattr() syscall to take over the remount-bind function.
---
fs/namespace.c | 146 +++++++++++++++++++++++++++++++------------------ include/linux/mount.h | 2 - 2 files changed, 93 insertions(+), 55 deletions(-)
fs/namespace.c +92 -54
@@ -273,13 +273,9 @@ static struct mount *alloc_vfsmnt(const char *name)* mnt_want/drop_write() will _keep_ the filesystem * r/w. */ -int __mnt_is_readonly (struct vfsmount *mnt) +bool __mnt_is_readonly (struct vfsmount *mnt) { -if (mnt->mnt_flags &MNT_READONLY ) -return 1 ; -if (sb_rdonly (mnt->mnt_sb)) -return 1 ; -return 0 ; +return (mnt->mnt_flags &MNT_READONLY ) ||sb_rdonly (mnt->mnt_sb); }EXPORT_SYMBOL_GPL (__mnt_is_readonly);
@@ -594,11 +590,12 @@ static int mnt_make_readonly(struct mount *mnt)return ret; } -static void __mnt_unmake_readonly (struct mount *mnt) +static int __mnt_unmake_readonly (struct mount *mnt) {lock_mount_hash (); mnt->mnt.mnt_flags &= ~MNT_READONLY ;unlock_mount_hash (); +return 0 ; }int sb_prepare_remount_readonly (struct super_block *sb)
@@ -2355,21 +2352,91 @@ SYSCALL_DEFINE3(open_tree, int, dfd, const char *, filename, unsigned, flags)return error; } -static int change_mount_flags (struct vfsmount *mnt,int ms_flags) +/* +* Don't allow locked mount flags to be cleared. +* +* No locks need to be held here while testing the various MNT_LOCK +* flags because those flags can never be cleared once they are set. +*/ +static bool can_change_locked_flags (struct mount *mnt,unsigned int mnt_flags) +{ +unsigned int fl = mnt->mnt.mnt_flags; + +if ((fl &MNT_LOCK_READONLY ) && + !(mnt_flags &MNT_READONLY )) +return false; + +if ((fl &MNT_LOCK_NODEV ) && + !(mnt_flags &MNT_NODEV )) +return false; + +if ((fl &MNT_LOCK_NOSUID ) && + !(mnt_flags &MNT_NOSUID )) +return false; + +if ((fl &MNT_LOCK_NOEXEC ) && + !(mnt_flags &MNT_NOEXEC )) +return false; + +if ((fl &MNT_LOCK_ATIME ) && + ((fl &MNT_ATIME_MASK ) != (mnt_flags &MNT_ATIME_MASK ))) +return false; + +return true; +} + +static int change_mount_ro_state (struct mount *mnt,unsigned int mnt_flags) { -int error =0 ; -int readonly_request =0 ; +bool readonly_request = (mnt_flags &MNT_READONLY ); -if (ms_flags &MS_RDONLY ) - readonly_request =1 ; -if (readonly_request ==__mnt_is_readonly (mnt)) +if (readonly_request ==__mnt_is_readonly (&mnt->mnt))return 0 ;if (readonly_request) - error =mnt_make_readonly (real_mount (mnt)); -else -__mnt_unmake_readonly (real_mount (mnt)); -return error; +return mnt_make_readonly (mnt); + +return __mnt_unmake_readonly (mnt); +} + +/* +* Update the user-settable attributes on a mount. The caller must hold +* sb->s_umount for writing. +*/ +static void set_mount_attributes (struct mount *mnt,unsigned int mnt_flags) +{ +lock_mount_hash (); + mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK ; + mnt->mnt.mnt_flags = mnt_flags; +touch_mnt_namespace (mnt->mnt_ns); +unlock_mount_hash (); +} + +/* +* Handle reconfiguration of the mountpoint only without alteration of the +* superblock it refers to. This is triggered by specifying MS_REMOUNT|MS_BIND +* to mount(2). +*/ +static int do_reconfigure_mnt (struct path *path,unsigned int mnt_flags) +{ +struct super_block *sb = path->mnt->mnt_sb; +struct mount *mnt =real_mount (path->mnt); +int ret; + +if (!check_mnt (mnt)) +return -EINVAL ; + +if (path->dentry != mnt->mnt.mnt_root) +return -EINVAL ; + +if (!can_change_locked_flags (mnt, mnt_flags)) +return -EPERM ; + +down_write (&sb->s_umount); + ret =change_mount_ro_state (mnt, mnt_flags); +if (ret ==0 ) +set_mount_attributes (mnt, mnt_flags); +up_write (&sb->s_umount); +return ret; }/*
@@ -2390,50 +2457,19 @@ static int do_remount(struct path *path, int ms_flags, int sb_flags,if (path->dentry != path->mnt->mnt_root)return -EINVAL ; -/* Don't allow changing of locked mnt flags. -* -* No locks need to be held here while testing the various -* MNT_LOCK flags because those flags can never be cleared -* once they are set. -*/ -if ((mnt->mnt.mnt_flags &MNT_LOCK_READONLY ) && - !(mnt_flags &MNT_READONLY )) { -return -EPERM ; - } -if ((mnt->mnt.mnt_flags &MNT_LOCK_NODEV ) && - !(mnt_flags &MNT_NODEV )) { -return -EPERM ; - } -if ((mnt->mnt.mnt_flags &MNT_LOCK_NOSUID ) && - !(mnt_flags &MNT_NOSUID )) { -return -EPERM ; - } -if ((mnt->mnt.mnt_flags &MNT_LOCK_NOEXEC ) && - !(mnt_flags &MNT_NOEXEC )) { +if (!can_change_locked_flags (mnt, mnt_flags))return -EPERM ; - } -if ((mnt->mnt.mnt_flags &MNT_LOCK_ATIME ) && - ((mnt->mnt.mnt_flags &MNT_ATIME_MASK ) != (mnt_flags &MNT_ATIME_MASK ))) { -return -EPERM ; - } err =security_sb_remount (sb, data, data_size);if (err)return err;down_write (&sb->s_umount); -if (ms_flags &MS_BIND ) - err =change_mount_flags (path->mnt, ms_flags); -else if (!ns_capable (sb->s_user_ns,CAP_SYS_ADMIN )) - err = -EPERM ; -else + err = -EPERM ; +if (ns_capable (sb->s_user_ns,CAP_SYS_ADMIN )) { err =do_remount_sb (sb, sb_flags, data, data_size,0 ); -if (!err) { -lock_mount_hash (); - mnt_flags |= mnt->mnt.mnt_flags & ~MNT_USER_SETTABLE_MASK ; - mnt->mnt.mnt_flags = mnt_flags; -touch_mnt_namespace (mnt->mnt_ns); -unlock_mount_hash (); +if (!err) +set_mount_attributes (mnt, mnt_flags); }up_write (&sb->s_umount);return err;
@@ -2949,7 +2985,9 @@ long do_mount(const char *dev_name, const char __user *dir_name,SB_LAZYTIME | SB_I_VERSION); -if (flags &MS_REMOUNT ) +if ((flags & (MS_REMOUNT |MS_BIND )) == (MS_REMOUNT |MS_BIND )) + retval =do_reconfigure_mnt (&path, mnt_flags); +else if (flags &MS_REMOUNT ) retval =do_remount (&path, flags, sb_flags, mnt_flags, data_page, data_size);else if (flags &MS_BIND )
include/linux/mount.h +1 -1
@@ -81,7 +81,7 @@ extern void mnt_drop_write_file(struct file *file);extern void mntput (struct vfsmount *mnt);extern struct vfsmount *mntget (struct vfsmount *mnt);extern struct vfsmount *mnt_clone_internal (const struct path *path); -extern int __mnt_is_readonly (struct vfsmount *mnt); +extern bool __mnt_is_readonly (struct vfsmount *mnt);extern bool mnt_may_suid (struct vfsmount *mnt);struct path ;
David Howells
maintainerPATCH 13/32 vfs: Implement a filesystem superblock creation/configuration context [ver #9]
In reply to David HowellsImplement a filesystem context concept to be used during superblock creation for mount and superblock reconfiguration for remount.
The mounting procedure then becomes:
(1) Allocate new fs_context context.
(2) Configure the context.
(3) Create superblock.
(4) Mount the superblock any number of times.
(5) Destroy the context.
Rather than calling fs_type->mount(), an fs_context struct is created and fs_type->init_fs_context() is called to set it up. Pointers exist for the filesystem and LSM to hang their private data off.
A set of operations has to be set by ->init_fs_context() to provide freeing, duplication, option parsing, binary data parsing, validation, mounting and superblock filling.
Legacy filesystems are supported by the provision of a set of legacy fs_context operations that build up a list of mount options and then invoke fs_type->mount() from within the fs_context ->get_tree() operation. This allows all filesystems to be accessed using fs_context.
It should be noted that, whilst this patch adds a lot of lines of code, there is quite a bit of duplication with existing code that can be eliminated should all filesystems be converted over.
---
fs/Makefile | 3 fs/fs_context.c | 625 ++++++++++++++++++++++++++++++++++++++++++++ fs/internal.h | 3 fs/libfs.c | 19 + fs/namespace.c | 350 ++++++++++++++++--------- fs/super.c | 303 ++++++++++++++++++++- include/linux/fs.h | 14 + include/linux/fs_context.h | 45 +++ include/linux/mount.h | 3 9 files changed, 1222 insertions(+), 143 deletions(-) create mode 100644 fs/fs_context.c
fs/Makefile +2 -1
@@ -12,7 +12,8 @@ obj-y := open.o read_write.o file_table.o super.o \ attr.o bad_inode.o file.o filesystems.o namespace.o \ seq_file.o xattr.o libfs.o fs-writeback.o \ pnode.o splice.o sync.o utimes.o d_path.o \ - stack.o fs_struct.o statfs.o fs_pin.o nsfs.o + stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ + fs_context.o ifeq ($(CONFIG_BLOCK),y) obj-y += buffer.o block_dev.o direct-io.o mpage.o
fs/fs_context.c new file +625 -0
625 lines not on this page · raw message
fs/internal.h +2 -1
@@ -99,7 +99,8 @@ extern struct file *get_empty_filp(void);/* * super.c */ -extern int do_remount_sb (struct super_block *,int ,void *,size_t ,int ); +extern int do_remount_sb (struct super_block *,int ,void *,size_t ,int , +struct fs_context *);extern bool trylock_super (struct super_block *sb);extern struct dentry *mount_fs (struct file_system_type *,int ,const char *,void *,size_t );
fs/libfs.c +18 -1
@@ -9,6 +9,7 @@#include <linux/slab.h> #include <linux/cred.h> #include <linux/mount.h> +#include <linux/fs_context.h> #include <linux/vfs.h> #include <linux/quotaops.h> #include <linux/mutex.h>
@@ -574,13 +575,29 @@ static DEFINE_SPINLOCK(pin_fs_lock);int simple_pin_fs (struct file_system_type *type,struct vfsmount **mount,int *count) { +struct fs_context *fc;struct vfsmount *mnt =NULL ; +int ret; +spin_lock (&pin_fs_lock);if (unlikely (!*mount)) {spin_unlock (&pin_fs_lock); - mnt =vfs_kern_mount (type,SB_KERNMOUNT , type->name,NULL ,0 ); + + fc =vfs_new_fs_context (type,NULL ,0 ,FS_CONTEXT_FOR_KERNEL_MOUNT ); +if (IS_ERR (fc)) +return PTR_ERR (fc); + + ret =vfs_get_tree (fc); +if (ret <0 ) { +put_fs_context (fc); +return ret; + } + + mnt =vfs_create_mount (fc,0 ); +put_fs_context (fc);if (IS_ERR (mnt))return PTR_ERR (mnt); +spin_lock (&pin_fs_lock);if (!*mount) *mount = mnt;
fs/namespace.c +229 -121
469 lines not on this page · raw message
fs/super.c +286 -17
391 lines not on this page · raw message
include/linux/fs.h +13 -1
@@ -61,6 +61,7 @@ struct workqueue_struct;struct iov_iter ;struct fscrypt_info ;struct fscrypt_operations ; +struct fs_context ;extern void __init inode_init (void );extern void __init inode_init_early (void );
@@ -723,6 +724,11 @@ static inline void inode_unlock(struct inode *inode)up_write (&inode->i_rwsem); } +static inline int inode_lock_killable (struct inode *inode) +{ +return down_write_killable (&inode->i_rwsem); +} +static inline void inode_lock_shared (struct inode *inode) {down_read (&inode->i_rwsem);
@@ -1842,6 +1848,7 @@ struct super_operations {int (*unfreeze_fs) (struct super_block *);int (*statfs) (struct dentry *,struct kstatfs *);int (*remount_fs) (struct super_block *,int *,char *,size_t ); +int (*reconfigure) (struct super_block *,struct fs_context *);void (*umount_begin) (struct super_block *);int (*show_options)(struct seq_file *,struct dentry *);
@@ -2098,6 +2105,7 @@ struct file_system_type {#define FS_HAS_SUBTYPE 4#define FS_USERNS_MOUNT 8/* Can be mounted by userns root */ #define FS_RENAME_DOES_D_MOVE 32768/* FS will handle d_move() during rename() internally. */ +int (*init_fs_context)(struct fs_context *,struct dentry *);struct dentry *(*mount) (struct file_system_type *,int ,const char *,void *,size_t );void (*kill_sb) (struct super_block *);
@@ -2154,8 +2162,12 @@ void kill_litter_super(struct super_block *sb);void deactivate_super (struct super_block *sb);void deactivate_locked_super (struct super_block *sb);int set_anon_super (struct super_block *s,void *data); +int set_anon_super_fc (struct super_block *s,struct fs_context *fc);int get_anon_bdev (dev_t *);void free_anon_bdev (dev_t ); +struct super_block *sget_fc (struct fs_context *fc, +int (*test)(struct super_block *,struct fs_context *), +int (*set)(struct super_block *,struct fs_context *)); struct super_block *sget_userns(struct file_system_type *type, int (*test)(struct super_block *,void *), int (*set)(struct super_block *,void *),
@@ -2198,8 +2210,8 @@ mount_pseudo(struct file_system_type *fs_type, char *name,extern int register_filesystem (struct file_system_type *);extern int unregister_filesystem (struct file_system_type *); +extern struct vfsmount *kern_mount (struct file_system_type *);extern struct vfsmount *kern_mount_data (struct file_system_type *,void *,size_t ); -#define kern_mount (type) kern_mount_data(type, NULL, 0)extern void kern_unmount (struct vfsmount *mnt);extern int may_umount_tree (struct vfsmount *);extern int may_umount (struct vfsmount *);
include/linux/fs_context.h +44 -1
71 lines not on this page · raw message
include/linux/mount.h +3 -0
@@ -21,6 +21,7 @@ struct super_block;struct vfsmount ;struct dentry ;struct mnt_namespace ; +struct fs_context ;#define MNT_NOSUID 0x01#define MNT_NODEV 0x02
@@ -88,6 +89,8 @@ struct path;extern struct vfsmount *clone_private_mount (const struct path *path);struct file_system_type ; +extern struct vfsmount *vfs_create_mount (struct fs_context *fc, +unsigned int mnt_flags);extern struct vfsmount *vfs_kern_mount (struct file_system_type *type,int flags,const char *name,void *data,size_t data_size);
David Howells
maintainerPATCH 14/32 vfs: Remove unused code after filesystem context changes [ver #9]
In reply to David HowellsRemove code that is now unused after the filesystem context changes.
---
fs/internal.h | 2 - fs/super.c | 62 -------------------------------------------- include/linux/lsm_hooks.h | 3 -- include/linux/security.h | 7 ----- security/security.c | 5 ---- security/selinux/hooks.c | 20 -------------- security/smack/smack_lsm.c | 33 ----------------------- 7 files changed, 132 deletions(-)
fs/internal.h +0 -2
@@ -102,8 +102,6 @@ extern struct file *get_empty_filp(void);extern int do_remount_sb (struct super_block *,int ,void *,size_t ,int ,struct fs_context *);extern bool trylock_super (struct super_block *sb); -extern struct dentry *mount_fs (struct file_system_type *, -int ,const char *,void *,size_t );extern struct super_block *user_get_super (dev_t );/*
fs/super.c +0 -62
68 lines not on this page · raw message
include/linux/lsm_hooks.h +0 -3
@@ -1527,8 +1527,6 @@ union security_list_options {void (*sb_free_security)(struct super_block *sb);int (*sb_copy_data)(char *orig,size_t orig_size,char *copy);int (*sb_remount)(struct super_block *sb,void *data,size_t data_size); -int (*sb_kern_mount)(struct super_block *sb,int flags, -void *data,size_t data_size);int (*sb_show_options)(struct seq_file *m,struct super_block *sb);int (*sb_statfs)(struct dentry *dentry); int (*sb_mount)(const char *dev_name, const struct path *path,
@@ -1877,7 +1875,6 @@ struct security_hook_heads {struct hlist_head sb_free_security;struct hlist_head sb_copy_data;struct hlist_head sb_remount; -struct hlist_head sb_kern_mount;struct hlist_head sb_show_options;struct hlist_head sb_statfs;struct hlist_head sb_mount;
include/linux/security.h +0 -7
@@ -240,7 +240,6 @@ int security_sb_alloc(struct super_block *sb);void security_sb_free (struct super_block *sb);int security_sb_copy_data (char *orig,size_t orig_size,char *copy);int security_sb_remount (struct super_block *sb,void *data,size_t data_size); -int security_sb_kern_mount (struct super_block *sb,int flags,void *data,size_t data_size);int security_sb_show_options (struct seq_file *m,struct super_block *sb);int security_sb_statfs (struct dentry *dentry); int security_sb_mount(const char *dev_name, const struct path *path,
@@ -593,12 +592,6 @@ static inline int security_sb_remount(struct super_block *sb, void *data, size_treturn 0 ; } -static inline int security_sb_kern_mount (struct super_block *sb,int flags, -void *data,size_t data_size) -{ -return 0 ; -} -static inline int security_sb_show_options (struct seq_file *m,struct super_block *sb) {
security/security.c +0 -5
@@ -425,11 +425,6 @@ int security_sb_remount(struct super_block *sb, void *data, size_t data_size)return call_int_hook (sb_remount,0 , sb, data, data_size); } -int security_sb_kern_mount (struct super_block *sb,int flags,void *data,size_t data_size) -{ -return call_int_hook (sb_kern_mount,0 , sb, flags, data, data_size); -} -int security_sb_show_options (struct seq_file *m,struct super_block *sb) {return call_int_hook (sb_show_options,0 , m, sb);
security/selinux/hooks.c +0 -20
@@ -2922,25 +2922,6 @@ static int selinux_sb_remount(struct super_block *sb, void *data, size_t data_si goto out_free_opts; } -static int selinux_sb_kern_mount (struct super_block *sb,int flags,void *data,size_t data_size) -{ -const struct cred *cred =current_cred (); -struct common_audit_data ad; -int rc; - - rc =superblock_doinit (sb, data); -if (rc) -return rc; - -/* Allow all mounts performed by the kernel */ -if (flags &MS_KERNMOUNT ) -return 0 ; - - ad.type =LSM_AUDIT_DATA_DENTRY ; - ad.u.dentry = sb->s_root; -return superblock_has_perm (cred, sb,FILESYSTEM__MOUNT , &ad); -} -static int selinux_sb_statfs (struct dentry *dentry) {const struct cred *cred =current_cred ();
@@ -7174,7 +7155,6 @@ static struct security_hook_list selinux_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (sb_free_security, selinux_sb_free_security),LSM_HOOK_INIT (sb_copy_data, selinux_sb_copy_data),LSM_HOOK_INIT (sb_remount, selinux_sb_remount), -LSM_HOOK_INIT (sb_kern_mount, selinux_sb_kern_mount),LSM_HOOK_INIT (sb_show_options, selinux_sb_show_options),LSM_HOOK_INIT (sb_statfs, selinux_sb_statfs), LSM_HOOK_INIT(sb_mount, selinux_mount),
security/smack/smack_lsm.c +0 -33
@@ -1150,38 +1150,6 @@ static int smack_set_mnt_opts(struct super_block *sb,return 0 ; } -/** -* smack_sb_kern_mount - Smack specific mount processing -* @sb: the file system superblock -* @flags: the mount flags -* @data: the smack mount options -* -* Returns 0 on success, an error code on failure -*/ -static int smack_sb_kern_mount (struct super_block *sb,int flags, -void *data,size_t data_size) -{ -int rc =0 ; -char *options = data; -struct security_mnt_opts opts; - -security_init_mnt_opts (&opts); - -if (!options) - goto out; - - rc =smack_parse_opts_str (options, &opts); -if (rc) - goto out_err; - -out: - rc =smack_set_mnt_opts (sb, &opts,0 ,NULL ); - -out_err: -security_free_mnt_opts (&opts); -return rc; -} -/** * smack_sb_statfs - Smack check on statfs * @dentry: identifies the file system in question
@@ -4961,7 +4929,6 @@ static struct security_hook_list smack_hooks[] __lsm_ro_after_init = {LSM_HOOK_INIT (sb_alloc_security, smack_sb_alloc_security),LSM_HOOK_INIT (sb_free_security, smack_sb_free_security),LSM_HOOK_INIT (sb_copy_data, smack_sb_copy_data), -LSM_HOOK_INIT (sb_kern_mount, smack_sb_kern_mount),LSM_HOOK_INIT (sb_statfs, smack_sb_statfs),LSM_HOOK_INIT (sb_set_mnt_opts, smack_set_mnt_opts), LSM_HOOK_INIT(sb_parse_opts_str, smack_parse_opts_str),
David Howells
maintainerPATCH 15/32 procfs: Move proc_fill_super() to fs/proc/root.c [ver #9]
In reply to David HowellsMove proc_fill_super() to fs/proc/root.c as that's where the other superblock stuff is.
---
fs/proc/inode.c | 49 +------------------------------------------------ fs/proc/internal.h | 4 +--- fs/proc/root.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 52 deletions(-)
fs/proc/inode.c +1 -48
@@ -24,7 +24,6 @@#include <linux/seq_file.h> #include <linux/slab.h> #include <linux/mount.h> -#include <linux/magic.h> #include <linux/uaccess.h>
@@ -122,7 +121,7 @@ static int proc_show_options(struct seq_file *seq, struct dentry *root)return 0 ; } -static const struct super_operations proc_sops = { +const struct super_operations proc_sops = { .alloc_inode = proc_alloc_inode, .destroy_inode = proc_destroy_inode, .drop_inode = generic_delete_inode,
@@ -488,49 +487,3 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)pde_put (de);return inode; } - -int proc_fill_super (struct super_block *s,void *data,size_t data_size, -int silent) -{ -struct pid_namespace *ns =get_pid_ns (s->s_fs_info); -struct inode *root_inode; -int ret; - -if (!proc_parse_options (data, ns)) -return -EINVAL ; - -/* User space would break if executables or devices appear on proc */ - s->s_iflags |=SB_I_USERNS_VISIBLE |SB_I_NOEXEC |SB_I_NODEV ; - s->s_flags |=SB_NODIRATIME |SB_NOSUID |SB_NOEXEC ; - s->s_blocksize =1024 ; - s->s_blocksize_bits =10 ; - s->s_magic =PROC_SUPER_MAGIC ; - s->s_op = &proc_sops; - s->s_time_gran =1 ; - -/* -* procfs isn't actually a stacking filesystem; however, there is -* too much magic going on inside it to permit stacking things on -* top of it -*/ - s->s_stack_depth =FILESYSTEM_MAX_STACK_DEPTH ; - -pde_get (&proc_root); - root_inode =proc_get_inode (s, &proc_root); -if (!root_inode) { -pr_err ("proc_fill_super: get root inode failed\n" ); -return -ENOMEM ; - } - - s->s_root =d_make_root (root_inode); -if (!s->s_root) { -pr_err ("proc_fill_super: allocate dentry failed\n" ); -return -ENOMEM ; - } - - ret =proc_setup_self (s); -if (ret) { -return ret; - } -return proc_setup_thread_self (s); -}
fs/proc/internal.h +1 -3
@@ -208,13 +208,12 @@ struct pde_opener {struct completion *c; } __randomize_layout;extern const struct inode_operations proc_link_inode_operations; -extern const struct inode_operations proc_pid_link_inode_operations; +extern const struct super_operations proc_sops;void proc_init_kmemcache (void );void set_proc_pid_nlink (void );extern struct inode *proc_get_inode (struct super_block *,struct proc_dir_entry *); -extern int proc_fill_super (struct super_block *,void *,size_t ,int );extern void proc_entry_rundown (struct proc_dir_entry *);/*
@@ -272,7 +271,6 @@ static inline void proc_tty_init(void) {}* root.c */ extern struct proc_dir_entry proc_root; -extern int proc_parse_options (char *options,struct pid_namespace *pid);extern void proc_self_init (void );extern int proc_remount (struct super_block *,int *,char *,size_t );
fs/proc/root.c +47 -1
66 lines not on this page · raw message
David Howells
maintainerPATCH 16/32 proc: Add fs_context support to procfs [ver #9]
In reply to David HowellsAdd fs_context support to procfs.
---
fs/proc/inode.c | 2 - fs/proc/internal.h | 2 - fs/proc/root.c | 179 ++++++++++++++++++++++++++++++++++------------------ 3 files changed, 120 insertions(+), 63 deletions(-)
fs/proc/inode.c +1 -1
@@ -127,7 +127,7 @@ const struct super_operations proc_sops = { .drop_inode = generic_delete_inode, .evict_inode = proc_evict_inode, .statfs = simple_statfs, - .remount_fs = proc_remount, + .reconfigure = proc_reconfigure, .show_options = proc_show_options, };
fs/proc/internal.h +1 -1
@@ -273,7 +273,7 @@ static inline void proc_tty_init(void) {}extern struct proc_dir_entry proc_root;extern void proc_self_init (void ); -extern int proc_remount (struct super_block *,int *,char *,size_t ); +extern int proc_reconfigure (struct super_block *,struct fs_context *);/* * task_[no]mmu.c
fs/proc/root.c +118 -61
251 lines not on this page · raw message
David Howells
maintainerPATCH 17/32 ipc: Convert mqueue fs to fs_context [ver #9]
In reply to David HowellsConvert the mqueue filesystem to use the filesystem context stuff.
Notes:
(1) The relevant ipc namespace is selected in when the context is initialised (and it defaults to the current task's ipc namespace). The caller can override this before calling vfs_get_tree().
(2) Rather than simply calling kern_mount_data(), mq_init_ns() and mq_internal_mount() create a context, adjust it and then do the rest of the mount procedure.
(3) The lazy mqueue mounting on creation of a new namespace is retained from a previous patch, but the avoidance of sget() if no superblock yet exists is reverted and the superblock is again keyed on the namespace pointer.
Yes, there was a performance gain in not searching the superblock hash, but it's only paid once per ipc namespace - and only if someone uses mqueue within that namespace, so I'm not sure it's worth it, especially as calling sget() allows avoidance of recursion.
---
ipc/mqueue.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 99 insertions(+), 22 deletions(-)
ipc/mqueue.c +99 -22
@@ -18,6 +18,7 @@#include <linux/pagemap.h> #include <linux/file.h> #include <linux/mount.h> +#include <linux/fs_context.h> #include <linux/namei.h> #include <linux/sysctl.h> #include <linux/poll.h>
@@ -42,6 +43,10 @@#include <net/sock.h> #include "util.h" +struct mqueue_fs_context { +struct ipc_namespace *ipc_ns; +}; +#define MQUEUE_MAGIC 0x19800202#define DIRENT_SIZE 20#define FILENT_SIZE 80
@@ -87,9 +92,11 @@ struct mqueue_inode_info {unsigned long qsize;/* size of queue in memory (sum of all msgs) */ }; +static struct file_system_type mqueue_fs_type;static const struct inode_operations mqueue_dir_inode_operations;static const struct file_operations mqueue_file_operations;static const struct super_operations mqueue_super_ops; +static const struct fs_context_operations mqueue_fs_context_ops;static void remove_notification (struct mqueue_inode_info *info);static struct kmem_cache *mqueue_inode_cachep;
@@ -322,7 +329,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,return ERR_PTR (ret); } -static int mqueue_fill_super (struct super_block *sb,void *data,size_t data_size,int silent) +static int mqueue_fill_super (struct super_block *sb,struct fs_context *fc) {struct inode *inode;struct ipc_namespace *ns = sb->s_fs_info;
@@ -343,19 +350,84 @@ static int mqueue_fill_super(struct super_block *sb, void *data, size_t data_sizreturn 0 ; } -static struct dentry *mqueue_mount (struct file_system_type *fs_type, -int flags,const char *dev_name, -void *data,size_t data_size) +static int mqueue_get_tree (struct fs_context *fc) { -struct ipc_namespace *ns; -if (flags &SB_KERNMOUNT ) { - ns = data; - data =NULL ; - }else { - ns = current->nsproxy->ipc_ns; +struct mqueue_fs_context *ctx = fc->fs_private; + +/* As a shortcut, if the namespace already has a superblock created, +* use the root from that directly rather than invoking sget() again. +*/ +spin_lock (&mq_lock); +if (ctx->ipc_ns->mq_mnt) { + fc->root =dget (ctx->ipc_ns->mq_mnt->mnt_sb->s_root); +atomic_inc (&fc->root->d_sb->s_active); } -return mount_ns (fs_type, flags, data, data_size, ns, ns->user_ns, - mqueue_fill_super); +spin_unlock (&mq_lock); +if (fc->root) { +down_write (&fc->root->d_sb->s_umount); +return 0 ; + } + + fc->s_fs_info = ctx->ipc_ns; +return vfs_get_super (fc, vfs_get_keyed_super, mqueue_fill_super); +} + +static void mqueue_fs_context_free (struct fs_context *fc) +{ +struct mqueue_fs_context *ctx = fc->fs_private; + +if (ctx->ipc_ns) +put_ipc_ns (ctx->ipc_ns); +kfree (ctx); +} + +static int mqueue_init_fs_context (struct fs_context *fc, +struct dentry *reference) +{ +struct mqueue_fs_context *ctx; + + ctx =kzalloc (sizeof (struct mqueue_fs_context ),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + + ctx->ipc_ns =get_ipc_ns (current->nsproxy->ipc_ns); + fc->fs_private = ctx; + fc->ops = &mqueue_fs_context_ops; +return 0 ; +} + +static struct vfsmount *mq_create_mount (struct ipc_namespace *ns) +{ +struct mqueue_fs_context *ctx; +struct fs_context *fc; +struct vfsmount *mnt; +int ret; + + fc =vfs_new_fs_context (&mqueue_fs_type,NULL ,0 , +FS_CONTEXT_FOR_KERNEL_MOUNT ); +if (IS_ERR (fc)) +return ERR_CAST (fc); + + ctx = fc->fs_private; +put_ipc_ns (ctx->ipc_ns); + ctx->ipc_ns =get_ipc_ns (ns); + + ret =vfs_get_tree (fc); +if (ret <0 ) + goto err_fc; + + mnt =vfs_create_mount (fc,0 ); +if (IS_ERR (mnt)) { + ret =PTR_ERR (mnt); + goto err_fc; + } + +put_fs_context (fc); +return mnt; + +err_fc: +put_fs_context (fc); +return ERR_PTR (ret); }static void init_once (void *foo)
@@ -1523,15 +1595,22 @@ static const struct super_operations mqueue_super_ops = { .statfs = simple_statfs, }; +static const struct fs_context_operations mqueue_fs_context_ops = { + .free = mqueue_fs_context_free, + .get_tree = mqueue_get_tree, +}; +static struct file_system_type mqueue_fs_type = { - .name ="mqueue" , - .mount = mqueue_mount, - .kill_sb = kill_litter_super, - .fs_flags =FS_USERNS_MOUNT , + .name ="mqueue" , + .init_fs_context = mqueue_init_fs_context, + .kill_sb = kill_litter_super, + .fs_flags =FS_USERNS_MOUNT , };int mq_init_ns (struct ipc_namespace *ns) { +struct vfsmount *m; + ns->mq_queues_count =0 ; ns->mq_queues_max =DFLT_QUEUESMAX ; ns->mq_msg_max =DFLT_MSGMAX ;
@@ -1539,12 +1618,10 @@ int mq_init_ns(struct ipc_namespace *ns) ns->mq_msg_default =DFLT_MSG ; ns->mq_msgsize_default =DFLT_MSGSIZE ; - ns->mq_mnt =kern_mount_data (&mqueue_fs_type, ns,0 ); -if (IS_ERR (ns->mq_mnt)) { -int err =PTR_ERR (ns->mq_mnt); - ns->mq_mnt =NULL ; -return err; - } + m =mq_create_mount (&init_ipc_ns); +if (IS_ERR (m)) +return PTR_ERR (m); + ns->mq_mnt = m;return 0 ; }
David Howells
maintainerPATCH 18/32 cpuset: Use fs_context [ver #9]
In reply to David HowellsMake the cpuset filesystem use the filesystem context. This is potentially tricky as the cpuset fs is almost an alias for the cgroup filesystem, but with some special parameters.
This can, however, be handled by setting up an appropriate cgroup filesystem and returning the root directory of that as the root dir of this one.
---
kernel/cgroup/cpuset.c | 66 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 14 deletions(-)
kernel/cgroup/cpuset.c +52 -14
@@ -38,7 +38,7 @@#include <linux/mm.h> #include <linux/memory.h> #include <linux/export.h> -#include <linux/mount.h> +#include <linux/fs_context.h> #include <linux/namei.h> #include <linux/pagemap.h> #include <linux/proc_fs.h>
@@ -315,26 +315,64 @@ static inline bool is_in_v2_mode(void)* users. If someone tries to mount the "cpuset" filesystem, we * silently switch it to mount "cgroup" instead */ -static struct dentry *cpuset_mount (struct file_system_type *fs_type, -int flags,const char *unused_dev_name, -void *data,size_t data_size) +static int cpuset_get_tree (struct fs_context *fc) { -struct file_system_type *cgroup_fs =get_fs_type ("cgroup" ); -struct dentry *ret =ERR_PTR (-ENODEV ); +static const char opts[] ="cpuset,noprefix,release_agent=/sbin/cpuset_release_agent" ; +struct file_system_type *cgroup_fs; +struct fs_context *cg_fc; +char *p; +int ret = -ENODEV ; + + cgroup_fs =get_fs_type ("cgroup" );if (cgroup_fs) { -char mountopts[] = -"cpuset,noprefix," -"release_agent=/sbin/cpuset_release_agent" ; - ret = cgroup_fs->mount (cgroup_fs, flags, unused_dev_name, - mountopts, data_size); -put_filesystem (cgroup_fs); + ret =PTR_ERR (cgroup_fs); + goto out; + } + + cg_fc =vfs_new_fs_context (cgroup_fs,NULL , fc->sb_flags, fc->purpose); +put_filesystem (cgroup_fs); +if (IS_ERR (cg_fc)) { + ret =PTR_ERR (cg_fc); + goto out; } + + ret = -ENOMEM ; + p =kstrdup (opts,GFP_KERNEL ); +if (!p) + goto out_fc; + + ret =generic_parse_monolithic (fc, p,sizeof (opts) -1 ); +kfree (p); +if (ret <0 ) + goto out_fc; + + ret =vfs_get_tree (cg_fc); +if (ret <0 ) + goto out_fc; + + fc->root =dget (cg_fc->root); + ret =0 ; + +out_fc: +put_fs_context (cg_fc); +out:return ret; } +static const struct fs_context_operations cpuset_fs_context_ops = { + .get_tree = cpuset_get_tree, +}; + +static int cpuset_init_fs_context (struct fs_context *fc, +struct dentry *reference) +{ + fc->ops = &cpuset_fs_context_ops; +return 0 ; +} +static struct file_system_type cpuset_fs_type = { - .name ="cpuset" , - .mount = cpuset_mount, + .name ="cpuset" , + .init_fs_context = cpuset_init_fs_context, };/*
David Howells
maintainerPATCH 19/32 kernfs, sysfs, cgroup, intel_rdt: Support fs_context [ver #9]
In reply to David HowellsMake kernfs support superblock creation/mount/remount with fs_context.
This requires that sysfs, cgroup and intel_rdt, which are built on kernfs, be made to support fs_context also.
Notes:
(1) A kernfs_fs_context struct is created to wrap fs_context and the kernfs mount parameters are moved in here (or are in fs_context).
(2) kernfs_mount{,_ns}() are made into kernfs_get_tree(). The extra namespace tag parameter is passed in the context if desired
(3) kernfs_free_fs_context() is provided as a destructor for the kernfs_fs_context struct, but for the moment it does nothing except get called in the right places.
(4) sysfs doesn't wrap kernfs_fs_context since it has no parameters to pass, but possibly this should be done anyway in case someone wants to add a parameter in future.
(5) A cgroup_fs_context struct is created to wrap kernfs_fs_context and the cgroup v1 and v2 mount parameters are all moved there.
(6) cgroup1 parameter parsing error messages are now handled by invalf(), which allows userspace to collect them directly.
(7) cgroup1 parameter cleanup is now done in the context destructor rather than in the mount/get_tree and remount functions.
Weirdies:
(*) cgroup_do_get_tree() calls cset_cgroup_from_root() with locks held,
but then uses the resulting pointer after dropping the locks. I'm told this is okay and needs commenting.
(*) The cgroup refcount web. This really needs documenting.
(*) cgroup2 only has one root?
Add a suggestion from Thomas Gleixner in which the RDT enablement code is placed into its own function.
---
arch/x86/kernel/cpu/intel_rdt.h | 15 + arch/x86/kernel/cpu/intel_rdt_rdtgroup.c | 149 ++++++++------- fs/kernfs/mount.c | 89 ++++----- fs/sysfs/mount.c | 67 +++++-- include/linux/cgroup.h | 3 include/linux/kernfs.h | 39 ++-- kernel/cgroup/cgroup-internal.h | 49 +++-- kernel/cgroup/cgroup-v1.c | 302 +++++++++++++++--------------- kernel/cgroup/cgroup.c | 226 +++++++++++++--------- kernel/cgroup/cpuset.c | 4 10 files changed, 527 insertions(+), 416 deletions(-)
arch/x86/kernel/cpu/intel_rdt.h +15 -0
@@ -33,6 +33,21 @@#define RMID_VAL_ERROR BIT_ULL(63)#define RMID_VAL_UNAVAIL BIT_ULL(62) + +struct rdt_fs_context { +struct kernfs_fs_context kfc; +bool enable_cdpl2; +bool enable_cdpl3; +bool enable_mba_mbps; +}; + +static inline struct rdt_fs_context *rdt_fc2context (struct fs_context *fc) +{ +struct kernfs_fs_context *kfc = fc->fs_private; + + return container_of(kfc, struct rdt_fs_context, kfc); +} +DECLARE_STATIC_KEY_FALSE (rdt_enable_key);/**
arch/x86/kernel/cpu/intel_rdt_rdtgroup.c +83 -66
215 lines not on this page · raw message
fs/kernfs/mount.c +43 -46
162 lines not on this page · raw message
fs/sysfs/mount.c +48 -19
91 lines not on this page · raw message
include/linux/cgroup.h +2 -1
@@ -829,10 +829,11 @@ copy_cgroup_ns(unsigned long flags, struct user_namespace *user_ns,#endif /* !CONFIG_CGROUPS */ -static inline void get_cgroup_ns (struct cgroup_namespace *ns) +static inline struct cgroup_namespace *get_cgroup_ns (struct cgroup_namespace *ns) {if (ns)refcount_inc (&ns->count); +return ns; }static inline void put_cgroup_ns (struct cgroup_namespace *ns)
include/linux/kernfs.h +21 -18
@@ -16,6 +16,7 @@#include <linux/rbtree.h> #include <linux/atomic.h> #include <linux/wait.h> +#include <linux/fs_context.h> struct file ;struct dentry ;
@@ -25,6 +26,7 @@ struct vm_area_struct;struct super_block ;struct file_system_type ; +struct kernfs_fs_context ;struct kernfs_open_node ;struct kernfs_iattrs ;
@@ -166,7 +168,7 @@ struct kernfs_node {* kernfs_node parameter. */ struct kernfs_syscall_ops { -int (*remount_fs)(struct kernfs_root *root,int *flags,char *data); +int (*reconfigure)(struct kernfs_root *root,struct fs_context *fc);int (*show_options)(struct seq_file *sf,struct kernfs_root *root); int (*mkdir)(struct kernfs_node *parent, const char *name,
@@ -267,6 +269,18 @@ struct kernfs_ops {#endif }; +/* +* The kernfs superblock creation/mount parameter context. +*/ +struct kernfs_fs_context { +struct kernfs_root *root;/* Root of the hierarchy being mounted */ +void *ns_tag;/* Namespace tag of the mount (or NULL) */ +unsigned long magic;/* File system specific magic number */ + +/* The following are set/used by kernfs_mount() */ +bool new_sb_created;/* Set to T if we allocated a new sb */ +}; +#ifdef CONFIG_KERNFS static inline enum kernfs_node_type kernfs_type (struct kernfs_node *kn)
@@ -350,9 +364,8 @@ int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);void kernfs_notify (struct kernfs_node *kn);const void *kernfs_super_ns (struct super_block *sb); -struct dentry *kernfs_mount_ns (struct file_system_type *fs_type,int flags, -struct kernfs_root *root,unsigned long magic, -bool *new_sb_created,const void *ns); +int kernfs_get_tree (struct fs_context *fc); +void kernfs_free_fs_context (struct fs_context *fc);void kernfs_kill_sb (struct super_block *sb);struct super_block *kernfs_pin_sb (struct kernfs_root *root,const void *ns);
@@ -454,11 +467,10 @@ static inline void kernfs_notify(struct kernfs_node *kn) { }static inline const void *kernfs_super_ns (struct super_block *sb) {return NULL ; } -static inline struct dentry * -kernfs_mount_ns (struct file_system_type *fs_type,int flags, -struct kernfs_root *root,unsigned long magic, -bool *new_sb_created,const void *ns) -{return ERR_PTR (-ENOSYS ); } +static inline int kernfs_get_tree (struct fs_context *fc) +{return -ENOSYS ; } + +static inline void kernfs_free_fs_context (struct fs_context *fc) { }static inline void kernfs_kill_sb (struct super_block *sb) { }
@@ -535,13 +547,4 @@ static inline int kernfs_rename(struct kernfs_node *kn, return kernfs_rename_ns(kn, new_parent, new_name, NULL); } -static inline struct dentry * -kernfs_mount (struct file_system_type *fs_type,int flags, -struct kernfs_root *root,unsigned long magic, -bool *new_sb_created) -{ -return kernfs_mount_ns (fs_type, flags, root, - magic, new_sb_created,NULL ); -} -#endif /* __LINUX_KERNFS_H */
kernel/cgroup/cgroup-internal.h +32 -17
74 lines not on this page · raw message
kernel/cgroup/cgroup-v1.c +148 -154
473 lines not on this page · raw message
kernel/cgroup/cgroup.c +134 -92
323 lines not on this page · raw message
kernel/cgroup/cpuset.c +1 -3
@@ -324,10 +324,8 @@ static int cpuset_get_tree(struct fs_context *fc)int ret = -ENODEV ; cgroup_fs =get_fs_type ("cgroup" ); -if (cgroup_fs) { - ret =PTR_ERR (cgroup_fs); +if (!cgroup_fs) goto out; - } cg_fc =vfs_new_fs_context (cgroup_fs,NULL , fc->sb_flags, fc->purpose);put_filesystem (cgroup_fs);
David Howells
maintainerPATCH 20/32 hugetlbfs: Convert to fs_context [ver #9]
In reply to David HowellsConvert the hugetlbfs to use the fs_context during mount.
---
fs/hugetlbfs/inode.c | 342 +++++++++++++++++++++++++++++--------------------- 1 file changed, 197 insertions(+), 145 deletions(-)
fs/hugetlbfs/inode.c +197 -145
@@ -45,11 +45,17 @@ const struct file_operations hugetlbfs_file_operations;static const struct inode_operations hugetlbfs_dir_inode_operations;static const struct inode_operations hugetlbfs_inode_operations; -struct hugetlbfs_config { +enum hugetlbfs_size_type {NO_SIZE ,SIZE_STD ,SIZE_PERCENT }; + +struct hugetlbfs_fs_context {struct hstate *hstate; +unsigned long long max_size_opt; +unsigned long long min_size_opt;long max_hpages;long nr_inodes;long min_hpages; +enum hugetlbfs_size_type max_val_type; +enum hugetlbfs_size_type min_val_type;kuid_t uid;kgid_t gid;umode_t mode;
@@ -708,16 +714,16 @@ static int hugetlbfs_setattr(struct dentry *dentry, struct iattr *attr) }static struct inode *hugetlbfs_get_root (struct super_block *sb, -struct hugetlbfs_config *config) +struct hugetlbfs_fs_context *ctx) {struct inode *inode; inode =new_inode (sb);if (inode) { inode->i_ino =get_next_ino (); - inode->i_mode =S_IFDIR | config->mode; - inode->i_uid = config->uid; - inode->i_gid = config->gid; + inode->i_mode =S_IFDIR | ctx->mode; + inode->i_uid = ctx->uid; + inode->i_gid = ctx->gid; inode->i_atime = inode->i_mtime = inode->i_ctime =current_time (inode); inode->i_op = &hugetlbfs_dir_inode_operations; inode->i_fop = &simple_dir_operations;
@@ -1081,8 +1087,6 @@ static const struct super_operations hugetlbfs_ops = { .show_options = hugetlbfs_show_options, }; -enum hugetlbfs_size_type {NO_SIZE ,SIZE_STD ,SIZE_PERCENT }; -/* * Convert size option passed from command line to number of huge pages * in the pool specified by hstate. Size option could be in bytes
@@ -1105,171 +1109,156 @@ hugetlbfs_size_to_hpages(struct hstate *h, unsigned long long size_opt,return size_opt; } -static int -hugetlbfs_parse_options (char *options,struct hugetlbfs_config *pconfig) +/* +* Parse one mount option. +*/ +static int hugetlbfs_parse_option (struct fs_context *fc,char *opt,size_t len) { -char *p, *rest; +struct hugetlbfs_fs_context *ctx = fc->fs_private; +char *rest; +unsigned long ps;substring_t args[MAX_OPT_ARGS ]; -int option; -unsigned long long max_size_opt =0 , min_size_opt =0 ; -enum hugetlbfs_size_type max_val_type =NO_SIZE , min_val_type =NO_SIZE ; - -if (!options) +int token, option; + + token =match_token (opt, tokens, args); +switch (token) { +case Opt_uid: +if (match_int (&args[0 ], &option)) + goto bad_val; + ctx->uid =make_kuid (current_user_ns (), option); +if (!uid_valid (ctx->uid)) + goto bad_val;return 0 ; -while ((p =strsep (&options,"," )) !=NULL ) { -int token; -if (!*p) -continue ; +case Opt_gid: +if (match_int (&args[0 ], &option)) + goto bad_val; + ctx->gid =make_kgid (current_user_ns (), option); +if (!gid_valid (ctx->gid)) + goto bad_val; +return 0 ; - token =match_token (p, tokens, args); -switch (token) { -case Opt_uid: -if (match_int (&args[0 ], &option)) - goto bad_val; - pconfig->uid =make_kuid (current_user_ns (), option); -if (!uid_valid (pconfig->uid)) - goto bad_val; -break ; +case Opt_mode: +if (match_octal (&args[0 ], &option)) + goto bad_val; + ctx->mode = option &01777U ; +return 0 ; -case Opt_gid: -if (match_int (&args[0 ], &option)) - goto bad_val; - pconfig->gid =make_kgid (current_user_ns (), option); -if (!gid_valid (pconfig->gid)) - goto bad_val; -break ; +case Opt_size: +/* memparse() will accept a K/M/G without a digit */ +if (!isdigit (*args[0 ].from)) + goto bad_val; + ctx->max_size_opt =memparse (args[0 ].from, &rest); + ctx->max_val_type =SIZE_STD ; +if (*rest =='%' ) + ctx->max_val_type =SIZE_PERCENT ; +return 0 ; -case Opt_mode: -if (match_octal (&args[0 ], &option)) - goto bad_val; - pconfig->mode = option &01777U ; -break ; +case Opt_nr_inodes: +/* memparse() will accept a K/M/G without a digit */ +if (!isdigit (*args[0 ].from)) + goto bad_val; + ctx->nr_inodes =memparse (args[0 ].from, &rest); +return 0 ; -case Opt_size: { -/* memparse() will accept a K/M/G without a digit */ -if (!isdigit (*args[0 ].from)) - goto bad_val; - max_size_opt =memparse (args[0 ].from, &rest); - max_val_type =SIZE_STD ; -if (*rest =='%' ) - max_val_type =SIZE_PERCENT ; -break ; +case Opt_pagesize: + ps =memparse (args[0 ].from, &rest); + ctx->hstate =size_to_hstate (ps); +if (!ctx->hstate) { +pr_err ("Unsupported page size %lu MB\n" , ps >>20 ); +return -EINVAL ; } +return 0 ; -case Opt_nr_inodes: -/* memparse() will accept a K/M/G without a digit */ -if (!isdigit (*args[0 ].from)) - goto bad_val; - pconfig->nr_inodes =memparse (args[0 ].from, &rest); -break ; +case Opt_min_size: +/* memparse() will accept a K/M/G without a digit */ +if (!isdigit (*args[0 ].from)) + goto bad_val; + ctx->min_size_opt =memparse (args[0 ].from, &rest); + ctx->min_val_type =SIZE_STD ; +if (*rest =='%' ) + ctx->min_val_type =SIZE_PERCENT ; +return 0 ; -case Opt_pagesize: { -unsigned long ps; - ps =memparse (args[0 ].from, &rest); - pconfig->hstate =size_to_hstate (ps); -if (!pconfig->hstate) { -pr_err ("Unsupported page size %lu MB\n" , - ps >>20 ); -return -EINVAL ; - } -break ; - } +default : +pr_err ("Bad mount option: \"%s\"\n" , opt); +return -EINVAL ; + } -case Opt_min_size: { -/* memparse() will accept a K/M/G without a digit */ -if (!isdigit (*args[0 ].from)) - goto bad_val; - min_size_opt =memparse (args[0 ].from, &rest); - min_val_type =SIZE_STD ; -if (*rest =='%' ) - min_val_type =SIZE_PERCENT ; -break ; - } +bad_val: +pr_err ("Bad value '%s' for mount option '%s'\n" , args[0 ].from, opt); +return -EINVAL ; +} -default : -pr_err ("Bad mount option: \"%s\"\n" , p); -return -EINVAL ; -break ; - } - } +/* +* Validate the parsed options. +*/ +static int hugetlbfs_validate (struct fs_context *fc) +{ +struct hugetlbfs_fs_context *ctx = fc->fs_private;/* * Use huge page pool size (in hstate) to convert the size * options to number of huge pages. If NO_SIZE, -1 is returned. */ - pconfig->max_hpages =hugetlbfs_size_to_hpages (pconfig->hstate, - max_size_opt, max_val_type); - pconfig->min_hpages =hugetlbfs_size_to_hpages (pconfig->hstate, - min_size_opt, min_val_type); + ctx->max_hpages =hugetlbfs_size_to_hpages (ctx->hstate, + ctx->max_size_opt, + ctx->max_val_type); + ctx->min_hpages =hugetlbfs_size_to_hpages (ctx->hstate, + ctx->min_size_opt, + ctx->min_val_type);/* * If max_size was specified, then min_size must be smaller */ -if (max_val_type >NO_SIZE && - pconfig->min_hpages > pconfig->max_hpages) { -pr_err ("minimum size can not be greater than maximum size\n" ); +if (ctx->max_val_type >NO_SIZE && + ctx->min_hpages > ctx->max_hpages) { +pr_err ("Minimum size can not be greater than maximum size\n" );return -EINVAL ; }return 0 ; - -bad_val: -pr_err ("Bad value '%s' for mount option '%s'\n" , args[0 ].from, p); -return -EINVAL ; }static int -hugetlbfs_fill_super (struct super_block *sb,void *data,size_t data_size, -int silent) +hugetlbfs_fill_super (struct super_block *sb,struct fs_context *fc) { -int ret; -struct hugetlbfs_config config; +struct hugetlbfs_fs_context *ctx = + fc->fs_private;struct hugetlbfs_sb_info *sbinfo; - config.max_hpages =-1 ;/* No limit on size by default */ - config.nr_inodes =-1 ;/* No limit on number of inodes by default */ - config.uid =current_fsuid (); - config.gid =current_fsgid (); - config.mode =0755 ; - config.hstate = &default_hstate; - config.min_hpages =-1 ;/* No default minimum size */ - ret =hugetlbfs_parse_options (data, &config); -if (ret) -return ret; - sbinfo =kmalloc (sizeof (struct hugetlbfs_sb_info ),GFP_KERNEL );if (!sbinfo)return -ENOMEM ; sb->s_fs_info = sbinfo; - sbinfo->hstate = config.hstate;spin_lock_init (&sbinfo->stat_lock); - sbinfo->max_inodes = config.nr_inodes; - sbinfo->free_inodes = config.nr_inodes; - sbinfo->spool =NULL ; - sbinfo->uid = config.uid; - sbinfo->gid = config.gid; - sbinfo->mode = config.mode; + sbinfo->hstate = ctx->hstate; + sbinfo->max_inodes = ctx->nr_inodes; + sbinfo->free_inodes = ctx->nr_inodes; + sbinfo->spool =NULL ; + sbinfo->uid = ctx->uid; + sbinfo->gid = ctx->gid; + sbinfo->mode = ctx->mode;/* * Allocate and initialize subpool if maximum or minimum size is * specified. Any needed reservations (for minimim size) are taken * taken when the subpool is created. */ -if (config.max_hpages !=-1 || config.min_hpages !=-1 ) { - sbinfo->spool =hugepage_new_subpool (config.hstate, - config.max_hpages, - config.min_hpages); +if (ctx->max_hpages !=-1 || ctx->min_hpages !=-1 ) { + sbinfo->spool =hugepage_new_subpool (ctx->hstate, + ctx->max_hpages, + ctx->min_hpages);if (!sbinfo->spool) goto out_free; } sb->s_maxbytes =MAX_LFS_FILESIZE ; - sb->s_blocksize =huge_page_size (config.hstate); - sb->s_blocksize_bits =huge_page_shift (config.hstate); + sb->s_blocksize =huge_page_size (ctx->hstate); + sb->s_blocksize_bits =huge_page_shift (ctx->hstate); sb->s_magic =HUGETLBFS_MAGIC ; sb->s_op = &hugetlbfs_ops; sb->s_time_gran =1 ; - sb->s_root =d_make_root (hugetlbfs_get_root (sb, &config)); + sb->s_root =d_make_root (hugetlbfs_get_root (sb, ctx));if (!sb->s_root) goto out_free;return 0 ;
@@ -1279,17 +1268,50 @@ hugetlbfs_fill_super(struct super_block *sb, void *data, size_t data_size,return -ENOMEM ; } -static struct dentry *hugetlbfs_mount (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data,size_t data_size) +static int hugetlbfs_get_tree (struct fs_context *fc) +{ +return vfs_get_super (fc, vfs_get_independent_super, hugetlbfs_fill_super); +} + +static void hugetlbfs_fs_context_free (struct fs_context *fc) { -return mount_nodev (fs_type, flags, data, data_size, - hugetlbfs_fill_super); +kfree (fc->fs_private); +} + +static const struct fs_context_operations hugetlbfs_fs_context_ops = { + .free = hugetlbfs_fs_context_free, + .parse_option = hugetlbfs_parse_option, + .validate = hugetlbfs_validate, + .get_tree = hugetlbfs_get_tree, +}; + +static int hugetlbfs_init_fs_context (struct fs_context *fc, +struct dentry *reference) +{ +struct hugetlbfs_fs_context *ctx; + + ctx =kzalloc (sizeof (struct hugetlbfs_fs_context ),GFP_KERNEL ); +if (!ctx) +return -ENOMEM ; + + ctx->max_hpages =-1 ;/* No limit on size by default */ + ctx->nr_inodes =-1 ;/* No limit on number of inodes by default */ + ctx->uid =current_fsuid (); + ctx->gid =current_fsgid (); + ctx->mode =0755 ; + ctx->hstate = &default_hstate; + ctx->min_hpages =-1 ;/* No default minimum size */ + ctx->max_val_type =NO_SIZE ; + ctx->min_val_type =NO_SIZE ; + fc->fs_private = ctx; + fc->ops = &hugetlbfs_fs_context_ops; +return 0 ; }static struct file_system_type hugetlbfs_fs_type = { - .name ="hugetlbfs" , - .mount = hugetlbfs_mount, - .kill_sb = kill_litter_super, + .name ="hugetlbfs" , + .init_fs_context = hugetlbfs_init_fs_context, + .kill_sb = kill_litter_super, };static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE ];
@@ -1396,8 +1418,47 @@ struct file *hugetlb_file_setup(const char *name, size_t size,return file; } +static struct vfsmount *__init mount_one_hugetlbfs (struct hstate *h) +{ +struct hugetlbfs_fs_context *ctx; +struct fs_context *fc; +struct vfsmount *mnt; +int ret; + + fc =vfs_new_fs_context (&hugetlbfs_fs_type,NULL ,0 , +FS_CONTEXT_FOR_KERNEL_MOUNT ); +if (IS_ERR (fc)) { + ret =PTR_ERR (fc); + goto err; + } + + ctx = fc->fs_private; + ctx->hstate = h; + + ret =vfs_get_tree (fc); +if (ret <0 ) + goto err_fc; + + mnt =vfs_create_mount (fc,0 ); +if (IS_ERR (mnt)) { + ret =PTR_ERR (mnt); + goto err_fc; + } + +put_fs_context (fc); +return mnt; + +err_fc: +put_fs_context (fc); +err: +pr_err ("Cannot mount internal hugetlbfs for page size %uK" , +1U << (h->order +PAGE_SHIFT -10 )); +return ERR_PTR (ret); +} +static int __init init_hugetlbfs_fs (void ) { +struct vfsmount *mnt;struct hstate *h;int error;int i;
@@ -1420,25 +1481,16 @@ static int __init init_hugetlbfs_fs(void) i =0 ;for_each_hstate (h) { -char buf[50 ]; -unsigned ps_kb =1U << (h->order +PAGE_SHIFT -10 ); -int n; - - n =snprintf (buf,sizeof (buf),"pagesize=%uK" , ps_kb); - hugetlbfs_vfsmount[i] =kern_mount_data (&hugetlbfs_fs_type, - buf, n +1 ); - -if (IS_ERR (hugetlbfs_vfsmount[i])) { -pr_err ("Cannot mount internal hugetlbfs for " -"page size %uK" , ps_kb); - error =PTR_ERR (hugetlbfs_vfsmount[i]); - hugetlbfs_vfsmount[i] =NULL ; + mnt =mount_one_hugetlbfs (h); +if (IS_ERR (mnt) && i ==0 ) { + error =PTR_ERR (mnt); + goto out; } + hugetlbfs_vfsmount[i] = mnt; i++; } -/* Non default hstates are optional */ -if (!IS_ERR_OR_NULL (hugetlbfs_vfsmount[default_hstate_idx])) -return 0 ; + +return 0 ; out:kmem_cache_destroy (hugetlbfs_inode_cachep);
David Howells
maintainerPATCH 21/32 vfs: Remove kern_mount_data() [ver #9]
In reply to David HowellsThe kern_mount_data() isn't used any more so remove it.
---
fs/namespace.c | 7 ------- include/linux/fs.h | 1 - 2 files changed, 8 deletions(-)
fs/namespace.c +0 -7
@@ -3346,13 +3346,6 @@ struct vfsmount *kern_mount(struct file_system_type *type) }EXPORT_SYMBOL_GPL (kern_mount); -struct vfsmount *kern_mount_data (struct file_system_type *type, -void *data,size_t data_size) -{ -return vfs_kern_mount (type,SB_KERNMOUNT , type->name, data, data_size); -} -EXPORT_SYMBOL_GPL (kern_mount_data); -/* * Move a mount from one place to another. * In combination with open_tree(OPEN_TREE_CLONE [| AT_RECURSIVE]) it can be
include/linux/fs.h +0 -1
@@ -2211,7 +2211,6 @@ mount_pseudo(struct file_system_type *fs_type, char *name,extern int register_filesystem (struct file_system_type *);extern int unregister_filesystem (struct file_system_type *);extern struct vfsmount *kern_mount (struct file_system_type *); -extern struct vfsmount *kern_mount_data (struct file_system_type *,void *,size_t );extern void kern_unmount (struct vfsmount *mnt);extern int may_umount_tree (struct vfsmount *);extern int may_umount (struct vfsmount *);
David Howells
maintainerPATCH 22/32 vfs: Provide documentation for new mount API [ver #9]
In reply to David HowellsProvide documentation for the new mount API.
---
Documentation/filesystems/mount_api.txt | 439 +++++++++++++++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 Documentation/filesystems/mount_api.txt
Documentation/filesystems/mount_api.txt new file +439 -0
@@ -0,0 +1,439 @@ + ==================== + FILESYSTEM MOUNT API + ==================== + +CONTENTS + + (1) Overview. + + (2) The filesystem context. + + (3) The filesystem context operations. + + (4) Filesystem context security. + + (5) VFS filesystem context operations. + + +======== +OVERVIEW +======== + +The creation of new mounts is now to be done in a multistep process: + + (1) Create a filesystem context. + + (2) Parse the options and attach them to the context. Options are expected to + be passed individually from userspace, though legacy binary options can be + handled. + + (3) Validate and pre-process the context. + + (4) Get or create a superblock and mountable root. + + (5) Perform the mount. + + (6) Return an error message attached to the context. + + (7) Destroy the context. + +To support this, the file_system_type struct gains a new field: + + int (*init_fs_context)(struct fs_context *fc, struct dentry *reference); + +which is invoked to set up the filesystem-specific parts of a filesystem +context, including the additional space. The reference parameter is used to +convey a superblock and an automount point or a point to reconfigure from which +the filesystem may draw extra information (such as namespaces) for submount +(FS_CONTEXT_FOR_SUBMOUNT) or reconfiguration (FS_CONTEXT_FOR_RECONFIGURE) +purposes - otherwise it will be NULL. + +Note that security initialisation is done *after* the filesystem is called so +that the namespaces may be adjusted first. + +And the super_operations struct gains one field: + + int (*reconfigure)(struct super_block *, struct fs_context *); + +This shadows the ->reconfigure() operation and takes a prepared filesystem +context instead of the mount flags and data page. It may modify the sb_flags +in the context for the caller to pick up. + +[NOTE] reconfigure is intended as a replacement for remount_fs. + + +====================== +THE FILESYSTEM CONTEXT +====================== + +The creation and reconfiguration of a superblock is governed by a filesystem +context. This is represented by the fs_context structure: + + struct fs_context { + const struct fs_context_operations *ops; + struct file_system_type *fs_type; + void *fs_private; + struct dentry *root; + struct user_namespace *user_ns; + struct net *net_ns; + const struct cred *cred; + char *source; + char *subtype; + void *security; + void *s_fs_info; + unsigned int sb_flags; + enum fs_context_purpose purpose:8; + bool sloppy:1; + bool silent:1; + ... + }; + +The fs_context fields are as follows: + + (*) const struct fs_context_operations *ops + + These are operations that can be done on a filesystem context (see + below). This must be set by the ->init_fs_context() file_system_type + operation. + + (*) struct file_system_type *fs_type + + A pointer to the file_system_type of the filesystem that is being + constructed or reconfigured. This retains a reference on the type owner. + + (*) void *fs_private + + A pointer to the file system's private data. This is where the filesystem + will need to store any options it parses. + + (*) struct dentry *root + + A pointer to the root of the mountable tree (and indirectly, the + superblock thereof). This is filled in by the ->get_tree() op. If this + is set, an active reference on root->d_sb must also be held. + + (*) struct user_namespace *user_ns + (*) struct net *net_ns + + There are a subset of the namespaces in use by the invoking process. They + retain references on each namespace. The subscribed namespaces may be + replaced by the filesystem to reflect other sources, such as the parent + mount superblock on an automount. + + (*) const struct cred *cred + + The mounter's credentials. This retains a reference on the credentials. + + (*) char *source + + This specifies the source. It may be a block device (e.g. /dev/sda1) or + something more exotic, such as the "host:/path" that NFS desires. + + (*) char *subtype + + This is a string to be added to the type displayed in /proc/mounts to + qualify it (used by FUSE). This is available for the filesystem to set if + desired. + + (*) void *security + + A place for the LSMs to hang their security data for the superblock. The + relevant security operations are described below. + + (*) void *s_fs_info + + The proposed s_fs_info for a new superblock, set in the superblock by + sget_fc(). This can be used to distinguish superblocks. + + (*) unsigned int sb_flags + + This holds the SB_* flags to be set in super_block::s_flags. + + (*) enum fs_context_purpose + + This indicates the purpose for which the context is intended. The + available values are: + + FS_CONTEXT_FOR_USER_MOUNT, -- New superblock for user-specified mount + FS_CONTEXT_FOR_KERNEL_MOUNT, -- New superblock for kernel-internal mount + FS_CONTEXT_FOR_SUBMOUNT -- New automatic submount of extant mount + FS_CONTEXT_FOR_RECONFIGURE -- Change an existing mount + + (*) bool sloppy + (*) bool silent + + These are set if the sloppy or silent mount options are given. + + [NOTE] sloppy is probably unnecessary when userspace passes over one + option at a time since the error can just be ignored if userspace deems it + to be unimportant. + + [NOTE] silent is probably redundant with sb_flags & SB_SILENT. + +The mount context is created by calling vfs_new_fs_context(), vfs_sb_reconfig() +or vfs_dup_fs_context() and is destroyed with put_fs_context(). Note that the +structure is not refcounted. + +VFS, security and filesystem mount options are set individually with +vfs_parse_mount_option(). Options provided by the old mount(2) system call as +a page of data can be parsed with generic_parse_monolithic(). + +When mounting, the filesystem is allowed to take data from any of the pointers +and attach it to the superblock (or whatever), provided it clears the pointer +in the mount context. + +The filesystem is also allowed to allocate resources and pin them with the +mount context. For instance, NFS might pin the appropriate protocol version +module. + + +================================= +THE FILESYSTEM CONTEXT OPERATIONS +================================= + +The filesystem context points to a table of operations: + + struct fs_context_operations { + void (*free)(struct fs_context *fc); + int (*dup)(struct fs_context *fc, struct fs_context *src_fc); + int (*parse_source)(struct fs_context *fc, char *source); + int (*parse_option)(struct fs_context *fc, char *opt, size_t len); + int (*parse_monolithic)(struct fs_context *fc, void *data, + size_t data_size); + int (*validate)(struct fs_context *fc); + int (*get_tree)(struct fs_context *fc); + }; + +These operations are invoked by the various stages of the mount procedure to +manage the filesystem context. They are as follows: + + (*) void (*free)(struct fs_context *fc); + + Called to clean up the filesystem-specific part of the filesystem context + when the context is destroyed. It should be aware that parts of the + context may have been removed and NULL'd out by ->get_tree(). + + (*) int (*dup)(struct fs_context *fc, struct fs_context *src_fc); + + Called when a filesystem context has been duplicated to duplicate the + filesystem-private data. An error may be returned to indicate failure to + do this. + + [!] Note that even if this fails, put_fs_context() will be called + immediately thereafter, so ->dup() *must* make the + filesystem-private data safe for ->free(). + + (*) int (*parse_source)(struct fs_context *fc, char *source); + + Called when a source or device is specified for a filesystem context. + This may be called multiple times if the filesystem supports it. If + successful, 0 should be returned or a negative error code otherwise. + + (*) int (*parse_option)(struct fs_context *fc, char *opt, size_t len); + + Called when an option is to be added to the filesystem context. opt + points to the option string, likely in "key[=val]" format. VFS-specific + options will have been weeded out and fc->sb_flags updated in the context. + Security options will also have been weeded out and fc->security updated. + + If successful, 0 should be returned or a negative error code otherwise. + + (*) int (*parse_monolithic)(struct fs_context *fc, + void *data, size_t data_size); + + Called when the mount(2) system call is invoked to pass the entire data + page in one go. If this is expected to be just a list of "key[=val]" + items separated by commas, then this may be set to NULL. + + The return value is as for ->parse_option(). + + If the filesystem (e.g. NFS) needs to examine the data first and then + finds it's the standard key-val list then it may pass it off to + generic_parse_monolithic(). + + (*) int (*validate)(struct fs_context *fc); + + Called when all the options have been applied and the mount is about to + take place. It is should check for inconsistencies from mount options and + it is also allowed to do preliminary resource acquisition. For instance, + the core NFS module could load the NFS protocol module here. + + Note that if fc->purpose == FS_CONTEXT_FOR_RECONFIGURE, some of the + options necessary for a new mount may not be set. + + The return value is as for ->parse_option(). + + (*) int (*get_tree)(struct fs_context *fc); + + Called to get or create the mountable root and superblock, using the + information stored in the filesystem context (reconfiguration goes via a + different vector). It may detach any resources it desires from the + filesystem context and transfer them to the superblock it creates. + + On success it should set fc->root to the mountable root and return 0. In + the case of an error, it should return a negative error code. + + The phase on a userspace-driven context will be set to only allow this to + be called once on any particular context. + + +=========================== +FILESYSTEM CONTEXT SECURITY +=========================== + +The filesystem context contains a security pointer that the LSMs can use for +building up a security context for the superblock to be mounted. There are a +number of operations used by the new mount code for this purpose: + + (*) int security_fs_context_alloc(struct fs_context *fc, + struct dentry *reference); + + Called to initialise fc->security (which is preset to NULL) and allocate + any resources needed. It should return 0 on success or a negative error + code on failure. + + reference will be non-NULL if the context is being created for superblock + reconfiguration (FS_CONTEXT_FOR_RECONFIGURE) in which case it indicates + the root dentry of the superblock to be reconfigured. It will also be + non-NULL in the case of a submount (FS_CONTEXT_FOR_SUBMOUNT) in which case + it indicates the automount point. + + (*) int security_fs_context_dup(struct fs_context *fc, + struct fs_context *src_fc); + + Called to initialise fc->security (which is preset to NULL) and allocate + any resources needed. The original filesystem context is pointed to by + src_fc and may be used for reference. It should return 0 on success or a + negative error code on failure. + + (*) void security_fs_context_free(struct fs_context *fc); + + Called to clean up anything attached to fc->security. Note that the + contents may have been transferred to a superblock and the pointer cleared + during get_tree. + + (*) int security_fs_context_parse_source(struct fs_context *fc, char *src); + + Called for each source (there may be more than one if the filesystem + supports it). The arguments are as for the ->parse_source() method. It + should return 0 on success or a negative error code on failure. + + (*) int security_fs_context_parse_option(struct fs_context *fc, + char *opt, size_t len); + + Called for each mount option. The arguments are as for the + ->parse_option() method. It should return 0 to indicate that the option + should be passed on to the filesystem, 1 to indicate that the option + should be discarded or an error to indicate that the option should be + rejected. + + The buffer pointed to by opt may be modified. + + (*) int security_fs_context_validate(struct fs_context *fc); + + Called after all the options have been parsed to validate the collection + as a whole and to do any necessary allocation so that + security_sb_get_tree() is less likely to fail. It should return 0 or a + negative error code. + + (*) int security_sb_get_tree(struct fs_context *fc); + + Called during the mount procedure to verify that the specified superblock + is allowed to be mounted and to transfer the security data there. It + should return 0 or a negative error code. + + (*) int security_sb_mountpoint(struct fs_context *fc, struct path *mountpoint, + unsigned int mnt_flags); + + Called during the mount procedure to verify that the root dentry attached + to the context is permitted to be attached to the specified mountpoint. + It should return 0 on success or a negative error code on failure. + + +================================= +VFS FILESYSTEM CONTEXT OPERATIONS +================================= + +There are four operations for creating a filesystem context and +one for destroying a context: + + (*) struct fs_context *vfs_new_fs_context(struct file_system_type *fs_type, + struct dentry *reference, + unsigned int sb_flags, + enum fs_context_purpose purpose); + + Create a filesystem context for a given filesystem type and purpose. This + allocates the filesystem context, sets the flags, initialises the security + and calls fs_type->init_fs_context() to initialise the filesystem private + data. + + reference can be NULL or it may indicate the root dentry of a superblock + that is going to be reconfigured (FS_CONTEXT_FOR_RECONFIGURE) or the + automount point that triggered a submount (FS_CONTEXT_FOR_SUBMOUNT). This + is provided as a source of namespace information. + + (*) struct fs_context *vfs_sb_reconfig(struct vfsmount *mnt, + unsigned int sb_flags); + + Create a filesystem context from the same filesystem as an extant mount + and initialise the mount parameters from the superblock underlying that + mount. This is for use by superblock parameter reconfiguration. + + (*) struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc); + + Duplicate a filesystem context, copying any options noted and duplicating + or additionally referencing any resources held therein. This is available + for use where a filesystem has to get a mount within a mount, such as NFS4 + does by internally mounting the root of the target server and then doing a + private pathwalk to the target directory. + + (*) void put_fs_context(struct fs_context *fc); + + Destroy a filesystem context, releasing any resources it holds. This + calls the ->free() operation. This is intended to be called by anyone who + created a filesystem context. + + [!] filesystem contexts are not refcounted, so this causes unconditional + destruction. + +In all the above operations, apart from the put op, the return is a mount +context pointer or a negative error code. + +For the remaining operations, if an error occurs, a negative error code will be +returned. + + (*) int vfs_get_tree(struct fs_context *fc); + + Get or create the mountable root and superblock, using the parameters in + the filesystem context to select/configure the superblock. This invokes + the ->validate() op and then the ->get_tree() op. + + [NOTE] ->validate() could perhaps be rolled into ->get_tree() and + ->reconfigure(). + + (*) struct vfsmount *vfs_create_mount(struct fs_context *fc); + + Create a mount given the parameters in the specified filesystem context. + Note that this does not attach the mount to anything. + + (*) int vfs_set_fs_source(struct fs_context *fc, char *source, size_t len); + + Supply one or more source names or device names for the mount. This may + cause the filesystem to access the source. Multiple sources may be + specified if the filesystem supports it. + + (*) int vfs_parse_fs_option(struct fs_context *fc, char *opt, size_t len); + + Supply a single mount option to the filesystem context. The mount option + should likely be in a "key[=val]" string form. The option is first + checked to see if it corresponds to a standard mount flag (in which case + it is used to set an SB_xxx flag and consumed) or a security option (in + which case the LSM consumes it) before it is passed on to the filesystem. + + (*) int generic_parse_monolithic(struct fs_context *fc, + void *data, size_t data_len); + + Parse a sys_mount() data page, assuming the form to be a text list + consisting of key[=val] options separated by commas. Each item in the + list is passed to vfs_mount_option(). This is the default when the + ->parse_monolithic() operation is NULL.
Randy Dunlap
reviewerRe: [PATCH 22/32] vfs: Provide documentation for new mount API [ver #9]
Quoted 8 lines · David Howells
Provide documentation for the new mount API.
Signed-off-by David Howells <[email protected]>---
Documentation/filesystems/mount_api.txt | 439 +++++++++++++++++++++++++++++++ 1 file changed, 439 insertions(+) create mode 100644 Documentation/filesystems/mount_api.txt
Hi,
I would review this but it sounds like I should just wait for the next version.
Signature · 1 line
~Randy
David Howells
maintainerRe: [PATCH 22/32] vfs: Provide documentation for new mount API [ver #9]
Quoted 2 lines · Randy Dunlap
I would review this but it sounds like I should just wait for the next version.
Probably a good idea. Thanks for the consideration anyway.
David
David Howells
maintainerPATCH 23/32 Make anon_inodes unconditional [ver #9]
In reply to David HowellsMake the anon_inodes facility unconditional so that it can be used by core VFS code.
---
fs/Makefile | 2 +- init/Kconfig | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-)
fs/Makefile +1 -1
@@ -25,7 +25,7 @@ obj-$(CONFIG_PROC_FS) += proc_namespace.o obj-y += notify/ obj-$(CONFIG_EPOLL) += eventpoll.o -obj-$(CONFIG_ANON_INODES) += anon_inodes.o +obj-y += anon_inodes.o obj-$(CONFIG_SIGNALFD) += signalfd.o obj-$(CONFIG_TIMERFD) += timerfd.o obj-$(CONFIG_EVENTFD) += eventfd.o
init/Kconfig +0 -10
@@ -1066,9 +1066,6 @@ config LD_DEAD_CODE_DATA_ELIMINATION config SYSCTL bool -config ANON_INODES - bool - config HAVE_UID16 bool
@@ -1273,14 +1270,12 @@ config HAVE_FUTEX_CMPXCHG config EPOLL bool "Enable eventpoll support" if EXPERT default y - select ANON_INODES help Disabling this option will cause the kernel to be built without support for epoll family of system calls. config SIGNALFD bool "Enable signalfd() system call" if EXPERT - select ANON_INODES default y help Enable the signalfd() system call that allows to receive signals
@@ -1290,7 +1285,6 @@ config SIGNALFD config TIMERFD bool "Enable timerfd() system call" if EXPERT - select ANON_INODES default y help Enable the timerfd() system call that allows to receive timer
@@ -1300,7 +1294,6 @@ config TIMERFD config EVENTFD bool "Enable eventfd() system call" if EXPERT - select ANON_INODES default y help Enable the eventfd() system call that allows to receive both
@@ -1414,7 +1407,6 @@ config KALLSYMS_BASE_RELATIVE # syscall, maps, verifier config BPF_SYSCALL bool "Enable bpf() system call" - select ANON_INODES select BPF select IRQ_WORK default n
@@ -1431,7 +1423,6 @@ config BPF_JIT_ALWAYS_ON config USERFAULTFD bool "Enable userfaultfd() system call" - select ANON_INODES depends on MMU help Enable the userfaultfd() system call that allows to intercept and
@@ -1498,7 +1489,6 @@ config PERF_EVENTS bool "Kernel performance events and counters" default y if PROFILING depends on HAVE_PERF_EVENTS - select ANON_INODES select IRQ_WORK select SRCU help
David Howells
maintainerPATCH 24/32 vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsProvide an fsopen() system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle. fsopen() is given the name of the filesystem that will be used:
int mfd = fsopen(const char *fsname, unsigned int flags);
where flags can be 0 or FSOPEN_CLOEXEC.
For example:
sfd = fsopen("ext4", FSOPEN_CLOEXEC);
write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg
write(sfd, "o noatime");
write(sfd, "o acl");
write(sfd, "o user_attr");
write(sfd, "o iversion");
write(sfd, "o ");
write(sfd, "r /my/container"); // root inside the fs
write(sfd, "x create"); // create the superblock
fsinfo(sfd, NULL, ...); // query new superblock attributes
mfd = fsmount(sfd, FSMOUNT_CLOEXEC, MS_RELATIME);
move_mount(mfd, "", sfd, AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH);
sfd = fsopen("afs", -1);
write(sfd, "s %grand.central.org:root.cell");
write(sfd, "o cell=grand.central.org");
write(sfd, "r /");
write(sfd, "x create");
mfd = fsmount(sfd, 0, MS_NODEV);
move_mount(mfd, "", sfd, AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH);If an error is reported at any step, an error message may be available to be read() back (ENODATA will be reported if there isn't an error available) in the form:
"e <subsys>:<problem>" "e SELinux:Mount on mountpoint not permitted"
Once fsmount() has been called, further write() calls will incur EBUSY, even if the fsmount() fails. read() is still possible to retrieve error information.
The fsopen() syscall creates a mount context and hangs it of the fd that it returns.
Netlink is not used because it is optional and would make the core VFS dependent on the networking layer and also potentially add network namespace issues.
Note that, for the moment, the caller must have SYS_CAP_ADMIN to use fsopen().
---
arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 fs/Makefile | 2 fs/fs_context.c | 4 + fs/fsopen.c | 209 ++++++++++++++++++++++++++++++++ include/linux/fs_context.h | 2 include/linux/syscalls.h | 1 include/uapi/linux/fs.h | 5 + 8 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 fs/fsopen.c
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -400,3 +400,4 @@ 386 i386 rseq sys_rseq __ia32_sys_rseq 387 i386 open_tree sys_open_tree __ia32_sys_open_tree 388 i386 move_mount sys_move_mount __ia32_sys_move_mount +389 i386 fsopen sys_fsopen __ia32_sys_fsopen
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -345,6 +345,7 @@ 334 common rseq __x64_sys_rseq 335 common open_tree __x64_sys_open_tree 336 common move_mount __x64_sys_move_mount +337 common fsopen __x64_sys_fsopen # # x32-specific system call numbers start at 512 to avoid cache impact
fs/Makefile +1 -1
@@ -13,7 +13,7 @@ obj-y := open.o read_write.o file_table.o super.o \ seq_file.o xattr.o libfs.o fs-writeback.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_context.o + fs_context.o fsopen.o ifeq ($(CONFIG_BLOCK),y) obj-y += buffer.o block_dev.o direct-io.o mpage.o
fs/fs_context.c +4 -0
@@ -251,6 +251,8 @@ struct fs_context *vfs_new_fs_context(struct file_system_type *fs_type, fc->fs_type =get_filesystem (fs_type); fc->cred =get_current_cred (); +mutex_init (&fc->uapi_mutex); +switch (purpose) {case FS_CONTEXT_FOR_KERNEL_MOUNT : fc->sb_flags |=SB_KERNMOUNT ;
@@ -335,6 +337,8 @@ struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc)if (!fc)return ERR_PTR (-ENOMEM ); +mutex_init (&fc->uapi_mutex); + fc->fs_private =NULL ; fc->s_fs_info =NULL ; fc->source =NULL ;
fs/fsopen.c new file +209 -0
209 lines not on this page · raw message
include/linux/fs_context.h +2 -0
@@ -14,6 +14,7 @@#include <linux/kernel.h> #include <linux/errno.h> +#include <linux/mutex.h> struct cred ;struct dentry ;
@@ -58,6 +59,7 @@ enum fs_context_phase {*/ struct fs_context {const struct fs_context_operations *ops; +struct mutex uapi_mutex;/* Userspace access mutex */ struct file_system_type *fs_type;void *fs_private;/* The filesystem's context */ struct dentry *root;/* The root and superblock */
include/linux/syscalls.h +1 -0
@@ -904,6 +904,7 @@ asmlinkage long sys_open_tree(int dfd, const char __user *path, unsigned flags);asmlinkage long sys_move_mount (int from_dfd,const char __user *from_path,int to_dfd,const char __user *to_path,unsigned int ms_flags); +asmlinkage long sys_fsopen (const char __user *fs_name,unsigned int flags);/* * Architecture-specific system calls
include/uapi/linux/fs.h +5 -0
@@ -344,4 +344,9 @@ typedef int __bitwise __kernel_rwf_t;#define RWF_SUPPORTED (RWF_HIPRI | RWF_DSYNC | RWF_SYNC | RWF_NOWAIT |\ RWF_APPEND) +/* +* Flags for fsopen() and co. +*/ +#define FSOPEN_CLOEXEC 0x00000001 +#endif /* _UAPI_LINUX_FS_H */
David Howells
maintainerPATCH 1/1 Add manpage for fsopen(2), fspick(2) and fsmount(2)
Add a manual page to document the fsopen(), fspick() and fsmount() system calls.
---
man2/fsmount.2 | 1 man2/fsopen.2 | 357 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man2/fspick.2 | 1 3 files changed, 359 insertions(+) create mode 100644 man2/fsmount.2 create mode 100644 man2/fsopen.2 create mode 100644 man2/fspick.2
man2/fsmount.2 new file +1 -0
@@ -0,0 +1 @@ +.so man2/fsopen.2
man2/fsopen.2 new file +357 -0
357 lines not on this page · raw message
man2/fspick.2 new file +1 -0
@@ -0,0 +1 @@ +.so man2/fsopen.2
Re: [MANPAGE PATCH] Add manpage for fsopen(2), fspick(2) and fsmount(2)
Hello David,
See my previous mail.
With respect to the patch below, would you be willing to review the content of this man-pages patch to see if it accurately reflects what was merged into the kernel, and then resubmit please?
Thanks,
Michael
Quoted 392 lines · David Howells
Add a manual page to document the
fsopen(),fspick()andfsmount()system calls.Signed-off-by David Howells <[email protected]>---
man2/fsmount.2 | 1 man2/fsopen.2 | 357 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ man2/fspick.2 | 1 3 files changed, 359 insertions(+) create mode 100644 man2/fsmount.2 create mode 100644 man2/fsopen.2 create mode 100644 man2/fspick.2man2/fsmount.2 new file +1
-0@@ -0,0 +1 @@ +.so man2/fsopen.2man2/fsopen.2 new file +357
-0@@ -0,0 +1,357 @@ +'\" t +.\" Copyright (c) 2018 David Howells <[email protected]> +.\" +.\" %%%LICENSE_START(VERBATIM) +.\" Permission is granted to make and distribute verbatim copies of this +.\" manual provided the copyright notice and this permission notice are +.\" preserved on all copies. +.\" +.\" Permission is granted to copy and distribute modified versions of this +.\" manual under the conditions for verbatim copying, provided that the +.\" entire resulting derived work is distributed under the terms of a +.\" permission notice identical to this one. +.\" +.\" Since the Linux kernel and libraries are constantly changing, this +.\" manual page may be incorrect or out-of-date. The author(s) assume no +.\" responsibility for errors or omissions, or for damages resulting from +.\" the use of the information contained herein. The author(s) may not +.\" have taken the same level of care in the production of this manual, +.\" which is licensed free of charge, as they might when working +.\" professionally. +.\" +.\" Formatted or processed versions of this manual, if unaccompanied by +.\" the source, must acknowledge the copyright and authors of this work. +.\" %%%LICENSE_END +.\" +.TH FSOPEN 2 2018-06-07 "Linux" "Linux Programmer's Manual" +.SH NAME +fsopen, fsmount, fspick \- Handle filesystem (re-)configuration and mounting +.SH SYNOPSIS +.nf +.B #include <sys/types.h> +.br +.B #include <sys/mount.h> +.br +.B #include <unistd.h> +.br +.BR "#include <fcntl.h> " "/* Definition of AT_* constants */" +.PP +.BI "int fsopen(const char *" fsname ", unsigned int " flags ); +.PP +.BI "int fsmount(int " fd ", unsigned int " flags ", unsigned int " ms_flags ); +.PP +.BI "int fspick(int " dirfd ", const char *" pathname ", unsigned int " flags ); +.fi +.PP +.IR Note : +There are no glibc wrappers for these system calls. +.SH DESCRIPTION +.PP +.BR fsopen () +creates a new filesystem configuration context within the kernel for the +filesystem named in the +.I fsname +parameter and attaches it to a file descriptor, which it then returns. The +file descriptor can be marked close-on-exec by setting +.B FSOPEN_CLOEXEC +in flags. +.PP +The +file descriptor can then be used to configure the desired filesystem parameters +and security parameters by using +.BR write (2) +to pass parameters to it and then writing a command to actually create the +filesystem representation. +.PP +The file descriptor also serves as a channel by which more comprehensive error, +warning and information messages may be retrieved from the kernel using +.BR read (2). +.PP +Once the kernel's filesystem representation has been created, it can be queried +by calling +.BR fsinfo (2) +on the file descriptor. fsinfo() will spot that the target is actually a +creation context and look inside that. +.PP +.BR fsmount () +can then be called to create a mount object that refers to the newly created +filesystem representation, with the propagation and mount restrictions to be +applied specified in +.IR ms_flags . +The mount object is then attached to a new file descriptor that looks like one +created by +.BR open "(2) with " O_PATH " or " open_tree (2). +This can be passed to +.BR move_mount (2) +to attach the mount object to a mountpoint, thereby completing the process. +.PP +The file descriptor returned by fsmount() is marked close-on-exec if +FSMOUNT_CLOEXEC is specified in +.IR flags . +.PP +After fsmount() has completed, the context created by fsopen() is reset and +moved to reconfiguration state, allowing the new superblock to be reconfigured. +.PP +.BR fspick () +creates a new filesystem context within the kernel, attaches the superblock +specified by +.IR dfd ", " pathname ", " flags +and puts it into the reconfiguration state and attached the context to a new +file descriptor that can then be parameterised with +.BR write (2) +exactly the same as for the context created by fsopen() above. +.PP +.I flags +is an OR'd together mask of +.B FSPICK_CLOEXEC +which indicates that the returned file descriptor should be marked +close-on-exec and +.BR FSPICK_SYMLINK_NOFOLLOW ", " FSPICK_NO_AUTOMOUNT " and " FSPICK_EMPTY_PATH +which control the pathwalk to the target object (see below). + +.\"________________________________________________________ +.SS Writable Command Interface +Superblock (re-)configuration is achieved by writing command strings to the +context file descriptor using +.BR write (2). +Each string is prefixed with a specifier indicating the class of command +being specified. The available commands include: +.TP +\fB"o <option>"\fP +Specify a filesystem or security parameter. +.I <option> +is typically a key or key=val format string. Since the length of the option is +given to write(), the option may include any sort of character, including +spaces and commas or even binary data. +.TP +\fB"s <name>"\fP +Specify a device file, network server or other other source specification. +This may be optional, depending on the filesystem, and it may be possible to +provide multiple of them to a filesystem. +.TP +\fB"x create"\fP +End the filesystem configuration phase and try and create a representation in +the kernel with the parameters specified. After this, the context is shifted +to the mount-pending state waiting for an fsmount() call to occur. +.TP +\fB"x reconfigure"\fP +End a filesystem reconfiguration phase try to apply the parameters to the +filesystem representation. After this, the context gets reset and put back to +the start of the reconfiguration phase again. +.PP +With this interface, option strings are not limited to 4096 bytes, either +individually or in sum, and they are also not restricted to text-only options. +Further, errors may be given individually for each option and not aggregated or +dumped into the kernel log. + +.\"________________________________________________________ +.SS Message Retrieval Interface +The context file descriptor may be queried for message strings at any time by +calling +.BR read (2) +on the file descriptor. This will return formatted messages that are prefixed +to indicate their class: +.TP +\fB"e <message>"\fP +An error message string was logged. +.TP +\fB"i <message>"\fP +An informational message string was logged. +.TP +\fB"w <message>"\fP +An warning message string was logged. +.PP +Messages are removed from the queue as they're read. + +.\"________________________________________________________ +.SH EXAMPLES +To illustrate the process, here's an example whereby this can be used to mount +an ext4 filesystem on /dev/sdb1 onto /mnt. Note that the example ignores the +fact that +.BR write (2) +has a length parameter and that errors might occur. +.PP +.in +4n +.nf +sfd = fsopen("ext4", FSOPEN_CLOEXEC); +write(sfd, "s /dev/sdb1"); +write(sfd, "o noatime"); +write(sfd, "o acl"); +write(sfd, "o user_attr"); +write(sfd, "o iversion"); +write(sfd, "x create"); +fsinfo(sfd, NULL, ...); +mfd = fsmount(sfd, FSMOUNT_CLOEXEC, MS_RELATIME); +move_mount(mfd, "", sfd, AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.in +.PP +Here, an ext4 context is created first and attached to sfd. This is then told +where its source will be, given a bunch of options and created. +.BR fsinfo (2) +can then be used to query the filesystem. Then fsmount() is called to create a +mount object and +.BR move_mount (2) +is called to attach it to its intended mountpoint. +.PP +And here's an example of mounting from an NFS server: +.PP +.in +4n +.nf +sfd = fsopen("nfs", 0); +write(sfd, "s example.com/pub/linux"); +write(sfd, "o nfsvers=3"); +write(sfd, "o rsize=65536"); +write(sfd, "o wsize=65536"); +write(sfd, "o rdma"); +write(sfd, "x create"); +mfd = fsmount(sfd, 0, MS_NODEV); +move_mount(mfd, "", sfd, AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH); +.fi +.in +.PP +Reconfiguration can be achieved by: +.PP +.in +4n +.nf +sfd = fspick(AT_FDCWD, "/mnt", FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC); +write(sfd, "o ro"); +write(sfd, "x reconfigure"); +.fi +.in +.PP +or: +.PP +.in +4n +.nf +sfd = fsopen(...); +... +mfd = fsmount(sfd, ...); +... +write(sfd, "o ro"); +write(sfd, "x reconfigure"); +.fi +.in + + +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +.SH RETURN VALUE +On success, all three functions return a file descriptor. On error, \-1 is +returned, and +.I errno +is set appropriately. +.SH ERRORS +The error values given below result from filesystem type independent +errors. +Each filesystem type may have its own special errors and its +own special behavior. +See the Linux kernel source code for details. +.TP +.B EACCES +A component of a path was not searchable. +(See also +.BR path_resolution (7).) +.TP +.B EACCES +Mounting a read-only filesystem was attempted without giving the +.B MS_RDONLY +flag. +.TP +.B EACCES +The block device +.I source +is located on a filesystem mounted with the +.B MS_NODEV +option. +.\" mtk: Probably: write permission is required for MS_BIND, with +.\" the error EPERM if not present; CAP_DAC_OVERRIDE is required. +.TP +.B EBUSY +.I source +cannot be reconfigured read-only, because it still holds files open for +writing. +.TP +.B EFAULT +One of the pointer arguments points outside the user address space. +.TP +.B EINVAL +.I source +had an invalid superblock. +.TP +.B EINVAL +.I ms_flags +includes more than one of +.BR MS_SHARED , +.BR MS_PRIVATE , +.BR MS_SLAVE , +or +.BR MS_UNBINDABLE . +.TP +.BR EINVAL +An attempt was made to bind mount an unbindable mount. +.TP +.B ELOOP +Too many links encountered during pathname resolution. +.TP +.B EMFILE +The system has too many open files to create more. +.TP +.B ENFILE +The process has too many open files to create more. +.TP +.B ENAMETOOLONG +A pathname was longer than +.BR MAXPATHLEN . +.TP +.B ENODEV +Filesystem +.I fsname +not configured in the kernel. +.TP +.B ENOENT +A pathname was empty or had a nonexistent component. +.TP +.B ENOMEM +The kernel could not allocate sufficient memory to complete the call. +.TP +.B ENOTBLK +.I source +is not a block device (and a device was required). +.TP +.B ENOTDIR +.IR pathname , +or a prefix of +.IR source , +is not a directory. +.TP +.B ENXIO +The major number of the block device +.I source +is out of range. +.TP +.B EPERM +The caller does not have the required privileges. +.SH CONFORMING TO +These functions are Linux-specific and should not be used in programs intended +to be portable. +.SH VERSIONS +.BR fsopen "(), " fsmount "() and " fspick () +were added to Linux in kernel 4.18. +.SH NOTES +Glibc does not (yet) provide a wrapper for the +.BR fsopen "() , " fsmount "() or " fspick "()" +system calls; call them using +.BR syscall (2). +.SH SEE ALSO +.BR mountpoint (1), +.BR move_mount (2), +.BR open_tree (2), +.BR umount (2), +.BR mount_namespaces (7), +.BR path_resolution (7), +.BR findmnt (8), +.BR lsblk (8), +.BR mount (8), +.BR umount (8)man2/fspick.2 new file +1
-0@@ -0,0 +1 @@ +.so man2/fsopen.2
Signature · 3 lines
Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Linux/UNIX System Programming Training: http://man7.org/training/
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David Howells[cc Jann - you love this stuff]
Quoted 7 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);
This is great in principle, but I think you’re seriously playing with fire with the API.
Quoted 7 lines
where flags can be 0 or
FSOPEN_CLOEXEC.For example:
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg
Imagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write “s /etc/shadow”. What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.
Quoted 7 lines
write(sfd, "o noatime"); write(sfd, "o acl"); write(sfd, "o user_attr"); write(sfd, "o iversion"); write(sfd, "o "); write(sfd, "r /my/container"); // root inside the fs write(sfd, "x create"); // create the superblock
From cursory inspection of a bunch of the code, I think the expectation is that the actual device access happens in the “x” action. This is not okay. You can’t do this kind of thing in a write() handler, unless you somehow make every single access using f_cred, which is a real pain.
I think the right solution is one of:
(a) Pass a netlink-formatted blob to fsopen() and do the whole thing in one syscall. I don’t mean using netlink sockets — just the nlattr format. Or you could use a different format. The part that matters is using just one syscall to do the whole thing.
(b) Keep the current structure but use a new syscall instead of write().
(c) Keep using write() but literally just buffer the data. Then have a new syscall to commit it. In other words, replace “x” with a syscall and call all the fs_context_operations helpers in that context instead of from write().
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Yeah, Andy is right that we should *not* make "write()" have side effects.
Use it to queue things by all means, but not "do" things. Not unless there's a very sane security model.
Quoted 4 lines · Andy Lutomirski
I think the right solution is one of:
(a) Pass a netlink-formatted blob to
fsopen()and do the whole thing in one syscall. I don’t mean using netlink sockets — just the nlattr format. Or you could use a different format. The part that matters is using just one syscall to do the whole thing.
Please no. Not another nasty marshalling thing.
Quoted 3 lines
(b) Keep the current structure but use a new syscall instead of
write().(c) Keep using
write()but literally just buffer the data. Then have a new syscall to commit it. In other words, replace “x” with a syscall and call all thefs_context_operationshelpers in that context instead of fromwrite().
But yeah, b-or-c sounds fine.
Linus
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 11 lines · Linus Torvalds
Yeah, Andy is right that we should *not* make "
write()" have side effects.Use it to queue things by all means, but not "do" things. Not unless there's a very sane security model.
Quoted 4 lines · Andy Lutomirski
I think the right solution is one of:
(a) Pass a netlink-formatted blob to
fsopen()and do the whole thing in one syscall. I don’t mean using netlink sockets — just the nlattr format. Or you could use a different format. The part that matters is using just one syscall to do the whole thing.
Quoted 7 lines
Please no. Not another nasty marshalling thing.
Quoted 3 lines
(b) Keep the current structure but use a new syscall instead of
write().(c) Keep using
write()but literally just buffer the data. Then have a new syscall to commit it. In other words, replace “x” with a syscall and call all thefs_context_operationshelpers in that context instead of fromwrite().But yeah, b-or-c sounds fine.
Umm... How about "use credentials of opener for everything"?
Andy Lutomirski
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 14 lines · Al Viro
Quoted 13 lines · Linus Torvalds
Yeah, Andy is right that we should *not* make "
write()" have side effects.Use it to queue things by all means, but not "do" things. Not unless there's a very sane security model.
Quoted 4 lines · Andy Lutomirski
I think the right solution is one of:
(a) Pass a netlink-formatted blob to
fsopen()and do the whole thing in one syscall. I don’t mean using netlink sockets — just the nlattr format. Or you could use a different format. The part that matters is using just one syscall to do the whole thing.Please no. Not another nasty marshalling thing.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
(b) Keep the current structure but use a new syscall instead of
write().(c) Keep using
write()but literally just buffer the data. Then have a new syscall to commit it. In other words, replace “x” with a syscall and call all thefs_context_operationshelpers in that context instead of fromwrite().But yeah, b-or-c sounds fine.
Umm... How about "use credentials of opener for everything"?
If you want to audit every single filesystem for any code that uses credentials for anything and add all the right kernel APIs and make sure the filesystem uses them and somehow keep screwups from getting added down the line, then okay I guess. As far as I know, we don't even *have* an API for "open this device node using this struct cred *".
I kind of want to add a hack to set some poison bit in current->cred in sys_write() and clear it on the way out. Sigh.
--Andy
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 8 lines · Andy Lutomirski
Quoted 1 line
Umm... How about "use credentials of opener for everything"?
If you want to audit every single filesystem for any code that uses credentials for anything and add all the right kernel APIs and make sure the filesystem uses them and somehow keep screwups from getting added down the line, then okay I guess. As far as I know, we don't even *have* an API for "open this device node using this struct cred *".
You can use override_creds() too.
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Al ViroQuoted 2 lines · Al Viro
Umm... How about "use credentials of opener for everything"?
yeah, we have that for writes in general.
Nobody ever actually follows that rule. They may *think* they do, and then they call to some helper that does "capability(CAP_SYS_WHATEVAH)" without even realizing it.
But I'm certainly ok with writes, if it's just filling a buffer. Preferably a standard buffer we already have, like a seqfile or pipe (hey, splice!) or whatever.
And then you have that final op to actually "commit" the state. Which shouldn't be a write (and not the close).
Linus
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Linus TorvaldsQuoted 1 line · Linus Torvalds
Yeah, Andy is right that we should *not* make "
write()" have side effects.
Note that write() has side effects all over the place: procfs, sysfs, debugfs, tracefs, ... Though for the most part they're single-shot jobs and not cumulative (I'm not sure this is always true for debugfs - there's a lot of weird stuff in there).
Quoted 8 lines
Quoted 6 lines
(b) Keep the current structure but use a new syscall instead of
write().(c) Keep using
write()but literally just buffer the data. Then have a new syscall to commit it. In other words, replace “x” with a syscall and call all thefs_context_operationshelpers in that context instead of fromwrite().But yeah, b-or-c sounds fine.
I would prefer to avoid the "let's buffer everything" but rather parse the data as we go along. What I currently do is store the parsed data in the context and only actually *apply* it when someone sends the 'x' command.
There are two reasons for this:
(1) mount()'s error handling is slight: it can only return an error code, but creating and mounting something has so many different and interesting ways of going wrong and I want to be able to give better error reporting.
This gets more interesting if it happens inside a container where you can't see dmesg.
(2) Parsing the data means you only need to store the result of the parse and can reject anything that's unknown or contradictory.
Buffering till the end means you have to buffer *everything* - and, unless you limit your buffer, you risk running out of RAM.
Now, I can replace the 'x' command with an ioctl() so that just writing random rubbish to the fd won't cause anything to actually happen.
fd = fsopen("ext4");
write(fd, "s /dev/sda1");
write(fd, "o user_xattr");
ioctl(fd, FSOPEN_IOC_CREATE_SB, 0);or I could make a special syscall for it:
fscommit(fd, FSCOMMIT_CREATE);
or:
fscommit(fd, FSCOMMIT_RECONFIGURE);
and require that you have CAP_SYS_ADMIN to enact it.
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 3 lines · David Howells
Buffering till the end means you have to buffer *everything* - and, unless you limit your buffer, you risk running out of RAM
Do we really care?
Can't we limit the buffer size to something small?
Right now, the mount options can't be bigger than a page anyway. Why would we want to extend on that?
Btw, the magic word here is "why". I really really want to see a fairly exhaustive explanation of why this all is such a big deal, and exactly what limitations (including perhaps the mount option buffer size) are such a pain right now and need changing.
Quoted 10 lines
Now, I can replace the 'x' command with an
ioctl()so that just writing random rubbish to the fd won't cause anything to actually happen.fd = fsopen("ext4"); write(fd, "s /dev/sda1"); write(fd, "o user_xattr"); ioctl(fd, FSOPEN_IOC_CREATE_SB, 0);or I could make a special syscall for it:
Quoted 7 lines
fscommit(fd, FSCOMMIT_CREATE);or:
fscommit(fd, FSCOMMIT_RECONFIGURE);and require that you have
CAP_SYS_ADMINto enact it.
I think any of them sound fairly ok, with that whole "we need reasons" caveat.
Linus
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 33 lines · Andy Lutomirski
[cc Jann - you love this stuff]
Quoted 7 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);This is great in principle, but I think you’re seriously playing with fire with the API.
Quoted 7 lines
where flags can be 0 or
FSOPEN_CLOEXEC.For example:
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length argImagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write “s /etc/shadow”. What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.
Quoted 7 lines
write(sfd, "o noatime"); write(sfd, "o acl"); write(sfd, "o user_attr"); write(sfd, "o iversion"); write(sfd, "o "); write(sfd, "r /my/container"); // root inside the fs write(sfd, "x create"); // create the superblockFrom cursory inspection of a bunch of the code, I think the expectation is that the actual device access happens in the “x” action. This is not okay. You can’t do this kind of thing in a
write()handler, unless you somehow make every single access usingf_cred, which is a real pain.
Quoted 7 lines
I think the right solution is one of:
(a) Pass a netlink-formatted blob to
fsopen()and do the whole thing in one syscall. I don’t mean using netlink sockets — just the nlattr format. Or you could use a different format. The part that matters is using just one syscall to do the whole thing.(b) Keep the current structure but use a new syscall instead of
write().(c) Keep using
write()but literally just buffer the data. Then have a new syscall to commit it. In other words, replace “x” with a syscall and call all thefs_context_operationshelpers in that context instead of fromwrite().
I also love ioctls, so I think you could also use an ioctl to do the commit? You can do anything (well, almost anything) that you can do in syscall context in ioctl context, too; and when you already have a file descriptor of a specific type that you want to perform an operation on, an ioctl works just fine.
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 5 lines · Jann Horn
I also love ioctls, so I think you could also use an ioctl to do the commit? You can do anything (well, almost anything) that you can do in syscall context in ioctl context, too; and when you already have a file descriptor of a specific type that you want to perform an operation on, an ioctl works just fine.
Poe's Law in action...
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 7 lines · Andy Lutomirski
Quoted 2 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length argImagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write "s
/etc/shadow". What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.
Do note that you must already have CAP_SYS_ADMIN to be able to call fsopen().
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 5 lines · David Howells
Quoted 3 lines · Andy Lutomirski
Quoted 2 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg
Quoted 8 lines
Quoted 4 lines
Imagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write "s
/etc/shadow". What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.Do note that you must already have
CAP_SYS_ADMINto be able to callfsopen().David
Not really, by default an unprivileged user can still do:
unshare(CLONE_NEWUSER|CLONE_NEWNS); syscall(__NR_fsopen, "ext4", 0);
- Eric
Andy Lutomirski
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 7 lines · David Howells
Quoted 3 lines · Andy Lutomirski
Quoted 2 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg
Quoted 6 lines
Quoted 4 lines
Imagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write "s
/etc/shadow". What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.Do note that you must already have
CAP_SYS_ADMINto be able to callfsopen().
If you’re not allowing it already, someone will want user namespace root to be able to use this very, very soon.
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 12 lines · Andy Lutomirski
Quoted 12 lines · David Howells
Quoted 7 lines · Andy Lutomirski
Quoted 2 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length argImagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write "s
/etc/shadow". What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.
Quoted 5 lines
Quoted 2 lines
Do note that you must already have
CAP_SYS_ADMINto be able to callfsopen().If you're not allowing it already, someone will want user namespace root to be able to use this very, very soon.
Yeah, I'm sure. And I've been thinking on how to deal with it.
I think we *have* to open the source files/devices with the creds of whoever called fsopen() or fspick() - that way you can't upgrade your privs by passing your context fd to a suid program. To enforce this, I think it's simplest for fscontext_write() to call override_creds() right after taking the uapi_mutex and then call revert_creds() right before dropping the mutex.
Another thing we might want to look at is to allow a supervisory process to examine the context before permitting the create/reconfigure action to proceed. It might also be possible to do this through the LSM.
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 6 lines · David Howells
I think we *have* to open the source files/devices with the creds of whoever called
fsopen()orfspick()- that way you can't upgrade your privs by passing your context fd to a suid program. To enforce this, I think it's simplest forfscontext_write()to calloverride_creds()right after taking theuapi_mutexand then callrevert_creds()right before dropping the mutex.
No.
Don't play games with override_creds. It's wrong.
You have to use file->f_creds - no games, no garbage.
But "write()" simply is *NOT* a good "command" interface. If you want to send a command, use an ioctl or a system call.
Because it's not just about credentials. It's not just about fooling a suid app into writing an error message to a descriptor you wrote. It's also about things like "splice()", which can write to your target using a kernel buffer, and thus trick you into doing a command while we have the context set to kernel addresses.
Are we trying to get away from that issue? Yes. But it's just another example of why "write()" IS NOT TO BE USED FOR COMMANDS.
Only use write() for data.
That's final. We're not adding yet another clueless fuck-up of an interface just because people cannot understand this very simple rule:
"write()" is for data, not for commands.
No more excuses.
Linus
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 8 lines · Linus Torvalds
But "
write()" simply is *NOT* a good "command" interface. If you want to send a command, use an ioctl or a system call.Because it's not just about credentials. It's not just about fooling a suid app into writing an error message to a descriptor you wrote. It's also about things like "
splice()", which can write to your target using a kernel buffer, and thus trick you into doing a command while we have the context set to kernel addresses.
Wait a sec - that's only a problem if your command contains pointer-chasing et.al. Which is why e.g. /dev/sg is fucked in head. But for something that is plain text, what's the problem with splice/write/sendmsg/whatever?
I'm not talking about this particular interface, but "write is bad for commands" as general policy looks missing the point. If anything, it's pointer-chasing crap that should be banned everywhere. Just look at SG_IO - it's a ioctl, and it's absolute garbage...
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 3 lines · Al Viro
Wait a sec - that's only a problem if your command contains pointer-chasing et.al.
No.
It's a problem if anybody ever does something like "let's have a helper splice thread that uses splice to move data automatically from one buffer to another".
And yes, it's something people have wanted.
Seriously. I'm putting my foot down. NO COMMANDS IN WRITE DATA!
We have made that mistake in the past. Having done stupid things in the past is not an excuse for doing so again. Quite the reverse. Making the same mistake and not learning from your mistakes is the sign of stupidity.
So I repeat: write is for data. If you want an action, you do it with ioctl, or you do it with a system call.
Linus
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 15 lines · Linus Torvalds
Quoted 3 lines · Al Viro
Wait a sec - that's only a problem if your command contains pointer-chasing et.al.
No.
It's a problem if anybody ever does something like "let's have a helper splice thread that uses splice to move data automatically from one buffer to another".
And yes, it's something people have wanted.
Seriously. I'm putting my foot down. NO COMMANDS IN WRITE DATA!
Quoted 7 lines
We have made that mistake in the past. Having done stupid things in the past is not an excuse for doing so again. Quite the reverse. Making the same mistake and not learning from your mistakes is the sign of stupidity.
So I repeat: write is for data. If you want an action, you do it with ioctl, or you do it with a system call.
*shrug*
I think you are wrong[1], but it's your decision. And seriously, ioctl? _That_ has a great track record...
[1] one man's data is another man's commands, for starters. All networking protocols would fit your description. So would ANSI escape sequences ("move cursor to line 12 column 45" does sound like a command), so would writing postscript to printer, etc.
IME it's more about data structures that are not marshalled cleanly - that tends to go badly wrong. Again, see SG_IO for recent example...
Anyway, your tree, your policy.
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 2 lines · Al Viro
And seriously, ioctl? _That_ has a great track record...
I agree that a system call is likely saner. Especially since we'd have one to _start_ this (ie "fsopen()") it would make sense to have the one to finalize it.
Quoted 4 lines
[1] one man's data is another man's commands, for starters. All networking protocols would fit your description. So would ANSI escape sequences ("move cursor to line 12 column 45" does sound like a command), so would writing postscript to printer, etc.
.. and all of that is just data to the kernel.
Yes, vt100 escape sequences etc _are_ commands, and boy have we had bugs in that area. But there the excuse is "that's how the world is".
The thing is, "reality" is the ultimate argument. You can't argue with cold hard facts.
But when designing a new interface that doesn't have that kind of constraints, do it right.
Quoted 2 lines
IME it's more about data structures that are not marshalled cleanly - that tends to go badly wrong. Again, see
SG_IOfor recent example...
SG_IO actually gets it right. It doesn't do async, but that's part of the design (and a big part of why it's a lot simpler - the read-write thing is actually broken too and just forces user space to basically know SCSI).
Linus
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 4 lines · Linus Torvalds
I agree that a system call is likely saner. Especially since we'd have one to _start_ this (ie "
fsopen()") it would make sense to have the one to finalize it.
Side note: if we can make do with just a buffer, then we wouldn't need "fsopen()". You could literally just open a pipe, and write to it. It's got 16 pages worth of buffers by default, and you can increase it (within reason) as root.
Of course, depending on IO patterns, not all the buffer pages are necessarily fully used, so it's not like you get a buffer of size PAGE_SIZE*16, but we do merge buffers so you should be fairly close.
Then you really could do without a fsopen(). Just fill a pipe with data, and do "fsmount()" on the pipe contents.
Added upside? You can use "iov_iter_pipe()" to iterate over all that data.
I'm only half joking.
Linus
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 16 lines · Linus Torvalds
Quoted 4 lines · Linus Torvalds
I agree that a system call is likely saner. Especially since we'd have one to _start_ this (ie "
fsopen()") it would make sense to have the one to finalize it.Side note: if we can make do with just a buffer, then we wouldn't need "
fsopen()". You could literally just open a pipe, and write to it. It's got 16 pages worth of buffers by default, and you can increase it (within reason) as root.Of course, depending on IO patterns, not all the buffer pages are necessarily fully used, so it's not like you get a buffer of size PAGE_SIZE*16, but we do merge buffers so you should be fairly close.
Quoted 6 lines
Then you really could do without a
fsopen(). Just fill a pipe with data, and do "fsmount()" on the pipe contents.Added upside? You can use "
iov_iter_pipe()" to iterate over all that data.I'm only half joking.
One semi-historical note here.
Originally, mount(2) (and it had been there since v1) had only one filesystem type to deal with. So it was really just "mount <block device pathname> on <mountpoint pathname>, read-only or read-write". 3 arguments, two strings and one flag (flag, BTW, was a later addition).
It didn't last. I can dig out the archaeological notes and cut'n'paste the whole horror story here, but that'll be way too long and scary.
By 4.2BSD times there had been essentially an enum encoding the filesystem type and type-tagged union of structs with type-dependent options. Plus some options taking more bits in what used to be "is it r/w?" flag.
Leaving aside the whole "mount new/bind/remount/etc." overloading we have in mount(2) today, we have a bunch of named filesystems, each with its own set of options. Device name has ceased to be something special for many decades; the type name is what's universally present and that's what decides how the rest (including "device name") is to be interpreted.
Fundamentally, we start with selecting (by name) a filesystem driver we'll be talking to. The rest (device name + string options + flags like noexec that are not handled on VFS level) is given to that driver, which either tells us to take a hike or gives us a dentry tree that can be attached.
Separating type name from everything else makes a lot of sense, simply because it's what determines the parsing and interpretation of the rest. Speaking of half-joking, I suggested AF_FSTYPE at some point. Then fsopen(2) would be connect(2)...
I think that having that (connection used to talk to fs driver, with or without an already set up fs instance we are talking about) as first-class object makes sense. That's completely unrelated to the question of buffering, of course.
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 2 lines · Al Viro
Separating type name from everything else makes a lot of sense
I do not dispute that at all.
But you can specify the type name in the "commit" phase, it doesn't have to be at "fsopen" time.
In fact, doing so would _force_ a certain cleanliness to the interfaces - it would force the rest to be filesystem-agnostic, rather than possibly have semantic hacks for some part.
Linus
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Linus TorvaldsQuoted 9 lines · Linus Torvalds
Quoted 4 lines
[1] one man's data is another man's commands, for starters. All networking protocols would fit your description. So would ANSI escape sequences ("move cursor to line 12 column 45" does sound like a command), so would writing postscript to printer, etc.
.. and all of that is just data to the kernel.
Yes, vt100 escape sequences etc _are_ commands, and boy have we had bugs in that area. But there the excuse is "that's how the world is".
... along with "something similar to ncurses-based programs usable over ssh is a good thing to have, without having said ssh somehow intercept and marshal ioctls" ;-) I can just imagine something e.g. RDMA people would've designed instead... OTOH, I'm eating right now, so better not go there...
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Linus TorvaldsQuoted 3 lines · Linus Torvalds
Don't play games with
override_creds. It's wrong.You have to use
file->f_creds- no games, no garbage.
You missed the point.
It's all very well to say "use file->f_creds". The problem is this has to be handed down all the way through the filesystem and down into the block layer as appropriate to anywhere there's an LSM call, a CAP_* check or a pathwalk - but there's not currently any way to do that.
mount_bdev() and blkdev_get_by_path() are examples of this. At the moment there is no cred parameter there. We'd also have to pass the creds down into path_init() to store in struct nameidata and make sure that every permissions call that might be invoked during pathwalk in every filesystem uses that, not current_cred().
I made an attempt to do this a while ago and the patch got rather large before I gave up. In many ways, it's what we *should* do, but so many things need an extra parameter... If you really want, I can try that again. It's possible I can automate it with some perl scripting to parse the error messages from the compiler.
My suggestion was to use override_creds() to impose the appropriate creds at the top, be that file->f_creds or fs_context->creds (they would be the same in any case).
If we want to go down the pass-the-creds-down route, then we can temporarily do override_creds() until we've made the changes and then remove it later.
Quoted 2 lines
But "
write()" simply is *NOT* a good "command" interface. If you want to send a command, use an ioctl or a system call.
Okay.
Quoted 8 lines
Because it's not just about credentials. It's not just about fooling a suid app into writing an error message to a descriptor you wrote. It's also about things like "
splice()", which can write to your target using a kernel buffer, and thus trick you into doing a command while we have the context set to kernel addresses.Are we trying to get away from that issue? Yes. But it's just another example of why "
write()" IS NOT TO BE USED FOR COMMANDS.
Btw, do we protect sysfs, debugfs, tracefs, procfs, etc. writes against splice? Some of the things in debugfs are really icky, allowing you to muck directly with hardware.
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 10 lines · David Howells
Quoted 3 lines · Linus Torvalds
Don't play games with
override_creds. It's wrong.You have to use
file->f_creds- no games, no garbage.
Quoted 7 lines
You missed the point.
My suggestion was to use
override_creds()to impose the appropriate creds at the top, be thatfile->f_credsorfs_context->creds(they would be the same in any case).
I think it should be a new syscall and use current’s creds. No override needed.
Quoted 4 lines
Btw, do we protect sysfs, debugfs, tracefs, procfs, etc. writes against splice? Some of the things in debugfs are really icky, allowing you to muck directly with hardware.
We try. It has been a perennial source of severe bugs.
This is part of why I’d like to see splice() be an opt in. Also, it’s a major step toward getting rid of set_fs().
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 5 lines · David Howells
It's all very well to say "use
file->f_creds". The problem is this has to be handed down all the way through the filesystem and down into the block layer as appropriate to anywhere there's an LSM call, a CAP_* check or a pathwalk - but there's not currently any way to do that.
.. and the reason is simple: you damn well shouldn't do that.
The unix semantics are that credentials are checked at open time.
If your interface involves checking credentials at write() time, your interface is garbage shit.
Really.
This is the whole "write() is only for data". If you ever have credentials mattering at write time, you're doing something wrong.
Really really.
Don't do it.
Linus
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 7 lines · Linus Torvalds
This is the whole "
write()is only for data". If you ever have credentials mattering at write time, you're doing something wrong.Really really.
Don't do it.
.. and I'd like to repeat: we *have* done things wrong. But that's simply not an excuse. We've done it wrong in SCSI, we've done it wrong in various /proc files, we've done it wrong in many places.
But let's not do it wrong AGAIN.
Linus
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Linus TorvaldsQuoted 1 line · Linus Torvalds
The unix semantics are that credentials are checked at open time.
Sigh.
The problem is that there's more than one actual "open" involved.
fd = fsopen("ext4"); <--- #1
whatever_interface(fd, "s /dev/sda1");
whatever_interface(fd, "o journal_path=/dev/sda2");
do_the_create_thing(fd); <--- #2 and #3The initial check to see whether you can mount or not is done at #1.
But later there are two nested file opens. Internally, deep down inside the block layer, /dev/sda1 and /dev/sda2 are opened and further permissions checks are done, whether you like it or not. But these have no access to the creds attached to fd as things currently stand.
So we have three choices:
(1) Pass the creds from ->get_tree() all the way down into pathwalk and make sure *every* check that pathwalk does uses it.
(2) When do_the_create_thing() is invoked, it wraps the call to ->get_tree()
with override_creds(file->f_cred).
(3) Forget using an fd to refer to the context. fsopen() takes absolutely
everything, perhaps as a kv array and spits out an O_PATH fd. You don't
get improved error reporting, you don't get a chance for interaction -
say with the server, to construct an ID mapping table - and you don't get
the chance to query the superblock before creating a mount.
So, something like:
struct fsopen_param {
unsigned int type,
const char *key;
const void *val;
unsigned int val_len;
};
mfd = fsopen(const char *fs_type,
unsigned int flags, /* CLOEXEC */
const struct fsopen_param *params,
unsigned int param_count,
unsigned int ms_flags /* eg. MNT_NOEXEC */);
For example:
struct fsopen_param params[] = {
{ fsopen_source, "dev.fs", "/dev/sda1" }
{ fsopen_source, "dev.journal", "/dev/sda2" }
{ fsopen_option, "user_xattr" }
{ fsopen_option, "data", "journal" }
{ fsopen_option, "jqfmt", "vfsv1" }
{ fsopen_security, "selinux.context", "unconfined_u..." }
};
mfd = fsopen("ext4", FSOPEN_CLOEXEC, params, ARRAY_SIZE(params),
MNT_NOEXEC);
There would need to be an fsreconfig() also in a similar vein.David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 2 lines · David Howells
The problem is that there's more than one actual "open" involved.
No. The problem is "write()".
This is not about open, about fsopen, or about anything at all.
This is about the fact that "write()" by definition can happen in a different - and unexpected - context. Whether that be due to suid or due to splice, or due to any other random issue is entirely immaterial.
(The same is true of "read()" too, but very few people try to make "read()" have side effects, so it's less of an issue. It does happen, though).
But once you have another interface than "read/write()", the issues go away. Those other interfaces are synchronous, and now you can decide "ok, I'll just use current creds".
Quoted 2 lines
(1) Pass the creds from ->get_tree() all the way down into pathwalk and make sure *every* check that pathwalk does uses it.
No. See above.
If your write() does anything but buffering data, it's not getting merged.
Quoted 2 lines
(2) When
do_the_create_thing()is invoked, it wraps the call to ->get_tree()with override_creds(file->f_cred).
No.
We do not wrap creds in any case. It's just asking for *another* kind of security issue, where you fool some higher-security thing into giving you access because it wrapped the higher-security case instead.
Quoted 2 lines
(3) Forget using an fd to refer to the context.
fsopen()takes absolutely everything, perhaps as a kv array and spits out anO_PATHfd.
That works.
Or you know - do what I told you to do ALL THE TIME, which was to not use write(), or to only buffer things with write().
But yes, any option that simply avoids read and write is fine.
You can even have a file descriptor. We already have file descriptors that cannot be read from or written to. It's quite common for special devices, the whole "open /dev/floppy with O_NONBLOCK only to be able to do control operations with it" goes back to pretty much day #1.
More recently, we have the whole "FMODE_PATH" kind of file descriptor, which works as a directory entry, but not for read and write.
So file descriptors can have very useful properties.
But no. We do not use "write()" to implement actions. If you think you need to check permissions and think you need a "cred", then you're not using write(). It really is that simple.
Not using write just avouds *all* the problems. If you can fool a suid application to do arbitrary system calls for you, then it's not the system call that is the security problem.
Linus
Theodore Y. Ts'o
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 7 lines · David Howells
The problem is that there's more than one actual "open" involved.
fd = fsopen("ext4"); <--- #1 whatever_interface(fd, "s /dev/sda1"); whatever_interface(fd, "o journal_path=/dev/sda2"); do_the_create_thing(fd); <--- #2 and #3
Quoted 6 lines
The initial check to see whether you can mount or not is done at #1.
But later there are two nested file opens. Internally, deep down inside the block layer,
/dev/sda1and/dev/sda2are opened and further permissions checks are done, whether you like it or not. But these have no access to the creds attached to fd as things currently stand.
So maybe the answer is that you open /dev/sda1 and /dev/sda2 and then pass the file descriptors to the fsopen object? We can require that the fd's be opened with O_RDWR and O_EXCL, which has the benefit where if you have multiple block devices, you know *which* block device had a problem with being grabbed for an exclusive open.
Just a thought.
- Ted
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 5 lines · Theodore Y. Ts'o
So maybe the answer is that you open
/dev/sda1and/dev/sda2and then pass the file descriptors to the fsopen object? We can require that the fd's be opened withO_RDWRandO_EXCL, which has the benefit where if you have multiple block devices, you know *which* block device had a problem with being grabbed for an exclusive open.
Would that mean then that doing:
mount /dev/sda3 /a
mount /dev/sda3 /b
would then fail on the second command because /dev/sda3 is already open exclusively?
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 12 lines · David Howells
Quoted 5 lines · Theodore Y. Ts'o
So maybe the answer is that you open
/dev/sda1and/dev/sda2and then pass the file descriptors to the fsopen object? We can require that the fd's be opened withO_RDWRandO_EXCL, which has the benefit where if you have multiple block devices, you know *which* block device had a problem with being grabbed for an exclusive open.
Quoted 8 lines
Would that mean then that doing:
mount
/dev/sda3/a
mount/dev/sda3/bwould then fail on the second command because
/dev/sda3is already open exclusively?
I tend to think that this *should* fail using the new API. The semantics of the second mount request are bizarre at best.
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 2 lines · Andy Lutomirski
I tend to think that this *should* fail using the new API. The semantics of the second mount request are bizarre at best.
You still have to support existing behaviour lest you break userspace.
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 11 lines · David Howells
Quoted 2 lines · Andy Lutomirski
I tend to think that this *should* fail using the new API. The semantics of the second mount request are bizarre at best.
You still have to support existing behaviour lest you break userspace.
I assume the existing behavior is that a bind mount is created? If so, the new mount(8) tool could do it in user code.
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 8 lines · Andy Lutomirski
Quoted 5 lines
Quoted 2 lines
I tend to think that this *should* fail using the new API. The semantics of the second mount request are bizarre at best.
You still have to support existing behaviour lest you break userspace.
I assume the existing behavior is that a bind mount is created? If so, the new mount(8) tool could do it in user code.
You have a race there.
Also you can't currently directly create a bind mount from userspace as you can only bind from another path point - which you may not be able to access (either by permission failure or because it's not in your mount namespace).
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 12 lines · David Howells
Quoted 6 lines · Andy Lutomirski
Quoted 5 lines
Quoted 2 lines
I tend to think that this *should* fail using the new API. The semantics of the second mount request are bizarre at best.
You still have to support existing behaviour lest you break userspace.
Quoted 9 lines
Quoted 2 lines
I assume the existing behavior is that a bind mount is created? If so, the new mount(8) tool could do it in user code.
You have a race there.
Also you can't currently directly create a bind mount from userspace as you can only bind from another path point - which you may not be able to access (either by permission failure or because it's not in your mount namespace).
Are you trying to preserve the magic bind semantics with the new API? If you are, I think it should be by explicit opt in only. Otherwise you risk having your shiny new way to specify fs options get ignored when the magic bind mount happens.
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 6 lines · Andy Lutomirski
Quoted 4 lines
Also you can't currently directly create a bind mount from userspace as you can only bind from another path point - which you may not be able to access (either by permission failure or because it's not in your mount namespace).
Are you trying to preserve the magic bind semantics with the new API?
No, I'm pointing out that you can't emulate this by doing a bind mount from userspace if you can't access the thing you're binding from.
Now, we could create a syscall that just picks up an extant superblock using a device and attaches it to a mount for you, but that would have to be at least partially parameterised - which would be very fs-dependent - so that it can know whether or not you're allowed to create another mount to that sb.
What you're talking about is emulating sget() in userspace - when we have to do it in the kernel anyway if we still offer mount(2).
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 12 lines · David Howells
Quoted 6 lines · Andy Lutomirski
Quoted 4 lines
Also you can't currently directly create a bind mount from userspace as you can only bind from another path point - which you may not be able to access (either by permission failure or because it's not in your mount namespace).
Are you trying to preserve the magic bind semantics with the new API?
No, I'm pointing out that you can't emulate this by doing a bind mount from userspace if you can't access the thing you're binding from.
Quoted 7 lines
Now, we could create a syscall that just picks up an extant superblock using a device and attaches it to a mount for you, but that would have to be at least partially parameterised - which would be very fs-dependent - so that it can know whether or not you're allowed to create another mount to that sb.
What you're talking about is emulating
sget()in userspace - when we have to do it in the kernel anyway if we still offer mount(2).
I am just going to chime in and say that it is absolutely a problem in the current mount interface that when I mount a filesystem with fresh parameters I don't know if it is generates an sget and a new super_block or if it just increments the refcount on an existing super_block.
It is the kind of problem that is actually security sensitive and has resulted in a security issue in the current linux kernel with respect to proc.
So yes we absolutely need to have a clean way of dealing with:
mount /dev/sda3 /tmp
mount /dev/sda3 /mnt
So that the second one is forbidden fails. And userspace has to do the equivalent of sget to get a file descriptor it can bind into the mount namespace.
The deep problem is that the second mount does not parse the mount options and userspace does not know that. So userspace thinks it is getting one kind of mount and in practice it gets another (sometimes with different security properties). Those different security properties are an out and out bug. Although any kind of different and unexpected properties can be a problem.
Eric
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 9 lines · David Howells
Quoted 5 lines · Theodore Y. Ts'o
So maybe the answer is that you open
/dev/sda1and/dev/sda2and then pass the file descriptors to the fsopen object? We can require that the fd's be opened withO_RDWRandO_EXCL, which has the benefit where if you have multiple block devices, you know *which* block device had a problem with being grabbed for an exclusive open.
Quoted 7 lines
Would that mean then that doing:
mount
/dev/sda3/a
mount/dev/sda3/bwould then fail on the second command because
/dev/sda3is already open exclusively?
Not exactly. mount_bdev() uses FMODE_EXCL, which locks out parallel usage *with a different filesystem type*. This is the effect:
# strace -e trace=mount mount -t vfat /dev/loop0 mount
mount("/dev/loop0", "/home/jannh/tmp/x/mount", "vfat", MS_MGC_VAL, NULL) = 0
+++ exited with 0 +++
# strace -e trace=mount mount -t ext4 /dev/loop0 mount
mount("/dev/loop0", "/home/jannh/tmp/x/mount", "ext4", MS_MGC_VAL,
NULL) = -1 EBUSY (Device or resource busy)
mount: /home/jannh/tmp/x/mount: /dev/loop0 already mounted on
/home/jannh/tmp/x/mount.
+++ exited with 32 +++I don't really understand why it's not more strict though...
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 32 lines · Jann Horn
Quoted 9 lines · David Howells
Quoted 5 lines · Theodore Y. Ts'o
So maybe the answer is that you open
/dev/sda1and/dev/sda2and then pass the file descriptors to the fsopen object? We can require that the fd's be opened withO_RDWRandO_EXCL, which has the benefit where if you have multiple block devices, you know *which* block device had a problem with being grabbed for an exclusive open.Quoted 7 lines
Would that mean then that doing:
mount
/dev/sda3/a
mount/dev/sda3/bwould then fail on the second command because
/dev/sda3is already open exclusively?Not exactly.
mount_bdev()usesFMODE_EXCL, which locks out parallel usage *with a different filesystem type*. This is the effect:# strace -e trace=mount mount -t vfat /dev/loop0 mount mount("/dev/loop0", "/home/jannh/tmp/x/mount", "vfat", MS_MGC_VAL, NULL) = 0 +++ exited with 0 +++ # strace -e trace=mount mount -t ext4 /dev/loop0 mount mount("/dev/loop0", "/home/jannh/tmp/x/mount", "ext4", MS_MGC_VAL, NULL) = -1 EBUSY (Device or resource busy) mount: /home/jannh/tmp/x/mount: /dev/loop0 already mounted on /home/jannh/tmp/x/mount. +++ exited with 32 +++
Quoted 1 line
I don't really understand why it's not more strict though...
Er, sorry, of course that's the current behavior, not the behavior of the suggested API.
Theodore Y. Ts'o
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 8 lines · David Howells
Would that mean then that doing:
mount
/dev/sda3/a
mount/dev/sda3/bwould then fail on the second command because
/dev/sda3is already open exclusively?
Good point. One workaround would be to require an open with O_PATH instead.
- Ted
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 24 lines · David Howells
Quoted 12 lines · Andy Lutomirski
Quoted 12 lines · David Howells
Quoted 7 lines · Andy Lutomirski
Quoted 2 lines
sfd =
fsopen("ext4", FSOPEN_CLOEXEC);
write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length argImagine some malicious program passes sfd as stdout to a setuid program. That program gets persuaded to write "s
/etc/shadow". What happens? You’re okay as long as *every single fs* gets it right, but that’s asking a lot.Quoted 5 lines
Quoted 2 lines
Do note that you must already have
CAP_SYS_ADMINto be able to callfsopen().If you're not allowing it already, someone will want user namespace root to be able to use this very, very soon.
Quoted 8 lines
Yeah, I'm sure. And I've been thinking on how to deal with it.
I think we *have* to open the source files/devices with the creds of whoever called
fsopen()orfspick()- that way you can't upgrade your privs by passing your context fd to a suid program. To enforce this, I think it's simplest forfscontext_write()to calloverride_creds()right after taking theuapi_mutexand then callrevert_creds()right before dropping the mutex.
If you make a syscall that attaches a block device to an fscontext, you don’t need any of this. Heck, someone might actually *want* to grab a block device from a different namespace.
All this override_creds() stuff is maybe okay if we were fixing an old broken thing. But this is brand new. And having write() call override_creds() and do nontrivial things is a fascinating attack surface.
Just imagine what blows up if I abuse fscontext to open a block device on a path that traverses an AFS mount or /proc/.../fd or similar. Or if I splice() from a network filesystem into fscontext.
(Al- can’t we just stop allowing splice() at all on things that don’t use iov_iter?)
Quoted 3 lines
Another thing we might want to look at is to allow a supervisory process to examine the context before permitting the create/reconfigure action to proceed. It might also be possible to do this through the LSM.
Cc Tycho. He’s working on this exact idea using seccomp. And he’d probably much, much prefer if configuration of an fscontext didn’t use a performance-critical syscall like write().
As a straw man, I suggest:
fsconfigure(contextfd, ADD_BLOCKDEV, dfd, path, flags);
fsconfigure(contextfd, ADD_OPTION, 0, “foo=bar”, flags);
Etc.
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 2 lines · Andy Lutomirski
(Al- can’t we just stop allowing
splice()at all on things that don’t useiov_iter?)
We could add a FMODE_SPLICE_READ/WRITE bit, and let people opt in to splice. We probably should have.
But again, that really doesn't change the fundamentals. Using write() for commands is stupid.
It also means that you have to _parse_ all the damn input at that level, which is a mistake too. It easily leads to insane decisions like "you have to use 'write()' calls without buffering", because re-buffering the stream is a f*cking pain.
Just say no. Seriously. Stop this idiotic discussion.
I'm just happy this came up early, because that way I know to look out for it and not merge it.
Linus
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 1 line · Andy Lutomirski
If you make a syscall that attaches a block device to an fscontext, you don’t need any of this. Heck, someone might actually *want* to grab a block device from a different namespace.
Fuck, NO. The whole notion of "block device of filesystem" is fucking garbage. It's up to filesystem driver whether it uses any block devices. For backing store or otherwise. Single or multiple. Moreover, it's up to filesystem driver whether it cares if backing store is a block device, or mtd device, or...
Repeat after me: syscall that attaches a block device to an fscontext makes as much sense as a syscall that attaches a charset name to the same. With a special syscall for attaching a timestamp granularity, and another for selecting GID semantics on subdirectory creation.
Commit vs. write separation is one thing; fuckloads of special syscalls for passing vaguely defined classes of mount options (which device name *is*) is quite different.
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 5 lines · Andy Lutomirski
As a straw man, I suggest:
fsconfigure(contextfd, ADD_BLOCKDEV, dfd, path, flags);
fsconfigure(contextfd, ADD_OPTION, 0, “foo=bar”, flags);
Bollocks. First of all, block device *IS* a fucking option. Always had been. It's not even that it's passed as a separate argument for historical reasons - just look at NFS. That argument is a detached part of options, parsed (yes, *parsed*) by filesystem in question in whatever way it prefers.
Look at the things like e.g. cramfs. That argument is interpreted as pathname of block device. Or that of mtd device. Or the magic string "mtd" followed by mtd number.
What's more, filesystems can and do live on more than one device. Like e.g. btrfs. Or like something journalled with the journal on separate device. So you do *NOT* get away from the need to open stuff while doing mount - not unless you introduce arseloads of ADD_... shite in your scheme. And create a huge centralized pile of code dealing with it. ADD_NFS_IPV4_SERVER_AND_PATH, etc.?
You can't avoid parsing stuff. It's one thing to argue at which *point* you prefer doing that, but it has to be done kernel-side. Format of filesystem options is fundamentally up to filesystem, whichever syscall you use.
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 10 lines · Al Viro
Quoted 7 lines · Andy Lutomirski
As a straw man, I suggest:
fsconfigure(contextfd, ADD_BLOCKDEV, dfd, path, flags);
Quoted 7 lines
Quoted 1 line
fsconfigure(contextfd, ADD_OPTION, 0, “foo=bar”, flags);Bollocks. First of all, block device *IS* a fucking option. Always had been. It's not even that it's passed as a separate argument for historical reasons - just look at NFS. That argument is a detached part of options, parsed (yes, *parsed*) by filesystem in question in whatever way it prefers.
Fine, then generalize it. fsconfigure(context, ADD_FD, “some fs-specific string explaining what’s going on”, fd); The point being that there are tons of cases where the filesystem wants to identify some backing store by some device node, and it seems like we should support something along the lines of a modern *at interface.
If I’m writing a daemon that deals with filesystems, I don’t want an API that looks like do_god_knows_what(context, “filesystem specific string that may contain a path to a device node or a network address”). That API will be a pain to use, since that opaque string may come from some random config file and I have no clue what it does. If I want to pass a device node or other object to a filesystem, I want to pass an fd (so I can use openat, SCM_CREDS, etc), and I want it to be crystal clear that I’m passing some object in. And if I tell a filesystem to access the network, I want it to be entirely clear which network namespace is in use.
I realize that doing this right is tricky when there are lots of legacy filesystems that parse opaque strings. That’s fine. We can convert things slowly.
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 3 lines · Andy Lutomirski
fsconfigure(contextfd, ADD_BLOCKDEV, dfd, path, flags);
fsconfigure(contextfd, ADD_OPTION, 0, “foo=bar”, flags);
That seems okayish. I'm not sure we need the flags, but I do want to allow for binary data in an option. So perhaps something like:
int fsconfig(int fd, unsigned int type, const char *key, const void *val, size_t val_len);
for example:
fd = fsopen("ext4", FSOPEN_CLOEXEC);
fsconfig(fd, fsconfig_blockdev, "dev.data", "/dev/sda1", ...);
fsconfig(fd, fsconfig_blockdev, "dev.journal", "/dev/sda2", ...);
fsconfig(fd, fsconfig_option, "user_xattr", NULL, ...);
fsconfig(fd, fsconfig_option, "errors", "continue", ...);
fsconfig(fd, fsconfig_option, "data", "journal", ...);
fsconfig(fd, fsconfig_security, "selinux.context", "unconfined_u:...");
fsconfig(fd, fsconfig_create, NULL, NULL, 0);
mfd = fsmount(fd, FSMOUNT_CLOEXEC, MS_NOEXEC);or:
fd = fsopen("nfs", FSOPEN_CLOEXEC);
fsconfig(fd, fsconfig_namespace, "user", "<usernsfd>", ...);
fsconfig(fd, fsconfig_namespace, "net", "<netnsfd>", ...);
fsconfig(fd, fsconfig_option, "server", "foo.com", ...);
fsconfig(fd, fsconfig_option, "root", "/bar", ...);
fsconfig(fd, fsconfig_option, "soft", NULL, ...);
fsconfig(fd, fsconfig_option, "retry", "3", ...);
fsconfig(fd, fsconfig_option, "wsize", "4096", ...);
fsconfig(fd, fsconfig_uidmap, "dhowells", "1234", ...);
fsconfig(fd, fsconfig_security, "selinux.context", "unconfined_u:...");
fsconfig(fd, fsconfig_create, NULL, NULL, 0);
mfd = fsmount(fd, FSMOUNT_CLOEXEC, MS_NOEXEC);This does mean that userspace has to work harder, though, but it would simplify the LSM interface internally.
Al Viro <[email protected]>
Quoted 1 line
First of all, block device *IS* a fucking option.
Whilst that is true, I still need to be able to separate it out for unconverted filesystems.
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 7 lines · David Howells
for example:
fd = fsopen("ext4", FSOPEN_CLOEXEC); fsconfig(fd, fsconfig_blockdev, "dev.data", "/dev/sda1", ...); fsconfig(fd, fsconfig_blockdev, "dev.journal", "/dev/sda2", ...);
Ok, that looks good to me. It also avoids the parsing issue with using an interface like "write()", where the expectation is that you can append things etc.
Linus
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Whilst I'm at it, do we want the option of doing the equivalent of mountat()? I.e. offering the option to open all the device files used by a superblock with dfd and AT_* flags in combination with the filename?
David
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 8 lines · David Howells
Whilst I'm at it, do we want the option of doing the equivalent of
mountat()? I.e. offering the option to open all the device files used by a superblock with dfd and AT_* flags in combination with the filename?
Isn’t that more or less what I was suggesting? I suggested dfd and path and I also suggested just an fd and letting the caller open the file itself.
Quoted 1 line
David
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 6 lines · Andy Lutomirski
Quoted 4 lines
Whilst I'm at it, do we want the option of doing the equivalent of
mountat()? I.e. offering the option to open all the device files used by a superblock with dfd and AT_* flags in combination with the filename?Isn't that more or less what I was suggesting?
Yes, you suggested that. I'm asking if we actually need that.
Quoted 1 line
... I also suggested just an fd and letting the caller open the file itself.
I'm not entirely sure, but that might prevent the filesystem from being able to use it, since userspace might then prevent the filesystem getting exclusive holdership.
David
Andy Lutomirski
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 11 lines · David Howells
Quoted 6 lines · Andy Lutomirski
Quoted 4 lines
Whilst I'm at it, do we want the option of doing the equivalent of
mountat()? I.e. offering the option to open all the device files used by a superblock with dfd and AT_* flags in combination with the filename?Isn't that more or less what I was suggesting?
Yes, you suggested that. I'm asking if we actually need that.
Suppose some program in a container chroots itself and then tries to create an fscontext backed by "/path/to/blockdev". The syscall gets intercepted by a container manager. That manager now has a somewhat awkward time of mounting the same fs, although it could use "/proc/PID/root/path/to/blockdev", I suppose. Even that approach has some potentially awkward permission issues. I would defer to the people who actually write software like this, but I can imagine fds being considerably easier to work with.
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 6 lines · Andy Lutomirski
Quoted 4 lines
Whilst I'm at it, do we want the option of doing the equivalent of
mountat()? I.e. offering the option to open all the device files used by a superblock with dfd and AT_* flags in combination with the filename?Isn’t that more or less what I was suggesting? I suggested dfd and path and I also suggested just an fd and letting the caller open the file itself.
Do we need AT_* flags? There are three that we could use:
AT_SYMLINK_NOFOLLOW
AT_NO_AUTOMOUNT
AT_EMPTY_PATH
AT_EMPTY_PATH I can see, but I don't see it as likely that we'd want to use the other two for selecting a source? Note that we can always do:
fsfd = fsopen("ext4");
sfd = open("/dev/", O_PATH);
fsconfig(fsfd, fsconfig_set_path, "journal_path", "sda1", sfd);or:
fsfd = fsopen("ext4");
sfd = open("/dev/sda1", O_PATH);
fsconfig(fsfd, fsconfig_set_path_empty, "journal_path", "", sfd);or:
fsfd = fsopen("ext4");
jfd = open("/dev/sda1", O_RDWR);
fsconfig(fsfd, fsconfig_set_fd, "journal_path", NULL, jfd);assuming the open on the latter doesn't exclude the use by the filesystem.
This way I don't need a second syscall or a 6-arg syscall to handle path specification.
David
Jonathan Corbet
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 9 lines · On Tue, 10 Jul 2018 23:44:09 +0100 David Howells <[email protected]> wrote:
sfd = fsopen("ext4", FSOPEN_CLOEXEC);
write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg
write(sfd, "o noatime");
write(sfd, "o acl");
write(sfd, "o user_attr");
write(sfd, "o iversion");
write(sfd, "o ");
write(sfd, "r /my/container"); // root inside the fs
write(sfd, "x create"); // create the superblockA minor detail but ... the "r" operation mentioned above is not actually implemented in this system call.
jon
David Howells
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 2 lines · Jonathan Corbet
A minor detail but ... the "r" operation mentioned above is not actually implemented in this system call.
Yeah, that's something I'd like to add. NFS4 already does this inside its ->mount() method, so my thought is that we might be able to move this from there to the core.
David
Greg KH
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to David HowellsQuoted 10 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);where flags can be 0 or
FSOPEN_CLOEXEC.For example:
Quoted 9 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC);
write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg
write(sfd, "o noatime");
write(sfd, "o acl");
write(sfd, "o user_attr");
write(sfd, "o iversion");
write(sfd, "o ");
write(sfd, "r /my/container"); // root inside the fs
write(sfd, "x create"); // create the superblockUgh, creating configfs again in a syscall form? I know people love file descriptors, but can't you do this with a configfs entry instead if you really want to do this type of thing from userspace in this type of "style"?
Why reinvent the wheel again?
thanks,
greg k-h
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 21 lines · Greg KH
Quoted 10 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);where flags can be 0 or
FSOPEN_CLOEXEC.For example:
Quoted 9 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg write(sfd, "o noatime"); write(sfd, "o acl"); write(sfd, "o user_attr"); write(sfd, "o iversion"); write(sfd, "o "); write(sfd, "r /my/container"); // root inside the fs write(sfd, "x create"); // create the superblock
Quoted 6 lines
Ugh, creating configfs again in a syscall form? I know people love file descriptors, but can't you do this with a configfs entry instead if you really want to do this type of thing from userspace in this type of "style"?
Why reinvent the wheel again?
The damn thing REALLY, REALLY depends upon the fs type. How would you map it on configfs?
Greg KH
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 27 lines · Al Viro
Quoted 26 lines · Greg KH
Quoted 10 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);where flags can be 0 or
FSOPEN_CLOEXEC.For example:
Quoted 9 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg write(sfd, "o noatime"); write(sfd, "o acl"); write(sfd, "o user_attr"); write(sfd, "o iversion"); write(sfd, "o "); write(sfd, "r /my/container"); // root inside the fs write(sfd, "x create"); // create the superblockUgh, creating configfs again in a syscall form? I know people love file descriptors, but can't you do this with a configfs entry instead if you really want to do this type of thing from userspace in this type of "style"?
Quoted 4 lines
Quoted 1 line
Why reinvent the wheel again?
The damn thing REALLY, REALLY depends upon the fs type. How would you map it on configfs?
/sys/kernel/config/fs/ext4/ would work, right? Each fs "type" would be listed there.
Anyway, the whole "write a bunch of options and then do a 'create'" is exactly the way configfs works. Why not use that?
thanks,
greg k-h
Re: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 33 lines · Greg KH
Quoted 31 lines · Al Viro
Quoted 28 lines · Greg KH
Quoted 11 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);where flags can be 0 or
FSOPEN_CLOEXEC.For example:
Quoted 9 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg write(sfd, "o noatime"); write(sfd, "o acl"); write(sfd, "o user_attr"); write(sfd, "o iversion"); write(sfd, "o "); write(sfd, "r /my/container"); // root inside the fs write(sfd, "x create"); // create the superblockUgh, creating configfs again in a syscall form? I know people love file descriptors, but can't you do this with a configfs entry instead if you really want to do this type of thing from userspace in this type of "style"?
Why reinvent the wheel again?
Quoted 10 lines
Quoted 2 lines
The damn thing REALLY, REALLY depends upon the fs type. How would you map it on configfs?
/sys/kernel/config/fs/ext4/would work, right? Each fs "type" would be listed there.Anyway, the whole "write a bunch of options and then do a 'create'" is exactly the way configfs works. Why not use that?
How do you mount configfs in the first place? And how do you use this in a mount namespace without a private configfs instance or where you don’t want configfs mounted?
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
On Thu, Jul 12, 2018 at 11:30:32AM -0700, Andy Lutomirski wrote:
Andi, Greg - alt.tasteless is over -> that way.
And for fsck sake, fix your MUA. Lines are obscenely long...
Quoted 1 line
How do you mount configfs in the first place? And how do you use this in a mount namespace without a private configfs instance or where you don’t want configfs mounted?
Al Viro
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
Quoted 3 lines · Al Viro
On Thu, Jul 12, 2018 at 11:30:32AM -0700, Andy Lutomirski wrote:
Andi,
Apologies for misspelling - finger macros strike ;-/
Greg KH
maintainerRe: [PATCH 24/32] vfs: syscall: Add fsopen() to prepare for superblock creation [ver #9]
In reply to Andy LutomirskiQuoted 39 lines · Andy Lutomirski
Quoted 39 lines · Greg KH
Quoted 29 lines · Al Viro
Quoted 27 lines · Greg KH
Quoted 11 lines · David Howells
Provide an
fsopen()system call that starts the process of preparing to create a superblock that will then be mountable, using an fd as a context handle.fsopen()is given the name of the filesystem that will be used:int mfd = fsopen(const char *fsname, unsigned int flags);where flags can be 0 or
FSOPEN_CLOEXEC.For example:
Quoted 9 lines
sfd = fsopen("ext4", FSOPEN_CLOEXEC); write(sfd, "s /dev/sdb1"); // note I'm ignoring write's length arg write(sfd, "o noatime"); write(sfd, "o acl"); write(sfd, "o user_attr"); write(sfd, "o iversion"); write(sfd, "o "); write(sfd, "r /my/container"); // root inside the fs write(sfd, "x create"); // create the superblockUgh, creating configfs again in a syscall form? I know people love file descriptors, but can't you do this with a configfs entry instead if you really want to do this type of thing from userspace in this type of "style"?
Quoted 4 lines
Quoted 1 line
Why reinvent the wheel again?
The damn thing REALLY, REALLY depends upon the fs type. How would you map it on configfs?
/sys/kernel/config/fs/ext4/would work, right? Each fs "type" would be listed there.
Quoted 8 lines
Quoted 4 lines
Anyway, the whole "write a bunch of options and then do a 'create'" is exactly the way configfs works. Why not use that?
How do you mount configfs in the first place? And how do you use this in a mount namespace without a private configfs instance or where you don’t want configfs mounted?--
Ok, fair enough, I missed the part where this is going to replace mount(2). Although you could just use mount(2) to mount configfs on a mount point in the initramfs image and then go from there at boot time :)
/me runs away...
David Howells
maintainerPATCH 25/32 vfs: syscall: Add fsmount() to create a mount for a superblock [ver #9]
In reply to David HowellsProvide a system call by which a filesystem opened with fsopen() and configured by a series of writes can be mounted:
int ret = fsmount(int fsfd, unsigned int flags, unsigned int ms_flags);
where fsfd is the file descriptor returned by fsopen(). flags can be 0 or FSMOUNT_CLOEXEC. ms_flags is a bitwise-OR of the following flags:
MS_RDONLY
MS_NOSUID
MS_NODEV
MS_NOEXEC
MS_NOATIME
MS_NODIRATIME
MS_RELATIME
MS_STRICTATIME
MS_UNBINDABLE
MS_PRIVATE
MS_SLAVE
MS_SHARED
In the event that fsmount() fails, it may be possible to get an error message by calling read() on fsfd. If no message is available, ENODATA will be reported.
---
arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 fs/namespace.c | 140 +++++++++++++++++++++++++++++++- include/linux/fs_context.h | 2 include/linux/syscalls.h | 1 include/uapi/linux/fs.h | 2 6 files changed, 143 insertions(+), 4 deletions(-)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -401,3 +401,4 @@ 387 i386 open_tree sys_open_tree __ia32_sys_open_tree 388 i386 move_mount sys_move_mount __ia32_sys_move_mount 389 i386 fsopen sys_fsopen __ia32_sys_fsopen +390 i386 fsmount sys_fsmount __ia32_sys_fsmount
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -346,6 +346,7 @@ 335 common open_tree __x64_sys_open_tree 336 common move_mount __x64_sys_move_mount 337 common fsopen __x64_sys_fsopen +338 common fsmount __x64_sys_fsmount # # x32-specific system call numbers start at 512 to avoid cache impact
fs/namespace.c +136 -4
152 lines not on this page · raw message
include/linux/fs_context.h +2 -0
@@ -115,4 +115,6 @@ extern int vfs_get_super(struct fs_context *fc,int (*fill_super)(struct super_block *sb, struct fs_context *fc)); +extern const struct file_operations fscontext_fs_fops; +#endif /* _LINUX_FS_CONTEXT_H */
include/linux/syscalls.h +1 -0
@@ -905,6 +905,7 @@ asmlinkage long sys_move_mount(int from_dfd, const char __user *from_path, int to_dfd, const char __user *to_path, unsigned int ms_flags);asmlinkage long sys_fsopen (const char __user *fs_name,unsigned int flags); +asmlinkage long sys_fsmount (int fs_fd,unsigned int flags,unsigned int ms_flags);/* * Architecture-specific system calls
include/uapi/linux/fs.h +2 -0
@@ -349,4 +349,6 @@ typedef int __bitwise __kernel_rwf_t;*/ #define FSOPEN_CLOEXEC 0x00000001 +#define FSMOUNT_CLOEXEC 0x00000001 +#endif /* _UAPI_LINUX_FS_H */
David Howells
maintainerPATCH 26/32 vfs: syscall: Add fspick() to select a superblock for reconfiguration [ver #9]
In reply to David HowellsProvide an fspick() system call that can be used to pick an existing mountpoint into an fs_context which can thereafter be used to reconfigure a superblock (equivalent of the superblock side of -o remount).
This looks like:
int fd = fspick(AT_FDCWD, "/mnt", FSPICK_CLOEXEC | FSPICK_NO_AUTOMOUNT); write(fd, "o intr"); write(fd, "o noac"); write(fd, "x reconfigure");
At the point of fspick being called, the file descriptor referring to the filesystem context is in exactly the same state as the one that was created by fsopen() after fsmount() has been successfully called.
---
arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + fs/fsopen.c | 53 ++++++++++++++++++++++++++++++++ include/linux/syscalls.h | 1 + include/uapi/linux/fs.h | 5 +++ 5 files changed, 61 insertions(+)
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -402,3 +402,4 @@ 388 i386 move_mount sys_move_mount __ia32_sys_move_mount 389 i386 fsopen sys_fsopen __ia32_sys_fsopen 390 i386 fsmount sys_fsmount __ia32_sys_fsmount +391 i386 fspick sys_fspick __ia32_sys_fspick
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -347,6 +347,7 @@ 336 common move_mount __x64_sys_move_mount 337 common fsopen __x64_sys_fsopen 338 common fsmount __x64_sys_fsmount +339 common fspick __x64_sys_fspick # # x32-specific system call numbers start at 512 to avoid cache impact
fs/fsopen.c +53 -0
62 lines not on this page · raw message
include/linux/syscalls.h +1 -0
@@ -906,6 +906,7 @@ asmlinkage long sys_move_mount(int from_dfd, const char __user *from_path, unsigned int ms_flags);asmlinkage long sys_fsopen (const char __user *fs_name,unsigned int flags);asmlinkage long sys_fsmount (int fs_fd,unsigned int flags,unsigned int ms_flags); +asmlinkage long sys_fspick (int dfd,const char __user *path,unsigned int flags);/* * Architecture-specific system calls
include/uapi/linux/fs.h +5 -0
@@ -351,4 +351,9 @@ typedef int __bitwise __kernel_rwf_t;#define FSMOUNT_CLOEXEC 0x00000001 +#define FSPICK_CLOEXEC 0x00000001 +#define FSPICK_SYMLINK_NOFOLLOW 0x00000002 +#define FSPICK_NO_AUTOMOUNT 0x00000004 +#define FSPICK_EMPTY_PATH 0x00000008 +#endif /* _UAPI_LINUX_FS_H */
David Howells
maintainerPATCH 27/32 vfs: Implement logging through fs_context [ver #9]
In reply to David HowellsImplement the ability for filesystems to log error, warning and informational messages through the fs_context. These can be extracted by userspace by reading from an fd created by fsopen().
Error messages are prefixed with "e ", warnings with "w " and informational messages with "i ".
Inside the kernel, formatted messages are malloc'd but unformatted messages are not copied if they're either in the core .rodata section or in the .rodata section of the filesystem module pinned by fs_context::fs_type. The messages are only good till the fs_type is released.
Note that the logging object is shared between duplicated fs_context structures. This is so that such as NFS which do a mount within a mount can get at least some of the errors from the inner mount.
Five logging functions are provided for this:
(1) void logfc(struct fs_context *fc, const char *fmt, ...);
This logs a message into the context. If the buffer is full, the earliest message is discarded.
(2) void errorf(fc, fmt, ...);
This wraps logfc() to log an error.
(3) void invalf(fc, fmt, ...);
This wraps errorf() and returns -EINVAL for convenience.
(4) void warnf(fc, fmt, ...);
This wraps logfc() to log a warning.
(5) void infof(fc, fmt, ...);
This wraps logfc() to log an informational message.
---
fs/fs_context.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ fs/fsopen.c | 73 +++++++++++++++++++++++++++++++++++ include/linux/fs_context.h | 58 ++++++++++++++++++++++++++++ include/linux/module.h | 6 +++ 4 files changed, 229 insertions(+)
fs/fs_context.c +92 -0
@@ -11,6 +11,7 @@*/ #define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/module.h> #include <linux/fs_context.h> #include <linux/fs.h> #include <linux/mount.h>
@@ -23,6 +24,7 @@#include <linux/pid_namespace.h> #include <linux/user_namespace.h> #include <net/net_namespace.h> +#include <asm/sections.h> #include "mount.h" enum legacy_fs_param {
@@ -347,6 +349,8 @@ struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc)get_net (fc->net_ns);get_user_ns (fc->user_ns);get_cred (fc->cred); +if (fc->log) +refcount_inc (&fc->log->usage);/* Can't call put until we've called ->dup */ ret = fc->ops->dup (fc, src_fc);
@@ -364,6 +368,93 @@ struct fs_context *vfs_dup_fs_context(struct fs_context *src_fc) }EXPORT_SYMBOL (vfs_dup_fs_context); +/** +* logfc - Log a message to a filesystem context +* @fc: The filesystem context to log to. +* @fmt: The format of the buffer. +*/ +void logfc (struct fs_context *fc,const char *fmt, ...) +{ +static const char store_failure[] ="OOM: Can't store error string" ; +struct fc_log *log = fc->log; +unsigned int logsize =ARRAY_SIZE (log->buffer); +const char *p; +va_list va; +char *q; +u8 freeable, index; + +if (!log) +return ; + +va_start (va, fmt); +if (!strchr (fmt,'%' )) { + p = fmt; + goto unformatted_string; + } +if (strcmp (fmt,"%s" ) ==0 ) { + p = va_arg(va, const char *); + goto unformatted_string; + } + + q =kvasprintf (GFP_KERNEL , fmt, va); +copied_string: +if (!q) + goto store_failure; + freeable =1 ; + goto store_string; + +unformatted_string: +if ((unsigned long )p >= (unsigned long )__start_rodata && + (unsigned long )p < (unsigned long )__end_rodata) + goto const_string; +if (within_module_core ((unsigned long )p, log->owner)) + goto const_string; + q =kstrdup (p,GFP_KERNEL ); + goto copied_string; + +store_failure: + p = store_failure; +const_string: + q = (char *)p; + freeable =0 ; +store_string: + index = log->head & (logsize -1 ); +BUILD_BUG_ON (sizeof (log->head) !=sizeof (u8) || +sizeof (log->tail) !=sizeof (u8)); +if ((u8)(log->head - log->tail) == logsize) { +/* The buffer is full, discard the oldest message */ +if (log->need_free & (1 << index)) +kfree (log->buffer[index]); + log->tail++; + } + + log->buffer[index] = q; + log->need_free &= ~(1 << index); + log->need_free |= freeable << index; + log->head++; +va_end (va); +} +EXPORT_SYMBOL (logfc); + +/* +* Free a logging structure. +*/ +static void put_fc_log (struct fs_context *fc) +{ +struct fc_log *log = fc->log; +int i; + +if (log) { +if (refcount_dec_and_test (&log->usage)) { + fc->log =NULL ; +for (i =0 ; i <=7 ; i++) +if (log->need_free & (1 << i)) +kfree (log->buffer[i]); +kfree (log); + } + } +} +/** * put_fs_context - Dispose of a superblock configuration context. * @fc: The context to dispose of.
@@ -389,6 +480,7 @@ void put_fs_context(struct fs_context *fc)if (fc->cred)put_cred (fc->cred);kfree (fc->subtype); +put_fc_log (fc);put_filesystem (fc->fs_type);kfree (fc->source);kfree (fc);
fs/fsopen.c +73 -0
113 lines not on this page · raw message
include/linux/fs_context.h +58 -0
74 lines not on this page · raw message
include/linux/module.h +6 -0
@@ -682,6 +682,12 @@ static inline bool is_module_text_address(unsigned long addr)return false; } +static inline bool within_module_core (unsigned long addr, +const struct module *mod) +{ +return false; +} +/* Get/put a kernel symbol (calls should be symmetric) */ #define symbol_get (x) ({ extern typeof(x) x __attribute__((weak)); &(x); })#define symbol_put (x) do { } while (0)
David Howells
maintainerPATCH 28/32 vfs: Add some logging to the core users of the fs_context log [ver #9]
In reply to David HowellsAdd some logging to the core users of the fs_context log so that information can be extracted from them as to the reason for failure.
---
fs/super.c | 4 +++- kernel/cgroup/cgroup-v1.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-)
fs/super.c +3 -1
@@ -1735,8 +1735,10 @@ int vfs_get_tree(struct fs_context *fc)struct super_block *sb;int ret; -if (fc->fs_type->fs_flags &FS_REQUIRES_DEV && !fc->source) +if (fc->fs_type->fs_flags &FS_REQUIRES_DEV && !fc->source) { +errorf (fc,"Filesystem requires source device" );return -ENOENT ; + }if (fc->root)return -EBUSY ;
kernel/cgroup/cgroup-v1.c +1 -1
@@ -16,7 +16,7 @@#include <trace/events/cgroup.h> -#define cg_invalf (fc, fmt, ...) ({ pr_err(fmt, ## __VA_ARGS__); -EINVAL; }) +#define cg_invalf (fc, fmt, ...) invalf(fc, fmt, ## __VA_ARGS__)/* * pidlists linger the following amount before being destroyed. The goal
David Howells
maintainerPATCH 29/32 afs: Add fs_context support [ver #9]
In reply to David HowellsAdd fs_context support to the AFS filesystem, converting the parameter parsing to store options there.
This will form the basis for namespace propagation over mountpoints within the AFS model, thereby allowing AFS to be used in containers more easily.
---
fs/afs/internal.h | 8 + fs/afs/super.c | 424 ++++++++++++++++++++++++++++++----------------------- fs/afs/volume.c | 4 - 3 files changed, 247 insertions(+), 189 deletions(-)
fs/afs/internal.h +4 -4
@@ -34,15 +34,15 @@struct pagevec ;struct afs_call ; -struct afs_mount_params { +struct afs_fs_context {bool rwpath;/* T if the parent should be considered R/W */ bool force;/* T to force cell type */ bool autocell;/* T if set auto mount operation */ bool dyn_root;/* T if dynamic root */ +bool no_cell;/* T if the source is "none" (for dynroot) */ afs_voltype_t type;/* type of volume requested */ -int volnamesz;/* size of volume name */ +unsigned int volnamesz;/* size of volume name */ const char *volname;/* name of volume to mount */ -struct net *net_ns;/* Network namespace in effect */ struct afs_net *net;/* the AFS net namespace stuff */ struct afs_cell *cell;/* cell in which to find volume */ struct afs_volume *volume;/* volume record */
@@ -1055,7 +1055,7 @@ static inline struct afs_volume *__afs_get_volume(struct afs_volume *volume)return volume; } -extern struct afs_volume *afs_create_volume (struct afs_mount_params *); +extern struct afs_volume *afs_create_volume (struct afs_fs_context *);extern void afs_activate_volume (struct afs_volume *);extern void afs_deactivate_volume (struct afs_volume *);extern void afs_put_volume (struct afs_cell *,struct afs_volume *);
fs/afs/super.c +241 -183
598 lines not on this page · raw message
fs/afs/volume.c +2 -2
@@ -21,7 +21,7 @@ static const char *const afs_voltypes[] = { "R/W", "R/O", "BAK" };/* * Allocate a volume record and load it up from a vldb record. */ -static struct afs_volume *afs_alloc_volume (struct afs_mount_params *params, +static struct afs_volume *afs_alloc_volume (struct afs_fs_context *params,struct afs_vldb_entry *vldb,unsigned long type_mask) {
@@ -149,7 +149,7 @@ static struct afs_vldb_entry *afs_vl_lookup_vldb(struct afs_cell *cell,* - Rule 3: If parent volume is R/W, then only mount R/W volume unless * explicitly told otherwise */ -struct afs_volume *afs_create_volume (struct afs_mount_params *params) +struct afs_volume *afs_create_volume (struct afs_fs_context *params) {struct afs_vldb_entry *vldb;struct afs_volume *volume;
David Howells
maintainerPATCH 30/32 afs: Use fs_context to pass parameters over automount [ver #9]
In reply to David HowellsAlter the AFS automounting code to create and modify an fs_context struct when parameterising a new mount triggered by an AFS mountpoint rather than constructing device name and option strings.
Also remove the cell=, vol= and rwpath options as they are then redundant. The reason they existed is because the 'device name' may be derived literally from a mountpoint object in the filesystem, so default cell and parent-type information needed to be passed in by some other method from the automount routines. The vol= option didn't end up being used.
---
fs/afs/internal.h | 1 fs/afs/mntpt.c | 148 +++++++++++++++++++++++++++-------------------------- fs/afs/super.c | 43 +-------------- 3 files changed, 79 insertions(+), 113 deletions(-)
fs/afs/internal.h +0 -1
@@ -35,7 +35,6 @@ struct pagevec;struct afs_call ;struct afs_fs_context { -bool rwpath;/* T if the parent should be considered R/W */ bool force;/* T to force cell type */ bool autocell;/* T if set auto mount operation */ bool dyn_root;/* T if dynamic root */
fs/afs/mntpt.c +75 -73
188 lines not on this page · raw message
fs/afs/super.c +4 -39
85 lines not on this page · raw message
David Howells
maintainerPATCH 31/32 vfs: syscall: Add fsinfo() to query filesystem information [ver #9]
In reply to David HowellsAdd a system call to allow filesystem information to be queried. A request value can be given to indicate the desired attribute. Support is provided for enumerating multi-value attributes.
===============
NEW SYSTEM CALL
===============
The new system call looks like:
int ret = fsinfo(int dfd,
const char *filename, const struct fsinfo_params *params, void *buffer,
size_t buf_size);
The params parameter optionally points to a block of parameters:
struct fsinfo_params {
__u32 at_flags;
__u32 request;
__u32 Nth;
__u32 Mth;
__u32 __reserved[6];
};If params is NULL, it is assumed params->request should be fsinfo_attr_statfs, params->Nth should be 0, params->Mth should be 0 and params->at_flags should be 0.
If params is given, all of params->__reserved[] must be 0.
dfd, filename and params->at_flags indicate the file to query. There is no equivalent of lstat() as that can be emulated with fsinfo() by setting AT_SYMLINK_NOFOLLOW in params->at_flags. There is also no equivalent of fstat() as that can be emulated by passing a NULL filename to fsinfo() with the fd of interest in dfd. AT_NO_AUTOMOUNT can also be used to an allow automount point to be queried without triggering it.
params->request indicates the attribute/attributes to be queried. This can be one of:
fsinfo_attr_statfs - statfs-style info
fsinfo_attr_fsinfo - Information about fsinfo()
fsinfo_attr_ids - Filesystem IDs
fsinfo_attr_limits - Filesystem limits
fsinfo_attr_supports - What's supported in statx(), IOC flags
fsinfo_attr_capabilities - Filesystem capabilities
fsinfo_attr_timestamp_info - Inode timestamp info
fsinfo_attr_volume_id - Volume ID (string)
fsinfo_attr_volume_uuid - Volume UUID
fsinfo_attr_volume_name - Volume name (string)
fsinfo_attr_cell_name - Cell name (string)
fsinfo_attr_domain_name - Domain name (string)
fsinfo_attr_realm_name - Realm name (string)
fsinfo_attr_server_name - Name of the Nth server (string)
fsinfo_attr_server_address - Mth address of the Nth server
fsinfo_attr_parameter - Nth mount parameter (string)
fsinfo_attr_source - Nth mount source name (string)
fsinfo_attr_name_encoding - Filename encoding (string)
fsinfo_attr_name_codepage - Filename codepage (string)
fsinfo_attr_io_size - Optimal I/O sizes
Some attributes (such as the servers backing a network filesystem) can have multiple values. These can be enumerated by setting params->Nth and params->Mth to 0, 1, ... until ENODATA is returned.
buffer and buf_size point to the reply buffer. The buffer is filled up to the specified size, even if this means truncating the reply. The full size of the reply is returned. In future versions, this will allow extra fields to be tacked on to the end of the reply, but anyone not expecting them will only get the subset they're expecting. If either buffer of buf_size are 0, no copy will take place and the data size will be returned.
At the moment, this will only work on x86_64 and i386 as it requires the system call to be wired up.
---
arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 fs/statfs.c | 470 ++++++++++++++++++++++++++++ include/linux/fs.h | 4 include/linux/fsinfo.h | 40 ++ include/linux/syscalls.h | 4 include/uapi/linux/fsinfo.h | 237 ++++++++++++++ samples/statx/Makefile | 5 samples/statx/test-fsinfo.c | 539 ++++++++++++++++++++++++++++++++ 9 files changed, 1300 insertions(+), 1 deletion(-) create mode 100644 include/linux/fsinfo.h create mode 100644 include/uapi/linux/fsinfo.h create mode 100644 samples/statx/test-fsinfo.c
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -403,3 +403,4 @@ 389 i386 fsopen sys_fsopen __ia32_sys_fsopen 390 i386 fsmount sys_fsmount __ia32_sys_fsmount 391 i386 fspick sys_fspick __ia32_sys_fspick +392 i386 fsinfo sys_fsinfo __ia32_sys_fsinfo
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -348,6 +348,7 @@ 337 common fsopen __x64_sys_fsopen 338 common fsmount __x64_sys_fsmount 339 common fspick __x64_sys_fspick +340 common fsinfo __x64_sys_fsinfo # # x32-specific system call numbers start at 512 to avoid cache impact
fs/statfs.c +470 -0
479 lines not on this page · raw message
include/linux/fs.h +4 -0
@@ -62,6 +62,8 @@ struct iov_iter;struct fscrypt_info ;struct fscrypt_operations ;struct fs_context ; +struct fsinfo_kparams ; +enum fsinfo_attribute ;extern void __init inode_init (void );extern void __init inode_init_early (void );
@@ -1847,6 +1849,7 @@ struct super_operations {int (*thaw_super) (struct super_block *);int (*unfreeze_fs) (struct super_block *);int (*statfs) (struct dentry *,struct kstatfs *); +int (*get_fsinfo) (struct dentry *,struct fsinfo_kparams *);int (*remount_fs) (struct super_block *,int *,char *,size_t );int (*reconfigure) (struct super_block *,struct fs_context *);void (*umount_begin) (struct super_block *);
@@ -2223,6 +2226,7 @@ extern int iterate_mounts(int (*)(struct vfsmount *, void *), void *,extern int vfs_statfs (const struct path *,struct kstatfs *);extern int user_statfs (const char __user *,struct kstatfs *);extern int fd_statfs (int ,struct kstatfs *); +extern int vfs_fsinfo (const struct path *,struct fsinfo_kparams *);extern int freeze_super (struct super_block *super);extern int thaw_super (struct super_block *super);extern bool our_mnt (struct vfsmount *mnt);
include/linux/fsinfo.h new file +40 -0
@@ -0,0 +1,40 @@ +/* Filesystem information query +* +* Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#ifndef _LINUX_FSINFO_H +#define _LINUX_FSINFO_H + +#include <uapi/linux/fsinfo.h> + +struct fsinfo_kparams { +__u32 at_flags;/* AT_SYMLINK_NOFOLLOW and similar */ +enum fsinfo_attribute request;/* What is being asking for */ +__u32 Nth;/* Instance of it (some may have multiple) */ +__u32 Mth;/* Subinstance */ +void *buffer;/* Where to place the reply */ +size_t buf_size;/* Size of the buffer */ +}; + +extern int generic_fsinfo (struct dentry *,struct fsinfo_kparams *); + +static inline void fsinfo_set_cap (struct fsinfo_capabilities *c, +enum fsinfo_capability cap) +{ + c->capabilities[cap /8 ] |=1 << (cap %8 ); +} + +static inline void fsinfo_clear_cap (struct fsinfo_capabilities *c, +enum fsinfo_capability cap) +{ + c->capabilities[cap /8 ] &= ~(1 << (cap %8 )); +} + +#endif /* _LINUX_FSINFO_H */
include/linux/syscalls.h +4 -0
@@ -49,6 +49,7 @@ struct stat64;struct statfs ;struct statfs64 ;struct statx ; +struct fsinfo_params ;struct __sysctl_args ;struct sysinfo ;struct timespec ;
@@ -907,6 +908,9 @@ asmlinkage long sys_move_mount(int from_dfd, const char __user *from_path,asmlinkage long sys_fsopen (const char __user *fs_name,unsigned int flags);asmlinkage long sys_fsmount (int fs_fd,unsigned int flags,unsigned int ms_flags);asmlinkage long sys_fspick (int dfd,const char __user *path,unsigned int flags); +asmlinkage long sys_fsinfo (int dfd,const char __user *path, +struct fsinfo_params __user *params, +void __user *buffer,size_t buf_size);/* * Architecture-specific system calls
include/uapi/linux/fsinfo.h new file +237 -0
237 lines not on this page · raw message
samples/statx/Makefile +4 -1
@@ -1,7 +1,10 @@ # List of programs to build -hostprogs-$(CONFIG_SAMPLE_STATX) := test-statx +hostprogs-$(CONFIG_SAMPLE_STATX) := test-statx test-fsinfo # Tell kbuild to always build the programs always := $(hostprogs-y) HOSTCFLAGS_test-statx.o += -I$(objtree)/usr/include + +HOSTCFLAGS_test-fsinfo.o += -I$(objtree)/usr/include +HOSTLOADLIBES_test-fsinfo += -lm
samples/statx/test-fsinfo.c new file +539 -0
539 lines not on this page · raw message