Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: add ksys_mount() helper; remove in-kernel calls to sys_mount()

Using this helper allows us to avoid the in-kernel calls to the sys_mount()
syscall. The ksys_ prefix denotes that this function is meant as a drop-in
replacement for the syscall. In particular, it uses the same calling
convention as sys_mount().

In the near future, all callers of ksys_mount() should be converted to call
do_mount() directly.

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>

+19 -9
+3 -2
drivers/base/devtmpfs.c
··· 356 356 if (!thread) 357 357 return 0; 358 358 359 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL); 359 + err = ksys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, 360 + NULL); 360 361 if (err) 361 362 printk(KERN_INFO "devtmpfs: error mounting %i\n", err); 362 363 else ··· 383 382 *err = sys_unshare(CLONE_NEWNS); 384 383 if (*err) 385 384 goto out; 386 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options); 385 + *err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options); 387 386 if (*err) 388 387 goto out; 389 388 sys_chdir("/.."); /* will traverse into overmounted root */
+8 -2
fs/namespace.c
··· 3032 3032 } 3033 3033 EXPORT_SYMBOL(mount_subtree); 3034 3034 3035 - SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 3036 - char __user *, type, unsigned long, flags, void __user *, data) 3035 + int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type, 3036 + unsigned long flags, void __user *data) 3037 3037 { 3038 3038 int ret; 3039 3039 char *kernel_type; ··· 3064 3064 kfree(kernel_type); 3065 3065 out_type: 3066 3066 return ret; 3067 + } 3068 + 3069 + SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, 3070 + char __user *, type, unsigned long, flags, void __user *, data) 3071 + { 3072 + return ksys_mount(dev_name, dir_name, type, flags, data); 3067 3073 } 3068 3074 3069 3075 /*
+3
include/linux/syscalls.h
··· 946 946 * the ksys_xyzyyz() functions prototyped below. 947 947 */ 948 948 949 + int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type, 950 + unsigned long flags, void __user *data); 951 + 949 952 #endif
+2 -2
init/do_mounts.c
··· 363 363 static int __init do_mount_root(char *name, char *fs, int flags, void *data) 364 364 { 365 365 struct super_block *s; 366 - int err = sys_mount(name, "/root", fs, flags, data); 366 + int err = ksys_mount(name, "/root", fs, flags, data); 367 367 if (err) 368 368 return err; 369 369 ··· 599 599 mount_root(); 600 600 out: 601 601 devtmpfs_mount("dev"); 602 - sys_mount(".", "/", NULL, MS_MOVE, NULL); 602 + ksys_mount(".", "/", NULL, MS_MOVE, NULL); 603 603 sys_chroot("."); 604 604 } 605 605
+3 -3
init/do_mounts_initrd.c
··· 43 43 sys_dup(0); 44 44 /* move initrd over / and chdir/chroot in initrd root */ 45 45 sys_chdir("/root"); 46 - sys_mount(".", "/", NULL, MS_MOVE, NULL); 46 + ksys_mount(".", "/", NULL, MS_MOVE, NULL); 47 47 sys_chroot("."); 48 48 sys_setsid(); 49 49 return 0; ··· 81 81 current->flags &= ~PF_FREEZER_SKIP; 82 82 83 83 /* move initrd to rootfs' /old */ 84 - sys_mount("..", ".", NULL, MS_MOVE, NULL); 84 + ksys_mount("..", ".", NULL, MS_MOVE, NULL); 85 85 /* switch root and cwd back to / of rootfs */ 86 86 sys_chroot(".."); 87 87 ··· 95 95 mount_root(); 96 96 97 97 printk(KERN_NOTICE "Trying to move old root to /initrd ... "); 98 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); 98 + error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL); 99 99 if (!error) 100 100 printk("okay\n"); 101 101 else {