Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1268542rwn; Thu, 15 Sep 2022 13:01:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+xteSXgCmaiWSOK+H/gqXqzHOSMbrd0h9iIGhMPwVR2mTDAf8zxY4bsqGfexovUVYTvD5 X-Received: by 2002:a17:902:f08c:b0:178:25ab:aaef with SMTP id p12-20020a170902f08c00b0017825abaaefmr1217894pla.57.1663272103401; Thu, 15 Sep 2022 13:01:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663272103; cv=none; d=google.com; s=arc-20160816; b=1CatAr6LXSXHwtAB75dbtw60F/wkJYfeDso2ptJmCHstVdSZ720D8NM6Ws1JimG53K +t6FttjK5Q2lrNV9NrWgsmJ/HH2rODChW0sjS9Q6+LX30y9onX7OAnl92bsR/AJfRnba 55WuDR4lEBOYRNWY726MPKqR5pHU+l5PtvhSLpzHyyyxXBPrYWGG3pqz9/PEHhj+aiLu qjs+M8hH/oa7zTVc7LdBR5GEmCKELdaYS/pwkqGKWSGaB5gAoQCkVzuMvOnorWry/xsR YUi5gh/3KVC0EG86sWuagQVw506ZlrQtvirngyBnzlU8QgzSueynGeFYBqhI5A+rUYW5 wMsw== 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=qJ1zmGiwBWgKL/r8S2S20/K9mzwUQjahDkEVG/zJe9U=; b=LZeg0xw39K0VniBjGtmRN3JTucBRL7uK+8Mf2F2FwucgMrdOi8+nAcUNg4vbZrviAz 5GklY2FNWzQdHF87q7aiqrklRu3CGQgWdT+l//KW9SbgTQMPrqN94SYMFYhRukuHSCG/ TuJF0A52cjBHQugXaK3IcIQMhdWDgDWNj+9Ht0tRsEeQIMTmTMto1h5V2YUsgeYTqT8X FqEGPcvzRdRoSdEKOrbMO7+BIazovC0GfG9kfMJQ/V8rccguJb6PER5X65at9vw6+7hM eMJS5ijZIp5ftRZ7BHKITUqLQv0/gJcypN+IOSCTU/FgsWZ2OsFXQLXvlWHnL7CN/6ba W3hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=Z+inTTpc; 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 m11-20020a1709026bcb00b00177fb0a918asi20244091plt.71.2022.09.15.13.01.30; Thu, 15 Sep 2022 13:01:43 -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=Z+inTTpc; 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 S229960AbiIOTet (ORCPT + 99 others); Thu, 15 Sep 2022 15:34:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiIOTdT (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 85E949D660; Thu, 15 Sep 2022 12:33:11 -0700 (PDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 28FJGbwP013294; Thu, 15 Sep 2022 19:32:40 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=qJ1zmGiwBWgKL/r8S2S20/K9mzwUQjahDkEVG/zJe9U=; b=Z+inTTpccxDVmtJbi36isCYc8AQI8NEru4IASiWyVMI4DNNZJwwgmY85KaBVetewXJI2 S7G14NtzC9lAliA1tOGn5dXys6mEYedaEE0/9MeQBnikbKRQkLDMxhHoPLkzEiaPWI+W ztOFsLSkHQ8SydeMhhuNEkrm5RlR+NnVE8hIX7ZKQMIiwj6CEXVWEk2dXjOt6Hh8DWlq VCQAs6p1CvWW+p0bYPPcVe4XPSmgZaKiJ+sV+JyU4YOuKPIocooWllZuX36uAnL2JXJQ RSr6A4kVqgm6gVPrskXHIqU7qFvlYtthh7i+0j3ugT5JuV6VjfuMBP8JYv01n58IFpq0 2Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3jma2mgfmt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:40 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 28FJI9b8017381; Thu, 15 Sep 2022 19:32:39 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 3jma2mgfkv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 15 Sep 2022 19:32:39 +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 28FJJvTT004489; 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 3jm91q8gdm-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 28FJWbK811404080 (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 43B6EAE05C; 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 272E8AE063; 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 15/26] ima: Implement ima_free_policy_rules() for freeing of an ima_namespace Date: Thu, 15 Sep 2022 15:32:10 -0400 Message-Id: <20220915193221.1728029-16-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-GUID: 9wLZEXFvDJVDnEejhWrEu40zvfJKON3Q X-Proofpoint-ORIG-GUID: G0tvP_HKfY10BTlgDo-6TzP23RCYcCSd 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 suspectscore=0 mlxlogscore=999 malwarescore=0 spamscore=0 priorityscore=1501 adultscore=0 impostorscore=0 lowpriorityscore=0 phishscore=0 clxscore=1015 mlxscore=0 bulkscore=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 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 Reviewed-by: Serge Hallyn --- 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 e662641772fd..528d792c82c1 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 e81eebc7d41e..fb4f08f86330 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -1967,6 +1967,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.36.1