summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Brodowski <linux@dominikbrodowski.net>2018-03-11 06:34:40 -0400
committerDominik Brodowski <linux@dominikbrodowski.net>2018-04-02 14:15:49 -0400
commitc7248321a3d42ffba78db0dde88d1c49ca1c045f (patch)
treeecd2b86a077f764e200b3c214cd1f851d4e3c6e0
parent3a18ef5c1b3935cb05888fc37964321f7bd6231d (diff)
fs: add ksys_dup{,3}() helper; remove in-kernel calls to sys_dup{,3}()
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. The ksys_ prefix denotes that these functions are meant as a drop-in replacement for the syscalls. In particular, they use the same calling convention as sys_dup{,3}(). In the near future, the fs-external callers of ksys_dup{,3}() should be converted to call do_dup2() directly. Then, ksys_dup{,3}() can be moved within sys_dup{,3}() again. This patch is part of a series which removes in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. For details, see http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net Cc: Alexander Viro <viro@zeniv.linux.org.uk> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
-rw-r--r--fs/file.c16
-rw-r--r--include/linux/syscalls.h1
-rw-r--r--init/do_mounts_initrd.c4
-rw-r--r--init/main.c4
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 @@ out_unlock:
870 return err; 870 return err;
871} 871}
872 872
873SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags) 873static int ksys_dup3(unsigned int oldfd, unsigned int newfd, int flags)
874{ 874{
875 int err = -EBADF; 875 int err = -EBADF;
876 struct file *file; 876 struct file *file;
@@ -904,6 +904,11 @@ out_unlock:
904 return err; 904 return err;
905} 905}
906 906
907SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
908{
909 return ksys_dup3(oldfd, newfd, flags);
910}
911
907SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd) 912SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd)
908{ 913{
909 if (unlikely(newfd == oldfd)) { /* corner case */ 914 if (unlikely(newfd == oldfd)) { /* corner case */
@@ -916,10 +921,10 @@ SYSCALL_DEFINE2(dup2, unsigned int, oldfd, unsigned int, newfd)
916 rcu_read_unlock(); 921 rcu_read_unlock();
917 return retval; 922 return retval;
918 } 923 }
919 return sys_dup3(oldfd, newfd, 0); 924 return ksys_dup3(oldfd, newfd, 0);
920} 925}
921 926
922SYSCALL_DEFINE1(dup, unsigned int, fildes) 927int ksys_dup(unsigned int fildes)
923{ 928{
924 int ret = -EBADF; 929 int ret = -EBADF;
925 struct file *file = fget_raw(fildes); 930 struct file *file = fget_raw(fildes);
@@ -934,6 +939,11 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
934 return ret; 939 return ret;
935} 940}
936 941
942SYSCALL_DEFINE1(dup, unsigned int, fildes)
943{
944 return ksys_dup(fildes);
945}
946
937int f_dupfd(unsigned int from, struct file *file, unsigned flags) 947int f_dupfd(unsigned int from, struct file *file, unsigned flags)
938{ 948{
939 int err; 949 int err;
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 48964c408c7b..50876ae1d17b 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -949,5 +949,6 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
949int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type, 949int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
950 unsigned long flags, void __user *data); 950 unsigned long flags, void __user *data);
951int ksys_umount(char __user *name, int flags); 951int ksys_umount(char __user *name, int flags);
952int ksys_dup(unsigned int fildes);
952 953
953#endif 954#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)
39 sys_unshare(CLONE_FS | CLONE_FILES); 39 sys_unshare(CLONE_FS | CLONE_FILES);
40 /* stdin/stdout/stderr for /linuxrc */ 40 /* stdin/stdout/stderr for /linuxrc */
41 sys_open("/dev/console", O_RDWR, 0); 41 sys_open("/dev/console", O_RDWR, 0);
42 sys_dup(0); 42 ksys_dup(0);
43 sys_dup(0); 43 ksys_dup(0);
44 /* move initrd over / and chdir/chroot in initrd root */ 44 /* move initrd over / and chdir/chroot in initrd root */
45 sys_chdir("/root"); 45 sys_chdir("/root");
46 ksys_mount(".", "/", NULL, MS_MOVE, NULL); 46 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)
1077 if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0) 1077 if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1078 pr_err("Warning: unable to open an initial console.\n"); 1078 pr_err("Warning: unable to open an initial console.\n");
1079 1079
1080 (void) sys_dup(0); 1080 (void) ksys_dup(0);
1081 (void) sys_dup(0); 1081 (void) ksys_dup(0);
1082 /* 1082 /*
1083 * check if there is an early userspace init. If yes, let it do all 1083 * check if there is an early userspace init. If yes, let it do all
1084 * the work 1084 * the work