init: add an init_symlink helper
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jul 2020 09:14:36 +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 symlink with a kernel space file name and switch
the early init code over to it.  Remove the now unused ksys_symlink.

Signed-off-by: Christoph Hellwig <hch@lst.de>
fs/init.c
fs/internal.h
fs/namei.c
include/linux/init_syscalls.h
include/linux/syscalls.h
init/initramfs.c

index 5db9d9f..09ef2b5 100644 (file)
--- a/fs/init.c
+++ b/fs/init.c
@@ -155,6 +155,22 @@ out:
        return error;
 }
 
+int __init init_symlink(const char *oldname, const char *newname)
+{
+       struct dentry *dentry;
+       struct path path;
+       int error;
+
+       dentry = kern_path_create(AT_FDCWD, newname, &path, 0);
+       if (IS_ERR(dentry))
+               return PTR_ERR(dentry);
+       error = security_path_symlink(&path, dentry, oldname);
+       if (!error)
+               error = vfs_symlink(path.dentry->d_inode, dentry, oldname);
+       done_path_create(&path, dentry);
+       return error;
+}
+
 int __init init_unlink(const char *pathname)
 {
        return do_unlinkat(AT_FDCWD, getname_kernel(pathname));
index 58451b0..40b50a2 100644 (file)
@@ -67,8 +67,6 @@ long do_mknodat(int dfd, const char __user *filename, umode_t mode,
 long do_mkdirat(int dfd, const char __user *pathname, umode_t mode);
 long do_rmdir(int dfd, struct filename *name);
 long do_unlinkat(int dfd, struct filename *name);
-long do_symlinkat(const char __user *oldname, int newdfd,
-                 const char __user *newname);
 int may_linkat(struct path *link);
 
 /*
index 13de64c..2f6fa53 100644 (file)
@@ -3955,7 +3955,7 @@ int vfs_symlink(struct inode *dir, struct dentry *dentry, const char *oldname)
 }
 EXPORT_SYMBOL(vfs_symlink);
 
-long do_symlinkat(const char __user *oldname, int newdfd,
+static long do_symlinkat(const char __user *oldname, int newdfd,
                  const char __user *newname)
 {
        int error;
index 5ca15a5..125f55a 100644 (file)
@@ -9,5 +9,6 @@ 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_link(const char *oldname, const char *newname);
+int __init init_symlink(const char *oldname, const char *newname);
 int __init init_unlink(const char *pathname);
 int __init init_rmdir(const char *pathname);
index 4b18b91..7cdc0d7 100644 (file)
@@ -1277,15 +1277,6 @@ static inline long ksys_mkdir(const char __user *pathname, umode_t mode)
        return do_mkdirat(AT_FDCWD, pathname, mode);
 }
 
-extern long do_symlinkat(const char __user *oldname, int newdfd,
-                        const char __user *newname);
-
-static inline long ksys_symlink(const char __user *oldname,
-                               const char __user *newname)
-{
-       return do_symlinkat(oldname, AT_FDCWD, newname);
-}
-
 extern long do_mknodat(int dfd, const char __user *filename, umode_t mode,
                       unsigned int dev);
 
index 516a669..c91fc9a 100644 (file)
@@ -392,7 +392,7 @@ static int __init do_symlink(void)
 {
        collected[N_ALIGN(name_len) + body_len] = '\0';
        clean_path(collected, 0);
-       ksys_symlink(collected + N_ALIGN(name_len), collected);
+       init_symlink(collected + N_ALIGN(name_len), collected);
        init_chown(collected, uid, gid, AT_SYMLINK_NOFOLLOW);
        do_utime(collected, mtime);
        state = SkipIt;