Skip to content

Commit 312db1a

Browse files
author
Dominik Brodowski
committed
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>
1 parent ab0d1e8 commit 312db1a

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

‎drivers/base/devtmpfs.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ int devtmpfs_mount(const char *mntdir)
356356
if (!thread)
357357
return 0;
358358

359-
err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
359+
err = ksys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT,
360+
NULL);
360361
if (err)
361362
printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
362363
else
@@ -382,7 +383,7 @@ static int devtmpfsd(void *p)
382383
*err = sys_unshare(CLONE_NEWNS);
383384
if (*err)
384385
goto out;
385-
*err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
386+
*err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
386387
if (*err)
387388
goto out;
388389
sys_chdir("/.."); /* will traverse into overmounted root */

‎fs/namespace.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,8 +3032,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
30323032
}
30333033
EXPORT_SYMBOL(mount_subtree);
30343034

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)
30373037
{
30383038
int ret;
30393039
char *kernel_type;
@@ -3066,6 +3066,12 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
30663066
return ret;
30673067
}
30683068

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);
3073+
}
3074+
30693075
/*
30703076
* Return true if path is reachable from root
30713077
*

‎include/linux/syscalls.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,4 +946,7 @@ asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags,
946946
* the ksys_xyzyyz() functions prototyped below.
947947
*/
948948

949+
int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
950+
unsigned long flags, void __user *data);
951+
949952
#endif

‎init/do_mounts.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ static void __init get_fs_names(char *page)
363363
static int __init do_mount_root(char *name, char *fs, int flags, void *data)
364364
{
365365
struct super_block *s;
366-
int err = sys_mount(name, "/root", fs, flags, data);
366+
int err = ksys_mount(name, "/root", fs, flags, data);
367367
if (err)
368368
return err;
369369

@@ -599,7 +599,7 @@ void __init prepare_namespace(void)
599599
mount_root();
600600
out:
601601
devtmpfs_mount("dev");
602-
sys_mount(".", "/", NULL, MS_MOVE, NULL);
602+
ksys_mount(".", "/", NULL, MS_MOVE, NULL);
603603
sys_chroot(".");
604604
}
605605

‎init/do_mounts_initrd.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
4343
sys_dup(0);
4444
/* move initrd over / and chdir/chroot in initrd root */
4545
sys_chdir("/root");
46-
sys_mount(".", "/", NULL, MS_MOVE, NULL);
46+
ksys_mount(".", "/", NULL, MS_MOVE, NULL);
4747
sys_chroot(".");
4848
sys_setsid();
4949
return 0;
@@ -81,7 +81,7 @@ static void __init handle_initrd(void)
8181
current->flags &= ~PF_FREEZER_SKIP;
8282

8383
/* move initrd to rootfs' /old */
84-
sys_mount("..", ".", NULL, MS_MOVE, NULL);
84+
ksys_mount("..", ".", NULL, MS_MOVE, NULL);
8585
/* switch root and cwd back to / of rootfs */
8686
sys_chroot("..");
8787

@@ -95,7 +95,7 @@ static void __init handle_initrd(void)
9595
mount_root();
9696

9797
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);
9999
if (!error)
100100
printk("okay\n");
101101
else {

0 commit comments

Comments
 (0)