Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+11 -5
+1 -1
drivers/base/devtmpfs.c
··· 387 387 if (*err) 388 388 goto out; 389 389 sys_chdir("/.."); /* will traverse into overmounted root */ 390 - sys_chroot("."); 390 + ksys_chroot("."); 391 391 complete(&setup_done); 392 392 while (1) { 393 393 spin_lock(&req_lock);
+6 -1
fs/open.c
··· 479 479 return error; 480 480 } 481 481 482 - SYSCALL_DEFINE1(chroot, const char __user *, filename) 482 + int ksys_chroot(const char __user *filename) 483 483 { 484 484 struct path path; 485 485 int error; ··· 510 510 } 511 511 out: 512 512 return error; 513 + } 514 + 515 + SYSCALL_DEFINE1(chroot, const char __user *, filename) 516 + { 517 + return ksys_chroot(filename); 513 518 } 514 519 515 520 static int chmod_common(const struct path *path, umode_t mode)
+1
include/linux/syscalls.h
··· 950 950 unsigned long flags, void __user *data); 951 951 int ksys_umount(char __user *name, int flags); 952 952 int ksys_dup(unsigned int fildes); 953 + int ksys_chroot(const char __user *filename); 953 954 954 955 #endif
+1 -1
init/do_mounts.c
··· 600 600 out: 601 601 devtmpfs_mount("dev"); 602 602 ksys_mount(".", "/", NULL, MS_MOVE, NULL); 603 - sys_chroot("."); 603 + ksys_chroot("."); 604 604 } 605 605 606 606 static bool is_tmpfs;
+2 -2
init/do_mounts_initrd.c
··· 44 44 /* move initrd over / and chdir/chroot in initrd root */ 45 45 sys_chdir("/root"); 46 46 ksys_mount(".", "/", NULL, MS_MOVE, NULL); 47 - sys_chroot("."); 47 + ksys_chroot("."); 48 48 sys_setsid(); 49 49 return 0; 50 50 } ··· 83 83 /* move initrd to rootfs' /old */ 84 84 ksys_mount("..", ".", NULL, MS_MOVE, NULL); 85 85 /* switch root and cwd back to / of rootfs */ 86 - sys_chroot(".."); 86 + ksys_chroot(".."); 87 87 88 88 if (new_decode_dev(real_root_dev) == Root_RAM0) { 89 89 sys_chdir("/old");