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

fs: add ksys_chdir() helper; remove in-kernel calls to sys_chdir()

Using this helper allows us to avoid the in-kernel calls to the sys_chdir()
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_chdir().

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: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>

+13 -7
+1 -1
drivers/base/devtmpfs.c
··· 386 386 *err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options); 387 387 if (*err) 388 388 goto out; 389 - sys_chdir("/.."); /* will traverse into overmounted root */ 389 + ksys_chdir("/.."); /* will traverse into overmounted root */ 390 390 ksys_chroot("."); 391 391 complete(&setup_done); 392 392 while (1) {
+6 -1
fs/open.c
··· 431 431 return sys_faccessat(AT_FDCWD, filename, mode); 432 432 } 433 433 434 - SYSCALL_DEFINE1(chdir, const char __user *, filename) 434 + int ksys_chdir(const char __user *filename) 435 435 { 436 436 struct path path; 437 437 int error; ··· 455 455 } 456 456 out: 457 457 return error; 458 + } 459 + 460 + SYSCALL_DEFINE1(chdir, const char __user *, filename) 461 + { 462 + return ksys_chdir(filename); 458 463 } 459 464 460 465 SYSCALL_DEFINE1(fchdir, unsigned int, fd)
+1
include/linux/syscalls.h
··· 952 952 int ksys_dup(unsigned int fildes); 953 953 int ksys_chroot(const char __user *filename); 954 954 ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count); 955 + int ksys_chdir(const char __user *filename); 955 956 956 957 #endif
+1 -1
init/do_mounts.c
··· 367 367 if (err) 368 368 return err; 369 369 370 - sys_chdir("/root"); 370 + ksys_chdir("/root"); 371 371 s = current->fs->pwd.dentry->d_sb; 372 372 ROOT_DEV = s->s_dev; 373 373 printk(KERN_INFO
+4 -4
init/do_mounts_initrd.c
··· 42 42 ksys_dup(0); 43 43 ksys_dup(0); 44 44 /* move initrd over / and chdir/chroot in initrd root */ 45 - sys_chdir("/root"); 45 + ksys_chdir("/root"); 46 46 ksys_mount(".", "/", NULL, MS_MOVE, NULL); 47 47 ksys_chroot("."); 48 48 sys_setsid(); ··· 61 61 /* mount initrd on rootfs' /root */ 62 62 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY); 63 63 sys_mkdir("/old", 0700); 64 - sys_chdir("/old"); 64 + ksys_chdir("/old"); 65 65 66 66 /* try loading default modules from initrd */ 67 67 load_default_modules(); ··· 86 86 ksys_chroot(".."); 87 87 88 88 if (new_decode_dev(real_root_dev) == Root_RAM0) { 89 - sys_chdir("/old"); 89 + ksys_chdir("/old"); 90 90 return; 91 91 } 92 92 93 - sys_chdir("/"); 93 + ksys_chdir("/"); 94 94 ROOT_DEV = new_decode_dev(real_root_dev); 95 95 mount_root(); 96 96