summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2020-07-14 09:47:43 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-04-13 13:51:35 +0300
commit8eba8d11459240e5a8132e4e50ae00a9a41954f4 (patch)
tree21ea8f4f88087dadc71fd0776894fa915b5d7ba1
parent9550632ba9989ad55843129cb297d92e06e25cf2 (diff)
downloadlinux-8eba8d11459240e5a8132e4e50ae00a9a41954f4.tar.xz
fs: add a vfs_fchown helper
[ 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>
-rw-r--r--fs/open.c29
-rw-r--r--include/linux/fs.h2
2 files changed, 19 insertions, 12 deletions
diff --git a/fs/open.c b/fs/open.c
index dcbd01611237..9213c15d8a8d 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -708,23 +708,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;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 272f261894b1..03de5c713456 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1730,6 +1730,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);
#ifdef CONFIG_COMPAT