From mboxrd@z Thu Jan 1 00:00:00 1970 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 52CF22582 for ; Thu, 7 Jul 2022 14:48:33 +0000 (UTC) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 267Egq75034934; Thu, 7 Jul 2022 14:48:09 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=vWFGda3y0jdDDeceqjAI6jAh9vBi4cCK7PUVHe1oZ1w=; b=YEUMAFNsu9sospruCgtT04k97HckEMCdx5rLLnh5yK60jvMuFsTEx8jNnGeKQymeDDp7 JOvD1886PCE+xiqZM76gHyHIpk8ZwSRmo+4y2U3juHNH5q3IJ/a53OJkVAlFB6SE1GB8 m2ARHhyVY9qzMvNKFJiMN3esUZj3y8CLFFyaUfyFKg7sWL0VOqnUHVWL64hXYIS/0brM hbJkgdWy7KZoRjOjovtIpnjOsfTeirch2nOOywl9rHMBaSqUrBjjdwE3SEl0OFvbH/BY 707p1uduApOatOW00z10JG7bGHvJd833Qj69COVtO7LnnoCzSmucGgMN26FR8Kcy/1Wk Uw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h61g0r6xk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Jul 2022 14:48:09 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 267EhuwF037786; Thu, 7 Jul 2022 14:48:08 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3h61g0r6wv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Jul 2022 14:48:08 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 267EaJVW018428; Thu, 7 Jul 2022 14:48:07 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma03dal.us.ibm.com with ESMTP id 3h4v5vemdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 07 Jul 2022 14:48:07 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 267Em6dT5833548 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 7 Jul 2022 14:48:06 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AF6FF112062; Thu, 7 Jul 2022 14:48:06 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C6E8112069; Thu, 7 Jul 2022 14:48:06 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 7 Jul 2022 14:48:06 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, serge@hallyn.com, christian.brauner@ubuntu.com, containers@lists.linux.dev, dmitry.kasatkin@gmail.com, ebiederm@xmission.com, krzysztof.struczynski@huawei.com, roberto.sassu@huawei.com, mpeters@redhat.com, lhinds@redhat.com, lsturman@redhat.com, puiterwi@redhat.com, jejb@linux.ibm.com, jamjoom@us.ibm.com, linux-kernel@vger.kernel.org, paul@paul-moore.com, rgb@redhat.com, linux-security-module@vger.kernel.org, jmorris@namei.org, jpenumak@redhat.com, Stefan Berger Subject: [PATCH v13 18/26] integrity: Add optional callback function to integrity_inode_free() Date: Thu, 7 Jul 2022 10:47:52 -0400 Message-Id: <20220707144800.828288-19-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220707144800.828288-1-stefanb@linux.ibm.com> References: <20220707144800.828288-1-stefanb@linux.ibm.com> Precedence: bulk X-Mailing-List: containers@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 6SmXdPVcr8EAVY0vs3gt83b4knWbbqb0 X-Proofpoint-ORIG-GUID: pMW9FpRGF5KVh5avU73ItiyCkIcAYlHN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-07_12,2022-06-28_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 mlxscore=0 priorityscore=1501 phishscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=963 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207070057 Add an optional callback function to integrity_inode_free() that, if provided, must be called and determines whether the iint can be freed. Adjust all callers of this function to provide a NULL pointer since none of the existing callers needs this check. Signed-off-by: Stefan Berger --- include/linux/integrity.h | 8 ++++++-- security/integrity/iint.c | 15 +++++++++++++-- security/security.c | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/linux/integrity.h b/include/linux/integrity.h index 2ea0f2f65ab6..9fe826b9146e 100644 --- a/include/linux/integrity.h +++ b/include/linux/integrity.h @@ -19,10 +19,13 @@ enum integrity_status { INTEGRITY_UNKNOWN, }; +struct integrity_iint_cache; +typedef bool (*iint_removable_cb)(struct integrity_iint_cache *iint); + /* List of EVM protected security xattrs */ #ifdef CONFIG_INTEGRITY extern struct integrity_iint_cache *integrity_inode_get(struct inode *inode); -extern void integrity_inode_free(struct inode *inode); +extern void integrity_inode_free(struct inode *inode, iint_removable_cb check); extern void __init integrity_load_keys(void); #else @@ -32,7 +35,8 @@ static inline struct integrity_iint_cache * return NULL; } -static inline void integrity_inode_free(struct inode *inode) +static inline void integrity_inode_free(struct inode *inode, + iint_removable_cb check) { return; } diff --git a/security/integrity/iint.c b/security/integrity/iint.c index 371cbceaf479..4580df0e716e 100644 --- a/security/integrity/iint.c +++ b/security/integrity/iint.c @@ -143,21 +143,32 @@ struct integrity_iint_cache *integrity_inode_get(struct inode *inode) /** * integrity_inode_free - called on security_inode_free * @inode: pointer to the inode + * @check: optional callback function to check whether the iint can be freed * * Free the integrity information(iint) associated with an inode. */ -void integrity_inode_free(struct inode *inode) +void integrity_inode_free(struct inode *inode, iint_removable_cb check) { struct integrity_iint_cache *iint; + bool freeit = true; if (!IS_IMA(inode)) return; write_lock(&integrity_iint_lock); + iint = __integrity_iint_find(inode); - rb_erase(&iint->rb_node, &integrity_iint_tree); + + if (check) + freeit = check(iint); + if (freeit) + rb_erase(&iint->rb_node, &integrity_iint_tree); + write_unlock(&integrity_iint_lock); + if (!freeit) + return; + ima_free_ns_status_list(&iint->ns_list, &iint->ns_list_lock); iint_free(iint); diff --git a/security/security.c b/security/security.c index 188b8f782220..7cf553b795da 100644 --- a/security/security.c +++ b/security/security.c @@ -1041,7 +1041,7 @@ static void inode_free_by_rcu(struct rcu_head *head) void security_inode_free(struct inode *inode) { - integrity_inode_free(inode); + integrity_inode_free(inode, NULL); call_void_hook(inode_free_security, inode); /* * The inode may still be referenced in a path walk and -- 2.36.1