Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2512330rwb; Mon, 3 Oct 2022 01:40:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Z78vj87yp7yGCFyhUq0dKXiB36Krz8wifhev+F1zJG/wzArBs8DyoTV12W8do3keSBv+I X-Received: by 2002:a05:6a00:1304:b0:555:6d3f:1223 with SMTP id j4-20020a056a00130400b005556d3f1223mr21718286pfu.60.1664786411880; Mon, 03 Oct 2022 01:40:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664786411; cv=none; d=google.com; s=arc-20160816; b=GYAI997o8KOelxT8pphAojrvyWByY7l9k1K7tmgSCu/jQrQ7pGKzkXJ7nCgW3UqbVq X8RoArLobTBP+0Z/Yxi5zjkJE2wWsTkuYLYOArbm7Bu8wfHoThgGTeOyqT4rzoeTxrda qMs6Sa0fWwL8gorby5NwUcyWob3pJzq3zDsMpAiKiOZ4lW6G8eIsYbr6wqlxKippQjKw ClwInfb3CqUyPIFndozkU/avivE/8grxRFSS1x9mCp5YldM6E1krrBE5J9a2MiqLAAih XHhoRcjzTxmJjTdta0zpOpxjKxKzqCCqMjmFi2IqLSox9mYuQjNKYFd0wOyRdHvpQGG8 Q/xw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=G5PeqJ6ll543Xgsg5MPv1Q1ZTMzFh6qaXKWWQQ5pAzg=; b=PM0cr/dy6tqyr/ogU8VyF8bo1PxMf7oErZcpZPRlU+/dpAu3hV9EwGGMkzk5jKk0I6 vGrrA81jyIPJq+gTe5KFnXh1k8S2aryHU5Gr1CNVrA9Qk+nusvtlmnVcozU6iswLePKl cktUrqMd1/7LXRgt2WYZe+aA6gtWs9bKHMvDd4wemWLmEMBghzJqBW23tpp9erRjFufg MxfNBEcooqh9FMiNv50d7EMUtlxeSxT7Ubdf6LWEgSKCZ+HNrG8L/4u8z5UIyslWO8oP ATSW6Nw27KPJt+mPgyVjWWuS1NEOgB09l2vMaSKPosdJnkB1qKi4Iw3+Z0nhCVZenlwe AENA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="M/kslXZd"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a170902ef4400b00176841aa2e3si10211384plx.93.2022.10.03.01.40.00; Mon, 03 Oct 2022 01:40:11 -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=@linuxfoundation.org header.s=korg header.b="M/kslXZd"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232288AbiJCHrm (ORCPT + 99 others); Mon, 3 Oct 2022 03:47:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbiJCHqm (ORCPT ); Mon, 3 Oct 2022 03:46:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4596D58526; Mon, 3 Oct 2022 00:26:29 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8823CB80E89; Mon, 3 Oct 2022 07:24:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F020DC433D7; Mon, 3 Oct 2022 07:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781874; bh=lfT5Sb/B3uL8Vk29p+EkIcR/HdZXKH5A9Ykqm1Y9UAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M/kslXZdKPsIn1Th4BAnee+n4e/CYdHw1eE8bAfAHfsXZhPHMGVlV3LtSTryFD5Zw LnRLHyU7PPOYS3aBrKBqrefh/j7YrBu2JxRIPsSUxRgG228OZmtcoXIXCfbG64G1xq deTWxbdyExkP1qCRBijYAOGMZNuxa6/hgH8kp9Fg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Tyler Hicks , Janne Karhunen , Casey Schaufler , Mimi Zohar , Gou Hao Subject: [PATCH 4.19 12/25] ima: Have the LSM free its audit rule Date: Mon, 3 Oct 2022 09:12:15 +0200 Message-Id: <20221003070715.772124468@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070715.406550966@linuxfoundation.org> References: <20221003070715.406550966@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Tyler Hicks commit 9ff8a616dfab96a4fa0ddd36190907dc68886d9b upstream. Ask the LSM to free its audit rule rather than directly calling kfree(). Both AppArmor and SELinux do additional work in their audit_rule_free() hooks. Fix memory leaks by allowing the LSMs to perform necessary work. Fixes: b16942455193 ("ima: use the lsm policy update notifier") Signed-off-by: Tyler Hicks Cc: Janne Karhunen Cc: Casey Schaufler Reviewed-by: Mimi Zohar Signed-off-by: Mimi Zohar Cc: # 4.19+ Signed-off-by: Gou Hao Signed-off-by: Greg Kroah-Hartman --- security/integrity/ima/ima.h | 5 +++++ security/integrity/ima/ima_policy.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -298,6 +298,7 @@ static inline int ima_read_xattr(struct #ifdef CONFIG_IMA_LSM_RULES #define security_filter_rule_init security_audit_rule_init +#define security_filter_rule_free security_audit_rule_free #define security_filter_rule_match security_audit_rule_match #else @@ -308,6 +309,10 @@ static inline int security_filter_rule_i return -EINVAL; } +static inline void security_filter_rule_free(void *lsmrule) +{ +} + static inline int security_filter_rule_match(u32 secid, u32 field, u32 op, void *lsmrule, struct audit_context *actx) --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -1044,8 +1044,10 @@ void ima_delete_rules(void) temp_ima_appraise = 0; list_for_each_entry_safe(entry, tmp, &ima_temp_rules, list) { - for (i = 0; i < MAX_LSM_RULES; i++) + for (i = 0; i < MAX_LSM_RULES; i++) { + security_filter_rule_free(entry->lsm[i].rule); kfree(entry->lsm[i].args_p); + } list_del(&entry->list); kfree(entry);