Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2611505rda; Wed, 25 Oct 2023 07:39:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmR9E1EnNupJz2GduKabnfWaSrXThb9a0+CZPPhdcSK2FzwiPKK9NL2lioHG9lTHfLJ7Al X-Received: by 2002:a0d:d58b:0:b0:5a8:1812:a7ee with SMTP id x133-20020a0dd58b000000b005a81812a7eemr16078053ywd.3.1698244779214; Wed, 25 Oct 2023 07:39:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698244779; cv=none; d=google.com; s=arc-20160816; b=IiFya98En9iSaLKxuW0xPiQguMy3qDQ/NQBWPEGc/jIRjyGJD1dtTlHJl11AdaQGdJ Y0H3bW2AmEAaVNeX0Kp/ZFhxv5wFrB8Hnr+x0Z6e/obnlRfrRwMH6aliFEEVkv6+1lbC R8Kk2Xi+LTVKyhZj0pYK01/KrTqhGal8XA7CuKry2NB7+GJyaeqFoNyDk2Iuqpd+DYTm U4MeugCkJNTQ2DV/wuAxN4Wv095NtgsUwJ2n/I6xRQrhmiiqnB7ArfRz40cqIBN7NVMx eSMZgASp7w4D5bJy1VOUWlxYoOzHQag8t7QDFwAlk3kGwuJkxrxLlmp4DCl48xNaboUa SccQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=RYXWvuKz5XjJBreeczhKCB8gTjqEoUBBUnk+NwYH+4E=; fh=xKVNmpQa5xE4zT/QDxs3lUX6VRQglE/OAj1V+dMkM48=; b=JAEm7Verdrt7SRXa6+9xnFNDu2NwtWVcCH2NpYSD2JeRahe+Av/IaMwxSfE5Er7qdn 7fDY1tqbcVkYsnmBoQeVQR/x/zF5+4+keO6ee5eR04qhxHbFd3K8KLkrRtf6wC8k43fE cOP3jL0NqUr2nqFYX5D4i4TPEcYQTl1HYavS+gMRv7eW4Y+NzAqyLuKUVfFLRzTabCWb XMTQ0wMwVjedSzfstg10+KIEvhOAMVLr444gaP7cAywbJpdU2hg33Iq27TFfAYNpMbjM MiHC3YRwY2bi5IXjUXbOwDDEfPPHU+/UTs1WGHX+rKXOhToj+xR02xrzVp4Nm2Mi/h4h 3xXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=OYkpf110; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id j5-20020a0dc705000000b005a83af25d52si11547284ywd.450.2023.10.25.07.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 07:39:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=OYkpf110; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 349598075029; Wed, 25 Oct 2023 07:39:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235048AbjJYOjW (ORCPT + 99 others); Wed, 25 Oct 2023 10:39:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235035AbjJYOjU (ORCPT ); Wed, 25 Oct 2023 10:39:20 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D16B9DC; Wed, 25 Oct 2023 07:39:18 -0700 (PDT) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39PEbVSZ024028; Wed, 25 Oct 2023 14:39:15 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=pp1; bh=RYXWvuKz5XjJBreeczhKCB8gTjqEoUBBUnk+NwYH+4E=; b=OYkpf1109S/oUqzR+BosX5SlIrviFIq7sYugVLF4s5MB46BU0R2ojlmDpuL1Nh3C1Nyo jOSIrPdS7APQ+GeOrhZ7QEyL8airBVBE5kpQA53pY2lXk31K/mHaiR4F7BprwJjDhWfm 7ruc51/ofrag7sMog+qdVtevygxOUmk21F3uZ7vKK6qq185kEWNIVGG3UTP077IxPBiL UqFJrR3dLYJYlwwXAeTLfD2ep7t03jnPXXKIdHazACygjIRuqfmR416EgSMy4DUHm+Uz VKLbXdlZuV5VhXt5TNMp0kX2Y+CtNeWJmoRinJvwXB71nwJRjI7juFJlGQtF2cNzpxCa 3A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ty4xm841h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Oct 2023 14:39:15 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39PEcMVV028948; Wed, 25 Oct 2023 14:39:14 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3ty4xm83ye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Oct 2023 14:39:14 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39PCmdJ4023782; Wed, 25 Oct 2023 14:39:13 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tvryt7ghr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Oct 2023 14:39:13 +0000 Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39PEdBWb18940616 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 25 Oct 2023 14:39:11 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 981BF20043; Wed, 25 Oct 2023 14:39:11 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 040832004B; Wed, 25 Oct 2023 14:39:10 +0000 (GMT) Received: from li-f45666cc-3089-11b2-a85c-c57d1a57929f.ibm.com.com (unknown [9.61.173.216]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 25 Oct 2023 14:39:09 +0000 (GMT) From: Mimi Zohar To: linux-integrity@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Mimi Zohar , Raul Rangel , Eric Snowberg , Amir Goldstein Subject: [PATCH v3] ima: detect changes to the backing overlay file Date: Wed, 25 Oct 2023 10:39:06 -0400 Message-Id: <20231025143906.133218-1-zohar@linux.ibm.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: joOI4uH9uQaVio3nKlfp2aKU68fHikf1 X-Proofpoint-ORIG-GUID: 8ZoHP_6UuIBbW08_9lxLtmvKMoVu_EO2 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-25_04,2023-10-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 phishscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 adultscore=0 malwarescore=0 impostorscore=0 spamscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310170001 definitions=main-2310250127 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 25 Oct 2023 07:39:35 -0700 (PDT) Commit 18b44bc5a672 ("ovl: Always reevaluate the file signature for IMA") forced signature re-evaulation on every file access. Instead of always re-evaluating the file's integrity, detect a change to the backing file, by comparing the cached file metadata with the backing file's metadata. Verifying just the i_version has not changed is insufficient. In addition save and compare the i_ino and s_dev as well. Signed-off-by: Mimi Zohar --- Changelog: - Changes made based on Amir's review: v2: Use s_dev, not i_rdev. Limit setting real_ino, real_dev. v1: Removal of unnecessary overlay magic test. Verify i_version, i_ino and i_rdev haven't changed. fs/overlayfs/super.c | 2 +- security/integrity/ima/ima_api.c | 5 +++++ security/integrity/ima/ima_main.c | 16 +++++++++++++++- security/integrity/integrity.h | 2 ++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 3fa2416264a4..c71d185980c0 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -1489,7 +1489,7 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc) ovl_trusted_xattr_handlers; sb->s_fs_info = ofs; sb->s_flags |= SB_POSIXACL; - sb->s_iflags |= SB_I_SKIP_SYNC | SB_I_IMA_UNVERIFIABLE_SIGNATURE; + sb->s_iflags |= SB_I_SKIP_SYNC; err = -ENOMEM; root_dentry = ovl_get_root(sb, ctx->upper.dentry, oe); diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index 452e80b541e5..597ea0c4d72f 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c @@ -243,6 +243,7 @@ int ima_collect_measurement(struct integrity_iint_cache *iint, { const char *audit_cause = "failed"; struct inode *inode = file_inode(file); + struct inode *real_inode = d_real_inode(file_dentry(file)); const char *filename = file->f_path.dentry->d_name.name; struct ima_max_digest_data hash; struct kstat stat; @@ -302,6 +303,10 @@ int ima_collect_measurement(struct integrity_iint_cache *iint, iint->ima_hash = tmpbuf; memcpy(iint->ima_hash, &hash, length); iint->version = i_version; + if (real_inode != inode) { + iint->real_ino = real_inode->i_ino; + iint->real_dev = real_inode->i_sb->s_dev; + } /* Possibly temporary failure due to type of read (eg. O_DIRECT) */ if (!result) diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 365db0e43d7c..cc1217ac2c6f 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -25,6 +25,7 @@ #include #include #include +#include #include "ima.h" @@ -207,7 +208,7 @@ static int process_measurement(struct file *file, const struct cred *cred, u32 secid, char *buf, loff_t size, int mask, enum ima_hooks func) { - struct inode *inode = file_inode(file); + struct inode *backing_inode, *inode = file_inode(file); struct integrity_iint_cache *iint = NULL; struct ima_template_desc *template_desc = NULL; char *pathbuf = NULL; @@ -284,6 +285,19 @@ static int process_measurement(struct file *file, const struct cred *cred, iint->measured_pcrs = 0; } + /* Detect and re-evaluate changes made to the backing file. */ + backing_inode = d_real_inode(file_dentry(file)); + if (backing_inode != inode && + (action & IMA_DO_MASK) && (iint->flags & IMA_DONE_MASK)) { + if (!IS_I_VERSION(backing_inode) || + backing_inode->i_sb->s_dev != iint->real_dev || + backing_inode->i_ino != iint->real_ino || + !inode_eq_iversion(backing_inode, iint->version)) { + iint->flags &= ~IMA_DONE_MASK; + iint->measured_pcrs = 0; + } + } + /* Determine if already appraised/measured based on bitmask * (IMA_MEASURE, IMA_MEASURED, IMA_XXXX_APPRAISE, IMA_XXXX_APPRAISED, * IMA_AUDIT, IMA_AUDITED) diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index d7553c93f5c0..9561db7cf6b4 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h @@ -164,6 +164,8 @@ struct integrity_iint_cache { unsigned long flags; unsigned long measured_pcrs; unsigned long atomic_flags; + unsigned long real_ino; + dev_t real_dev; enum integrity_status ima_file_status:4; enum integrity_status ima_mmap_status:4; enum integrity_status ima_bprm_status:4; -- 2.39.3