Skip to content

Commit 03450e2

Browse files
author
Dominik Brodowski
committed
fs: add ksys_fchmod() and do_fchmodat() helpers and ksys_chmod() wrapper; remove in-kernel calls to syscall
Using the fs-internal do_fchmodat() helper allows us to get rid of fs-internal calls to the sys_fchmodat() syscall. Introducing the ksys_fchmod() helper and the ksys_chmod() wrapper allows us to avoid the in-kernel calls to the sys_fchmod() and sys_chmod() syscalls. The ksys_ prefix denotes that these functions are meant as a drop-in replacement for the syscalls. In particular, they use the same calling convention as sys_fchmod() and sys_chmod(). 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 46ea89e commit 03450e2

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎fs/internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ extern struct file *do_filp_open(int dfd, struct filename *pathname,
119119
extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
120120
const char *, const struct open_flags *);
121121

122+
int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
123+
122124
extern int open_check_o_direct(struct file *f);
123125
extern int vfs_open(const struct path *, struct file *, const struct cred *);
124126
extern struct file *filp_clone_open(struct file *);

‎fs/open.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ static int chmod_common(const struct path *path, umode_t mode)
551551
return error;
552552
}
553553

554-
SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
554+
int ksys_fchmod(unsigned int fd, umode_t mode)
555555
{
556556
struct fd f = fdget(fd);
557557
int err = -EBADF;
@@ -564,7 +564,12 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
564564
return err;
565565
}
566566

567-
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode)
567+
SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
568+
{
569+
return ksys_fchmod(fd, mode);
570+
}
571+
572+
int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
568573
{
569574
struct path path;
570575
int error;
@@ -582,9 +587,15 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode
582587
return error;
583588
}
584589

590+
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename,
591+
umode_t, mode)
592+
{
593+
return do_fchmodat(dfd, filename, mode);
594+
}
595+
585596
SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode)
586597
{
587-
return sys_fchmodat(AT_FDCWD, filename, mode);
598+
return do_fchmodat(AT_FDCWD, filename, mode);
588599
}
589600

590601
static int chown_common(const struct path *path, uid_t user, gid_t group)

‎include/linux/syscalls.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ 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);
955955
int ksys_chdir(const char __user *filename);
956+
int ksys_fchmod(unsigned int fd, umode_t mode);
956957

957958
/*
958959
* The following kernel syscall equivalents are just wrappers to fs-internal
@@ -1006,4 +1007,11 @@ static inline long ksys_link(const char __user *oldname,
10061007
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
10071008
}
10081009

1010+
extern int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
1011+
1012+
static inline int ksys_chmod(const char __user *filename, umode_t mode)
1013+
{
1014+
return do_fchmodat(AT_FDCWD, filename, mode);
1015+
}
1016+
10091017
#endif

‎init/initramfs.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static int __init do_name(void)
344344

345345
if (wfd >= 0) {
346346
sys_fchown(wfd, uid, gid);
347-
sys_fchmod(wfd, mode);
347+
ksys_fchmod(wfd, mode);
348348
if (body_len)
349349
sys_ftruncate(wfd, body_len);
350350
vcollected = kstrdup(collected, GFP_KERNEL);
@@ -354,14 +354,14 @@ static int __init do_name(void)
354354
} else if (S_ISDIR(mode)) {
355355
ksys_mkdir(collected, mode);
356356
sys_chown(collected, uid, gid);
357-
sys_chmod(collected, mode);
357+
ksys_chmod(collected, mode);
358358
dir_add(collected, mtime);
359359
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
360360
S_ISFIFO(mode) || S_ISSOCK(mode)) {
361361
if (maybe_link() == 0) {
362362
ksys_mknod(collected, mode, rdev);
363363
sys_chown(collected, uid, gid);
364-
sys_chmod(collected, mode);
364+
ksys_chmod(collected, mode);
365365
do_utime(collected, mtime);
366366
}
367367
}

0 commit comments

Comments
 (0)