Skip to content

Commit

Permalink
init: add an init_eaccess helper
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Christoph Hellwig committed Jul 31, 2020
1 parent 1097742 commit eb9d7d3
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
13 changes: 13 additions & 0 deletions fs/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ int __init init_chmod(const char *filename, umode_t mode)
return error;
}

int __init init_eaccess(const char *filename)
{
struct path path;
int error;

error = kern_path(filename, LOOKUP_FOLLOW, &path);
if (error)
return error;
error = inode_permission(d_inode(path.dentry), MAY_ACCESS);
path_put(&path);
return error;
}

int __init init_unlink(const char *pathname)
{
return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
Expand Down
2 changes: 1 addition & 1 deletion fs/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static const struct cred *access_override_creds(void)
return old_cred;
}

long do_faccessat(int dfd, const char __user *filename, int mode, int flags)
static long do_faccessat(int dfd, const char __user *filename, int mode, int flags)
{
struct path path;
struct inode *inode;
Expand Down
1 change: 1 addition & 0 deletions include/linux/init_syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ int __init init_chdir(const char *filename);
int __init init_chroot(const char *filename);
int __init init_chown(const char *filename, uid_t user, gid_t group, int flags);
int __init init_chmod(const char *filename, umode_t mode);
int __init init_eaccess(const char *filename);
int __init init_unlink(const char *pathname);
int __init init_rmdir(const char *pathname);
7 changes: 0 additions & 7 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -1304,13 +1304,6 @@ static inline long ksys_link(const char __user *oldname,
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
}

long do_faccessat(int dfd, const char __user *filename, int mode, int flags);

static inline long ksys_access(const char __user *filename, int mode)
{
return do_faccessat(AT_FDCWD, filename, mode, 0);
}

extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
gid_t group, int flag);

Expand Down
4 changes: 2 additions & 2 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
#include <linux/jump_label.h>
#include <linux/mem_encrypt.h>
#include <linux/kcsan.h>
#include <linux/init_syscalls.h>

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

0 comments on commit eb9d7d3

Please sign in to comment.