Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp855397pxb; Fri, 22 Apr 2022 12:42:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw23trPpXlU5R0kjAm6PC3gpMIp04Q5w23O/dnU3rpMb7qNg9dWTG8GqdPV814AjECcOFZH X-Received: by 2002:a63:bf0e:0:b0:386:361f:e97a with SMTP id v14-20020a63bf0e000000b00386361fe97amr5159449pgf.552.1650656565393; Fri, 22 Apr 2022 12:42:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650656565; cv=none; d=google.com; s=arc-20160816; b=lTudn0cLkXj6K0KQHWrcPnMfgmLD0H5xAy51HoL7tFck/aL2d5NAPl3mZqi2Kyow8L GYoP0XRbzFo1QcXerXwmTg69Z8uVV1HYKDHXotyfkwJco94YG/g9PywdO71a0LRgSVN/ kS2DvIKKv7CKzeiADfVK8jhEcJPAs2Z2gYPsjShpbansM3+lIu40YsLiRZN9wWTEJpCg LX11XTaQuHGcaYGDey2RHRM6nwjA4zCCSnMSgLUV2lPQq3QP20nTDm5JWlNiB7kKyeiV AHRo8ja125iyUBxG0KNAi0mZN6MnfFGwZKlHagPkJ9CK0Ok9IKgU7lQTQx43Vg3FaGqa ea1Q== 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=/+fZEDTvAFBMwvbP6YNYQcdH1wz6kH2Mrn71IOIdFus=; b=GOwQnVaZyxQa7Cduq3yfu+tt9MTW6QofbwC8TcVwmG4B9AivdfyW1A9YffPh+8BAGo IzbpcLBFcV4ixanpkWbtJOPKxfPbsMxXDpuWgOYgv2Z/xeEpn864S1dLqbb/c+4iLMyV 84qyAHh7/W2ZScNI8gWjhmpKfqgkdeur+DBJjF+wbqM3t8+hqWUtz7cTLSd/yqdguOV7 8IaCpyx2Yck0+giE2/+FmH1UIitoVrUPg2u3ZY8rqOw2t/1YnfnhYN8LfqIApkF2shs9 zbhtI8kmcY3TXQMCWox8MmFFLYz/U4/05BzMMdbHql/Xw8PeWP0mPoVgV6SKiN9WAEA7 bgbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=hjKjVAC7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k7-20020a056a00168700b004fa3a8dffc4si9428731pfc.123.2022.04.22.12.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 12:42:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=hjKjVAC7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B7A6E0AC5; Fri, 22 Apr 2022 11:47:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379298AbiDTOKf (ORCPT + 99 others); Wed, 20 Apr 2022 10:10:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244883AbiDTOKJ (ORCPT ); Wed, 20 Apr 2022 10:10:09 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2BFB44752; Wed, 20 Apr 2022 07:07:13 -0700 (PDT) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 23KCRCSU024495; Wed, 20 Apr 2022 14:06:46 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=/+fZEDTvAFBMwvbP6YNYQcdH1wz6kH2Mrn71IOIdFus=; b=hjKjVAC7stOwsaO8dCi73Ciiec5FUiD7K4p6pNxoEmKTKshpvffPjuvBIl7R7Z5FTG81 vi9dvotSUfb4PlGa5EnlpFdkTi9+A3tI+M7589UUlx8nwj2MfUFb2IrOnnouSgvVilgW edcmAC+Eb7HrTDMG6kYfxdjzcHZftTw9Uf8KgSV7gbeUTca5eOZD5lz2qwoL1H/Kvkrs a6Ia2IokGTKxdNh9yuVJFRulGoKEcJxCyLl61JL049Lx9r8kJu2o0u730vBpqZ8LU+vj K7WasN2Oe3wxJQg/5XAonHFitN7D9+GI/suxcoS3ECG9JRiFI8NpWQ4HeI+52YGvLh/e 3A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjff2wtmv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 14:06:45 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 23KDOMkq002227; Wed, 20 Apr 2022 14:06:45 GMT Received: from ppma02wdc.us.ibm.com (aa.5b.37a9.ip4.static.sl-reverse.com [169.55.91.170]) by mx0a-001b2d01.pphosted.com with ESMTP id 3fjff2wtm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 14:06:45 +0000 Received: from pps.filterd (ppma02wdc.us.ibm.com [127.0.0.1]) by ppma02wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 23KE3H0e006676; Wed, 20 Apr 2022 14:06:43 GMT Received: from b01cxnp22034.gho.pok.ibm.com (b01cxnp22034.gho.pok.ibm.com [9.57.198.24]) by ppma02wdc.us.ibm.com with ESMTP id 3fg2xw1aqa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Apr 2022 14:06:43 +0000 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 23KE6hkK61014410 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Apr 2022 14:06:43 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0845CAE062; Wed, 20 Apr 2022 14:06:43 +0000 (GMT) Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DFAECAE05F; Wed, 20 Apr 2022 14:06:42 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP; Wed, 20 Apr 2022 14:06:42 +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 v12 15/26] ima: Implement ima_free_policy_rules() for freeing of an ima_namespace Date: Wed, 20 Apr 2022 10:06:22 -0400 Message-Id: <20220420140633.753772-16-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220420140633.753772-1-stefanb@linux.ibm.com> References: <20220420140633.753772-1-stefanb@linux.ibm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yfS2xLelOmUrOd-_0e0HqR6LOlMbmQw8 X-Proofpoint-ORIG-GUID: ShChNvj4bG5o_0MfqlbRxA91gxIcQzJs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-04-20_04,2022-04-20_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=999 adultscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204200081 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no 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 Implement ima_free_policy_rules() to free the current custom IMA policy's rules. This function will be called when an ima_namespace is freed. Signed-off-by: Stefan Berger Reviewed-by: Mimi Zohar --- v10: - Not calling ima_delete_rules() anymore - Move access check from ima_delete_rules into very last patch v9: - Only reset temp_ima_appraise when using init_ima_ns. --- security/integrity/ima/ima.h | 1 + security/integrity/ima/ima_policy.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 2775a6d89e6d..054b8f67be04 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -333,6 +333,7 @@ void ima_update_policy_flags(struct ima_namespace *ns); ssize_t ima_parse_add_rule(struct ima_namespace *ns, char *rule); void ima_delete_rules(struct ima_namespace *ns); int ima_check_policy(struct ima_namespace *ns); +void ima_free_policy_rules(struct ima_namespace *ns); void *ima_policy_start(struct seq_file *m, loff_t *pos); void *ima_policy_next(struct seq_file *m, void *v, loff_t *pos); void ima_policy_stop(struct seq_file *m, void *v); diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 45a997709200..eb10d895923d 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -1905,6 +1905,20 @@ void ima_delete_rules(struct ima_namespace *ns) } } +/** + * ima_free_policy_rules - free all policy rules + * @ns: IMA namespace that has the policy + */ +void ima_free_policy_rules(struct ima_namespace *ns) +{ + struct ima_rule_entry *entry, *tmp; + + list_for_each_entry_safe(entry, tmp, &ns->ima_policy_rules, list) { + list_del(&entry->list); + ima_free_rule(entry); + } +} + #define __ima_hook_stringify(func, str) (#func), const char *const func_tokens[] = { -- 2.34.1