History

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.

Dominik Brodowski committed 8 years ago

Commit cccaa5e1 parent d4440aa3 files · +24 −16Browse files

Unified · Split

3 files
  1. fs/namespace.c +2 −8
  2. include/linux/syscalls.h +0 −2
  3. init/do_mounts.c +22 −6
fs/namespace.c+2−8
@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name) · 3324 unmodified lines
33253325 }
33263326 EXPORT_SYMBOL(mount_subtree);
33273327
3328−int ksys_mount(const char __user *dev_name, const char __user *dir_name,
3329− const char __user *type, unsigned long flags, void __user *data)
3328+SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
3329+ char __user *, type, unsigned long, flags, void __user *, data)
33303330 {
33313331 int ret;
33323332 char *kernel_type;
@@ -3359,12 +3359,6 @@ out_type: · 26 unmodified lines
33593359 return ret;
33603360 }
33613361
3362−SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
3363− char __user *, type, unsigned long, flags, void __user *, data)
3364−{
3365− return ksys_mount(dev_name, dir_name, type, flags, data);
3366−}
3367−
33683362 /*
33693363 * Create a kernel mount representation for a new, prepared superblock
33703364 * (specified by fs_fd) and attach to an open_tree-like file descriptor.
include/linux/syscalls.h+0−2
@@ -1231,8 +1231,6 @@ asmlinkage long sys_ni_syscall(void); · 1230 unmodified lines
12311231 * the ksys_xyzyyz() functions prototyped below.
12321232 */
12331233
1234−int ksys_mount(const char __user *dev_name, const char __user *dir_name,
1235− const char __user *type, unsigned long flags, void __user *data);
12361234 int ksys_umount(char __user *name, int flags);
12371235 int ksys_dup(unsigned int fildes);
12381236 int ksys_chroot(const char __user *filename);
init/do_mounts.c+22−6
@@ -387,12 +387,25 @@ static void __init get_fs_names(char *page) · 386 unmodified lines
387387 *s = '\0';
388388 }
389389
390−static int __init do_mount_root(char *name, char *fs, int flags, void *data)
390+static int __init do_mount_root(const char *name, const char *fs,
391+ const int flags, const void *data)
391392 {
392393 struct super_block *s;
393− int err = ksys_mount(name, "/root", fs, flags, data);
394− if (err)
395− return err;
394+ char *data_page;
395+ struct page *p;
396+ int ret;
397+
398+ /* do_mount() requires a full page as fifth argument */
399+ p = alloc_page(GFP_KERNEL);
400+ if (!p)
401+ return -ENOMEM;
402+
403+ data_page = page_address(p);
404+ strncpy(data_page, data, PAGE_SIZE - 1);
405+
406+ ret = do_mount(name, "/root", fs, flags, data_page);
407+ if (ret)
408+ goto out;
396409
397410 ksys_chdir("/root");
398411 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) · 3 unmodified lines
402415 s->s_type->name,
403416 sb_rdonly(s) ? " readonly" : "",
404417 MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
405− return 0;
418+
419+out:
420+ put_page(p);
421+ return ret;
406422 }
407423
408424 void __init mount_block_root(char *name, int flags)
@@ -671,7 +687,7 @@ void __init prepare_namespace(void) · 262 unmodified lines
671687 mount_root();
672688 out:
673689 devtmpfs_mount();
674− ksys_mount(".", "/", NULL, MS_MOVE, NULL);
690+ do_mount(".", "/", NULL, MS_MOVE, NULL);
675691 ksys_chroot(".");
676692 }
677693

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t