use do_mount() instead of ksys_mount()
Subsystems (3)
cover use do_mount() instead of ksys_mount()
This small series replaces all in-kernel calls to the userspace-focused wrapper ksys_mount() with calls to the kernel-centric do_mount().
For each replacement, one needs to verify that the first and third parameter (char *dev_name, char *type) are strings allocated in kernelspace and that the fifth parameter (void *data) is either NULL or refers to a full page (only occurence in init/do_mounts.c::do_mount_root()). The second and fourth parameters (char *dir_name, unsigned long flags) are passed by ksys_mount() to do_mount() unchanged, and therefore do not require particular care.
---
@viro: is this something for you to take and push upstream for the next cycle?
The same changes (on top of commit ae4b064e2a616b545acf02b8f50cc513b32c7522:
Merge tag 'afs-fixes-20191211' of git://git.kernel.org/pub/scm/linux/kernel/git/dhowells/linux-fs (2019-12-11 18:10:40 -0800)
are also available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux.git remove-ksys-mount
including all changes up to cccaa5e33525fc07f4a2ce0518e50b9ddf435e47:
init: use do_mount() instead of ksys_mount() (2019-12-12 14:50:05 +0100)
----------------------------------------------------------------
Dominik Brodowski (3):
devtmpfs: use do_mount() instead of ksys_mount()
initrd: use do_mount() instead of ksys_mount()
init: use do_mount() instead of ksys_mount()
drivers/base/devtmpfs.c | 6 +++--- fs/namespace.c | 10 ++-------- include/linux/device.h | 4 ++-- include/linux/syscalls.h | 2 -- init/do_mounts.c | 30 +++++++++++++++++++++++------- init/do_mounts_initrd.c | 6 +++--- 6 files changed, 33 insertions(+), 25 deletions(-)
Thanks,
Dominik
Signature · 1 line
2.24.1
PATCH 1/3 devtmpfs: use do_mount() instead of ksys_mount()
In devtmpfs, do_mount() can be called directly instead of complex wrapping by ksys_mount():
- the first and third arguments are const strings in the kernel, and do not need to be copied over from userspace;
- the fifth argument is NULL, and therefore no page needs to be copied over from userspace;
- the second and fourth argument are passed through anyway.
--- drivers/base/devtmpfs.c | 6 +++--- include/linux/device.h | 4 ++-- init/do_mounts.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/base/devtmpfs.c +3 -3
@@ -359,7 +359,7 @@ static int handle_remove(const char *nodename, struct device *dev)* If configured, or requested by the commandline, devtmpfs will be * auto-mounted after the kernel mounted the root filesystem. */ -int devtmpfs_mount (const char *mntdir) +int devtmpfs_mount (void ) {int err;
@@ -369,7 +369,7 @@ int devtmpfs_mount(const char *mntdir)if (!thread)return 0 ; - err =ksys_mount ("devtmpfs" , mntdir,"devtmpfs" ,MS_SILENT ,NULL ); + err =do_mount ("devtmpfs" ,"dev" ,"devtmpfs" ,MS_SILENT ,NULL );if (err)printk (KERN_INFO "devtmpfs: error mounting %i\n" , err);else
@@ -394,7 +394,7 @@ static int devtmpfsd(void *p) *err =ksys_unshare (CLONE_NEWNS );if (*err) goto out; - *err =ksys_mount ("devtmpfs" ,"/" ,"devtmpfs" ,MS_SILENT ,NULL ); + *err =do_mount ("devtmpfs" ,"/" ,"devtmpfs" ,MS_SILENT ,NULL );if (*err) goto out;ksys_chdir ("/.." );/* will traverse into overmounted root */
include/linux/device.h +2 -2
@@ -1666,11 +1666,11 @@ extern bool kill_device(struct device *dev);#ifdef CONFIG_DEVTMPFS extern int devtmpfs_create_node (struct device *dev);extern int devtmpfs_delete_node (struct device *dev); -extern int devtmpfs_mount (const char *mntdir); +extern int devtmpfs_mount (void );#else static inline int devtmpfs_create_node (struct device *dev) {return 0 ; }static inline int devtmpfs_delete_node (struct device *dev) {return 0 ; } -static inline int devtmpfs_mount (const char *mountpoint) {return 0 ; } +static inline int devtmpfs_mount (void ) {return 0 ; }#endif /* drivers/base/power/shutdown.c */
init/do_mounts.c +1 -1
@@ -670,7 +670,7 @@ void __init prepare_namespace(void)mount_root (); out: -devtmpfs_mount ("dev" ); +devtmpfs_mount ();ksys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );ksys_chroot ("." ); }
Signature · 1 line
2.24.1
PATCH 2/3 initrd: use do_mount() instead of ksys_mount()
In reply to Dominik BrodowskiAll three calls to ksys_mount() in initrd-related kernel code can be switched over to do_mount():
- the first and third arguments are const strings in the kernel, and do not need to be copied over from userspace;
- the fifth argument is NULL, and therefore no page needs to be, copied over from userspace;
- the second and fourth argument are passed through anyway.
--- init/do_mounts_initrd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
init/do_mounts_initrd.c +3 -3
@@ -54,7 +54,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)ksys_dup (0 );/* move initrd over / and chdir/chroot in initrd root */ ksys_chdir ("/root" ); -ksys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );ksys_chroot ("." );ksys_setsid ();return 0 ;
@@ -89,7 +89,7 @@ static void __init handle_initrd(void) current->flags &= ~PF_FREEZER_SKIP ;/* move initrd to rootfs' /old */ -ksys_mount (".." ,"." ,NULL ,MS_MOVE ,NULL ); +do_mount (".." ,"." ,NULL ,MS_MOVE ,NULL );/* switch root and cwd back to / of rootfs */ ksys_chroot (".." );
@@ -103,7 +103,7 @@ static void __init handle_initrd(void)mount_root ();printk (KERN_NOTICE "Trying to move old root to /initrd ... " ); - error =ksys_mount ("/old" ,"/root/initrd" ,NULL ,MS_MOVE ,NULL ); + error =do_mount ("/old" ,"/root/initrd" ,NULL ,MS_MOVE ,NULL );if (!error)printk ("okay\n" );else {
Signature · 1 line
2.24.1
PATCH 3/3 init: use do_mount() instead of ksys_mount()
In reply to Dominik BrodowskiIn 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.
--- fs/namespace.c | 10 ++-------- include/linux/syscalls.h | 2 -- init/do_mounts.c | 28 ++++++++++++++++++++++------ 3 files changed, 24 insertions(+), 16 deletions(-)
fs/namespace.c +2 -8
@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name) }EXPORT_SYMBOL (mount_subtree); -int ksys_mount (const char __user *dev_name,const char __user *dir_name, -const char __user *type,unsigned long flags,void __user *data) +SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, + char __user *, type, unsigned long, flags, void __user *, data) {int ret;char *kernel_type;
@@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name,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 * (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);* 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_dup (unsigned int fildes);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) *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; -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); +strncpy (data_page, data,PAGE_SIZE -1 ); + + ret =do_mount (name,"/root" , fs, flags, data_page); +if (ret) + goto out;ksys_chdir ("/root" ); 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) 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)
@@ -671,7 +687,7 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount (); -ksys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );ksys_chroot ("." ); }
Signature · 1 line
2.24.1
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Hello,
Quoted 81 lines · Dominik Brodowski
In
prepare_namespace(),do_mount()can be used instead ofksys_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 todo_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 ofksys_mount().Once this is done, there are no in-kernel users to
ksys_mount()left, which can therefore be removed.Signed-off-by Dominik Brodowski <[email protected]>--- fs/namespace.c | 10 ++-------- include/linux/syscalls.h | 2 -- init/do_mounts.c | 28 ++++++++++++++++++++++------ 3 files changed, 24 insertions(+), 16 deletions(-)fs/namespace.c +2
-8@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name) }EXPORT_SYMBOL (mount_subtree); -int ksys_mount (const char __user *dev_name,const char __user *dir_name, -const char __user *type,unsigned long flags,void __user *data) +SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, + char __user *, type, unsigned long, flags, void __user *, data) {int ret;char *kernel_type;@@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name,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 * (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);* 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_dup (unsigned int fildes);int ksys_chroot (const char __user *filename);init/do_mounts.c +3
-4@@ -387,12 +387,25 @@ static void __init get_fs_names(char *page) *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; -int err =ksys_mount (name,"/root" , fs, flags, data); -if (err) -return err; +char *data_page;
init/do_mounts.c static void __init get_fs_names(char *page) · line 404
Quoted 10 lines
init/do_mounts.c +10
-0+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); +strncpy (data_page, data,PAGE_SIZE -1 );
I tried 5.2-rc2 and I get kernel OOPS/panic here (do_mount_root gets inlined into mount_block_root):
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
Mem abort info:
ESR = 0x96000005
EC = 0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS = 0x00000005
CM = 0, WnR = 0
[0000000000000000] user address but active_mm is swapper
Internal error: Oops: 96000005 [#1] SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.5.0-rc2-00128-ge93c94cc04ae #5 Hardware name: OrangePi 3 (DT) pstate: 80000005 (Nzcv daif -PAN -UAO) pc : strncpy+0x10/0x30 lr : do_mount_root+0x70/0x114
sp : ffffffc01002bd20
x29: ffffffc01002bd20 x28: 0000000000000000
x27: 0000000000000000 x26: ffffffc011400468
x25: ffffffc0110d23a0 x24: ffffffff01c396c0
x23: 0000000000008000 x22: ffffff8078e5b000
x21: ffffffc0110d23a0 x20: ffffffc0110d2220
x19: ffffffff01c39700 x18: 00000000fffffffe
x17: 00000000dbaba8be x16: 0000000000000000
x15: ffffffffffffffff x14: ffffff0000000000
x13: ffffff807b490000 x12: 0000000000000000
x11: 0000000000000000 x10: ffffff807bb96120
x9 : 0000000000000000 x8 : 0000000000000000
x7 : ffffffc06a6e6000 x6 : 0000000000000000
x5 : 000000000003b820 x4 : ffffff8078e5cfff
x3 : 0000000000000201 x2 : ffffff8078e5c000
x1 : 0000000000000000 x0 : ffffff8078e5c000
Call trace: strncpy+0x10/0x30 mount_block_root+0x100/0x224 mount_root+0x10c/0x124 prepare_namespace+0x12c/0x168 kernel_init_freeable+0x214/0x258 kernel_init+0x10/0xfc ret_from_fork+0x10/0x1c Code: b4000142 8b020004 aa0003e2 d503201f (39400023) ---[ end trace b72d58d1ea940426 ]--- Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000b
SMP: stopping secondary CPUs
Kernel Offset: disabled
CPU features: 0x00002,20002000
Memory Limit: none
Rebooting in 3 seconds..
regards,
o.
Quoted 30 lines
init/do_mounts.c +8
-2+ ret =do_mount (name,"/root" , fs, flags, data_page); +if (ret) + goto out;ksys_chdir ("/root" ); 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) 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)@@ -671,7 +687,7 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount (); -ksys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );ksys_chroot ("." ); }Signature · 1 line
2.24.1
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Quoted 89 lines · megi xff
Hello,
Quoted 86 lines · Dominik Brodowski
In
prepare_namespace(),do_mount()can be used instead ofksys_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 todo_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 ofksys_mount().Once this is done, there are no in-kernel users to
ksys_mount()left, which can therefore be removed.Signed-off-by Dominik Brodowski <[email protected]>--- fs/namespace.c | 10 ++-------- include/linux/syscalls.h | 2 -- init/do_mounts.c | 28 ++++++++++++++++++++++------ 3 files changed, 24 insertions(+), 16 deletions(-)fs/namespace.c +2
-8@@ -3325,8 +3325,8 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name) }EXPORT_SYMBOL (mount_subtree); -int ksys_mount (const char __user *dev_name,const char __user *dir_name, -const char __user *type,unsigned long flags,void __user *data) +SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name, + char __user *, type, unsigned long, flags, void __user *, data) {int ret;char *kernel_type;@@ -3359,12 +3359,6 @@ int ksys_mount(const char __user *dev_name, const char __user *dir_name,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 * (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);* 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_dup (unsigned int fildes);int ksys_chroot (const char __user *filename);init/do_mounts.c +8
-4@@ -387,12 +387,25 @@ static void __init get_fs_names(char *page) *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; -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 );
Quoted 8 lines
init/do_mounts.c static void __init get_fs_names(char *page) · line 404
Quoted 5 lines
init/do_mounts.c +5
-0+if (!p) +return -ENOMEM ; + + data_page =page_address (p); +strncpy (data_page, data,PAGE_SIZE -1 );I tried 5.2-rc2 and I get kernel OOPS/panic here (
do_mount_rootgets inlined intomount_block_root):
5.5-rc2 of course. :)
Quoted 83 lines
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000Mem abort info:
ESR =0x96000005
EC =0x25: DABT (current EL), IL = 32 bits SET = 0, FnV = 0
EA = 0, S1PTW = 0
Data abort info:
ISV = 0, ISS =0x00000005
CM = 0, WnR = 0
[0000000000000000] user address butactive_mmis swapperInternal error: Oops: 96000005 [#1] SMP Modules linked in: CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.5.0-rc2-00128-ge93c94cc04ae #5 Hardware name: OrangePi 3 (DT) pstate: 80000005 (Nzcv daif -PAN -UAO) pc : strncpy+0x10/0x30 lr : do_mount_root+0x70/0x114sp :
ffffffc01002bd20
x29:ffffffc01002bd20x28: 0000000000000000
x27: 0000000000000000 x26:ffffffc011400468
x25:ffffffc0110d23a0x24:ffffffff01c396c0
x23: 0000000000008000 x22:ffffff8078e5b000
x21:ffffffc0110d23a0x20:ffffffc0110d2220
x19:ffffffff01c39700x18:00000000fffffffe
x17:00000000dbaba8bex16: 0000000000000000
x15: ffffffffffffffff x14:ffffff0000000000
x13:ffffff807b490000x12: 0000000000000000
x11: 0000000000000000 x10:ffffff807bb96120
x9 : 0000000000000000 x8 : 0000000000000000
x7 :ffffffc06a6e6000x6 : 0000000000000000
x5 :000000000003b820x4 :ffffff8078e5cfff
x3 : 0000000000000201 x2 :ffffff8078e5c000
x1 : 0000000000000000 x0 :ffffff8078e5c000Call trace: strncpy+0x10/0x30 mount_block_root+0x100/0x224 mount_root+0x10c/0x124 prepare_namespace+0x12c/0x168 kernel_init_freeable+0x214/0x258 kernel_init+0x10/0xfc ret_from_fork+0x10/0x1c Code: b4000142 8b020004 aa0003e2 d503201f (39400023) ---[ end trace b72d58d1ea940426 ]--- Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000000bSMP: stopping secondary CPUs
Kernel Offset: disabled
CPU features: 0x00002,20002000
Memory Limit: none
Rebooting in 3 seconds..regards,
o.Quoted 30 lines
init/do_mounts.c +8
-2+ ret =do_mount (name,"/root" , fs, flags, data_page); +if (ret) + goto out;ksys_chdir ("/root" ); 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) 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)@@ -671,7 +687,7 @@ void __init prepare_namespace(void)mount_root (); out:devtmpfs_mount (); -ksys_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL ); +do_mount ("." ,"/" ,NULL ,MS_MOVE ,NULL );ksys_chroot ("." ); }Signature · 1 line
2.24.1
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
In reply to Ondřej JirmanQuoted 2 lines · Ondřej Jirman
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000
Duh. So much for the trivial obvious conversion.
It didn't take "data might be NULL" into account.
A patch like this, perhaps? Untested..
Linus
init/do_mounts.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
init/do_mounts.c +13 -10
@@ -391,17 +391,19 @@ static int __init do_mount_root(const char *name, const char *fs, const int flags, const void *data) { struct super_block *s; -char *data_page; -struct page *p; +struct page *p =NULL ; +char *data_page =NULL ;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 ); +if (data) { +/* 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 ); + data_page[PAGE_SIZE -1 ] ='\0' ; + } ret =do_mount (name,"/root" , fs, flags, data_page);if (ret)
@@ -417,7 +419,8 @@ static int __init do_mount_root(const char *name, const char *fs, MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); out: -put_page (p); +if (p) +put_page (p);return ret; }
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Quoted 49 lines · Linus Torvalds
Quoted 2 lines · Ondřej Jirman
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000Duh. So much for the trivial obvious conversion.
It didn't take "data might be NULL" into account.
A patch like this, perhaps? Untested..
Linus
init/do_mounts.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)init/do_mounts.c +11
-9@@ -391,17 +391,19 @@ static int __init do_mount_root(const char *name, const char *fs, const int flags, const void *data) { struct super_block *s; -char *data_page; -struct page *p; +struct page *p =NULL ; +char *data_page =NULL ;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 ); +if (data) { +/* 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 ); + data_page[PAGE_SIZE -1 ] ='\0' ; + } ret =do_mount (name,"/root" , fs, flags, data_page);if (ret)
init/do_mounts.c static int __init do_mount_root(const char *name, const char *fs, · line 424
Quoted 7 lines
init/do_mounts.c +2
-1@@ -417,7 +419,8 @@ static int __init do_mount_root(const char *name, const char *fs, MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); out: -put_page (p); +if (p) +put_page (p);return ret;
I'm seeing the boot crash too, and Linus' patch fixes it.
Note that adding the line
data_page[PAGE_SIZE - 1] = '\0';
is not necessary since do_mount() already does it.
- Eric
Geert Uytterhoeven
Tested-byRe: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Hi all,
Quoted 44 lines · Eric Biggers
Quoted 43 lines · Linus Torvalds
Quoted 1 line · Ondřej Jirman
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000Duh. So much for the trivial obvious conversion.
It didn't take "data might be NULL" into account.
A patch like this, perhaps? Untested..
init/do_mounts.c +11
-9@@ -391,17 +391,19 @@ static int __init do_mount_root(const char *name, const char *fs, const int flags, const void *data) { struct super_block *s; -char *data_page; -struct page *p; +struct page *p =NULL ; +char *data_page =NULL ;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 ); +if (data) { +/* 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 ); + data_page[PAGE_SIZE -1 ] ='\0' ; + } ret =do_mount (name,"/root" , fs, flags, data_page);if (ret)@@ -417,7 +419,8 @@ static int __init do_mount_root(const char *name, const char *fs, MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
Quoted 7 lines
init/do_mounts.c static int __init do_mount_root(const char *name, const char *fs, · line 424
Quoted 5 lines
init/do_mounts.c +2
-1out: -put_page (p); +if (p) +put_page (p);return ret;I'm seeing the boot crash too, and Linus' patch fixes it.
#metoo ;-)
Quoted 5 lines
Note that adding the line
data_page[PAGE_SIZE - 1] = '\0';is not necessary since
do_mount()already does it.
Indeed. So the "-1" can be dropped from the strncpy() call, which brings it even more in-line with the "full page" comment.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
In reply to Linus TorvaldsQuoted 11 lines · Linus Torvalds
Quoted 2 lines · Ondřej Jirman
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000Duh. So much for the trivial obvious conversion.
It didn't take "data might be NULL" into account.
A patch like this, perhaps? Untested..
Linus
That one must be a record.
Qemu test results:
total: 387 pass: 93 fail: 294
For my education, what is so bad with calls like ksys_mount() that warrants the extra code needed to remove it (and, of course, the resulting breakage) ?
Thanks,
Guenter
Guido Günther
Tested-byRe: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
In reply to Linus TorvaldsHi,
Quoted 20 lines · Linus Torvalds
Quoted 2 lines · Ondřej Jirman
Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000Duh. So much for the trivial obvious conversion.
It didn't take "data might be NULL" into account.
A patch like this, perhaps? Untested..
Linus
init/do_mounts.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)init/do_mounts.c +0
-0
init/do_mounts.c static int __init do_mount_root(const char *name, const char *fs, · line 395
Quoted 7 lines
init/do_mounts.c +2
-2@@ -391,17 +391,19 @@ static int __init do_mount_root(const char *name, const char *fs, const int flags, const void *data) { struct super_block *s; -char *data_page; -struct page *p; +struct page *p =NULL ; +char *data_page =NULL ;
n> int ret;
Quoted 21 lines
init/do_mounts.c +9
-7-/* 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 ); +if (data) { +/* 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 ); + data_page[PAGE_SIZE -1 ] ='\0' ; + } ret =do_mount (name,"/root" , fs, flags, data_page);if (ret)
init/do_mounts.c static int __init do_mount_root(const char *name, const char *fs, · line 426
Quoted 9 lines
init/do_mounts.c +2
-1@@ -417,7 +419,8 @@ static int __init do_mount_root(const char *name, const char *fs, MAJOR(ROOT_DEV), MINOR(ROOT_DEV)); out: -put_page (p); +if (p) +put_page (p);return ret; }
This unbroke tftpboot on arm64 on next-20191216 for me as well:
Cheers,
-- Guido
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
In reply to Dominik BrodowskiShouldn't patches bake for a while in -next? (That way we catch regressions before they hit mainline?)
This lit up our CI this morning.
https://travis-ci.com/ClangBuiltLinux/continuous-integration/builds
(Apologies for missing context, replying via lore.kernel.org directions.)
https://lore.kernel.org/lkml/[email protected]/
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Quoted 9 lines · Nick Desaulniers
Shouldn't patches bake for a while in -next? (That way we catch regressions before they hit mainline?)
This lit up our CI this morning.
https://travis-ci.com/ClangBuiltLinux/continuous-integration/builds
(Apologies for missing context, replying via lore.kernel.org directions.)
https://lore.kernel.org/lkml/[email protected]/
A fix for this issue is already upstream, 7de7de7ca0ae .
Thanks,
Dominik
Re: [PATCH 3/3] init: use do_mount() instead of ksys_mount()
Quoted 5 lines · Dominik Brodowski
Quoted 3 lines · Nick Desaulniers
Shouldn't patches bake for a while in -next? (That way we catch regressions before they hit mainline?)
Quoted 8 lines
Quoted 6 lines
This lit up our CI this morning.
https://travis-ci.com/ClangBuiltLinux/continuous-integration/builds
(Apologies for missing context, replying via lore.kernel.org directions.)
https://lore.kernel.org/lkml/[email protected]/A fix for this issue is already upstream,
7de7de7ca0ae.
I appreciate that. I was just surprised to have no advanced notice; -next is our "canary in the coalmine." Mainline is usually pretty stable; if it goes red then we're missing testing coverage somewhere. For mainline to break suddenly implies that either a pull was merged from a branch that wasn't flowing into -next, or someone got [un]lucky with the merge window, or something worse. I saw -next failed the same day as mainline for the same reason, so I'm going to give you the benefit of the doubt and chalk it up to luck with timing of the merge window.
In the future, please give patches more time to soak in -next. We expect -next to be noisy, mainline not so much.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 4 lines · Dominik Brodowski
This small series replaces all in-kernel calls to the userspace-focused wrapper
ksys_mount()with calls to the kernel-centricdo_mount().
If you fix the pointless cast I pointed out, and put it in a git branch, I'll pull it.
In fact, just do both series in the same branch, they do conceptually the same thing, after all.
Linus
Al Viro
maintainerQuoted 7 lines · Linus Torvalds
Quoted 4 lines · Dominik Brodowski
This small series replaces all in-kernel calls to the userspace-focused wrapper
ksys_mount()with calls to the kernel-centricdo_mount().
Quoted 5 lines
If you fix the pointless cast I pointed out, and put it in a git branch, I'll pull it.
In fact, just do both series in the same branch, they do conceptually the same thing, after all.
IMO it's not a good idea. Exposing the guts of fs/namespace.c to what's essentially a userland code that happens to run in kernel thread is asking for trouble - we'd been there and it had been hell to untangle.