Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1141964ybl; Thu, 12 Dec 2019 10:15:23 -0800 (PST) X-Google-Smtp-Source: APXvYqzwbOhd691EJ5W1X8I6+2m+8n3r3rdZsqlClbMyCvYmZ275rs92KqJWvQP/9FaRbtt3NMHH X-Received: by 2002:a9d:2028:: with SMTP id n37mr10015810ota.127.1576174523219; Thu, 12 Dec 2019 10:15:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576174523; cv=none; d=google.com; s=arc-20160816; b=enqUiT9vnYnssNY/kV+Ak0kXuAYz2bvz9vZRcuIUw+lgazjg9jg11clEcWtgHPKV5Z RgY5Z9iuNNt69hkHjqWtKbW1pU49ZtlcmD6/KehvMD6ypuk9cJeoSuFUuLA115Hj8GQ5 +d0FvehPxLVhrCj/pEhPGI+t/f13qhFCYdn7Hamqur6rRtCz0rSLCW8mTJ7PR8SpnRw+ eUIRRSDdRc3XOsx9c13OzILCsEGAJkguRuAfbCcP72tfW+WhfFDmbwwek7kook/Z9fiE CpNlZXf5DkecQZMITtCBd/gwdPcqnegJo6Tf1zyO4LwWiCMRBcGxOT7uzqki2zvPcaZm 5TvQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uidnp0g3/dBrH+EAVvtzLmvnX9p1+iaJ9urm5lguG8g=; b=StVZw1u8paUPCeCyGwxsyUNDqRCcOPP1nwhJGyNx21Nmca7pusj+K83kNEUyyWh9Yc M2cfEBIxy7hp9Gon1E7K0r1ETUdOjMBe0tS9WzTds1GdDemmxzRHilZ6L+ZGRoeaxF0t TdMPK8/2KT+eBLpPiPL3yPIM9Ep0uNmwufZ9GI9HyakAKY9bBRRkaK8knG+WBlmDR9Ms t/dOuaPIL8lhFdnEtLUgU7wmNo+S54U+MTWZRyaIJL4fiWgOFitWOE4Qky7ncNogZ7Iz vU6m+/PNKCwf8PJjziIbkrKMLbEMF17xKCMZ0nr3M/qVM3mQstYFd31UG0wRKvnRrX9/ 0Qxw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t184si3540000oig.184.2019.12.12.10.15.10; Thu, 12 Dec 2019 10:15:23 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730363AbfLLSOh (ORCPT + 99 others); Thu, 12 Dec 2019 13:14:37 -0500 Received: from isilmar-4.linta.de ([136.243.71.142]:56756 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730293AbfLLSOg (ORCPT ); Thu, 12 Dec 2019 13:14:36 -0500 X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES X-isilmar-external: YES Received: from light.dominikbrodowski.net (brodo.linta [10.1.0.102]) by isilmar-4.linta.de (Postfix) with ESMTPSA id DB169200A94; Thu, 12 Dec 2019 18:14:33 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 62F5D20B70; Thu, 12 Dec 2019 19:14:30 +0100 (CET) From: Dominik Brodowski To: Alexander Viro , Linus Torvalds Cc: Greg Kroah-Hartman , "Rafael J . Wysocki" , Andrew Morton , Ingo Molnar , linux-kernel@vger.kernel.org Subject: [PATCH 3/5] init: use do_mount() instead of ksys_mount() Date: Thu, 12 Dec 2019 19:14:20 +0100 Message-Id: <20191212181422.31033-4-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191212181422.31033-1-linux@dominikbrodowski.net> References: <20191212181422.31033-1-linux@dominikbrodowski.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In prepare_namespace(), do_mount() can be used instead of ksys_mount() as the first and third argument are const strings in the kernel, the second and fourth argument are passed through anyway, and the fifth argument is NULL. In do_mount_root(), ksys_mount() is called with the first and third argument being already kernelspace strings, which do not need to be copied over from userspace to kernelspace (again). The second and fourth arguments are passed through to do_mount() anyway. The fifth argument, while already residing in kernelspace, needs to be put into a page of its own. Then, do_mount() can be used instead of ksys_mount(). Once this is done, there are no in-kernel users to ksys_mount() left, which can therefore be removed. Signed-off-by: Dominik Brodowski --- fs/namespace.c | 10 ++-------- include/linux/syscalls.h | 2 -- init/do_mounts.c | 28 ++++++++++++++++++++++------ 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 2fd0c8bcb8c1..be601d3a8008 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name) } EXPORT_SYMBOL(mount_subtree); -int ksys_mount(const char __user *dev_name, const char __user *dir_name, - const char __user *type, unsigned long flags, void __user *data) +SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, + char __user *, type, unsigned long, flags, void __user *, data) { int ret; char *kernel_type; @@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name, return ret; } -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, - char __user *, type, unsigned long, flags, void __user *, data) -{ - return ksys_mount(dev_name, dir_name, type, flags, data); -} - /* * Create a kernel mount representation for a new, prepared superblock * (specified by fs_fd) and attach to an open_tree-like file descriptor. diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index d0391cc2dae9..5262b7a76d39 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -1231,8 +1231,6 @@ asmlinkage long sys_ni_syscall(void); * the ksys_xyzyyz() functions prototyped below. */ -int ksys_mount(const char __user *dev_name, const char __user *dir_name, - const char __user *type, unsigned long flags, void __user *data); int ksys_umount(char __user *name, int flags); int ksys_dup(unsigned int fildes); int ksys_chroot(const char __user *filename); diff --git a/init/do_mounts.c b/init/do_mounts.c index 43f6d098c880..f55cbd9cb818 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -387,12 +387,25 @@ static void __init get_fs_names(char *page) *s = '\0'; } -static int __init do_mount_root(char *name, char *fs, int flags, void *data) +static int __init do_mount_root(const char *name, const char *fs, + const int flags, const void *data) { struct super_block *s; - int err = ksys_mount(name, "/root", fs, flags, data); - if (err) - return err; + char *data_page; + struct page *p; + int ret; + + /* do_mount() requires a full page as fifth argument */ + p = alloc_page(GFP_KERNEL); + if (!p) + return -ENOMEM; + + data_page = page_address(p); + strncpy(data_page, data, PAGE_SIZE - 1); + + ret = do_mount(name, "/root", fs, flags, data_page); + if (ret) + goto out; ksys_chdir("/root"); s = current->fs->pwd.dentry->d_sb; @@ -402,7 +415,10 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data) s->s_type->name, sb_rdonly(s) ? " readonly" : "", MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); - return 0; + +out: + put_page(p); + return ret; } void __init mount_block_root(char *name, int flags) @@ -671,7 +687,7 @@ void __init prepare_namespace(void) mount_root(); out: devtmpfs_mount(); - ksys_mount(".", "/", NULL, MS_MOVE, NULL); + do_mount(".", "/", NULL, MS_MOVE, NULL); ksys_chroot("."); } -- 2.24.1