]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
fs: add a vfs_fchown helper
authorChristoph Hellwig <hch@lst.de>
Tue, 14 Jul 2020 06:47:43 +0000 (08:47 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Apr 2024 10:50:13 +0000 (12:50 +0200)
[ Upstream commit c04011fe8cbd80af1be6e12b53193bf3846750d7 ]

Add a helper for struct file based chown operations.  To be used by
the initramfs code soon.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Stable-dep-of: 4624b346cf67 ("init: open /initrd.image with O_LARGEFILE")
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/open.c
include/linux/fs.h

index 76996f920ebf5ac10bdfffcffe41bcfc5248c452..e072e86003f567835e61babf3b11c7e8db803af9 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -707,23 +707,28 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
                           AT_SYMLINK_NOFOLLOW);
 }
 
+int vfs_fchown(struct file *file, uid_t user, gid_t group)
+{
+       int error;
+
+       error = mnt_want_write_file(file);
+       if (error)
+               return error;
+       audit_file(file);
+       error = chown_common(&file->f_path, user, group);
+       mnt_drop_write_file(file);
+       return error;
+}
+
 int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
 {
        struct fd f = fdget(fd);
        int error = -EBADF;
 
-       if (!f.file)
-               goto out;
-
-       error = mnt_want_write_file(f.file);
-       if (error)
-               goto out_fput;
-       audit_file(f.file);
-       error = chown_common(&f.file->f_path, user, group);
-       mnt_drop_write_file(f.file);
-out_fput:
-       fdput(f);
-out:
+       if (f.file) {
+               error = vfs_fchown(f.file, user, group);
+               fdput(f);
+       }
        return error;
 }
 
index e2c87c056742c28e2edbdce73cbeac81df8d8b55..7d93d22ad10629f13c91f5ce4382c9d45649333e 100644 (file)
@@ -1660,6 +1660,8 @@ int vfs_mkobj(struct dentry *, umode_t,
                int (*f)(struct dentry *, umode_t, void *),
                void *);
 
+int vfs_fchown(struct file *file, uid_t user, gid_t group);
+
 extern long vfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
 
 /*