summaryrefslogtreecommitdiffstats
path: root/fs/open.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-07-14 08:47:43 +0200
committerChristoph Hellwig <hch@lst.de>2020-07-16 15:33:00 +0200
commitc04011fe8cbd80af1be6e12b53193bf3846750d7 (patch)
tree7cf3bf49adc28ad5ff133986dee7f0e888bc16da /fs/open.c
parentf8456690ba8eb18ea4714e68554e242a04f65cff (diff)
downloadlinux-stable-c04011fe8cbd80af1be6e12b53193bf3846750d7.tar.gz
linux-stable-c04011fe8cbd80af1be6e12b53193bf3846750d7.tar.bz2
linux-stable-c04011fe8cbd80af1be6e12b53193bf3846750d7.zip
fs: add a vfs_fchown helper
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>
Diffstat (limited to 'fs/open.c')
-rw-r--r--fs/open.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/fs/open.c b/fs/open.c
index 6cd48a61cda3..103c66309bee 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -740,23 +740,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;
}