浏览代码

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>
Dominik Brodowski 7 年之前
父节点
当前提交
312db1aa1d
共有 5 个文件被更改,包括 19 次插入9 次删除
  1. 3 2
      drivers/base/devtmpfs.c
  2. 8 2
      fs/namespace.c
  3. 3 0
      include/linux/syscalls.h
  4. 2 2
      init/do_mounts.c
  5. 3 3
      init/do_mounts_initrd.c

+ 3 - 2
drivers/base/devtmpfs.c

@@ -356,7 +356,8 @@ int devtmpfs_mount(const char *mntdir)
 	if (!thread)
 	if (!thread)
 		return 0;
 		return 0;
 
 
-	err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
+	err = ksys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT,
+			 NULL);
 	if (err)
 	if (err)
 		printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
 		printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
 	else
 	else
@@ -382,7 +383,7 @@ static int devtmpfsd(void *p)
 	*err = sys_unshare(CLONE_NEWNS);
 	*err = sys_unshare(CLONE_NEWNS);
 	if (*err)
 	if (*err)
 		goto out;
 		goto out;
-	*err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
+	*err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
 	if (*err)
 	if (*err)
 		goto out;
 		goto out;
 	sys_chdir("/.."); /* will traverse into overmounted root */
 	sys_chdir("/.."); /* will traverse into overmounted root */

+ 8 - 2
fs/namespace.c

@@ -3032,8 +3032,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
 }
 }
 EXPORT_SYMBOL(mount_subtree);
 EXPORT_SYMBOL(mount_subtree);
 
 
-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
-		char __user *, type, unsigned long, flags, void __user *, data)
+int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
+	       unsigned long flags, void __user *data)
 {
 {
 	int ret;
 	int ret;
 	char *kernel_type;
 	char *kernel_type;
@@ -3066,6 +3066,12 @@ out_type:
 	return ret;
 	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);
+}
+
 /*
 /*
  * Return true if path is reachable from root
  * Return true if path is reachable from root
  *
  *

+ 3 - 0
include/linux/syscalls.h

@@ -946,4 +946,7 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
  * the ksys_xyzyyz() functions prototyped below.
  * the ksys_xyzyyz() functions prototyped below.
  */
  */
 
 
+int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
+	       unsigned long flags, void __user *data);
+
 #endif
 #endif

+ 2 - 2
init/do_mounts.c

@@ -363,7 +363,7 @@ static void __init get_fs_names(char *page)
 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
 {
 {
 	struct super_block *s;
 	struct super_block *s;
-	int err = sys_mount(name, "/root", fs, flags, data);
+	int err = ksys_mount(name, "/root", fs, flags, data);
 	if (err)
 	if (err)
 		return err;
 		return err;
 
 
@@ -599,7 +599,7 @@ void __init prepare_namespace(void)
 	mount_root();
 	mount_root();
 out:
 out:
 	devtmpfs_mount("dev");
 	devtmpfs_mount("dev");
-	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+	ksys_mount(".", "/", NULL, MS_MOVE, NULL);
 	sys_chroot(".");
 	sys_chroot(".");
 }
 }
 
 

+ 3 - 3
init/do_mounts_initrd.c

@@ -43,7 +43,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
 	sys_dup(0);
 	sys_dup(0);
 	/* move initrd over / and chdir/chroot in initrd root */
 	/* move initrd over / and chdir/chroot in initrd root */
 	sys_chdir("/root");
 	sys_chdir("/root");
-	sys_mount(".", "/", NULL, MS_MOVE, NULL);
+	ksys_mount(".", "/", NULL, MS_MOVE, NULL);
 	sys_chroot(".");
 	sys_chroot(".");
 	sys_setsid();
 	sys_setsid();
 	return 0;
 	return 0;
@@ -81,7 +81,7 @@ static void __init handle_initrd(void)
 	current->flags &= ~PF_FREEZER_SKIP;
 	current->flags &= ~PF_FREEZER_SKIP;
 
 
 	/* move initrd to rootfs' /old */
 	/* move initrd to rootfs' /old */
-	sys_mount("..", ".", NULL, MS_MOVE, NULL);
+	ksys_mount("..", ".", NULL, MS_MOVE, NULL);
 	/* switch root and cwd back to / of rootfs */
 	/* switch root and cwd back to / of rootfs */
 	sys_chroot("..");
 	sys_chroot("..");
 
 
@@ -95,7 +95,7 @@ static void __init handle_initrd(void)
 	mount_root();
 	mount_root();
 
 
 	printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
 	printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
-	error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
+	error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
 	if (!error)
 	if (!error)
 		printk("okay\n");
 		printk("okay\n");
 	else {
 	else {