init/do_mounts.c: replace sys_mount() to do_mount()
PATCH 1/1 init/do_mounts.c: replace sys_mount() to do_mount()
sys_mount() just copies all (string) arguments from user space to kernel and calls do_mount(). In this case we have all args in kernel already so there is no need to call sys_mount(). One thing we should take care is 'data' have to be in a page unless it is NULL. Do it manually.
--- init/do_mounts.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)
init/do_mounts.c +16 -2
@@ -217,7 +217,21 @@ static void __init get_fs_names(char *page)static int __init do_mount_root (char *name,char *fs,int flags,void *data) { -int err =sys_mount (name,"/root" , fs, flags, data); +int err; +unsigned long data_page =0 ; + +if (data) { +/* data should be in a page */ + data_page =__get_free_page (GFP_KERNEL ); +if (!data_page) +return -ENOMEM ; +strlcpy ((char *) data_page, data,PAGE_SIZE ); + } + + err =do_mount (name,"/root" , fs, flags, (void *) data_page); + +if (data_page) +free_page (data_page);if (err)return err;
@@ -417,6 +431,6 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount ("dev" ); -sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );sys_chroot ("." ); }
Signature · 1 line
1.7.0.4
Quoted 8 lines · Namhyung Kim
static int
__initdo_mount_root(char *name, char *fs, int flags, void *data){init/do_mounts.c +5
-1-int err =sys_mount (name,"/root" , fs, flags, data); +int err; +unsigned long data_page =0 ; + +if (data) { +/* data should be in a page */
init/do_mounts.c static void __init get_fs_names(char *page) · line 234
Quoted 10 lines
init/do_mounts.c +10
-0+ data_page =__get_free_page (GFP_KERNEL ); +if (!data_page) +return -ENOMEM ; +strlcpy ((char *) data_page, data,PAGE_SIZE ); + } + + err =do_mount (name,"/root" , fs, flags, (void *) data_page); + +if (data_page) +free_page (data_page);
AFAICT there is no need for the copy at all here. The reason that sys_mount copies to a separate page is that it gets passed an arbitrary-length user input.
Arnd
2010-08-17 (화), 15:15 +0200, Arnd Bergmann:
Quoted 5 lines
AFAICT there is no need for the copy at all here. The reason that
sys_mountcopies to a separate page is that it gets passed an arbitrary-length user input.Arnd
Right. But make sure to user options never exceed a page, do_mount() has following code:
if (data_page) ((char *)data_page)[PAGE_SIZE - 1] = 0;
Signature · 2 lines
Regards, Namhyung Kim
Quoted 10 lines · Namhyung Kim
2010-08-17 (화), 15:15 +0200, Arnd Bergmann:
Quoted 3 lines
AFAICT there is no need for the copy at all here. The reason that
sys_mountcopies to a separate page is that it gets passed an arbitrary-length user input.Right. But make sure to user options never exceed a page,
do_mount()has following code:if (data_page) ((char *)data_page)[PAGE_SIZE - 1] = 0;
Hmm, how very unexpected...
Maybe you can fix that as well in the same patch and move this safeguard into the copy_mount_options() function? I guess ideally we'd even mark the arguments to do_mount() as pointers to const, but that might create an excessive amount of churn.
Arnd
PATCH v2 1/1 init: replace sys_mount() to do_mount()
sys_mount() just copies all (string) arguments from user space to kernel and calls do_mount(). In this case we have all args in kernel already so there is no need to call sys_mount(). One thing we should take care is 'data' have to be in a page unless it is NULL. Do it manually.
---
I found 3 more calls in init/do_mounts_initrd.c and merged them. Please apply this instead.
2010-08-17 (Tue), 15:41 +0200, Arnd Bergmann:
Quoted 4 lines
Maybe you can fix that as well in the same patch and move this safeguard into the
copy_mount_options()function? I guess ideally we'd even mark the arguments todo_mount()as pointers to const, but that might create an excessive amount of churn.
Arnd, thanks for reviewing and the suggestion but I think that should be in a different patch (set).
init/do_mounts.c | 18 ++++++++++++++++-- init/do_mounts_initrd.c | 6 +++--- 2 files changed, 19 insertions(+), 5 deletions(-)
init/do_mounts.c +16 -2
@@ -217,7 +217,21 @@ static void __init get_fs_names(char *page)static int __init do_mount_root (char *name,char *fs,int flags,void *data) { -int err =sys_mount (name,"/root" , fs, flags, data); +int err; +unsigned long data_page =0 ; + +if (data) { +/* data should be in a page */ + data_page =__get_free_page (GFP_KERNEL ); +if (!data_page) +return -ENOMEM ; +strlcpy ((char *) data_page, data,PAGE_SIZE ); + } + + err =do_mount (name,"/root" , fs, flags, (void *) data_page); + +if (data_page) +free_page (data_page);if (err)return err;
@@ -417,6 +431,6 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount ("dev" ); -sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );sys_chroot ("." ); }
init/do_mounts_initrd.c +3 -3
@@ -48,7 +48,7 @@ static void __init handle_initrd(void) old_fd =sys_open ("/old" ,0 ,0 );/* move initrd over / and chdir/chroot in initrd root */ sys_chdir ("/root" ); -sys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );sys_chroot ("." );/*
@@ -66,7 +66,7 @@ static void __init handle_initrd(void)/* move initrd to rootfs' /old */ sys_fchdir (old_fd); -sys_mount ("/" ,"." ,NULL ,MS_MOVE ,NULL ); +do_mount ("/" ,"." ,NULL ,MS_MOVE ,NULL );/* switch root and cwd back to / of rootfs */ sys_fchdir (root_fd);sys_chroot ("." );
@@ -82,7 +82,7 @@ static void __init handle_initrd(void)mount_root ();printk (KERN_NOTICE "Trying to move old root to /initrd ... " ); - error =sys_mount ("/old" ,"/root/initrd" ,NULL ,MS_MOVE ,NULL ); + error =do_mount ("/old" ,"/root/initrd" ,NULL ,MS_MOVE ,NULL );if (!error)printk ("okay\n" );else {
--
1.7.0.4