Merge tag 'for-5.15/io_uring-vfs-2021-08-30' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / fs / namei.c
index 41f58da..32351c0 100644 (file)
@@ -2467,7 +2467,7 @@ static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
        return err;
 }
 
-int filename_lookup(int dfd, struct filename *name, unsigned flags,
+static int __filename_lookup(int dfd, struct filename *name, unsigned flags,
                    struct path *path, struct path *root)
 {
        int retval;
@@ -2485,6 +2485,14 @@ int filename_lookup(int dfd, struct filename *name, unsigned flags,
                audit_inode(name, path->dentry,
                            flags & LOOKUP_MOUNTPOINT ? AUDIT_INODE_NOEVAL : 0);
        restore_nameidata();
+       return retval;
+}
+
+int filename_lookup(int dfd, struct filename *name, unsigned flags,
+                   struct path *path, struct path *root)
+{
+       int retval = __filename_lookup(dfd, name, flags, path, root);
+
        putname(name);
        return retval;
 }
@@ -3038,9 +3046,7 @@ static int handle_truncate(struct user_namespace *mnt_userns, struct file *filp)
        /*
         * Refuse to truncate files with mandatory locks held on them.
         */
-       error = locks_verify_locked(filp);
-       if (!error)
-               error = security_path_truncate(path);
+       error = security_path_truncate(path);
        if (!error) {
                error = do_truncate(mnt_userns, path->dentry, 0,
                                    ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
@@ -3747,7 +3753,7 @@ static int may_mknod(umode_t mode)
        }
 }
 
-static long do_mknodat(int dfd, struct filename *name, umode_t mode,
+static int do_mknodat(int dfd, struct filename *name, umode_t mode,
                unsigned int dev)
 {
        struct user_namespace *mnt_userns;
@@ -3852,7 +3858,7 @@ int vfs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
 }
 EXPORT_SYMBOL(vfs_mkdir);
 
-long do_mkdirat(int dfd, struct filename *name, umode_t mode)
+int do_mkdirat(int dfd, struct filename *name, umode_t mode)
 {
        struct dentry *dentry;
        struct path path;
@@ -3949,7 +3955,7 @@ out:
 }
 EXPORT_SYMBOL(vfs_rmdir);
 
-long do_rmdir(int dfd, struct filename *name)
+int do_rmdir(int dfd, struct filename *name)
 {
        struct user_namespace *mnt_userns;
        int error;
@@ -4087,7 +4093,7 @@ EXPORT_SYMBOL(vfs_unlink);
  * writeout happening, and we don't want to prevent access to the directory
  * while waiting on the I/O.
  */
-long do_unlinkat(int dfd, struct filename *name)
+int do_unlinkat(int dfd, struct filename *name)
 {
        int error;
        struct dentry *dentry;
@@ -4215,8 +4221,7 @@ int vfs_symlink(struct user_namespace *mnt_userns, struct inode *dir,
 }
 EXPORT_SYMBOL(vfs_symlink);
 
-static long do_symlinkat(struct filename *from, int newdfd,
-                 struct filename *to)
+int do_symlinkat(struct filename *from, int newdfd, struct filename *to)
 {
        int error;
        struct dentry *dentry;
@@ -4361,8 +4366,8 @@ EXPORT_SYMBOL(vfs_link);
  * with linux 2.0, and to avoid hard-linking to directories
  * and other special files.  --ADM
  */
-static int do_linkat(int olddfd, const char __user *oldname, int newdfd,
-             const char __user *newname, int flags)
+int do_linkat(int olddfd, struct filename *old, int newdfd,
+             struct filename *new, int flags)
 {
        struct user_namespace *mnt_userns;
        struct dentry *new_dentry;
@@ -4371,31 +4376,32 @@ static int do_linkat(int olddfd, const char __user *oldname, int newdfd,
        int how = 0;
        int error;
 
-       if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0)
-               return -EINVAL;
+       if ((flags & ~(AT_SYMLINK_FOLLOW | AT_EMPTY_PATH)) != 0) {
+               error = -EINVAL;
+               goto out_putnames;
+       }
        /*
         * To use null names we require CAP_DAC_READ_SEARCH
         * This ensures that not everyone will be able to create
         * handlink using the passed filedescriptor.
         */
-       if (flags & AT_EMPTY_PATH) {
-               if (!capable(CAP_DAC_READ_SEARCH))
-                       return -ENOENT;
-               how = LOOKUP_EMPTY;
+       if (flags & AT_EMPTY_PATH && !capable(CAP_DAC_READ_SEARCH)) {
+               error = -ENOENT;
+               goto out_putnames;
        }
 
        if (flags & AT_SYMLINK_FOLLOW)
                how |= LOOKUP_FOLLOW;
 retry:
-       error = user_path_at(olddfd, oldname, how, &old_path);
+       error = __filename_lookup(olddfd, old, how, &old_path, NULL);
        if (error)
-               return error;
+               goto out_putnames;
 
-       new_dentry = user_path_create(newdfd, newname, &new_path,
+       new_dentry = __filename_create(newdfd, new, &new_path,
                                        (how & LOOKUP_REVAL));
        error = PTR_ERR(new_dentry);
        if (IS_ERR(new_dentry))
-               goto out;
+               goto out_putpath;
 
        error = -EXDEV;
        if (old_path.mnt != new_path.mnt)
@@ -4423,8 +4429,11 @@ out_dput:
                how |= LOOKUP_REVAL;
                goto retry;
        }
-out:
+out_putpath:
        path_put(&old_path);
+out_putnames:
+       putname(old);
+       putname(new);
 
        return error;
 }
@@ -4432,12 +4441,13 @@ out:
 SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
                int, newdfd, const char __user *, newname, int, flags)
 {
-       return do_linkat(olddfd, oldname, newdfd, newname, flags);
+       return do_linkat(olddfd, getname_uflags(oldname, flags),
+               newdfd, getname(newname), flags);
 }
 
 SYSCALL_DEFINE2(link, const char __user *, oldname, const char __user *, newname)
 {
-       return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
+       return do_linkat(AT_FDCWD, getname(oldname), AT_FDCWD, getname(newname), 0);
 }
 
 /**