From patchwork Wed Aug 16 17:30:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mimi Zohar X-Patchwork-Id: 9904377 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 A9ED660231 for ; Wed, 16 Aug 2017 17:31:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 949CF28A56 for ; Wed, 16 Aug 2017 17:31:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8938B28A5B; Wed, 16 Aug 2017 17:31:08 +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 E5A9928946 for ; Wed, 16 Aug 2017 17:31:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751798AbdHPRao (ORCPT ); Wed, 16 Aug 2017 13:30:44 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39221 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752031AbdHPRan (ORCPT ); Wed, 16 Aug 2017 13:30:43 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7GHSmph070939 for ; Wed, 16 Aug 2017 13:30:43 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ccrrt5suk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 16 Aug 2017 13:30:43 -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:39 +1000 Received: from d23relay09.au.ibm.com (202.81.31.228) 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:36 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7GHUapP39190772; Thu, 17 Aug 2017 03:30:36 +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 v7GHUZJZ014640; Thu, 17 Aug 2017 03:30:35 +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 v7GHUNh7014102; Thu, 17 Aug 2017 03:30:32 +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 2/4] ima: define new ima_sb_post_new_mount hook Date: Wed, 16 Aug 2017 13:30:18 -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-0000015379BC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17081617-0009-0000-0000-000009863C96 Message-Id: <1502904620-20075-3-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 IMA measures a file, verifies a file's integrity, and caches the results. On filesystems with MS_I_VERSION enabled, IMA can detect file changes and cause them to be re-measured and verified. On filesystems without MS_I_VERSION enabled, files are measured and verified just once. This patch logs filesystems mounted without MS_I_VERSION. Signed-off-by: Mimi Zohar Reviewed-by: Jeff Layton --- include/linux/ima.h | 5 +++++ security/integrity/ima/ima_main.c | 44 +++++++++++++++++++++++++++++++++++++++ security/security.c | 1 + 3 files changed, 50 insertions(+) diff --git a/include/linux/ima.h b/include/linux/ima.h index 0e4647e0eb60..4475cb01149c 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -23,6 +23,8 @@ extern int ima_read_file(struct file *file, enum kernel_read_file_id id); extern int ima_post_read_file(struct file *file, void *buf, loff_t size, enum kernel_read_file_id id); extern void ima_post_path_mknod(struct dentry *dentry); +extern void ima_sb_post_new_mount(const struct vfsmount *newmnt, + const struct path *path); #ifdef CONFIG_IMA_KEXEC extern void ima_add_kexec_buffer(struct kimage *image); @@ -65,6 +67,9 @@ static inline void ima_post_path_mknod(struct dentry *dentry) return; } +static inline void ima_sb_post_new_mount(const struct vfsmount *newmnt, + const struct path *path) +{ } #endif /* CONFIG_IMA */ #ifndef CONFIG_IMA_KEXEC diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index b00186914df8..a0a685189001 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -354,6 +354,50 @@ void ima_post_path_mknod(struct dentry *dentry) } /** + * ima_sb_post_new_mount - check filesystem mounted flags + * + * Indicate that filesystem isn't mounted with i_version enabled. + */ +void ima_sb_post_new_mount(const struct vfsmount *newmnt, + const struct path *path) +{ + struct super_block *sb; + unsigned long pseudo_fs[] = {CGROUP_SUPER_MAGIC, CGROUP2_SUPER_MAGIC, + SYSFS_MAGIC, DEVPTS_SUPER_MAGIC, PSTOREFS_MAGIC, EFIVARFS_MAGIC, + DEBUGFS_MAGIC, TMPFS_MAGIC}; + char *pathbuf = NULL; + char filename[NAME_MAX]; + const char *pathname; + bool found = 0; + int i; + + sb = newmnt ? newmnt->mnt_sb : path->mnt->mnt_sb; + + if ((sb->s_flags & MS_I_VERSION) || (sb->s_flags & MS_RDONLY) || + (sb->s_flags & MS_KERNMOUNT)) + return; + + for (i = 0; i < ARRAY_SIZE(pseudo_fs); i++) { + if (pseudo_fs[i] != sb->s_magic) + continue; + + found = 1; + break; + } + if (found) + return; + + pathname = ima_d_path(path, &pathbuf, filename); + if (!pathname) + return; + + if (newmnt) + pr_warn("ima: %s mounted without i_version enabled\n", + pathname); + __putname(pathbuf); +} + +/** * ima_read_file - pre-measure/appraise hook decision based on policy * @file: pointer to the file to be measured/appraised/audit * @read_id: caller identifier diff --git a/security/security.c b/security/security.c index 592153e8d2b6..79111141b383 100644 --- a/security/security.c +++ b/security/security.c @@ -402,6 +402,7 @@ void security_sb_post_new_mount(const struct vfsmount *newmnt, const struct path *path) { call_void_hook(sb_post_new_mount, newmnt, path); + ima_sb_post_new_mount(newmnt, path); } int security_sb_umount(struct vfsmount *mnt, int flags)