From patchwork Wed Aug 16 17:30:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 9904373 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 4C3ED60231 for ; Wed, 16 Aug 2017 17:31:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34FB328A2E for ; Wed, 16 Aug 2017 17:31:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2928528A57; Wed, 16 Aug 2017 17:31:07 +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=ham 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 84E5D28A2E for ; Wed, 16 Aug 2017 17:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752018AbdHPRal (ORCPT ); Wed, 16 Aug 2017 13:30:41 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41759 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751640AbdHPRah (ORCPT ); Wed, 16 Aug 2017 13:30:37 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7GHSn0n053612 for ; Wed, 16 Aug 2017 13:30:37 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ccnyfh56d-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Aug 2017 13:30:37 -0400 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 Aug 2017 03:30:35 +1000 Received: from d23relay10.au.ibm.com (202.81.31.229) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 17 Aug 2017 03:30:33 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7GHUWFS42664008; Thu, 17 Aug 2017 03:30:32 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7GHUV7A014525; Thu, 17 Aug 2017 03:30:32 +1000 Received: from localhost.localdomain.com ([9.80.83.117]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7GHUNh6014102; Thu, 17 Aug 2017 03:30:28 +1000 From: Mimi Zohar To: Christoph Hellwig , Al Viro Cc: Jan Kara , Jeff Layton , Mimi Zohar , linux-fsdevel@vger.kernel.org, linux-ima-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org Subject: [RFC PATCH 1/4] security: define new LSM sb_post_new_mount hook Date: Wed, 16 Aug 2017 13:30:17 -0400 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502904620-20075-1-git-send-email-zohar@linux.vnet.ibm.com> References: <1502904620-20075-1-git-send-email-zohar@linux.vnet.ibm.com> X-TM-AS-MML: disable x-cbid: 17081617-0008-0000-0000-0000015379BA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17081617-0009-0000-0000-000009863C94 Message-Id: <1502904620-20075-2-git-send-email-zohar@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-16_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708160288 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 Different filesystems enable different flags automatically, while others require the mount flag to be supplied as a mount option (eg. i_version). Although this hook is post mount, permit logging or auditing missing flags. Signed-off-by: Mimi Zohar --- fs/namespace.c | 2 ++ include/linux/lsm_hooks.h | 7 +++++++ include/linux/security.h | 2 ++ security/security.c | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/fs/namespace.c b/fs/namespace.c index f8893dc6a989..a7fa13f422ad 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2468,6 +2468,8 @@ static int do_new_mount(struct path *path, const char *fstype, int flags, err = do_add_mount(real_mount(mnt), path, mnt_flags); if (err) mntput(mnt); + else + security_sb_post_new_mount(mnt, path); return err; } diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h index ce02f76a6188..c3ecea0d0dca 100644 --- a/include/linux/lsm_hooks.h +++ b/include/linux/lsm_hooks.h @@ -128,6 +128,10 @@ * @mnt contains the mounted file system. * @flags contains the unmount flags, e.g. MNT_FORCE. * Return 0 if permission is granted. + * @sb_post_new_mount: + * Check mounted options conform to expectations + * @newmnt contains the newly mounted file system. + * @path contains the path for mount point object. * @sb_pivotroot: * Check permission before pivoting the root filesystem. * @old_path contains the path for the new location of the @@ -1396,6 +1400,8 @@ union security_list_options { int (*sb_statfs)(struct dentry *dentry); int (*sb_mount)(const char *dev_name, const struct path *path, const char *type, unsigned long flags, void *data); + void (*sb_post_new_mount)(const struct vfsmount *newmnt, + const struct path *path); int (*sb_umount)(struct vfsmount *mnt, int flags); int (*sb_pivotroot)(const struct path *old_path, const struct path *new_path); int (*sb_set_mnt_opts)(struct super_block *sb, @@ -1716,6 +1722,7 @@ struct security_hook_heads { struct list_head sb_statfs; struct list_head sb_mount; struct list_head sb_umount; + struct list_head sb_post_new_mount; struct list_head sb_pivotroot; struct list_head sb_set_mnt_opts; struct list_head sb_clone_mnt_opts; diff --git a/include/linux/security.h b/include/linux/security.h index 458e24bea2d4..4acdaae7aa04 100644 --- a/include/linux/security.h +++ b/include/linux/security.h @@ -242,6 +242,8 @@ int security_sb_show_options(struct seq_file *m, struct super_block *sb); int security_sb_statfs(struct dentry *dentry); int security_sb_mount(const char *dev_name, const struct path *path, const char *type, unsigned long flags, void *data); +void security_sb_post_new_mount(const struct vfsmount *mnt, + const struct path *path); int security_sb_umount(struct vfsmount *mnt, int flags); int security_sb_pivotroot(const struct path *old_path, const struct path *new_path); int security_sb_set_mnt_opts(struct super_block *sb, diff --git a/security/security.c b/security/security.c index 55b5997e4b72..592153e8d2b6 100644 --- a/security/security.c +++ b/security/security.c @@ -398,6 +398,12 @@ int security_sb_mount(const char *dev_name, const struct path *path, return call_int_hook(sb_mount, 0, dev_name, path, type, flags, data); } +void security_sb_post_new_mount(const struct vfsmount *newmnt, + const struct path *path) +{ + call_void_hook(sb_post_new_mount, newmnt, path); +} + int security_sb_umount(struct vfsmount *mnt, int flags) { return call_int_hook(sb_umount, 0, mnt, flags);