Received: by 10.213.65.68 with SMTP id h4csp143678imn; Thu, 15 Mar 2018 12:10:43 -0700 (PDT) X-Google-Smtp-Source: AG47ELu/N5l6or+0Uh8Aws2FdVLc18XvhlDRU68qVWl+vQV7DaVjKVWQJIbfh5u1sx5kaAneo+Ao X-Received: by 10.99.42.72 with SMTP id q69mr7563224pgq.168.1521141043336; Thu, 15 Mar 2018 12:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521141043; cv=none; d=google.com; s=arc-20160816; b=Z+ZMz4TjHSycblxkKXwXacv1iVBdTWEoF9UvV/zrrOq2KpSUGDxLerPuUu4OLYFcMA GEplfPJcdK3lK+IwBMcwxSICVSGAZjBIz3ovWVx748EAg3CDqnKfb95+HfvDQkzneRx/ pTvv0gCLAOLT557u5/8FR2QOFIWBg+wXMfwZ3mbRGgyutdz6RaIzNPFwqYO/3YnLPzwd 1TdLfY5PBflvRx3cw4zXsEmEw0D1xNGmFuxmQgz0pFuMSTIbpadU1/uihm+j7mcJLyFc SMhw9Pw8d0L3T4sE/UcHxPuR2evEGVntcRBYDIxvJiwE1nud/7r3neQCjkeWV7h3InwA pvHQ== 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=ugcwt3aIvor8TUI4rEIjtvlJ+cSyQoXcM9xHTcbh2TE=; b=sRYAHRFMC9n4oRABrCndNhptP5IpNRz5O34O9mVU0/F119dSIVmsKT100SchFU1Ehj MSkTLx2dcWi2st69Ux2KvBM9GRjTJKoBuorLXGUL0VMZloePADMiDvboZQLXM4LFXBRD xXWStG58HcjmW+l1rYS/A3inIkA7ufM40OkKpL4LKO7ZaFhpb2H3oFHHhesiATPuKLQf 1BEpcP4B6BdQUElT1M5oFwbisx/FaEZ15/6pCVCpGf/gJJHnHwwbrHgWIr0DdEaXMcha mUMTyzZbFsAikrQ4swAk6S6WkClSSVopRIw5TrlvJhz8fKX4oynP39Gz/Xsp6CjNp3oA rqpg== 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 y38-v6si4471139plh.304.2018.03.15.12.10.29; Thu, 15 Mar 2018 12:10:43 -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 S932811AbeCOTHQ (ORCPT + 99 others); Thu, 15 Mar 2018 15:07:16 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:36226 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932689AbeCOTGY (ORCPT ); Thu, 15 Mar 2018 15:06:24 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id 08D4520092F; Thu, 15 Mar 2018 19:06:19 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 2B71020672; 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 16/36] fs: add ksys_dup{,3}() helper; remove in-kernel calls to sys_dup{,3}() Date: Thu, 15 Mar 2018 20:05:09 +0100 Message-Id: <20180315190529.20943-17-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 ksys_dup() and ksys_dup3() as helper functions allows us to avoid the in-kernel calls to the sys_dup() and sys_dup3() syscalls. Cc: Alexander Viro Signed-off-by: Dominik Brodowski --- fs/file.c | 16 +++++++++++++--- include/linux/syscalls.h | 1 + init/do_mounts_initrd.c | 4 ++-- init/main.c | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/fs/file.c b/fs/file.c index 42f0db4bd0fb..d304004f0b65 100644 --- a/fs/file.c +++ b/fs/file.c @@ -870,7 +870,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags) return err; } -SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) +static int ksys_dup3(unsigned int oldfd, unsigned int newfd, int flags) { int err = -EBADF; struct file *file; @@ -904,6 +904,11 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) return err; } +SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) +{ + return ksys_dup3(oldfd, newfd, flags); +} + SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd) { if (unlikely(newfd == oldfd)) { /* corner case */ @@ -916,10 +921,10 @@ SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd) rcu_read_unlock(); return retval; } - return sys_dup3(oldfd, newfd, 0); + return ksys_dup3(oldfd, newfd, 0); } -SYSCALL_DEFINE1(dup, unsigned int, fildes) +int ksys_dup(unsigned int fildes) { int ret = -EBADF; struct file *file = fget_raw(fildes); @@ -934,6 +939,11 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes) return ret; } +SYSCALL_DEFINE1(dup, unsigned int, fildes) +{ + return ksys_dup(fildes); +} + int f_dupfd(unsigned int from, struct file *file, unsigned flags) { int err; diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 929dfc6c2906..73f1889e73a5 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -951,5 +951,6 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, 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); #endif diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c index 1c4da8353332..e8573e1776f6 100644 --- a/init/do_mounts_initrd.c +++ b/init/do_mounts_initrd.c @@ -39,8 +39,8 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new) sys_unshare(CLONE_FS | CLONE_FILES); /* stdin/stdout/stderr for /linuxrc */ sys_open("/dev/console", O_RDWR, 0); - sys_dup(0); - sys_dup(0); + ksys_dup(0); + ksys_dup(0); /* move initrd over / and chdir/chroot in initrd root */ sys_chdir("/root"); ksys_mount(".", "/", NULL, MS_MOVE, NULL); diff --git a/init/main.c b/init/main.c index 969eaf140ef0..b8649d1466e1 100644 --- a/init/main.c +++ b/init/main.c @@ -1077,8 +1077,8 @@ static noinline void __init kernel_init_freeable(void) if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) pr_err("Warning: unable to open an initial console.\n"); - (void) sys_dup(0); - (void) sys_dup(0); + (void) ksys_dup(0); + (void) ksys_dup(0); /* * check if there is an early userspace init. If yes, let it do all * the work -- 2.16.2