From 6dcfbd35bdda9b51f59d7e9dcd70509fb6709910 Mon Sep 17 00:00:00 2001 From: Dominik Brodowski Date: Thu, 12 Dec 2019 14:57:24 +0100 Subject: [PATCH] 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. Change-Id: Ie21248b26e4a98796e092e20c9b8cb8126dc5eee Signed-off-by: Dominik Brodowski Patch-mainline: linux-kernel@vger.kernel.org @ 12/12/2019, 14:57 [pragalla@codeaurora.org:fix merge conflicts and port changes to 5.4 kernel] Signed-off-by: Pradeep P V K --- init/do_mounts.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/init/do_mounts.c b/init/do_mounts.c index 9634ecf3743d..871dbc3e9cb5 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -386,9 +386,21 @@ static void __init get_fs_names(char *page) static int __init do_mount_root(char *name, char *fs, int flags, void *data) { struct super_block *s; - int err = ksys_mount(name, "/root", fs, flags, data); - if (err) - return err; + char *data_page; + struct page *p; + 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); + strscpy(data_page, data, PAGE_SIZE - 1); + + ret = ksys_mount(name, "/root", fs, flags, data_page); + if (ret) + goto out; ksys_chdir("/root"); s = current->fs->pwd.dentry->d_sb; @@ -398,7 +410,10 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data) s->s_type->name, sb_rdonly(s) ? " readonly" : "", MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); - return 0; + +out: + put_page(p); + return ret; } void __init mount_block_root(char *name, int flags)