Skip to content

Commit 55731b3

Browse files
author
Dominik Brodowski
committed
fs: add do_fchownat(), ksys_fchown() helpers and ksys_{,l}chown() wrappers
Using the fs-interal do_fchownat() wrapper allows us to get rid of fs-internal calls to the sys_fchownat() syscall. Introducing the ksys_fchown() helper and the ksys_{,}chown() wrappers allows us to avoid the in-kernel calls to the sys_{,l,f}chown() 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_{,l,f}chown(). 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/[email protected] Cc: Al Viro <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Dominik Brodowski <[email protected]>
1 parent cbfe20f commit 55731b3

File tree

6 files changed

+46
-16
lines changed

6 files changed

+46
-16
lines changed

arch/s390/kernel/compat_linux.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@
8989
COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename,
9090
u16, user, u16, group)
9191
{
92-
return sys_chown(filename, low2highuid(user), low2highgid(group));
92+
return ksys_chown(filename, low2highuid(user), low2highgid(group));
9393
}
9494

9595
COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *,
9696
filename, u16, user, u16, group)
9797
{
98-
return sys_lchown(filename, low2highuid(user), low2highgid(group));
98+
return ksys_lchown(filename, low2highuid(user), low2highgid(group));
9999
}
100100

101101
COMPAT_SYSCALL_DEFINE3(s390_fchown16, unsigned int, fd, u16, user, u16, group)
102102
{
103-
return sys_fchown(fd, low2highuid(user), low2highgid(group));
103+
return ksys_fchown(fd, low2highuid(user), low2highgid(group));
104104
}
105105

106106
COMPAT_SYSCALL_DEFINE2(s390_setregid16, u16, rgid, u16, egid)

fs/internal.h

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ extern struct file *do_file_open_root(struct dentry *, struct vfsmount *,
121121

122122
long do_faccessat(int dfd, const char __user *filename, int mode);
123123
int do_fchmodat(int dfd, const char __user *filename, umode_t mode);
124+
int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
125+
int flag);
124126

125127
extern int open_check_o_direct(struct file *f);
126128
extern int vfs_open(const struct path *, struct file *, const struct cred *);

fs/open.c

+17-6
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ static int chown_common(const struct path *path, uid_t user, gid_t group)
645645
return error;
646646
}
647647

648-
SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
649-
gid_t, group, int, flag)
648+
int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group,
649+
int flag)
650650
{
651651
struct path path;
652652
int error = -EINVAL;
@@ -677,18 +677,24 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
677677
return error;
678678
}
679679

680+
SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
681+
gid_t, group, int, flag)
682+
{
683+
return do_fchownat(dfd, filename, user, group, flag);
684+
}
685+
680686
SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
681687
{
682-
return sys_fchownat(AT_FDCWD, filename, user, group, 0);
688+
return do_fchownat(AT_FDCWD, filename, user, group, 0);
683689
}
684690

685691
SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group)
686692
{
687-
return sys_fchownat(AT_FDCWD, filename, user, group,
688-
AT_SYMLINK_NOFOLLOW);
693+
return do_fchownat(AT_FDCWD, filename, user, group,
694+
AT_SYMLINK_NOFOLLOW);
689695
}
690696

691-
SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
697+
int ksys_fchown(unsigned int fd, uid_t user, gid_t group)
692698
{
693699
struct fd f = fdget(fd);
694700
int error = -EBADF;
@@ -708,6 +714,11 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
708714
return error;
709715
}
710716

717+
SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
718+
{
719+
return ksys_fchown(fd, user, group);
720+
}
721+
711722
int open_check_o_direct(struct file *f)
712723
{
713724
/* NB: we're sure to have correct a_ops only after f_op->open */

include/linux/syscalls.h

+17
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ int ksys_chroot(const char __user *filename);
954954
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
955955
int ksys_chdir(const char __user *filename);
956956
int ksys_fchmod(unsigned int fd, umode_t mode);
957+
int ksys_fchown(unsigned int fd, uid_t user, gid_t group);
957958

958959
/*
959960
* The following kernel syscall equivalents are just wrappers to fs-internal
@@ -1021,4 +1022,20 @@ static inline long ksys_access(const char __user *filename, int mode)
10211022
return do_faccessat(AT_FDCWD, filename, mode);
10221023
}
10231024

1025+
extern int do_fchownat(int dfd, const char __user *filename, uid_t user,
1026+
gid_t group, int flag);
1027+
1028+
static inline long ksys_chown(const char __user *filename, uid_t user,
1029+
gid_t group)
1030+
{
1031+
return do_fchownat(AT_FDCWD, filename, user, group, 0);
1032+
}
1033+
1034+
static inline long ksys_lchown(const char __user *filename, uid_t user,
1035+
gid_t group)
1036+
{
1037+
return do_fchownat(AT_FDCWD, filename, user, group,
1038+
AT_SYMLINK_NOFOLLOW);
1039+
}
1040+
10241041
#endif

init/initramfs.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static int __init do_name(void)
343343
wfd = sys_open(collected, openflags, mode);
344344

345345
if (wfd >= 0) {
346-
sys_fchown(wfd, uid, gid);
346+
ksys_fchown(wfd, uid, gid);
347347
ksys_fchmod(wfd, mode);
348348
if (body_len)
349349
sys_ftruncate(wfd, body_len);
@@ -353,14 +353,14 @@ static int __init do_name(void)
353353
}
354354
} else if (S_ISDIR(mode)) {
355355
ksys_mkdir(collected, mode);
356-
sys_chown(collected, uid, gid);
356+
ksys_chown(collected, uid, gid);
357357
ksys_chmod(collected, mode);
358358
dir_add(collected, mtime);
359359
} else if (S_ISBLK(mode) || S_ISCHR(mode) ||
360360
S_ISFIFO(mode) || S_ISSOCK(mode)) {
361361
if (maybe_link() == 0) {
362362
ksys_mknod(collected, mode, rdev);
363-
sys_chown(collected, uid, gid);
363+
ksys_chown(collected, uid, gid);
364364
ksys_chmod(collected, mode);
365365
do_utime(collected, mtime);
366366
}
@@ -393,7 +393,7 @@ static int __init do_symlink(void)
393393
collected[N_ALIGN(name_len) + body_len] = '\0';
394394
clean_path(collected, 0);
395395
ksys_symlink(collected + N_ALIGN(name_len), collected);
396-
sys_lchown(collected, uid, gid);
396+
ksys_lchown(collected, uid, gid);
397397
do_utime(collected, mtime);
398398
state = SkipIt;
399399
next_state = Reset;

kernel/uid16.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222

2323
SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
2424
{
25-
return sys_chown(filename, low2highuid(user), low2highgid(group));
25+
return ksys_chown(filename, low2highuid(user), low2highgid(group));
2626
}
2727

2828
SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
2929
{
30-
return sys_lchown(filename, low2highuid(user), low2highgid(group));
30+
return ksys_lchown(filename, low2highuid(user), low2highgid(group));
3131
}
3232

3333
SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
3434
{
35-
return sys_fchown(fd, low2highuid(user), low2highgid(group));
35+
return ksys_fchown(fd, low2highuid(user), low2highgid(group));
3636
}
3737

3838
SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)

0 commit comments

Comments
 (0)