Skip to content

Commit 447016e

Browse files
author
Dominik Brodowski
committed
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>
1 parent e7a3e8b commit 447016e

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎drivers/base/devtmpfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ static int devtmpfsd(void *p)
386386
*err = ksys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
387387
if (*err)
388388
goto out;
389-
sys_chdir("/.."); /* will traverse into overmounted root */
389+
ksys_chdir("/.."); /* will traverse into overmounted root */
390390
ksys_chroot(".");
391391
complete(&setup_done);
392392
while (1) {

‎fs/open.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ SYSCALL_DEFINE2(access, const char __user *, filename, int, mode)
431431
return sys_faccessat(AT_FDCWD, filename, mode);
432432
}
433433

434-
SYSCALL_DEFINE1(chdir, const char __user *, filename)
434+
int ksys_chdir(const char __user *filename)
435435
{
436436
struct path path;
437437
int error;
@@ -457,6 +457,11 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
457457
return error;
458458
}
459459

460+
SYSCALL_DEFINE1(chdir, const char __user *, filename)
461+
{
462+
return ksys_chdir(filename);
463+
}
464+
460465
SYSCALL_DEFINE1(fchdir, unsigned int, fd)
461466
{
462467
struct fd f = fdget_raw(fd);

‎include/linux/syscalls.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,5 +952,6 @@ int ksys_umount(char __user *name, int flags);
952952
int ksys_dup(unsigned int fildes);
953953
int ksys_chroot(const char __user *filename);
954954
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
955+
int ksys_chdir(const char __user *filename);
955956

956957
#endif

‎init/do_mounts.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int __init do_mount_root(char *name, char *fs, int flags, void *data)
367367
if (err)
368368
return err;
369369

370-
sys_chdir("/root");
370+
ksys_chdir("/root");
371371
s = current->fs->pwd.dentry->d_sb;
372372
ROOT_DEV = s->s_dev;
373373
printk(KERN_INFO

‎init/do_mounts_initrd.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
4242
ksys_dup(0);
4343
ksys_dup(0);
4444
/* move initrd over / and chdir/chroot in initrd root */
45-
sys_chdir("/root");
45+
ksys_chdir("/root");
4646
ksys_mount(".", "/", NULL, MS_MOVE, NULL);
4747
ksys_chroot(".");
4848
sys_setsid();
@@ -61,7 +61,7 @@ static void __init handle_initrd(void)
6161
/* mount initrd on rootfs' /root */
6262
mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
6363
sys_mkdir("/old", 0700);
64-
sys_chdir("/old");
64+
ksys_chdir("/old");
6565

6666
/* try loading default modules from initrd */
6767
load_default_modules();
@@ -86,11 +86,11 @@ static void __init handle_initrd(void)
8686
ksys_chroot("..");
8787

8888
if (new_decode_dev(real_root_dev) == Root_RAM0) {
89-
sys_chdir("/old");
89+
ksys_chdir("/old");
9090
return;
9191
}
9292

93-
sys_chdir("/");
93+
ksys_chdir("/");
9494
ROOT_DEV = new_decode_dev(real_root_dev);
9595
mount_root();
9696

0 commit comments

Comments
 (0)