Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1070655imm; Fri, 27 Jul 2018 10:37:10 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfPn3LrQ02p2v3/ka3jX+b68kQw8OYjkzc79j3gbHl7KRXcuAAo20DttWoJNopAxm7+3NaB X-Received: by 2002:a63:b02:: with SMTP id 2-v6mr6722269pgl.301.1532713030013; Fri, 27 Jul 2018 10:37:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532713029; cv=none; d=google.com; s=arc-20160816; b=G1nFoocSy4lO9DP0kO08AxvaBNQQshzuUbeERkE7A945T3hPVyKYRPpWAoqY/zJy1l Dr0fRWYkglb+io0Kzrt7/PvAoA1BwkeG9I/qZ5tnBQIvnf3JEIhmrypCgXElC7wVaGql r1jeyiWsjRGHPjo41NZueEZCN9TC+FTIyd+LXY+T16YNRVX5m/ot2rog9Lt9U6g5qqaJ N8YjhkXbsaAr3m7LMFStTjFxEmOq5MoWfhSIB4yHqidU/3gpmDlp4JXXL4Yvkn2QFNUg iwLr59bM/FS4+G2fSAhrJz0XvYlPwtO6hXiQdt7DVnqT4Sere/gGCwIVwSIuwO9CaZf+ MY6Q== 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=Ut8Dwa9sU+9ulYuT+CGmRpC/R+mwj1qVQFIVDa5vH3g=; b=S+tk+o/1mF35CBzYlTO2wWAknZMPZHyKaj5ytqwULnFwKWD1FK4exPtv6SIYJdXbcc byfieRF4E+8qXj9aUd116daNweiy/QHrWSjE9GKfzakyv/uK0RP+m1sgc3gYzwgPk2Hd KSJvtsCNz0lxOMLQn5cSB18HQk7dtPaU70DqtnGo9uu7RGieStmEnv1miWmHFJ2iE2Fr vud8qm6HGAbPc62rHoEyR9d2tfCPYlb0E74suQm7pnPnf1xkv2U1GjicM0AkfedoXDDZ Idj6cZpmrYiqMTx8VFQ0/Uvm/N2jDwncnLgCCn4JuZTH6FVNCMmIFnFQy2LqcwoFTMyi TGRw== 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 c192-v6si4371382pfg.347.2018.07.27.10.36.55; Fri, 27 Jul 2018 10:37:09 -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 S2389778AbeG0S5p (ORCPT + 99 others); Fri, 27 Jul 2018 14:57:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:41770 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388701AbeG0S5o (ORCPT ); Fri, 27 Jul 2018 14:57:44 -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 3F44240216E5; Fri, 27 Jul 2018 17:34:50 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-120-116.rdu2.redhat.com [10.10.120.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62D4B2166BA3; Fri, 27 Jul 2018 17:34:49 +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 31/38] vfs: syscall: Add fspick() to select a superblock for reconfiguration [ver #10] From: David Howells To: viro@zeniv.linux.org.uk Cc: linux-api@vger.kernel.org, torvalds@linux-foundation.org, dhowells@redhat.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Date: Fri, 27 Jul 2018 18:34:48 +0100 Message-ID: <153271288891.9458.662944512216883451.stgit@warthog.procyon.org.uk> In-Reply-To: <153271267980.9458.7640156373438016898.stgit@warthog.procyon.org.uk> References: <153271267980.9458.7640156373438016898.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version 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]); Fri, 27 Jul 2018 17:34:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 27 Jul 2018 17:34:50 +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 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); fsconfig(fd, fsconfig_set_flag, "intr", NULL, 0); fsconfig(fd, fsconfig_set_flag, "noac", NULL, 0); fsconfig(fd, fsconfig_cmd_reconfigure, NULL, NULL, 0); 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. Signed-off-by: David Howells cc: linux-api@vger.kernel.org --- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + fs/fsopen.c | 58 ++++++++++++++++++++++++++++++++ include/linux/syscalls.h | 1 + include/uapi/linux/fs.h | 5 +++ 5 files changed, 66 insertions(+) diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index c78b68256f8a..d1eb6c815790 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -403,3 +403,4 @@ 389 i386 fsopen sys_fsopen __ia32_sys_fsopen 390 i386 fsconfig sys_fsconfig __ia32_sys_fsconfig 391 i386 fsmount sys_fsmount __ia32_sys_fsmount +392 i386 fspick sys_fspick __ia32_sys_fspick diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index d44ead5d4368..d3ab703c02bb 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -348,6 +348,7 @@ 337 common fsopen __x64_sys_fsopen 338 common fsconfig __x64_sys_fsconfig 339 common fsmount __x64_sys_fsmount +340 common fspick __x64_sys_fspick # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/fs/fsopen.c b/fs/fsopen.c index d2d23c02839a..51ce50904988 100644 --- a/fs/fsopen.c +++ b/fs/fsopen.c @@ -155,6 +155,64 @@ SYSCALL_DEFINE2(fsopen, const char __user *, _fs_name, unsigned int, flags) return ret; } +/* + * Pick a superblock into a context for reconfiguration. + */ +SYSCALL_DEFINE3(fspick, int, dfd, const char __user *, path, unsigned int, flags) +{ + struct fs_context *fc; + struct path target; + unsigned int lookup_flags; + int ret; + + if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN)) + return -EPERM; + + if ((flags & ~(FSPICK_CLOEXEC | + FSPICK_SYMLINK_NOFOLLOW | + FSPICK_NO_AUTOMOUNT | + FSPICK_EMPTY_PATH)) != 0) + return -EINVAL; + + lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT; + if (flags & FSPICK_SYMLINK_NOFOLLOW) + lookup_flags &= ~LOOKUP_FOLLOW; + if (flags & FSPICK_NO_AUTOMOUNT) + lookup_flags &= ~LOOKUP_AUTOMOUNT; + if (flags & FSPICK_EMPTY_PATH) + lookup_flags |= LOOKUP_EMPTY; + ret = user_path_at(dfd, path, lookup_flags, &target); + if (ret < 0) + goto err; + + ret = -EOPNOTSUPP; + if (!target.dentry->d_sb->s_op->reconfigure) + goto err_path; + + fc = vfs_new_fs_context(target.dentry->d_sb->s_type, target.dentry, + 0, FS_CONTEXT_FOR_RECONFIGURE); + if (IS_ERR(fc)) { + ret = PTR_ERR(fc); + goto err_path; + } + + fc->phase = FS_CONTEXT_RECONF_PARAMS; + + ret = fscontext_alloc_log(fc); + if (ret < 0) + goto err_fc; + + path_put(&target); + return fscontext_create_fd(fc, flags & FSPICK_CLOEXEC ? O_CLOEXEC : 0); + +err_fc: + put_fs_context(fc); +err_path: + path_put(&target); +err: + return ret; +} + /* * Check the state and apply the configuration. Note that this function is * allowed to 'steal' the value by setting param->xxx to NULL before returning. diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 65db661cc2da..701522957a12 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -908,6 +908,7 @@ 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); +asmlinkage long sys_fspick(int dfd, const char __user *path, unsigned int flags); /* * Architecture-specific system calls diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 297362908d01..be70cbac21b4 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -351,6 +351,11 @@ 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 + /* * The type of fsconfig() call made. */