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
3325}3325}
3326EXPORT_SYMBOL(mount_subtree);3326EXPORT_SYMBOL(mount_subtree);
3327 3327
3328int ksys_mount(const char __user *dev_name, const char __user *dir_name,3328SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
3329 const char __user *type, unsigned long flags, void __user *data)3329 char __user *, type, unsigned long, flags, void __user *, data)
3330{3330{
3331 int ret;3331 int ret;
3332 char *kernel_type;3332 char *kernel_type;
@@ -3359,12 +3359,6 @@ out_type: · 26 unmodified lines
3359 return ret;3359 return ret;
3360}3360}
3361 3361
3362SYSCALL_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
3368/*3362/*
3369 * Create a kernel mount representation for a new, prepared superblock3363 * Create a kernel mount representation for a new, prepared superblock
3370 * (specified by fs_fd) and attach to an open_tree-like file descriptor.3364 * (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
1231 * the ksys_xyzyyz() functions prototyped below.1231 * the ksys_xyzyyz() functions prototyped below.
1232 */1232 */
1233 1233
1234int ksys_mount(const char __user *dev_name, const char __user *dir_name,
1235 const char __user *type, unsigned long flags, void __user *data);
1236int ksys_umount(char __user *name, int flags);1234int ksys_umount(char __user *name, int flags);
1237int ksys_dup(unsigned int fildes);1235int ksys_dup(unsigned int fildes);
1238int ksys_chroot(const char __user *filename);1236int 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
387 *s = '\0';387 *s = '\0';
388}388}
389 389
390static int __init do_mount_root(char *name, char *fs, int flags, void *data)390static int __init do_mount_root(const char *name, const char *fs,
391 const int flags, const void *data)
391{392{
392 struct super_block *s;393 struct super_block *s;
393 int err = ksys_mount(name, "/root", fs, flags, data);394 char *data_page;
394 if (err)395 struct page *p;
395 return err;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;
396 409
397 ksys_chdir("/root");410 ksys_chdir("/root");
398 s = current->fs->pwd.dentry->d_sb;411 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
402 s->s_type->name,415 s->s_type->name,
403 sb_rdonly(s) ? " readonly" : "",416 sb_rdonly(s) ? " readonly" : "",
404 MAJOR(ROOT_DEV), MINOR(ROOT_DEV));417 MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
405 return 0;418
419out:
420 put_page(p);
421 return ret;
406}422}
407 423
408void __init mount_block_root(char *name, int flags)424void __init mount_block_root(char *name, int flags)
@@ -671,7 +687,7 @@ void __init prepare_namespace(void) · 262 unmodified lines
671 mount_root();687 mount_root();
672out:688out:
673 devtmpfs_mount();689 devtmpfs_mount();
674 ksys_mount(".", "/", NULL, MS_MOVE, NULL);690 do_mount(".", "/", NULL, MS_MOVE, NULL);
675 ksys_chroot(".");691 ksys_chroot(".");
676}692}
677 693

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