Commit cccaa5e3 authored by Dominik Brodowski's avatar Dominik Brodowski

init: use do_mount() instead of ksys_mount()

In prepare_namespace(), do_mount() can be used instead of ksys_mount()
as the first and third argument are const strings in the kernel, the
second and fourth argument are passed through anyway, and the fifth
argument is NULL.

In do_mount_root(), ksys_mount() is called with the first and third
argument being already kernelspace strings, which do not need to be
copied over from userspace to kernelspace (again). The second and
fourth arguments are passed through to do_mount() anyway. The fifth
argument, while already residing in kernelspace, needs to be put into
a page of its own. Then, do_mount() can be used instead of
ksys_mount().

Once this is done, there are no in-kernel users to ksys_mount() left,
which can therefore be removed.
Signed-off-by: default avatarDominik Brodowski <linux@dominikbrodowski.net>
parent d4440aac
...@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name) ...@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name)
} }
EXPORT_SYMBOL(mount_subtree); EXPORT_SYMBOL(mount_subtree);
int ksys_mount(const char __user *dev_name, const char __user *dir_name, SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
const char __user *type, unsigned long flags, void __user *data) char __user *, type, unsigned long, flags, void __user *, data)
{ {
int ret; int ret;
char *kernel_type; char *kernel_type;
...@@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name, ...@@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name,
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);
}
/* /*
* Create a kernel mount representation for a new, prepared superblock * Create a kernel mount representation for a new, prepared superblock
* (specified by fs_fd) and attach to an open_tree-like file descriptor. * (specified by fs_fd) and attach to an open_tree-like file descriptor.
......
...@@ -1231,8 +1231,6 @@ asmlinkage long sys_ni_syscall(void); ...@@ -1231,8 +1231,6 @@ asmlinkage long sys_ni_syscall(void);
* the ksys_xyzyyz() functions prototyped below. * the ksys_xyzyyz() functions prototyped below.
*/ */
int ksys_mount(const char __user *dev_name, const char __user *dir_name,
const char __user *type, unsigned long flags, void __user *data);
int ksys_umount(char __user *name, int flags); int ksys_umount(char __user *name, int flags);
int ksys_dup(unsigned int fildes); int ksys_dup(unsigned int fildes);
int ksys_chroot(const char __user *filename); int ksys_chroot(const char __user *filename);
......
...@@ -387,12 +387,25 @@ static void __init get_fs_names(char *page) ...@@ -387,12 +387,25 @@ static void __init get_fs_names(char *page)
*s = '\0'; *s = '\0';
} }
static int __init do_mount_root(char *name, char *fs, int flags, void *data) static int __init do_mount_root(const char *name, const char *fs,
const int flags, const void *data)
{ {
struct super_block *s; struct super_block *s;
int err = ksys_mount(name, "/root", fs, flags, data); char *data_page;
if (err) struct page *p;
return err; int ret;
/* do_mount() requires a full page as fifth argument */
p = alloc_page(GFP_KERNEL);
if (!p)
return -ENOMEM;
data_page = page_address(p);
strncpy(data_page, data, PAGE_SIZE - 1);
ret = do_mount(name, "/root", fs, flags, data_page);
if (ret)
goto out;
ksys_chdir("/root"); ksys_chdir("/root");
s = current->fs->pwd.dentry->d_sb; s = current->fs->pwd.dentry->d_sb;
...@@ -402,7 +415,10 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data) ...@@ -402,7 +415,10 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data)
s->s_type->name, s->s_type->name,
sb_rdonly(s) ? " readonly" : "", sb_rdonly(s) ? " readonly" : "",
MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
return 0;
out:
put_page(p);
return ret;
} }
void __init mount_block_root(char *name, int flags) void __init mount_block_root(char *name, int flags)
...@@ -671,7 +687,7 @@ void __init prepare_namespace(void) ...@@ -671,7 +687,7 @@ void __init prepare_namespace(void)
mount_root(); mount_root();
out: out:
devtmpfs_mount(); devtmpfs_mount();
ksys_mount(".", "/", NULL, MS_MOVE, NULL); do_mount(".", "/", NULL, MS_MOVE, NULL);
ksys_chroot("."); ksys_chroot(".");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment