Skip to content

Commit a16fe33

Browse files
author
Dominik Brodowski
committed
fs: add ksys_chroot() helper; remove-in kernel calls to sys_chroot()
Using this helper allows us to avoid the in-kernel calls to the sys_chroot() syscall. The ksys_ prefix denotes that this function is meant as a drop-in replacement for the syscall. In particular, it uses the same calling convention as sys_chroot(). In the near future, the fs-external callers of ksys_chroot() should be converted to use kern_path()/set_fs_root() directly. Then ksys_chroot() can be moved within sys_chroot() again. This patch is part of a series which removes in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. For details, see http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net Cc: Alexander Viro <viro@zeniv.linux.org.uk> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent c724832 commit a16fe33

5 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎drivers/base/devtmpfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ static int devtmpfsd(void *p)
387387
if (*err)
388388
goto out;
389389
sys_chdir("/.."); /* will traverse into overmounted root */
390-
sys_chroot(".");
390+
ksys_chroot(".");
391391
complete(&setup_done);
392392
while (1) {
393393
spin_lock(&req_lock);

‎fs/open.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
479479
return error;
480480
}
481481

482-
SYSCALL_DEFINE1(chroot, const char __user *, filename)
482+
int ksys_chroot(const char __user *filename)
483483
{
484484
struct path path;
485485
int error;
@@ -512,6 +512,11 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
512512
return error;
513513
}
514514

515+
SYSCALL_DEFINE1(chroot, const char __user *, filename)
516+
{
517+
return ksys_chroot(filename);
518+
}
519+
515520
static int chmod_common(const struct path *path, umode_t mode)
516521
{
517522
struct inode *inode = path->dentry->d_inode;

‎include/linux/syscalls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,5 +950,6 @@ int ksys_mount(char __user *dev_name, char __user *dir_name, char __user *type,
950950
unsigned long flags, void __user *data);
951951
int ksys_umount(char __user *name, int flags);
952952
int ksys_dup(unsigned int fildes);
953+
int ksys_chroot(const char __user *filename);
953954

954955
#endif

‎init/do_mounts.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ void __init prepare_namespace(void)
600600
out:
601601
devtmpfs_mount("dev");
602602
ksys_mount(".", "/", NULL, MS_MOVE, NULL);
603-
sys_chroot(".");
603+
ksys_chroot(".");
604604
}
605605

606606
static bool is_tmpfs;

‎init/do_mounts_initrd.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
4444
/* move initrd over / and chdir/chroot in initrd root */
4545
sys_chdir("/root");
4646
ksys_mount(".", "/", NULL, MS_MOVE, NULL);
47-
sys_chroot(".");
47+
ksys_chroot(".");
4848
sys_setsid();
4949
return 0;
5050
}
@@ -83,7 +83,7 @@ static void __init handle_initrd(void)
8383
/* move initrd to rootfs' /old */
8484
ksys_mount("..", ".", NULL, MS_MOVE, NULL);
8585
/* switch root and cwd back to / of rootfs */
86-
sys_chroot("..");
86+
ksys_chroot("..");
8787

8888
if (new_decode_dev(real_root_dev) == Root_RAM0) {
8989
sys_chdir("/old");

0 commit comments

Comments
 (0)