From patchwork Fri Feb 23 17:25:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 205591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp739392dyb; Fri, 23 Feb 2024 09:41:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMwb0vCXWwElwamsVn8rmXt1JVYR12sasghT9jGEDqradEGCYery5rYpg/zyhbUkrEHmaJeBdC55uUMdLU95VXsTjOyg== X-Google-Smtp-Source: AGHT+IEL2ik0h22Fe3+Z/aB+NHEF8gKHt3RnNP17/JK4nXl40KHE4XpiJb9NJGxkFr5OtOFJ8Luw X-Received: by 2002:a17:903:1106:b0:1db:930e:e755 with SMTP id n6-20020a170903110600b001db930ee755mr662225plh.35.1708710118584; Fri, 23 Feb 2024 09:41:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708710118; cv=pass; d=google.com; s=arc-20160816; b=I8KtqKCA/AjJv/cUXmXlNo+6uPb6FWAxIZdGvTT3a2IyiyUVcKD4KVa+mW3TTZgYJI jeZjda6X/JMIq5hqnSoM28cCALJTe3RadIpJ6yvolfPT4gYjB07IhPpr3vz7KWuxfH+S tmzOZQRVSSfM6kLJ7ohu+NaVCG7aHRZvOPfkaDeYv+UlRH4y4egTIQ9pz42MX6RcU1yj mveDUbRbw8Snc2CDa2aORigd53juBZ4CNfTjbHZvs8u+pVaknJtburD3BY4KDSojDOJg tBM7soQ3vD4X7/aWRqFEEGbRZ4ICMyyI4qw6DVYC+P2/LjTQBEiAemE3Ub9OeEFqiQrk 11Ag== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=X/ePSxDdWpDwK8FN8vmj7V7eFK5aLdsPNvK8v5E61Ss=; fh=LCjsfXHko90XLLo/Ss+3GB7fGCgggrYzxgCo4KdLXMU=; b=YBdMhhqROhvMyfeZLdsQ9KyRuo9/WtD/Qgf/WESNeKHxFGLJjIgneu/Z1ai3M6S/uQ 91wwzW8dXRz2oACexxgIVzHGAGkf7dhD/zEjZBORIuvoy0Z7CySAoYxIjfN3c+9+m4j+ REys7bkDGodQwPYOpyT8ezOJXZXka33gZpT+b1d9oPe/8NHCMURGIWQiqgEKK2tU3cmy uxL8ky2VDATVkd0gqXZrDidB1RUURoNKepRWBnEYGSuhJKZ37FL5mgUFwTD3SBESSQtt LpXjL5Hibvk3zGZA6g8xJUCtW43EEdUOpQtUpFrDma0+QCY68dLvtBZlhgtsWqAZmulE A6Sw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=USP7ET2m; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-78832-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78832-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ja12-20020a170902efcc00b001d6fb87b11csi12159700plb.265.2024.02.23.09.41.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 09:41:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78832-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=USP7ET2m; arc=pass (i=1 spf=pass spfdomain=linux.ibm.com dkim=pass dkdomain=ibm.com dmarc=pass fromdomain=linux.ibm.com); spf=pass (google.com: domain of linux-kernel+bounces-78832-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78832-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D2DA9B24D2B for ; Fri, 23 Feb 2024 17:28:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA87B140E5D; Fri, 23 Feb 2024 17:25:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="USP7ET2m" Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E183313341F; Fri, 23 Feb 2024 17:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708709145; cv=none; b=CUkzruZG66N3eLPVfBTHQgNQCvSnqkKAC9hAYoq60Fop9sZUtM9pKsYCqhHyP1QsDCyWU0LEt6EZFoTyf3gDyvd+hYDEyz3zK+CNVTT1mkJ/8jlEHEV5XZddaSwSnyqg6Tg97SHXbHWLceY/QLmrxlsRC6uxOoJ5ziGKah5hI5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708709145; c=relaxed/simple; bh=9mXQ1BGzBOlg5izS1nn4EJTQWXx67AxBDxrlxoLTRBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QJbiO8XRcHA70bb0Yw3hMt5d/YZHiBf3st76ujXCSPyAKcTHQk4nntnfzlJpT3iIR86IstmFsIaioc8bN+0cF8Pt7AmdT7EZgoM8aflwozUiIshp7nFVGUrUH9XoYDnXKFqKjnuJysohWG3uNhp0Vo5Cn+9HjAyWF+6DGKxlJ5I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=USP7ET2m; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41NHMLjp026927; Fri, 23 Feb 2024 17:25:30 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=X/ePSxDdWpDwK8FN8vmj7V7eFK5aLdsPNvK8v5E61Ss=; b=USP7ET2mXNJpj+HekwBv5k2R2oCZazlb/WFlKCATli6R5gkDOmIsNu5Y0OJgEHbDlc0Q SiJdBpVWwZAK1VgjSboHCBg28o2b+3brm/pN/NNQkAp2VUNeC9NdUiz5/FXs7Snb23pE GcXXStG52a5YKxaV8soX37PNUJlYySOgkVLu6ksu0gU1uhbh8nFRKGe9vJ4h97CinLS3 Gl414zNknPQfEkEfwM0O/jh37eVGMKX5batskbRC+RWaFd+n2qvv+S9Ml8z4SoHB9XE7 E2J39PDzyfWvm+id9+e8xOU6zFrEHWcvPQSpWP4RLm49eETk8v70D6SE8njdsAiNXgr3 vw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3weypt83n8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 17:25:28 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 41NHNQIX030513; Fri, 23 Feb 2024 17:25:27 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 3weypt83mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 17:25:27 +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 41NFWGxf003611; Fri, 23 Feb 2024 17:25:26 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3wb74u756c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 23 Feb 2024 17:25:26 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 41NHPMY619661510 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Feb 2024 17:25:24 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C49A558043; Fri, 23 Feb 2024 17:25:22 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A17A358065; Fri, 23 Feb 2024 17:25:21 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Fri, 23 Feb 2024 17:25:21 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-unionfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com, zohar@linux.ibm.com, roberto.sassu@huawei.com, amir73il@gmail.com, brauner@kernel.org, miklos@szeredi.hu, Stefan Berger Subject: [PATCH v3 04/10] evm: Use the metadata inode to calculate metadata hash Date: Fri, 23 Feb 2024 12:25:07 -0500 Message-ID: <20240223172513.4049959-5-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240223172513.4049959-1-stefanb@linux.ibm.com> References: <20240223172513.4049959-1-stefanb@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: eVejRUY03dMWT6j6oSFXNpdfhfPBnong X-Proofpoint-GUID: SBDFzDF_Bd6udu3A4D50GeG50jjpmPgQ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-23_03,2024-02-23_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=970 spamscore=0 impostorscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2402230127 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791712421461139633 X-GMAIL-MSGID: 1791712421461139633 Changes to file attributes (mode bits, uid, gid) on the lower layer are not taken into account when d_backing_inode() is used when a file is accessed on the overlay layer and this file has not yet been copied up. This is because d_backing_inode() does not return the real inode of the lower layer but instead returns the backing inode which in this case holds wrong file attributes. Further, when CONFIG_OVERLAY_FS_METACOPY is enabled and a copy-up is triggered due to file metadata changes, then the metadata are held by the backing inode while the data are still held by the real inode. Therefore, use d_inode(d_real(dentry, D_REAL_METADATA)) to get to the file's metadata inode and use it to calculate the metadata hash with. Co-developed-by: Mimi Zohar Signed-off-by: Stefan Berger Acked-by: Amir Goldstein --- security/integrity/evm/evm_crypto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/integrity/evm/evm_crypto.c b/security/integrity/evm/evm_crypto.c index 7552d49d0725..35416f55391c 100644 --- a/security/integrity/evm/evm_crypto.c +++ b/security/integrity/evm/evm_crypto.c @@ -223,7 +223,7 @@ static int evm_calc_hmac_or_hash(struct dentry *dentry, size_t req_xattr_value_len, uint8_t type, struct evm_digest *data) { - struct inode *inode = d_backing_inode(dentry); + struct inode *inode = d_inode(d_real(dentry, D_REAL_METADATA)); struct xattr_list *xattr; struct shash_desc *desc; size_t xattr_size = 0;