Skip to content

Commit eb9d7d3

Browse files
author
Christoph Hellwig
committed
init: add an init_eaccess helper
Add a simple helper to check if a file exists based on kernel space file name and switch the early init code over to it. Note that this theoretically changes behavior as it always is based on the effective permissions. But during early init that doesn't make a difference. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 1097742 commit eb9d7d3

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

fs/init.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ int __init init_chmod(const char *filename, umode_t mode)
109109
return error;
110110
}
111111

112+
int __init init_eaccess(const char *filename)
113+
{
114+
struct path path;
115+
int error;
116+
117+
error = kern_path(filename, LOOKUP_FOLLOW, &path);
118+
if (error)
119+
return error;
120+
error = inode_permission(d_inode(path.dentry), MAY_ACCESS);
121+
path_put(&path);
122+
return error;
123+
}
124+
112125
int __init init_unlink(const char *pathname)
113126
{
114127
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));

fs/open.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ static const struct cred *access_override_creds(void)
394394
return old_cred;
395395
}
396396

397-
long do_faccessat(int dfd, const char __user *filename, int mode, int flags)
397+
static long do_faccessat(int dfd, const char __user *filename, int mode, int flags)
398398
{
399399
struct path path;
400400
struct inode *inode;

include/linux/init_syscalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ int __init init_chdir(const char *filename);
77
int __init init_chroot(const char *filename);
88
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
99
int __init init_chmod(const char *filename, umode_t mode);
10+
int __init init_eaccess(const char *filename);
1011
int __init init_unlink(const char *pathname);
1112
int __init init_rmdir(const char *pathname);

include/linux/syscalls.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,13 +1304,6 @@ static inline long ksys_link(const char __user *oldname,
13041304
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
13051305
}
13061306

1307-
long do_faccessat(int dfd, const char __user *filename, int mode, int flags);
1308-
1309-
static inline long ksys_access(const char __user *filename, int mode)
1310-
{
1311-
return do_faccessat(AT_FDCWD, filename, mode, 0);
1312-
}
1313-
13141307
extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
13151308
gid_t group, int flag);
13161309

init/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
#include <linux/jump_label.h>
9797
#include <linux/mem_encrypt.h>
9898
#include <linux/kcsan.h>
99+
#include <linux/init_syscalls.h>
99100

100101
#include <asm/io.h>
101102
#include <asm/bugs.h>
@@ -1514,8 +1515,7 @@ static noinline void __init kernel_init_freeable(void)
15141515
* check if there is an early userspace init. If yes, let it do all
15151516
* the work
15161517
*/
1517-
if (ksys_access((const char __user *)
1518-
ramdisk_execute_command, 0) != 0) {
1518+
if (init_eaccess(ramdisk_execute_command) != 0) {
15191519
ramdisk_execute_command = NULL;
15201520
prepare_namespace();
15211521
}

0 commit comments

Comments
 (0)