From patchwork Thu Aug 3 18:35:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 9879717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B0EB6037D for ; Thu, 3 Aug 2017 18:35:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2112C287B8 for ; Thu, 3 Aug 2017 18:35:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1642728948; Thu, 3 Aug 2017 18:35:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD4C8287B8 for ; Thu, 3 Aug 2017 18:35:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751773AbdHCSfP (ORCPT ); Thu, 3 Aug 2017 14:35:15 -0400 Received: from mx142.netapp.com ([216.240.21.19]:2372 "EHLO mx142.netapp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751696AbdHCSfM (ORCPT ); Thu, 3 Aug 2017 14:35:12 -0400 X-IronPort-AV: E=Sophos;i="5.41,317,1498546800"; d="scan'208";a="204150061" Received: from vmwexchts04-prd.hq.netapp.com ([10.122.105.32]) by mx142-out.netapp.com with ESMTP; 03 Aug 2017 11:12:56 -0700 Received: from smtp1.corp.netapp.com (10.57.156.124) by VMWEXCHTS04-PRD.hq.netapp.com (10.122.105.32) with Microsoft SMTP Server id 15.0.1210.3; Thu, 3 Aug 2017 11:35:10 -0700 Received: from localhost.localdomain ([10.63.238.77]) by smtp1.corp.netapp.com (8.13.1/8.13.1/NTAP-1.6) with ESMTP id v73IZ91W022909; Thu, 3 Aug 2017 11:35:10 -0700 (PDT) From: Olga Kornievskaia To: , Subject: [RFC 1/3] VFS adding destroy_creds call Date: Thu, 3 Aug 2017 14:35:06 -0400 Message-ID: <20170803183508.24565-2-kolga@netapp.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) In-Reply-To: <20170803183508.24565-1-kolga@netapp.com> References: <20170803183508.24565-1-kolga@netapp.com> MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Filesystems (like NFS) would benefit from an ability to destroy credentials for the current uid. Systemcall takes in a file descriptor that's a mount point of the file system. If a non-directory file descriptor supplied it will failed with EINVAL. It will return 1 upto success. If the file system doesn't define a destroy_creds callout, it will return 0. Signed-off-by: Olga Kornievskaia --- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + fs/read_write.c | 20 ++++++++++++++++++++ include/linux/fs.h | 2 ++ include/linux/syscalls.h | 2 +- include/uapi/asm-generic/unistd.h | 4 +++- kernel/sys_ni.c | 1 + 7 files changed, 29 insertions(+), 2 deletions(-) diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index 448ac21..298e72b 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -391,3 +391,4 @@ 382 i386 pkey_free sys_pkey_free 383 i386 statx sys_statx 384 i386 arch_prctl sys_arch_prctl compat_sys_arch_prctl +385 i386 destroy_creds sys_destroy_creds diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index 5aef183..c8a7e38 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -339,6 +339,7 @@ 330 common pkey_alloc sys_pkey_alloc 331 common pkey_free sys_pkey_free 332 common statx sys_statx +333 common destroy_creds sys_destroy_creds # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/fs/read_write.c b/fs/read_write.c index 406d1c6..2a3cce5 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -2085,3 +2085,23 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) return ret; } EXPORT_SYMBOL(vfs_dedupe_file_range); + +long vfs_destroy_creds(struct file *fd) +{ + if (!IS_DIR(fd)) + return -EINVAL; + if (fd->f_op->destroy_creds) + return fd->f_op->destroy_creds(fd); + return 0; +} +EXPORT_SYMBOL(vfs_destroy_creds); + +SYSCALL_DEFINE1(destroy_creds, int, fd_in) +{ + struct fd f_in; + + f_in = fdget(fd_in); + if (!f_in.file) + return 0; + return vfs_destroy_creds(f_in.file); +} diff --git a/include/linux/fs.h b/include/linux/fs.h index 803e5a9..28f93e9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1690,6 +1690,7 @@ struct file_operations { u64); ssize_t (*dedupe_file_range)(struct file *, u64, u64, struct file *, u64); + int (*destroy_creds)(struct file *); }; struct inode_operations { @@ -1770,6 +1771,7 @@ extern int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff, loff_t len, bool *is_same); extern int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same); +extern long vfs_destroy_creds(struct file *fd); struct super_operations { struct inode *(*alloc_inode)(struct super_block *sb); diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 980c3c9..586d0ae 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -905,5 +905,5 @@ asmlinkage long sys_pkey_mprotect(unsigned long start, size_t len, asmlinkage long sys_pkey_free(int pkey); asmlinkage long sys_statx(int dfd, const char __user *path, unsigned flags, unsigned mask, struct statx __user *buffer); - +asmlinkage long sys_destroy_creds(int fd_in); #endif diff --git a/include/uapi/asm-generic/unistd.h b/include/uapi/asm-generic/unistd.h index 061185a..8d9e9fe 100644 --- a/include/uapi/asm-generic/unistd.h +++ b/include/uapi/asm-generic/unistd.h @@ -731,9 +731,11 @@ __SYSCALL(__NR_pkey_free, sys_pkey_free) #define __NR_statx 291 __SYSCALL(__NR_statx, sys_statx) +#define __NR_copy_file_range 292 +__SYSCALL(__NR_destroy_creds, sys_destroy_creds) #undef __NR_syscalls -#define __NR_syscalls 292 +#define __NR_syscalls 293 /* * All syscalls below here should go away really, diff --git a/kernel/sys_ni.c b/kernel/sys_ni.c index 8acef85..cb9ee0b 100644 --- a/kernel/sys_ni.c +++ b/kernel/sys_ni.c @@ -178,6 +178,7 @@ asmlinkage long sys_ni_syscall(void) cond_syscall(sys_capget); cond_syscall(sys_capset); cond_syscall(sys_copy_file_range); +cond_syscall(sys_destroy_creds); /* arch-specific weak syscall entries */ cond_syscall(sys_pciconfig_read);