From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:40
Hi Al and Linus,
currently a lot of the file system calls in the early in code (and the
devtmpfs kthread) rely on the implicit set_fs(KERNEL_DS) during boot.
This is one of the few last remaining places we need to deal with to kill
off set_fs entirely, so this series adds new helpers that take kernel
pointers. These helpers are in init/ and marked __init and thus will
be discarded after bootup. A few also need to be duplicated in devtmpfs,
though unfortunately.
The series sits on top of my previous
"decruft the early init / initrd / initramfs code v2"
series.
Git tree:
git://git.infradead.org/users/hch/misc.git init_path
Gitweb:
http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/init_path
Changes since v1:
- avoid most core VFS changes
- renamed the functions and move them to init/ and devtmpfs
- drop a bunch of cleanups that can be submitted independently now
Diffstat:
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:28:32
devtmpfs is the only non-early init caller of ksys_chdir and ksys_chroot
with kernel pointers. Just open code the two operations which only
really need a single path lookup anyway in devtmpfs_setup instead.
The open coded verson doesn't need any of the stale dentry revalidation
logic from the full blown version as those can't happen on tmpfs and
ramfs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/base/devtmpfs.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
@@ -401,8 +403,16 @@ static int devtmpfs_setup(void *p)err=devtmpfs_do_mount("/");if(err)gotoout;-ksys_chdir("/..");/* will traverse into overmounted root */-ksys_chroot(".");++/* traverse into overmounted root and then chroot to it */+if(!kern_path("/..",LOOKUP_FOLLOW|LOOKUP_DIRECTORY,&path)&&+!inode_permission(path.dentry->d_inode,MAY_EXEC|MAY_CHDIR)&&+ns_capable(current_user_ns(),CAP_SYS_CHROOT)&&+!security_path_chroot(&path)){+set_fs_pwd(current->fs,&path);+set_fs_root(current->fs,&path);+}+path_put(&path);out:*(int*)p=err;complete(&setup_done);
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:28:42
Replace ksys_umount with an open coded version that takes the proper
kernel pointer instead of relying on the implicit set_fs(KERNEL_DS)
during early init.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/namespace.c | 4 ++--
include/linux/mount.h | 1 +
include/linux/syscalls.h | 1 -
init/do_mounts_initrd.c | 6 +++++-
4 files changed, 8 insertions(+), 4 deletions(-)
@@ -117,12 +118,15 @@ static void __init handle_initrd(void)if(!error)printk("okay\n");else{+structpathpath;+if(error==-ENOENT)printk("/initrd does not exist. Ignored.\n");elseprintk("failed\n");printk(KERN_NOTICE"Unmounting old root\n");-ksys_umount("/old",MNT_DETACH);+if(!kern_path("/old",LOOKUP_MOUNTPOINT,&path))+path_umount(&path,MNT_DETACH);}}
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:28:46
Add a simple helper to unlink with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_unlink.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/syscalls.h | 7 -------
init/do_mounts.h | 3 ++-
init/do_mounts_initrd.c | 4 ++--
init/do_mounts_rd.c | 2 +-
init/fs.c | 6 ++++++
init/initramfs.c | 3 ++-
6 files changed, 13 insertions(+), 12 deletions(-)
@@ -1273,13 +1273,6 @@ int compat_ksys_ipc(u32 call, int first, int second,*Thefollowingkernelsyscallequivalentsarejustwrapperstofs-internal*functions.Therefore,providestubstobeinlinedatthecallsites.*/-externlongdo_unlinkat(intdfd,structfilename*name);--staticinlinelongksys_unlink(constchar__user*pathname)-{-returndo_unlinkat(AT_FDCWD,getname(pathname));-}-longdo_rmdir(intdfd,structfilename*name);staticinlinelongksys_rmdir(constchar__user*pathname)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:28:53
Add a simple helper to chroot with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_chroot.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/open.c | 7 +------
include/linux/syscalls.h | 2 --
init/do_mounts.c | 2 +-
init/do_mounts.h | 1 +
init/do_mounts_initrd.c | 4 ++--
init/fs.c | 23 +++++++++++++++++++++++
6 files changed, 28 insertions(+), 11 deletions(-)
@@ -64,7 +64,7 @@ static int __init init_linuxrc(struct subprocess_info *info, struct cred *new)/* move initrd over / and chdir/chroot in initrd root */init_chdir("/root");init_mount(".","/",NULL,MS_MOVE,NULL);-ksys_chroot(".");+init_chroot(".");ksys_setsid();return0;}
@@ -102,7 +102,7 @@ static void __init handle_initrd(void)/* move initrd to rootfs' /old */init_mount("..",".",NULL,MS_MOVE,NULL);/* switch root and cwd back to / of rootfs */-ksys_chroot("..");+init_chroot("..");if(new_decode_dev(real_root_dev)==Root_RAM0){init_chdir("/old");
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:28:55
Add a simple helper to chdir with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_chdir.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/open.c | 7 +------
include/linux/syscalls.h | 1 -
init/do_mounts.c | 2 +-
init/do_mounts.h | 1 +
init/do_mounts_initrd.c | 8 ++++----
init/fs.c | 16 ++++++++++++++++
6 files changed, 23 insertions(+), 12 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:04
Add a simple helper to rmdir with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_rmdir.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/syscalls.h | 7 -------
init/do_mounts.h | 1 +
init/fs.c | 5 +++++
init/initramfs.c | 2 +-
4 files changed, 7 insertions(+), 8 deletions(-)
@@ -1273,13 +1273,6 @@ int compat_ksys_ipc(u32 call, int first, int second,*Thefollowingkernelsyscallequivalentsarejustwrapperstofs-internal*functions.Therefore,providestubstobeinlinedatthecallsites.*/-longdo_rmdir(intdfd,structfilename*name);--staticinlinelongksys_rmdir(constchar__user*pathname)-{-returndo_rmdir(AT_FDCWD,getname(pathname));-}-externlongdo_mkdirat(intdfd,constchar__user*pathname,umode_tmode);staticinlinelongksys_mkdir(constchar__user*pathname,umode_tmode)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:12
Add a simple helper to check if a file exists based on kernel space file
name and switch the early init code over to it. Note that this
theoretically changes behavior as it always is based on the effective
permissions. But during early init that doesn't make a difference.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/open.c | 2 +-
include/linux/syscalls.h | 7 -------
init/do_mounts.h | 1 +
init/fs.c | 13 +++++++++++++
init/main.c | 3 +--
5 files changed, 16 insertions(+), 10 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:13
Add a simple helper to link with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_link.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 3 +--
fs/namei.c | 4 ++--
include/linux/syscalls.h | 9 ---------
init/do_mounts.h | 1 +
init/fs.c | 33 +++++++++++++++++++++++++++++++++
init/initramfs.c | 2 +-
6 files changed, 38 insertions(+), 14 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:16
Add a simple helper to symlink with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_symlink.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 2 --
fs/namei.c | 2 +-
include/linux/syscalls.h | 9 ---------
init/do_mounts.h | 1 +
init/fs.c | 22 ++++++++++++++++++++++
init/initramfs.c | 2 +-
6 files changed, 25 insertions(+), 13 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:20
Add a simple helper to lstat with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_lstat.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/do_mounts.h | 1 +
init/fs.c | 14 ++++++++++++++
init/initramfs.c | 2 +-
3 files changed, 16 insertions(+), 1 deletion(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:30
Add a simple helper to mkdir with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_mkdir.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 1 -
fs/namei.c | 2 +-
include/linux/syscalls.h | 7 -------
init/do_mounts.h | 1 +
init/do_mounts_initrd.c | 2 +-
init/fs.c | 18 ++++++++++++++++++
init/initramfs.c | 2 +-
init/noinitramfs.c | 5 +++--
8 files changed, 25 insertions(+), 13 deletions(-)
@@ -1270,13 +1270,6 @@ int compat_ksys_ipc(u32 call, int first, int second,*Thefollowingkernelsyscallequivalentsarejustwrapperstofs-internal*functions.Therefore,providestubstobeinlinedatthecallsites.*/-externlongdo_mkdirat(intdfd,constchar__user*pathname,umode_tmode);--staticinlinelongksys_mkdir(constchar__user*pathname,umode_tmode)-{-returndo_mkdirat(AT_FDCWD,pathname,mode);-}-externlongdo_mknodat(intdfd,constchar__user*filename,umode_tmode,unsignedintdev);
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:32
Add a simple helper to mknod with a kernel space file name and switch
the early init code over to it. Remove the now unused ksys_mknod.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 2 --
fs/namei.c | 2 +-
include/linux/syscalls.h | 9 ---------
init/do_mounts.h | 3 ++-
init/fs.c | 25 +++++++++++++++++++++++++
init/initramfs.c | 2 +-
init/noinitramfs.c | 3 +--
7 files changed, 30 insertions(+), 16 deletions(-)
@@ -1270,15 +1270,6 @@ int compat_ksys_ipc(u32 call, int first, int second,*Thefollowingkernelsyscallequivalentsarejustwrapperstofs-internal*functions.Therefore,providestubstobeinlinedatthecallsites.*/-externlongdo_mknodat(intdfd,constchar__user*filename,umode_tmode,-unsignedintdev);--staticinlinelongksys_mknod(constchar__user*filename,umode_tmode,-unsignedintdev)-{-returndo_mknodat(AT_FDCWD,filename,mode,dev);-}-externintdo_fchownat(intdfd,constchar__user*filename,uid_tuser,gid_tgroup,intflag);
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:36
Add a simple helper to chmod with a kernel space file name and switch
the early init code over to it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 2 +-
fs/open.c | 4 ++--
include/linux/syscalls.h | 7 -------
init/do_mounts.h | 1 +
init/fs.c | 13 +++++++++++++
init/initramfs.c | 4 ++--
6 files changed, 19 insertions(+), 12 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:49
Add a simple helper to chown with a kernel space file name and switch
the early init code over to it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 2 +-
fs/open.c | 2 +-
init/do_mounts.h | 1 +
init/fs.c | 18 ++++++++++++++++++
init/initramfs.c | 6 +++---
5 files changed, 24 insertions(+), 5 deletions(-)
@@ -129,7 +129,7 @@ long do_sys_ftruncate(unsigned int fd, loff_t length, int small);intdo_fchmodat(intdfd,constchar__user*filename,umode_tmode);intdo_fchownat(intdfd,constchar__user*filename,uid_tuser,gid_tgroup,intflag);-+intchown_common(conststructpath*path,uid_tuser,gid_tgroup);externintvfs_open(conststructpath*,structfile*);/*
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:29:56
Open code the trivial utimes case in a version that takes proper kernel
pointers.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/initramfs.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:02
Like do_mount, but takes a kernel pointer for the destination path.
Switch over the mounts in the init code and devtmpfs to it, which
just happen to work due to the implicit set_fs(KERNEL_DS) during early
init right now.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/Makefile | 2 +-
init/do_mounts.c | 8 ++++----
init/do_mounts.h | 3 +++
init/do_mounts_initrd.c | 6 +++---
init/fs.c | 20 ++++++++++++++++++++
5 files changed, 31 insertions(+), 8 deletions(-)
create mode 100644 init/fs.c
@@ -395,16 +395,16 @@ static int __init do_mount_root(const char *name, const char *fs,intret;if(data){-/* do_mount() requires a full page as fifth argument */+/* init_mount() requires a full page as fifth argument */p=alloc_page(GFP_KERNEL);if(!p)return-ENOMEM;data_page=page_address(p);-/* zero-pad. do_mount() will make sure it's terminated */+/* zero-pad. init_mount() will make sure it's terminated */strncpy(data_page,data,PAGE_SIZE);}-ret=do_mount(name,"/root",fs,flags,data_page);+ret=init_mount(name,"/root",fs,flags,data_page);if(ret)gotoout;
@@ -63,7 +63,7 @@ static int __init init_linuxrc(struct subprocess_info *info, struct cred *new)console_on_rootfs();/* move initrd over / and chdir/chroot in initrd root */ksys_chdir("/root");-do_mount(".","/",NULL,MS_MOVE,NULL);+init_mount(".","/",NULL,MS_MOVE,NULL);ksys_chroot(".");ksys_setsid();return0;
@@ -100,7 +100,7 @@ static void __init handle_initrd(void)current->flags&=~PF_FREEZER_SKIP;/* move initrd to rootfs' /old */-do_mount("..",".",NULL,MS_MOVE,NULL);+init_mount("..",".",NULL,MS_MOVE,NULL);/* switch root and cwd back to / of rootfs */ksys_chroot("..");
@@ -114,7 +114,7 @@ static void __init handle_initrd(void)mount_root();printk(KERN_NOTICE"Trying to move old root to /initrd ... ");-error=do_mount("/old","/root/initrd",NULL,MS_MOVE,NULL);+error=init_mount("/old","/root/initrd",NULL,MS_MOVE,NULL);if(!error)printk("okay\n");else{
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:03
The helper is only used for the early init code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/do_mounts.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:07
No need to have this prototype in a global header included by
every driver.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/init.h | 1 -
init/do_mounts.h | 1 +
init/main.c | 2 ++
3 files changed, 3 insertions(+), 1 deletion(-)
@@ -147,7 +147,6 @@ extern unsigned int reset_devices;/* used by init/main.c */voidsetup_arch(char**);-voidprepare_namespace(void);void__initinit_rootfs(void);externstructfile_system_typerootfs_fs_type;
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:12
Set ramdisk_execute_command to "/init" at compile time. The command
line can still override it, but this saves a few instructions and
removes a NULL check.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
init/main.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:19
Replace do_umount with an open coded version that takes the proper
kernel pointer instead of relying on the implicit set_fs(KERNEL_DS)
during early init.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/base/devtmpfs.c | 17 +++++++++++++++--
fs/namespace.c | 2 +-
include/linux/mount.h | 3 +++
3 files changed, 19 insertions(+), 3 deletions(-)
@@ -359,7 +372,7 @@ int __init devtmpfs_mount(void)if(!thread)return0;-err=do_mount("devtmpfs","dev","devtmpfs",MS_SILENT,NULL);+err=devtmpfs_do_mount("dev");if(err)printk(KERN_INFO"devtmpfs: error mounting %i\n",err);else
@@ -385,7 +398,7 @@ static int devtmpfs_setup(void *p)err=ksys_unshare(CLONE_NEWNS);if(err)gotoout;-err=do_mount("devtmpfs","/","devtmpfs",MS_SILENT,NULL);+err=devtmpfs_do_mount("/");if(err)gotoout;ksys_chdir("/..");/* will traverse into overmounted root */
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:24
Instead of passing a kernel pointer to vfs_stat by relying on the
implicit set_fs(KERNEL_DS) in md_setup_drive, just open code the
trivial getattr, and use the opportunity to move a little bit more
code from the caller into the new helper.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/md/md-autodetect.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:29
This mirrors do_unlinkat and will make life a little easier for
the init code to reuse the whole function with a kernel filename.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/internal.h | 2 +-
fs/namei.c | 10 ++++------
include/linux/syscalls.h | 4 ++--
3 files changed, 7 insertions(+), 9 deletions(-)
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:31
Factor out a path_umount helper that takes a struct path * instead of the
actual file name. This will allow to convert the init and devtmpfs code
to properly mount based on a kernel pointer instead of relying on the
implicit set_fs(KERNEL_DS) during early init.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/namespace.c | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
@@ -1748,12 +1731,25 @@ int ksys_umount(char __user *name, int flags)retval=do_umount(mnt,flags);dput_and_out:/* we mustn't call path_put() as that would clear mnt_expiry_mark */-dput(path.dentry);+dput(path->dentry);mntput_no_expire(mnt);-out:returnretval;}+intksys_umount(char__user*name,intflags)+{+intlookup_flags=LOOKUP_MOUNTPOINT;+structpathpath;+intret;++if(!(flags&UMOUNT_NOFOLLOW))+lookup_flags|=LOOKUP_FOLLOW;+ret=user_path_at(AT_FDCWD,name,lookup_flags,&path);+if(ret)+returnret;+returnpath_umount(&path,flags);+}+SYSCALL_DEFINE2(umount,char__user*,name,int,flags){returnksys_umount(name,flags);
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 16:30:38
Factor out a path_mount helper that takes a struct path * instead of the
actual file name. This will allow to convert the init and devtmpfs code
to properly mount based on a kernel pointer instead of relying on the
implicit set_fs(KERNEL_DS) during early init.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/namespace.c | 67 ++++++++++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 32 deletions(-)
@@ -3133,19 +3132,13 @@ long do_mount(const char *dev_name, const char __user *dir_name,if(flags&MS_NOUSER)return-EINVAL;-/* ... and get the mountpoint */-retval=user_path_at(AT_FDCWD,dir_name,LOOKUP_FOLLOW,&path);-if(retval)-returnretval;--retval=security_sb_mount(dev_name,&path,-type_page,flags,data_page);-if(!retval&&!may_mount())-retval=-EPERM;-if(!retval&&(flags&SB_MANDLOCK)&&!may_mandlock())-retval=-EPERM;-if(retval)-gotodput_out;+ret=security_sb_mount(dev_name,path,type_page,flags,data_page);+if(ret)+returnret;+if(!may_mount())+return-EPERM;+if((flags&SB_MANDLOCK)&&!may_mandlock())+return-EPERM;/* Default to relatime unless overriden */if(!(flags&MS_NOATIME))
On Tue, Jul 21, 2020 at 9:28 AM Christoph Hellwig [off-list ref] wrote:
+
+ /* traverse into overmounted root and then chroot to it */
+ if (!kern_path("/..", LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path) &&
+ !inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR) &&
+ ns_capable(current_user_ns(), CAP_SYS_CHROOT) &&
+ !security_path_chroot(&path)) {
+ set_fs_pwd(current->fs, &path);
+ set_fs_root(current->fs, &path);
+ }
+ path_put(&path);
This looks wrong.
You're doing "path_put()" even if kern_path() didn't succeed.
As far as I can tell, that will either put some uninitialized garbage
and cause an oops, or put something that has already been released by
the failure path.
Maybe that doesn't happen in practice in this case, but it's still
very very wrong.
Plus you shouldn't have those kinds of insanely complex if-statements
in the first place. That was what caused the bug - trying to be
clever, instead of writing clear code.
I'm not liking how I'm finding fundamental mistakes in patches that
_should_ be trivial conversions with no semantic changes.
Linus
From: Al Viro <viro@zeniv.linux.org.uk> Date: 2020-07-21 17:03:50
On Tue, Jul 21, 2020 at 06:28:06PM +0200, Christoph Hellwig wrote:
Like do_mount, but takes a kernel pointer for the destination path.
Switch over the mounts in the init code and devtmpfs to it, which
just happen to work due to the implicit set_fs(KERNEL_DS) during early
init right now.
From: Al Viro <viro@zeniv.linux.org.uk> Date: 2020-07-21 17:03:55
On Tue, Jul 21, 2020 at 06:28:00PM +0200, Christoph Hellwig wrote:
Instead of passing a kernel pointer to vfs_stat by relying on the
implicit set_fs(KERNEL_DS) in md_setup_drive, just open code the
trivial getattr, and use the opportunity to move a little bit more
code from the caller into the new helper.
How about fs/for_init.c and putting the damn helpers there? With
calling conventions as close to syscalls as possible, and a fat
comment regarding their intended use being _ONLY_ the setup
in should-have-been-done-in-userland parts of init?
I really want to keep the surface as small as possible - we had
fun shite several releases ago when somebody tried that kind of
crap (with open(), IIRC). Let's not go there again...
Matter of taste, but if we do that, I wonder if we would be better off with
error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
if (!error && !ns_capable(current_user_ns(), CAP_SYS_CHROOT))
error = -EPERM;
if (!error)
error = security_path_chroot(&path);
if (!error)
set_fs_root(current->fs, &path);
path_put(&path);
return error;
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-21 18:27:09
On Tue, Jul 21, 2020 at 05:55:39PM +0100, Al Viro wrote:
How about fs/for_init.c and putting the damn helpers there? With
calling conventions as close to syscalls as possible, and a fat
comment regarding their intended use being _ONLY_ the setup
in should-have-been-done-in-userland parts of init?
Where do you want the prototypes to go? Also do you want devtmpfs
use the same helpers, which then't can't be marked __init (mount,
chdir, chroot), or separate copies?
From: Al Viro <viro@zeniv.linux.org.uk> Date: 2020-07-22 07:44:45
On Tue, Jul 21, 2020 at 08:27:01PM +0200, Christoph Hellwig wrote:
On Tue, Jul 21, 2020 at 05:55:39PM +0100, Al Viro wrote:
quoted
How about fs/for_init.c and putting the damn helpers there? With
calling conventions as close to syscalls as possible, and a fat
comment regarding their intended use being _ONLY_ the setup
in should-have-been-done-in-userland parts of init?
Where do you want the prototypes to go? Also do you want devtmpfs
use the same helpers, which then't can't be marked __init (mount,
chdir, chroot), or separate copies?
Hmm... mount still can be __init (devtmpfs_mount() is), and I suspect
devtmpfs_setup() could also be made such - just turn devtmpfsd()
into
static int __init devtmpfsd(void *p)
{
int err = devtmpfs_setup(p);
if (!err)
devtmpfsd_real(); /* never returns */
return err;
}
and you are done. As for the prototypes... include/linux/init_syscalls.h,
perhaps?
From: Christoph Hellwig <hch@lst.de> Date: 2020-07-22 14:05:32
On Wed, Jul 22, 2020 at 08:44:32AM +0100, Al Viro wrote:
On Tue, Jul 21, 2020 at 08:27:01PM +0200, Christoph Hellwig wrote:
quoted
On Tue, Jul 21, 2020 at 05:55:39PM +0100, Al Viro wrote:
quoted
How about fs/for_init.c and putting the damn helpers there? With
calling conventions as close to syscalls as possible, and a fat
comment regarding their intended use being _ONLY_ the setup
in should-have-been-done-in-userland parts of init?
Where do you want the prototypes to go? Also do you want devtmpfs
use the same helpers, which then't can't be marked __init (mount,
chdir, chroot), or separate copies?
Hmm... mount still can be __init (devtmpfs_mount() is), and I suspect
devtmpfs_setup() could also be made such - just turn devtmpfsd()
into
static int __init devtmpfsd(void *p)
{
int err = devtmpfs_setup(p);
if (!err)
devtmpfsd_real(); /* never returns */
return err;
}
and you are done.