init: add an init_eaccess helper
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jul 2020 09:14:02 +0000 (11:14 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 31 Jul 2020 06:17:53 +0000 (08:17 +0200)
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 <hch@lst.de>
fs/init.c
fs/open.c
include/linux/init_syscalls.h
include/linux/syscalls.h
init/main.c

index a66032d128b618de998866b965948057f748b986..6d9af40d2897b156e7c826997637dc2f8b232ed7 100644 (file)
--- a/fs/init.c
+++ b/fs/init.c
@@ -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));
index 7ba89eae46c5602778b3fef3d28bd98ce8de7bf2..aafecd1f7ba1a5fe6c1915cf18663db0cc160357 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -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;
index 2b1b4dc586825f66d75d14f2affe254d8449acb7..7031c0934bee9f6ac572ff3018e2e3ca0455c7fe 100644 (file)
@@ -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);
index 8b71fa321ca20c24e16b9e44f197cecad42af402..a2779638e41445591b1a38b2f3245e49875da63d 100644 (file)
@@ -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);
 
index 47698427b15f62dc2c0af08f7f2e2a0fbc7ea217..1c710d3e1d461a6b58d47179e418d940e79a7c9c 100644 (file)
@@ -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>
@@ -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();
        }