mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-01 10:42:11 +00:00
fs: add ksys_fchmod() and do_fchmodat() helpers and ksys_chmod() wrapper; remove in-kernel calls to syscall
Using the fs-internal do_fchmodat() helper allows us to get rid of fs-internal calls to the sys_fchmodat() syscall. Introducing the ksys_fchmod() helper and the ksys_chmod() wrapper allows us to avoid the in-kernel calls to the sys_fchmod() and sys_chmod() syscalls. The ksys_ prefix denotes that these functions are meant as a drop-in replacement for the syscalls. In particular, they use the same calling convention as sys_fchmod() and sys_chmod(). This patch is part of a series which removes in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. For details, see http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
This commit is contained in:
parent
46ea89eb65
commit
03450e271a
@ -119,6 +119,8 @@ extern struct file *do_filp_open(int dfd, struct filename *pathname,
|
|||||||
extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
|
extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
|
||||||
const char *, const struct open_flags *);
|
const char *, const struct open_flags *);
|
||||||
|
|
||||||
|
int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
|
||||||
|
|
||||||
extern int open_check_o_direct(struct file *f);
|
extern int open_check_o_direct(struct file *f);
|
||||||
extern int vfs_open(const struct path *, struct file *, const struct cred *);
|
extern int vfs_open(const struct path *, struct file *, const struct cred *);
|
||||||
extern struct file *filp_clone_open(struct file *);
|
extern struct file *filp_clone_open(struct file *);
|
||||||
|
17
fs/open.c
17
fs/open.c
@ -551,7 +551,7 @@ static int chmod_common(const struct path *path, umode_t mode)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
|
int ksys_fchmod(unsigned int fd, umode_t mode)
|
||||||
{
|
{
|
||||||
struct fd f = fdget(fd);
|
struct fd f = fdget(fd);
|
||||||
int err = -EBADF;
|
int err = -EBADF;
|
||||||
@ -564,7 +564,12 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode)
|
SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode)
|
||||||
|
{
|
||||||
|
return ksys_fchmod(fd, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int do_fchmodat(int dfd, const char __user *filename, umode_t mode)
|
||||||
{
|
{
|
||||||
struct path path;
|
struct path path;
|
||||||
int error;
|
int error;
|
||||||
@ -582,9 +587,15 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename,
|
||||||
|
umode_t, mode)
|
||||||
|
{
|
||||||
|
return do_fchmodat(dfd, filename, mode);
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode)
|
SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode)
|
||||||
{
|
{
|
||||||
return sys_fchmodat(AT_FDCWD, filename, mode);
|
return do_fchmodat(AT_FDCWD, filename, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int chown_common(const struct path *path, uid_t user, gid_t group)
|
static int chown_common(const struct path *path, uid_t user, gid_t group)
|
||||||
|
@ -953,6 +953,7 @@ int ksys_dup(unsigned int fildes);
|
|||||||
int ksys_chroot(const char __user *filename);
|
int ksys_chroot(const char __user *filename);
|
||||||
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
|
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
|
||||||
int ksys_chdir(const char __user *filename);
|
int ksys_chdir(const char __user *filename);
|
||||||
|
int ksys_fchmod(unsigned int fd, umode_t mode);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following kernel syscall equivalents are just wrappers to fs-internal
|
* The following kernel syscall equivalents are just wrappers to fs-internal
|
||||||
@ -1006,4 +1007,11 @@ static inline long ksys_link(const char __user *oldname,
|
|||||||
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
|
return do_linkat(AT_FDCWD, oldname, AT_FDCWD, newname, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
|
||||||
|
|
||||||
|
static inline int ksys_chmod(const char __user *filename, umode_t mode)
|
||||||
|
{
|
||||||
|
return do_fchmodat(AT_FDCWD, filename, mode);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -344,7 +344,7 @@ static int __init do_name(void)
|
|||||||
|
|
||||||
if (wfd >= 0) {
|
if (wfd >= 0) {
|
||||||
sys_fchown(wfd, uid, gid);
|
sys_fchown(wfd, uid, gid);
|
||||||
sys_fchmod(wfd, mode);
|
ksys_fchmod(wfd, mode);
|
||||||
if (body_len)
|
if (body_len)
|
||||||
sys_ftruncate(wfd, body_len);
|
sys_ftruncate(wfd, body_len);
|
||||||
vcollected = kstrdup(collected, GFP_KERNEL);
|
vcollected = kstrdup(collected, GFP_KERNEL);
|
||||||
@ -354,14 +354,14 @@ static int __init do_name(void)
|
|||||||
} else if (S_ISDIR(mode)) {
|
} else if (S_ISDIR(mode)) {
|
||||||
ksys_mkdir(collected, mode);
|
ksys_mkdir(collected, mode);
|
||||||
sys_chown(collected, uid, gid);
|
sys_chown(collected, uid, gid);
|
||||||
sys_chmod(collected, mode);
|
ksys_chmod(collected, mode);
|
||||||
dir_add(collected, mtime);
|
dir_add(collected, mtime);
|
||||||
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
|
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
|
||||||
S_ISFIFO(mode) || S_ISSOCK(mode)) {
|
S_ISFIFO(mode) || S_ISSOCK(mode)) {
|
||||||
if (maybe_link() == 0) {
|
if (maybe_link() == 0) {
|
||||||
ksys_mknod(collected, mode, rdev);
|
ksys_mknod(collected, mode, rdev);
|
||||||
sys_chown(collected, uid, gid);
|
sys_chown(collected, uid, gid);
|
||||||
sys_chmod(collected, mode);
|
ksys_chmod(collected, mode);
|
||||||
do_utime(collected, mtime);
|
do_utime(collected, mtime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user