Received: by 10.213.65.68 with SMTP id h4csp145621imn; Thu, 15 Mar 2018 12:14:31 -0700 (PDT) X-Google-Smtp-Source: AG47ELuReuCryz0XH5IFwORKGXY52LKk9Pv6FZl1DSxyh5gXUFvXCMjZLwKNO0Alh06fwfdfMYAw X-Received: by 2002:a17:902:9a08:: with SMTP id v8-v6mr9319633plp.252.1521141271357; Thu, 15 Mar 2018 12:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521141271; cv=none; d=google.com; s=arc-20160816; b=bHfNnkFJZTKN6BmMU/X14l5RF6kFzjQXPv6l0SIoQ6V4brYL6v1PvXJ0skNb7ckO31 lumMlXuW2nU6uzt3YAfKCdW5jYVJh0ILmbx45M2Q2ZyKoKEVnXejZIXy+nTPFK5FlIPI ouH4sv3r4aYyY9OBbYVGB1rathD3xCBaXT8P+KQw6ZA8n/NOHwJefooQYcLD026njoXJ ULXWvsU3zQClQDAx8sT9Xb2rLsFgK+RcChKzi5JYUaizvgvS5XLpvUKftxDDwakSgG+2 yt6XUnTqLGoO3ki0QaacInFtm5OQnnmzMDwmmvKcxOCFHU5sK0D6iMcFbu67yZRhoYyv U/lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=rszrL9mV6YLKOYwoG7dODFDduhIQTV0BkyVEMxBtbBk=; b=pjEr2f23rCvfvF9ft9Cgb7TxNe/di68PIdY807zMW+VglaUp2nwfjd6jwBWL/mBGIS zxvHbS0icHvupWoZYo1PdavcUjsMIU3p8WT4iXILP+BfGVRFN0BQy1jmAKc86ysmARIu O4D5RK4STWHCXqG+U8pqv428zk8QWofZgt7UmRM6EBc/bf2fMk6TijEAb37e5Z/DmAyV Hl3hsaLi3PpCQncucvb5Ea2fnJUcddyF4NhE6YkJIAlnJUVrZXnYoTnL3K9F+Ux+Ve08 tv2vZqfGLbvxajWG61wHaVubm1XKWiCXnL3XKg7qQI98HYnAWPCaQj0lI04ZylqEiPE0 TdBQ== 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 s12si3031883pfe.375.2018.03.15.12.14.16; Thu, 15 Mar 2018 12:14:31 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752822AbeCOTMY (ORCPT + 99 others); Thu, 15 Mar 2018 15:12:24 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:36142 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932615AbeCOTGV (ORCPT ); Thu, 15 Mar 2018 15:06:21 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id 52B92200910; Thu, 15 Mar 2018 19:06:18 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 37AC12067C; Thu, 15 Mar 2018 20:05:39 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk Cc: luto@kernel.org, mingo@kernel.org, akpm@linux-foundation.org, arnd@arndb.de Subject: [PATCH v2 17/36] fs: add ksys_chroot() helper; remove-in kernel calls to sys_chroot() Date: Thu, 15 Mar 2018 20:05:10 +0100 Message-Id: <20180315190529.20943-18-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180315190529.20943-1-linux@dominikbrodowski.net> References: <20180315190529.20943-1-linux@dominikbrodowski.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Using this helper allows us to avoid the in-kernel calls to the sys_chroot() syscall. Cc: Alexander Viro Signed-off-by: Dominik Brodowski --- drivers/base/devtmpfs.c | 2 +- fs/open.c | 7 ++++++- include/linux/syscalls.h | 1 + init/do_mounts.c | 2 +- init/do_mounts_initrd.c | 4 ++-- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index 4afb04686c8e..5743f04014ca 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c @@ -387,7 +387,7 @@ static int devtmpfsd(void *p) if (*err) goto out; sys_chdir("/.."); /* will traverse into overmounted root */ - sys_chroot("."); + ksys_chroot("."); complete(&setup_done); while (1) { spin_lock(&req_lock); diff --git a/fs/open.c b/fs/open.c index 7ea118471dce..7a475e8a2e41 100644 --- a/fs/open.c +++ b/fs/open.c @@ -479,7 +479,7 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd) return error; } -SYSCALL_DEFINE1(chroot, const char __user *, filename) +int ksys_chroot(const char __user *filename) { struct path path; int error; @@ -512,6 +512,11 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename) return error; } +SYSCALL_DEFINE1(chroot, const char __user *, filename) +{ + return ksys_chroot(filename); +} + static int chmod_common(const struct path *path, umode_t mode) { struct inode *inode = path->dentry->d_inode; diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 73f1889e73a5..13c7bc43b6ef 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -952,5 +952,6 @@ int ksys_mount(char __user *dev_name, char __user *dir_name, 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); #endif diff --git a/init/do_mounts.c b/init/do_mounts.c index eb768de43d84..2f06f7827b0c 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -600,7 +600,7 @@ void __init prepare_namespace(void) out: devtmpfs_mount("dev"); ksys_mount(".", "/", NULL, MS_MOVE, NULL); - sys_chroot("."); + ksys_chroot("."); } static bool is_tmpfs; diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c index e8573e1776f6..71293265ac4b 100644 --- a/init/do_mounts_initrd.c +++ b/init/do_mounts_initrd.c @@ -44,7 +44,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new) /* move initrd over / and chdir/chroot in initrd root */ sys_chdir("/root"); ksys_mount(".", "/", NULL, MS_MOVE, NULL); - sys_chroot("."); + ksys_chroot("."); sys_setsid(); return 0; } @@ -83,7 +83,7 @@ static void __init handle_initrd(void) /* move initrd to rootfs' /old */ ksys_mount("..", ".", NULL, MS_MOVE, NULL); /* switch root and cwd back to / of rootfs */ - sys_chroot(".."); + ksys_chroot(".."); if (new_decode_dev(real_root_dev) == Root_RAM0) { sys_chdir("/old"); -- 2.16.2