Skip to content

Commit cbfe20f

Browse files
author
Dominik Brodowski
committed
fs: add do_faccessat() helper and ksys_access() wrapper; remove in-kernel calls to syscall
Using the fs-internal do_faccessat() helper allows us to get rid of fs-internal calls to the sys_faccessat() syscall. Introducing the ksys_access() wrapper allows us to avoid the in-kernel calls to the sys_access() 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_access(). 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 03450e2 commit cbfe20f

4 files changed

Lines changed: 17 additions & 3 deletions

File tree

‎fs/internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ 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+
long do_faccessat(int dfd, const char __user *filename, int mode);
122123
int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
123124

124125
extern int open_check_o_direct(struct file *f);

‎fs/open.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
350350
* We do this by temporarily clearing all FS-related capabilities and
351351
* switching the fsuid/fsgid around to the real ones.
352352
*/
353-
SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
353+
long do_faccessat(int dfd, const char __user *filename, int mode)
354354
{
355355
const struct cred *old_cred;
356356
struct cred *override_cred;
@@ -426,9 +426,14 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
426426
return res;
427427
}
428428

429+
SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
430+
{
431+
return do_faccessat(dfd, filename, mode);
432+
}
433+
429434
SYSCALL_DEFINE2(access, const char __user *, filename, int, mode)
430435
{
431-
return sys_faccessat(AT_FDCWD, filename, mode);
436+
return do_faccessat(AT_FDCWD, filename, mode);
432437
}
433438

434439
int ksys_chdir(const char __user *filename)

‎include/linux/syscalls.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,4 +1014,11 @@ static inline int ksys_chmod(const char __user *filename, umode_t mode)
10141014
return do_fchmodat(AT_FDCWD, filename, mode);
10151015
}
10161016

1017+
extern long do_faccessat(int dfd, const char __user *filename, int mode);
1018+
1019+
static inline long ksys_access(const char __user *filename, int mode)
1020+
{
1021+
return do_faccessat(AT_FDCWD, filename, mode);
1022+
}
1023+
10171024
#endif

‎init/main.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,8 @@ static noinline void __init kernel_init_freeable(void)
10871087
if (!ramdisk_execute_command)
10881088
ramdisk_execute_command = "/init";
10891089

1090-
if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
1090+
if (ksys_access((const char __user *)
1091+
ramdisk_execute_command, 0) != 0) {
10911092
ramdisk_execute_command = NULL;
10921093
prepare_namespace();
10931094
}

0 commit comments

Comments
 (0)