Received: by 10.192.165.156 with SMTP id m28csp728481imm; Thu, 19 Apr 2018 06:39:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx49JEPFQAmZKSvbvdmXIzU7qaTIwhMz3MHWvaQTFPu0/E0TqRpB6LbJv3Xo0SQKYMfN/IzOI X-Received: by 10.99.178.83 with SMTP id t19mr5354455pgo.212.1524145179658; Thu, 19 Apr 2018 06:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524145179; cv=none; d=google.com; s=arc-20160816; b=Z3tSZKmwf5Ch/hVSGbpAVYhiKmWTdgT7xNpKlj5ZHchmJWPzrRvfQTjnyRZJKOE91h VjOkA0JogI3+k0nZe710YLLrJjjUDS+ZjoL20gXIVjzB+OAaCZfmVh8FFYYBi4pg5QEx CKm6dsIOCwrIrR4NXgrjc6NXr3gtLbwp/QfPPH+J/b8bpCI4D+mOBbKTXvNo6N356GLY TlqLaEj6AbiAAdErwGtXsrgQA2iHyWL8pxgsH3Jjms1/YbMYjMl6V/U6fx6X+p2mk+AP 6F+tn4pUvLu/txC87dwHtCwJKOmkr+iNG3Wd/S2wAT8tSZ+oSJzgL0BTG/gOhaqtjab6 TNKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization:arc-authentication-results; bh=IEEs8l+8aX9BpnMYYruorh9tcIQDzFp/6lesycBB12M=; b=xpcwpzxcxhzTw0QaqbihcYD0WLVbdlu+R67D8bQ10KbO5kbBHn2mglrK37ZnaWc9eb Sh1MEif6EqDPh+0X0NbPzh7HsqvG70+kIVwgtQps8jwPTim5MTHF5/to1O+EfJFrq1o4 op2qWSM7JSDwTJcWAmQrE2ngLVs1r21jCRv4YEEwSbNd+H6bKtygpZ9f9fYexycO6yoE HkaNSfPjWjLFWPQAH99Me5TYvCqm2+JbRSeJseH4VCqsTs3xQpmvKG5A2av74FZijMmp q+2BQmyw/CWtv2OB8RsHKyuY6cErEr3PHKj53Q3CwxSJXL78aw205xx+D79AUeYozilU UkjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u81si1142713pfg.289.2018.04.19.06.39.25; Thu, 19 Apr 2018 06:39:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753470AbeDSNd3 (ORCPT + 99 others); Thu, 19 Apr 2018 09:33:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42964 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752666AbeDSNdY (ORCPT ); Thu, 19 Apr 2018 09:33:24 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45F0B42B1B79; Thu, 19 Apr 2018 13:33:23 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-60.rdu2.redhat.com [10.10.121.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D8812166BC7; Thu, 19 Apr 2018 13:33:22 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 19/24] VFS: Implement fsmount() to effect a pre-configured mount [ver #7] From: David Howells To: viro@zeniv.linux.org.uk Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-afs@lists.infradead.org Date: Thu, 19 Apr 2018 14:33:21 +0100 Message-ID: <152414480180.23902.5252193699954530512.stgit@warthog.procyon.org.uk> In-Reply-To: <152414466005.23902.12967974041384198114.stgit@warthog.procyon.org.uk> References: <152414466005.23902.12967974041384198114.stgit@warthog.procyon.org.uk> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Apr 2018 13:33:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Thu, 19 Apr 2018 13:33:23 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'dhowells@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, int dfd, const char *path, unsigned int at_flags, unsigned int flags); where fsfd is the fd returned by fsopen(), dfd, path and at_flags locate the mountpoint and flags are the applicable MS_* flags. dfd can be AT_FDCWD or an fd open to a directory. In the event that fsmount() fails, it may be possible to get an error message by calling read(). If no message is available, ENODATA will be reported. Signed-off-by: David Howells --- arch/x86/entry/syscalls/syscall_32.tbl | 1 arch/x86/entry/syscalls/syscall_64.tbl | 1 fs/namespace.c | 82 ++++++++++++++++++++++++++++++++ include/linux/fs_context.h | 2 - include/linux/syscalls.h | 2 + kernel/sys_ni.c | 1 6 files changed, 88 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index d02346692c3f..5efec45b5ecb 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -397,3 +397,4 @@ 383 i386 statx sys_statx __ia32_sys_statx 384 i386 arch_prctl sys_arch_prctl __ia32_compat_sys_arch_prctl 385 i386 fsopen sys_fsopen __ia32_sys_fsopen +386 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 6708847571e2..f602389e1406 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -342,6 +342,7 @@ 331 common pkey_free __x64_sys_pkey_free 332 common statx __x64_sys_statx 333 common fsopen __x64_sys_fsopen +334 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 dff482ad87b4..14d110901bbe 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3192,6 +3192,88 @@ struct vfsmount *kern_mount(struct file_system_type *type) } EXPORT_SYMBOL_GPL(kern_mount); +/* + * Mount a new, prepared superblock (specified by fs_fd) on the location + * specified by dfd and dir_name. dfd can be AT_FDCWD, a dir fd or a container + * fd. This cannot be used for binding, moving or remounting mounts. + */ +SYSCALL_DEFINE5(fsmount, int, fs_fd, int, dfd, const char __user *, dir_name, + unsigned int, at_flags, unsigned int, flags) +{ + struct fs_context *fc; + struct path mountpoint; + struct fd f; + unsigned int lookup_flags, mnt_flags = 0; + long ret; + + if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | + AT_EMPTY_PATH)) != 0) + return -EINVAL; + + if (flags & ~(MS_RDONLY | MS_NOSUID | MS_NODEV | MS_NOEXEC | + MS_NOATIME | MS_NODIRATIME | MS_RELATIME | MS_STRICTATIME)) + return -EINVAL; + + if (flags & MS_RDONLY) + mnt_flags |= MNT_READONLY; + if (flags & MS_NOSUID) + mnt_flags |= MNT_NOSUID; + if (flags & MS_NODEV) + mnt_flags |= MNT_NODEV; + if (flags & MS_NOEXEC) + mnt_flags |= MNT_NOEXEC; + if (flags & MS_NODIRATIME) + mnt_flags |= MNT_NODIRATIME; + + if (flags & MS_STRICTATIME) { + if (flags & MS_NOATIME) + return -EINVAL; + } else if (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_fs_fops) + goto err_fsfd; + + fc = f.file->private_data; + + ret = -EPERM; + if (!may_mount() || + ((fc->sb_flags & MS_MANDLOCK) && !may_mandlock())) + goto err_fsfd; + + /* There must be a valid superblock or we can't mount it */ + ret = -EINVAL; + if (!fc->root) + goto err_fsfd; + + /* Find the mountpoint. A container can be specified in dfd. */ + lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; + if (at_flags & AT_SYMLINK_NOFOLLOW) + lookup_flags &= ~LOOKUP_FOLLOW; + if (at_flags & AT_NO_AUTOMOUNT) + lookup_flags &= ~LOOKUP_AUTOMOUNT; + if (at_flags & AT_EMPTY_PATH) + lookup_flags |= LOOKUP_EMPTY; + ret = user_path_at(dfd, dir_name, lookup_flags, &mountpoint); + if (ret < 0) + goto err_fsfd; + + ret = do_new_mount_fc(fc, &mountpoint, mnt_flags); + + path_put(&mountpoint); +err_fsfd: + fdput(f); + return ret; +} + /* * Return true if path is reachable from root * diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h index 536ae7d60f1f..dd79acddabec 100644 --- a/include/linux/fs_context.h +++ b/include/linux/fs_context.h @@ -102,5 +102,5 @@ 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 fs_fs_fops; +extern const struct file_operations fscontext_fs_fops; #endif /* _LINUX_FS_CONTEXT_H */ diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 3c9b10e92015..e5f68788a096 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -892,6 +892,8 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, unsigned mask, struct statx __user *buffer); asmlinkage long sys_fsopen(const char *fs_name, unsigned int flags, void *reserved3, void *reserved4, void *reserved5); +asmlinkage long sys_fsmount(int fsfd, int dfd, const char *path, unsigned int at_flags, + unsigned int flags); /* diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index c113fc9d5e77..2c236aad9b80 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -433,3 +433,4 @@ COND_SYSCALL(setuid16); /* fd-based mount */ COND_SYSCALL(sys_fsopen); +COND_SYSCALL(sys_fsmount);