Received: by 10.213.65.68 with SMTP id h4csp142710imn; Thu, 15 Mar 2018 12:08:52 -0700 (PDT) X-Google-Smtp-Source: AG47ELvxiaZUV6WTmjBllKEt/l2n2FgRT4YKnYW3zdRK8Av4awvTChTOBPqKfWLi/cUuD2+GeCQF X-Received: by 10.101.75.140 with SMTP id t12mr7681913pgq.442.1521140932085; Thu, 15 Mar 2018 12:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521140932; cv=none; d=google.com; s=arc-20160816; b=sshC9h2FWc+nKXrUZ/qRAIyeDE3q4XZI6/N8KYoHrNVrrQ81pobYY0wF4U9MQw4Xur WYJqmRSMa1Cvqjj8UPBhFWeDJbC/ccCuKIrX79mBky7Djs6cdzH61csJQMyP5j7qOs9T IQEmBfPF9OfnwJfYItFXFM7aVPdpD7bT2UstQ7CGnh/b/kMNgE63iTOUYGQ+Oe2TuEJo 839g+I/RRJ3iDwiPaE16/Ne9Yt9ywhJJX3xQUosck2lRmOeieDqNNT4FAOVcMuyNOZPu xKH95aOiaQuig5wtJ/LT/c26fZIq9HLbQGJ6lNnOP0r9FkhZGmFB++wEbeLbF97QTX8a epnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=6VldKi90Dq+RQkuJmlbt72+zIqHY5vlIZpvLHEfU0Zc=; b=keoasAWPaDvDjw1K5eQ6cDh4+udI52FRoaXMHvdHftz3L1sPyPax4yyUzlrrCBC3ck 7NVld5XIifAk4RTrPRrLbNeuA0m1wjwC0lWZqbdB6iEQCiAIWHGlR09QW2zBfgsvhinA 4mBFroC7q2Kb6iLL5fsp+ip0OKFtYPQegwanTvO2F4g9kShvIsihuGld3OO9VEMxJLr9 krwZwpdlC0uQiZ0FpTui2ln1bjOvkum+Cs+MqEKvN/b9XVuP+BYrevGgKipCRztjxsVP hQx4cJ8LTWIz8VEwKU79rgHlsmTKinY+qZNJF3606bjQ5eORUkkKJzUXbv1t8ePPc6H3 Tk7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h5si3815175pgn.402.2018.03.15.12.08.36; Thu, 15 Mar 2018 12:08:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932751AbeCOTGh (ORCPT + 99 others); Thu, 15 Mar 2018 15:06:37 -0400 Received: from isilmar-4.linta.de ([136.243.71.142]:36338 "EHLO isilmar-4.linta.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932705AbeCOTGZ (ORCPT ); Thu, 15 Mar 2018 15:06:25 -0400 Received: from light.dominikbrodowski.net (isilmar.linta [10.0.0.1]) by isilmar-4.linta.de (Postfix) with ESMTPS id 0244F20092B; Thu, 15 Mar 2018 19:06:19 +0000 (UTC) Received: by light.dominikbrodowski.net (Postfix, from userid 1000) id 102EC20A29; Thu, 15 Mar 2018 20:05:40 +0100 (CET) From: Dominik Brodowski To: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, viro@zeniv.linux.org.uk Cc: luto@kernel.org, mingo@kernel.org, akpm@linux-foundation.org, arnd@arndb.de Subject: [PATCH v2 34/36] fs: add do_fchownat(), ksys_fchown() helpers and ksys_{,l}chown() wrappers Date: Thu, 15 Mar 2018 20:05:27 +0100 Message-Id: <20180315190529.20943-35-linux@dominikbrodowski.net> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180315190529.20943-1-linux@dominikbrodowski.net> References: <20180315190529.20943-1-linux@dominikbrodowski.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Cc: Al Viro Cc: Andrew Morton Signed-off-by: Dominik Brodowski --- arch/s390/kernel/compat_linux.c | 6 +++--- fs/internal.h | 2 ++ fs/open.c | 23 +++++++++++++++++------ include/linux/syscalls.h | 17 +++++++++++++++++ init/initramfs.c | 8 ++++---- kernel/uid16.c | 6 +++--- 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/arch/s390/kernel/compat_linux.c b/arch/s390/kernel/compat_linux.c index 572349852b75..a1fa8051fe63 100644 --- a/arch/s390/kernel/compat_linux.c +++ b/arch/s390/kernel/compat_linux.c @@ -89,18 +89,18 @@ COMPAT_SYSCALL_DEFINE3(s390_chown16, const char __user *, filename, u16, user, u16, group) { - return sys_chown(filename, low2highuid(user), low2highgid(group)); + return ksys_chown(filename, low2highuid(user), low2highgid(group)); } COMPAT_SYSCALL_DEFINE3(s390_lchown16, const char __user *, filename, u16, user, u16, group) { - return sys_lchown(filename, low2highuid(user), low2highgid(group)); + return ksys_lchown(filename, low2highuid(user), low2highgid(group)); } COMPAT_SYSCALL_DEFINE3(s390_fchown16, unsigned int, fd, u16, user, u16, group) { - return sys_fchown(fd, low2highuid(user), low2highgid(group)); + return ksys_fchown(fd, low2highuid(user), low2highgid(group)); } COMPAT_SYSCALL_DEFINE2(s390_setregid16, u16, rgid, u16, egid) diff --git a/fs/internal.h b/fs/internal.h index 49e0bf51576c..980d005b21b4 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -122,6 +122,8 @@ extern struct file *do_file_open_root(struct dentry *, struct vfsmount *, long do_sys_ftruncate(unsigned int fd, loff_t length, int small); long do_faccessat(int dfd, const char __user *filename, int mode); int do_fchmodat(int dfd, const char __user *filename, umode_t mode); +int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, + int flag); extern int open_check_o_direct(struct file *f); extern int vfs_open(const struct path *, struct file *, const struct cred *); diff --git a/fs/open.c b/fs/open.c index 77a4494f605d..b3f3b2cd9f19 100644 --- a/fs/open.c +++ b/fs/open.c @@ -645,8 +645,8 @@ static int chown_common(const struct path *path, uid_t user, gid_t group) return error; } -SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user, - gid_t, group, int, flag) +int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, + int flag) { struct path path; int error = -EINVAL; @@ -677,18 +677,24 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user, return error; } +SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user, + gid_t, group, int, flag) +{ + return do_fchownat(dfd, filename, user, group, flag); +} + SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group) { - return sys_fchownat(AT_FDCWD, filename, user, group, 0); + return do_fchownat(AT_FDCWD, filename, user, group, 0); } SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group) { - return sys_fchownat(AT_FDCWD, filename, user, group, - AT_SYMLINK_NOFOLLOW); + return do_fchownat(AT_FDCWD, filename, user, group, + AT_SYMLINK_NOFOLLOW); } -SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) +int ksys_fchown(unsigned int fd, uid_t user, gid_t group) { struct fd f = fdget(fd); int error = -EBADF; @@ -708,6 +714,11 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) return error; } +SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) +{ + return ksys_fchown(fd, user, group); +} + int open_check_o_direct(struct file *f) { /* NB: we're sure to have correct a_ops only after f_op->open */ diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 1b453770cee8..fe9bac39f3c2 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -971,6 +971,7 @@ int ksys_chdir(const char __user *filename); int ksys_sync_file_range(int fd, loff_t offset, loff_t nbytes, unsigned int flags); int ksys_fchmod(unsigned int fd, umode_t mode); +int ksys_fchown(unsigned int fd, uid_t user, gid_t group); /* * The following kernel syscall equivalents are just wrappers to fs-internal @@ -1045,4 +1046,20 @@ static inline long ksys_ftruncate(unsigned int fd, unsigned long length) return do_sys_ftruncate(fd, length, 1); } +extern int do_fchownat(int dfd, const char __user *filename, uid_t user, + gid_t group, int flag); + +static inline long ksys_chown(const char __user *filename, uid_t user, + gid_t group) +{ + return do_fchownat(AT_FDCWD, filename, user, group, 0); +} + +static inline long ksys_lchown(const char __user *filename, uid_t user, + gid_t group) +{ + return do_fchownat(AT_FDCWD, filename, user, group, + AT_SYMLINK_NOFOLLOW); +} + #endif diff --git a/init/initramfs.c b/init/initramfs.c index 237a975738ba..0d3b001b0dc5 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -343,7 +343,7 @@ static int __init do_name(void) wfd = sys_open(collected, openflags, mode); if (wfd >= 0) { - sys_fchown(wfd, uid, gid); + ksys_fchown(wfd, uid, gid); ksys_fchmod(wfd, mode); if (body_len) ksys_ftruncate(wfd, body_len); @@ -353,14 +353,14 @@ static int __init do_name(void) } } else if (S_ISDIR(mode)) { ksys_mkdir(collected, mode); - sys_chown(collected, uid, gid); + ksys_chown(collected, uid, gid); ksys_chmod(collected, mode); dir_add(collected, mtime); } else if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { if (maybe_link() == 0) { ksys_mknod(collected, mode, rdev); - sys_chown(collected, uid, gid); + ksys_chown(collected, uid, gid); ksys_chmod(collected, mode); do_utime(collected, mtime); } @@ -393,7 +393,7 @@ static int __init do_symlink(void) collected[N_ALIGN(name_len) + body_len] = '\0'; clean_path(collected, 0); ksys_symlink(collected + N_ALIGN(name_len), collected); - sys_lchown(collected, uid, gid); + ksys_lchown(collected, uid, gid); do_utime(collected, mtime); state = SkipIt; next_state = Reset; diff --git a/kernel/uid16.c b/kernel/uid16.c index ef1da2a5f9bd..ea3cf87ff000 100644 --- a/kernel/uid16.c +++ b/kernel/uid16.c @@ -20,17 +20,17 @@ SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group) { - return sys_chown(filename, low2highuid(user), low2highgid(group)); + return ksys_chown(filename, low2highuid(user), low2highgid(group)); } SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group) { - return sys_lchown(filename, low2highuid(user), low2highgid(group)); + return ksys_lchown(filename, low2highuid(user), low2highgid(group)); } SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group) { - return sys_fchown(fd, low2highuid(user), low2highgid(group)); + return ksys_fchown(fd, low2highuid(user), low2highgid(group)); } SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid) -- 2.16.2