linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: David Howells <dhowells@redhat.com>
Cc: viro@zeniv.linux.org.uk, linux-api@vger.kernel.org,
	torvalds@linux-foundation.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 30/38] vfs: syscall: Add fsmount() to create a mount for a superblock [ver #10]
Date: Fri, 27 Jul 2018 12:27:23 -0700	[thread overview]
Message-ID: <D09916DC-DA22-48AA-A62B-F874BB3C15BC@amacapital.net> (raw)
In-Reply-To: <153271288242.9458.18050138471208178879.stgit@warthog.procyon.org.uk>



> On Jul 27, 2018, at 10:34 AM, David Howells <dhowells@redhat.com> wrote:
> 
> Provide 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:

I have a potentially silly objection. For the old timers, “mount” means to stick a reel of tape or some similar object onto a reader, which seems to imply that “mount” means to start up the filesystem. For younguns, this meaning is probably lost, and the more obvious meaning is to “mount” it into some location in the VFS hierarchy a la vfsmount. The patch description doesn’t disambiguate it, and obviously people used to mount(2)/mount(8) are just likely to be confused.

At the very least, your description should make it absolutely clear what you mean. Even better IMO would be to drop the use of the word “mount” entirely and maybe rename the syscall.

From a very brief reading, I think you are giving it the meaning that would be implied by fsstart(2).

> 
>    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.
> 
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: linux-api@vger.kernel.org
> ---
> 
> arch/x86/entry/syscalls/syscall_32.tbl |    1 
> arch/x86/entry/syscalls/syscall_64.tbl |    1 
> fs/namespace.c                         |  140 +++++++++++++++++++++++++++++++-
> include/linux/syscalls.h               |    1 
> include/uapi/linux/fs.h                |    2 
> 5 files changed, 141 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
> index f9970310c126..c78b68256f8a 100644
> --- a/arch/x86/entry/syscalls/syscall_32.tbl
> +++ b/arch/x86/entry/syscalls/syscall_32.tbl
> @@ -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    fsconfig        sys_fsconfig            __ia32_sys_fsconfig
> +391    i386    fsmount            sys_fsmount            __ia32_sys_fsmount
> diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
> index 4185d36e03bb..d44ead5d4368 100644
> --- a/arch/x86/entry/syscalls/syscall_64.tbl
> +++ b/arch/x86/entry/syscalls/syscall_64.tbl
> @@ -347,6 +347,7 @@
> 336    common    move_mount        __x64_sys_move_mount
> 337    common    fsopen            __x64_sys_fsopen
> 338    common    fsconfig        __x64_sys_fsconfig
> +339    common    fsmount            __x64_sys_fsmount
> 
> #
> # x32-specific system call numbers start at 512 to avoid cache impact
> diff --git a/fs/namespace.c b/fs/namespace.c
> index ea07066a2731..b1661b90256d 100644
> --- a/fs/namespace.c
> +++ b/fs/namespace.c
> @@ -2503,7 +2503,7 @@ static int do_move_mount(struct path *old_path, struct path *new_path)
> 
>    attached = mnt_has_parent(old);
>    /*
> -     * We need to allow open_tree(OPEN_TREE_CLONE) followed by
> +     * We need to allow open_tree(OPEN_TREE_CLONE) or fsmount() followed by
>     * move_mount(), but mustn't allow "/" to be moved.
>     */
>    if (old->mnt_ns && !attached)
> @@ -3348,9 +3348,141 @@ struct vfsmount *kern_mount(struct file_system_type *type)
> EXPORT_SYMBOL_GPL(kern_mount);
> 
> /*
> - * 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.
> + * Create a kernel mount representation for a new, prepared superblock
> + * (specified by fs_fd) and attach to an open_tree-like file descriptor.
> + */
> +SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags, unsigned int, ms_flags)
> +{
> +    struct fs_context *fc;
> +    struct file *file;
> +    struct path newmount;
> +    struct fd f;
> +    unsigned int mnt_flags = 0;
> +    long ret;
> +
> +    if (!may_mount())
> +        return -EPERM;
> +
> +    if ((flags & ~(FSMOUNT_CLOEXEC)) != 0)
> +        return -EINVAL;
> +
> +    if (ms_flags & ~(MS_RDONLY | MS_NOSUID | MS_NODEV | MS_NOEXEC |
> +             MS_NOATIME | MS_NODIRATIME | MS_RELATIME |
> +             MS_STRICTATIME))
> +        return -EINVAL;
> +
> +    if (ms_flags & MS_RDONLY)
> +        mnt_flags |= MNT_READONLY;
> +    if (ms_flags & MS_NOSUID)
> +        mnt_flags |= MNT_NOSUID;
> +    if (ms_flags & MS_NODEV)
> +        mnt_flags |= MNT_NODEV;
> +    if (ms_flags & MS_NOEXEC)
> +        mnt_flags |= MNT_NOEXEC;
> +    if (ms_flags & MS_NODIRATIME)
> +        mnt_flags |= MNT_NODIRATIME;
> +
> +    if (ms_flags & MS_STRICTATIME) {
> +        if (ms_flags & MS_NOATIME)
> +            return -EINVAL;
> +    } else if (ms_flags & MS_NOATIME) {
> +        mnt_flags |= MNT_NOATIME;
> +    } else {
> +        mnt_flags |= MNT_RELATIME;
> +    }
> +
> +    f = fdget(fs_fd);
> +    if (!f.file)
> +        return -EBADF;
> +
> +    ret = -EINVAL;
> +    if (f.file->f_op != &fscontext_fops)
> +        goto err_fsfd;
> +
> +    fc = f.file->private_data;
> +
> +    /* There must be a valid superblock or we can't mount it */
> +    ret = -EINVAL;
> +    if (!fc->root)
> +        goto err_fsfd;
> +
> +    ret = -EPERM;
> +    if (mount_too_revealing(fc->root->d_sb, &mnt_flags)) {
> +        pr_warn("VFS: Mount too revealing\n");
> +        goto err_fsfd;
> +    }
> +
> +    ret = mutex_lock_interruptible(&fc->uapi_mutex);
> +    if (ret < 0)
> +        goto err_fsfd;
> +
> +    ret = -EBUSY;
> +    if (fc->phase != FS_CONTEXT_AWAITING_MOUNT)
> +        goto err_unlock;
> +
> +    ret = -EPERM;
> +    if ((fc->sb_flags & SB_MANDLOCK) && !may_mandlock())
> +        goto err_unlock;
> +
> +    newmount.mnt = vfs_create_mount(fc, mnt_flags);
> +    if (IS_ERR(newmount.mnt)) {
> +        ret = PTR_ERR(newmount.mnt);
> +        goto err_unlock;
> +    }
> +    newmount.dentry = dget(fc->root);
> +
> +    /* We've done the mount bit - now move the file context into more or
> +     * less the same state as if we'd done an fspick().  We don't want to
> +     * do any memory allocation or anything like that at this point as we
> +     * don't want to have to handle any errors incurred.
> +     */
> +    if (fc->ops && fc->ops->free)
> +        fc->ops->free(fc);
> +    fc->fs_private = NULL;
> +    fc->s_fs_info = NULL;
> +    fc->sb_flags = 0;
> +    fc->sloppy = false;
> +    fc->silent = false;
> +    security_fs_context_free(fc);
> +    fc->security = NULL;
> +    kfree(fc->subtype);
> +    fc->subtype = NULL;
> +    kfree(fc->source);
> +    fc->source = NULL;
> +
> +    fc->purpose = FS_CONTEXT_FOR_RECONFIGURE;
> +    fc->phase = FS_CONTEXT_AWAITING_RECONF;
> +
> +    /* Attach to an apparent O_PATH fd with a note that we need to unmount
> +     * it, not just simply put it.
> +     */
> +    file = dentry_open(&newmount, O_PATH, fc->cred);
> +    if (IS_ERR(file)) {
> +        ret = PTR_ERR(file);
> +        goto err_path;
> +    }
> +    file->f_mode |= FMODE_NEED_UNMOUNT;
> +
> +    ret = get_unused_fd_flags((flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0);
> +    if (ret >= 0)
> +        fd_install(ret, file);
> +    else
> +        fput(file);
> +
> +err_path:
> +    path_put(&newmount);
> +err_unlock:
> +    mutex_unlock(&fc->uapi_mutex);
> +err_fsfd:
> +    fdput(f);
> +    return ret;
> +}
> +
> +/*
> + * Move a mount from one place to another.  In combination with
> + * fsopen()/fsmount() this is used to install a new mount and 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.
>  */
> diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
> index 9628d14a7ede..65db661cc2da 100644
> --- a/include/linux/syscalls.h
> +++ b/include/linux/syscalls.h
> @@ -907,6 +907,7 @@ 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_fsconfig(int fs_fd, unsigned int cmd, const char __user *key,
>                 const void __user *value, int aux);
> +asmlinkage long sys_fsmount(int fs_fd, unsigned int flags, unsigned int ms_flags);
> 
> /*
>  * Architecture-specific system calls
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index 7c9e165e8689..297362908d01 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -349,6 +349,8 @@ typedef int __bitwise __kernel_rwf_t;
>  */
> #define FSOPEN_CLOEXEC        0x00000001
> 
> +#define FSMOUNT_CLOEXEC        0x00000001
> +
> /*
>  * The type of fsconfig() call made.
>  */
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-api" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2018-07-27 20:50 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-27 17:31 [PATCH 00/38] VFS: Introduce filesystem context [ver #10] David Howells
2018-07-27 17:31 ` [PATCH 01/38] vfs: syscall: Add open_tree(2) to reference or clone a mount " David Howells
2018-07-27 17:31 ` [PATCH 02/38] vfs: syscall: Add move_mount(2) to move mounts around " David Howells
2018-07-27 17:31 ` [PATCH 03/38] teach move_mount(2) to work with OPEN_TREE_CLONE " David Howells
2018-07-27 17:31 ` [PATCH 04/38] vfs: Suppress MS_* flag defs within the kernel unless explicitly enabled " David Howells
2018-07-27 17:31 ` [PATCH 05/38] vfs: Introduce the basic header for the new mount API's filesystem context " David Howells
2018-07-27 17:32 ` [PATCH 06/38] vfs: Introduce logging functions " David Howells
2018-07-27 17:32 ` [PATCH 07/38] vfs: Add configuration parser helpers " David Howells
2018-07-27 17:32 ` [PATCH 08/38] vfs: Add LSM hooks for the new mount API " David Howells
2018-07-27 17:32 ` [PATCH 09/38] selinux: Implement the new mount API LSM hooks " David Howells
2018-07-27 17:32 ` [PATCH 10/38] smack: Implement filesystem context security " David Howells
2018-07-27 17:32 ` [PATCH 11/38] apparmor: Implement security hooks for the new mount API " David Howells
2018-07-27 17:32 ` [PATCH 12/38] vfs: Pass key and value into LSM and FS and provide a helper parser " David Howells
2018-07-27 17:32 ` [PATCH 13/38] tomoyo: Implement security hooks for the new mount API " David Howells
2018-07-28  2:29   ` Tetsuo Handa
2018-07-30 10:49   ` David Howells
2018-07-27 17:32 ` [PATCH 14/38] vfs: Separate changing mount flags full remount " David Howells
2018-07-27 17:33 ` [PATCH 15/38] vfs: Implement a filesystem superblock creation/configuration context " David Howells
2018-07-27 17:33 ` [PATCH 16/38] vfs: Remove unused code after filesystem context changes " David Howells
2018-07-27 17:33 ` [PATCH 17/38] procfs: Move proc_fill_super() to fs/proc/root.c " David Howells
2018-07-27 17:33 ` [PATCH 18/38] proc: Add fs_context support to procfs " David Howells
2018-07-27 17:33 ` [PATCH 19/38] ipc: Convert mqueue fs to fs_context " David Howells
2018-07-27 17:33 ` [PATCH 20/38] cpuset: Use " David Howells
2018-07-27 17:33 ` [PATCH 21/38] kernfs, sysfs, cgroup, intel_rdt: Support " David Howells
2018-07-27 17:33 ` [PATCH 22/38] hugetlbfs: Convert to " David Howells
2018-07-27 17:33 ` [PATCH 23/38] vfs: Remove kern_mount_data() " David Howells
2018-07-27 17:34 ` [PATCH 24/38] vfs: Provide documentation for new mount API " David Howells
2018-07-27 17:34 ` [PATCH 25/38] Make anon_inodes unconditional " David Howells
2018-07-27 20:04   ` Randy Dunlap
2018-07-30 10:52   ` David Howells
2018-07-27 17:34 ` [PATCH 26/38] vfs: syscall: Add fsopen() to prepare for superblock creation " David Howells
2018-07-27 17:34 ` [PATCH 27/38] vfs: Implement logging through fs_context " David Howells
2018-07-27 17:34 ` [PATCH 28/38] vfs: Add some logging to the core users of the fs_context log " David Howells
2018-07-27 17:34 ` [PATCH 29/38] vfs: syscall: Add fsconfig() for configuring and managing a context " David Howells
2018-07-27 19:42   ` Andy Lutomirski
2018-07-27 21:51   ` David Howells
2018-07-27 21:57     ` Andy Lutomirski
2018-07-27 22:27     ` David Howells
2018-07-27 22:32   ` Jann Horn
2018-07-29  8:50   ` David Howells
2018-07-29 11:14     ` Jann Horn
2018-07-30 12:32     ` David Howells
2018-07-27 17:34 ` [PATCH 30/38] vfs: syscall: Add fsmount() to create a mount for a superblock " David Howells
2018-07-27 19:27   ` Andy Lutomirski [this message]
2018-07-27 19:43     ` Andy Lutomirski
2018-07-27 22:09     ` David Howells
2018-07-27 22:06   ` David Howells
2018-07-27 17:34 ` [PATCH 31/38] vfs: syscall: Add fspick() to select a superblock for reconfiguration " David Howells
2018-07-27 17:34 ` [PATCH 32/38] afs: Add fs_context support " David Howells
2018-07-27 17:35 ` [PATCH 33/38] afs: Use fs_context to pass parameters over automount " David Howells
2018-07-27 17:35 ` [PATCH 34/38] vfs: syscall: Add fsinfo() to query filesystem information " David Howells
2018-07-27 19:35   ` Andy Lutomirski
2018-07-27 22:12   ` David Howells
2018-07-27 23:14   ` Jann Horn
2018-07-27 23:49   ` David Howells
2018-07-28  0:14     ` Anton Altaparmakov
2018-07-27 23:51   ` David Howells
2018-07-27 23:58     ` Jann Horn
2018-07-28  0:08     ` David Howells
2018-07-30 14:48   ` David Howells
2018-07-31  4:16   ` Al Viro
2018-07-31 12:39   ` David Howells
2018-07-31 13:20   ` David Howells
2018-07-31 23:49   ` Darrick J. Wong
2018-08-01  1:07   ` David Howells
2018-07-27 17:35 ` [PATCH 35/38] afs: Add fsinfo support " David Howells
2018-07-27 17:35 ` [PATCH 36/38] vfs: Add a sample program for the new mount API " David Howells
2018-07-29 11:37   ` Pavel Machek
2018-07-30 12:23   ` David Howells
2018-07-30 14:31     ` Pavel Machek
2018-07-30 18:08       ` Matthew Wilcox
2018-07-30 18:16         ` Pavel Machek
2018-07-30 18:18         ` Linus Torvalds
2018-07-30 18:38           ` Matthew Wilcox
2018-07-30 18:59             ` Linus Torvalds
2018-07-30 19:49               ` Matthew Wilcox
2018-07-30 21:02                 ` Theodore Y. Ts'o
2018-07-30 21:23                   ` Pavel Machek
2018-07-30 23:58                   ` Matthew Wilcox
2018-07-31  0:58                     ` Theodore Y. Ts'o
2018-07-31  9:40                       ` Pavel Machek
2018-07-31 10:11                       ` David Howells
2018-07-31 11:34                         ` Pavel Machek
2018-07-31 12:07                           ` Matthew Wilcox
2018-07-31 12:28                             ` Pavel Machek
2018-07-31 13:33                               ` Al Viro
2018-07-31 13:00                             ` David Howells
2018-07-31 19:39                               ` Pavel Machek
2018-07-31 21:00                               ` David Howells
2018-07-31 21:21                                 ` Linus Torvalds
2018-07-31 21:38                                 ` David Howells
2018-07-30 20:47               ` Pavel Machek
2018-07-30 15:33     ` David Howells
2018-07-30 17:30       ` Pavel Machek
2018-07-30 17:54         ` Linus Torvalds
2018-07-30 18:16           ` Pavel Machek
2018-07-27 17:35 ` [PATCH 37/38] vfs: Allow fsinfo() to query what's in an fs_context " David Howells
2018-07-27 17:35 ` [PATCH 38/38] vfs: Allow fsinfo() to be used to query an fs parameter description " David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D09916DC-DA22-48AA-A62B-F874BB3C15BC@amacapital.net \
    --to=luto@amacapital.net \
    --cc=dhowells@redhat.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).