Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1245810rwn; Thu, 15 Sep 2022 12:37:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM62pB8fDmvN6XiPXeSXeZ4aUSJdEaO+5g0zjWZDQholPyvuBHlOc/PZ61lf44SjzHtCg5ft X-Received: by 2002:a17:907:984:b0:77f:4d95:9e2f with SMTP id bf4-20020a170907098400b0077f4d959e2fmr1067909ejc.176.1663270642996; Thu, 15 Sep 2022 12:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663270642; cv=none; d=google.com; s=arc-20160816; b=N+M1Fx1krQTRWG52/KVBLetvPQbaqoFKMo3aNyyGDhw/YJa2PsIAbBZ9uFg8Hb5HZB ALsfbQp2xVSsVaKZR4HEt49w66cWtL2ONhFgev3oYqiHciiB5Cg7GiV727dRamYt0/4W ZlKOhGa5liq3ioRAJvpPagb5Vor1g2bZuMKyeY0KNGmWVzgpKpnviHrlKetZ9FmOZZem RXbQOmNx81Eg8vEcXDSZhjX7Rb2BhKl5ExXukY+UB2WG+mL3ONPRvjI/SflvXzySdVhc uNL0w2g1EGj0eFOwZ1obWiHXCZ98sDFZD1PvYfIb+5m1S5BYKi3j2OsdYb8k/aenfOCf YJpg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=St6YuQFRU1KJLdAMpl1mLzAAErk92wrx5yOlLlnUXsg=; b=QtOsZ+YJuKaaK3UhWDHzlGhaN/CFhpS0fdECz7dSRr5FcsoxtUGFclMwjlIKsnYyaw LiBHHAYiqRPJc8RvHJA8INAxAlxyHAW7cFhzaAVgWmTyCx8Xeh8Agou8TbeYeqO1tch5 1c78X4xOMKewOvduhoTjO3oW2Y1NmHZE9mBiRQi4P4fFNxmIhzpgN/j1JMm4yJFnnYpZ ctbkLNOcmSKUgyuGjS4JBYskgorDBaHDmJC50pP6l8i0xwSRJdeWfLVUu/YqL/nosl7O qEhRdDJ6XNvKUw3nosrNWW6qjbq7vcD/EH+16AD7/yK2XwWedi2K/dXUicKtkAvMT38r +OYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="LPc/zSWs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hu8-20020a170907a08800b0077a0dad5475si2108103ejc.313.2022.09.15.12.36.57; Thu, 15 Sep 2022 12:37:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b="LPc/zSWs"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229975AbiIOTfC (ORCPT + 99 others); Thu, 15 Sep 2022 15:35:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229790AbiIOTdT (ORCPT ); Thu, 15 Sep 2022 15:33:19 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 292B19D66E; Thu, 15 Sep 2022 12:33:12 -0700 (PDT) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28FI25jE024058; Thu, 15 Sep 2022 19:32:41 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=St6YuQFRU1KJLdAMpl1mLzAAErk92wrx5yOlLlnUXsg=; b=LPc/zSWsq7bGqY/n+1sP1TWEdxJi2/0/2YVX3pnJWmil7yFX4fY0+ccqnFe0Wck49VS/ AlLhA71nr/fybGePLHmEysOwh2RXGbU3zDN0VA/lUjTGRndadu/96y+ZiafJJ3prqCt4 J6KzOkX0N0tw2UlM4SNyCpEf7D93IBz8TJMEgCDdOBo44cxz8Do78oATwBHqHYHXHrul 370cTYz7jzwvKwDlEdH0D5QG2BD9ZV/NshrEnhnQWd/RRynp9PIkeI+z8CA5Ff+Q75Cg dN07xGuYkmywph6D8oOPIhp2OIilusnSEFLwwUzF9mnxTopaqZljZlQoKRXOYYuRgmdV 1g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jm8yn2p1k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:41 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28FILX4S019947; Thu, 15 Sep 2022 19:32:40 GMT Received: from ppma04dal.us.ibm.com (7a.29.35a9.ip4.static.sl-reverse.com [169.53.41.122]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jm8yn2nyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:40 +0000 Received: from pps.filterd (ppma04dal.us.ibm.com [127.0.0.1]) by ppma04dal.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 28FJJtqY004464; Thu, 15 Sep 2022 19:32:38 GMT Received: from b01cxnp22036.gho.pok.ibm.com (b01cxnp22036.gho.pok.ibm.com [9.57.198.26]) by ppma04dal.us.ibm.com with ESMTP id 3jm91q8gdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:38 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 28FJWbu917498774 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 15 Sep 2022 19:32:37 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B34BDAE063; Thu, 15 Sep 2022 19:32:37 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 96FE7AE062; Thu, 15 Sep 2022 19:32:37 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Thu, 15 Sep 2022 19:32:37 +0000 (GMT) From: Stefan Berger To: linux-integrity@vger.kernel.org Cc: zohar@linux.ibm.com, serge@hallyn.com, brauner@kernel.org, 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 v14 18/26] integrity: Add optional callback function to integrity_inode_free() Date: Thu, 15 Sep 2022 15:32:13 -0400 Message-Id: <20220915193221.1728029-19-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220915193221.1728029-1-stefanb@linux.ibm.com> References: <20220915193221.1728029-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 7Rm1lD8gpxDZGcdvBwENnWJZDYtM_EOU X-Proofpoint-GUID: qmIoEtyhZuYtppbsWV5_pnTyzBuJCh1l X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.528,FMLib:17.11.122.1 definitions=2022-09-15_10,2022-09-14_04,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 clxscore=1015 phishscore=0 mlxlogscore=925 mlxscore=0 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2209150119 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 4b95de24bc8d..0892a7c98d8c 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