Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2631913pxa; Mon, 17 Aug 2020 14:58:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4au9eBD9ubaj6OV3bHPNVBLuIRFEBz9Y3fHzRYXg11qRezQS+nrTalhU+FaDMr51Arxvm X-Received: by 2002:a17:906:2b57:: with SMTP id b23mr16757194ejg.26.1597701539329; Mon, 17 Aug 2020 14:58:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597701539; cv=none; d=google.com; s=arc-20160816; b=kr6khiXpDs4Yt/uK7xFgfy5F+uy3sQJA9Dj0ECjINdVXD/XcXdrzezEPeCz/ajd+wG 0hrtDVYpmSz3nNGnbzcAPziNa9gtQwCXCOv9C0JZ4alwOohK7uPG09YH/v5x9pm4pNbz 4bv/nXnFuF0FIpS1974HRSJDsl56Jka1qURzPc2pvrJn2p0HLRdC8HMCJlCKinJo6mMw 3EeBP6VH0xZ6aqMdiLbo61CzQAx4cmdvqGhl1ipW6mn6FmPWDBWHpOcpSuTkJhPWPQCK IalFrkJyi0hlY6R3Rp4jFGO27Rv94pgPLrL0MVR3bU4BDkKzliN3KMvCI1sLppFH3Di4 FHyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5a8ZzTOG+TimhxynWTSewuMSJ2MgrxURmxYiZzgBPRQ=; b=pUbWQR7pbIUOO8x96surnaBvxpinEWzF2KzS4lRztZdDNWHlkKZ1ylxTVGAlkJhOFf um6fDQWg0OOWJ89eMFLJPugZL9fKp1Amp+KvGST1GHRMQn1+nxibmQQq2TJmeWUJGadL hfG02USU96cHp7CZS2RLQccAgy0d/tZXTYfkAmhHVj5cyPufYx2qW059JCH1hyAMgDV4 LIIH3lz7S3wbw9Ij9+zrzjtOI6m8xBaJkUopQZ/ZLsaBQXyfJ5y2AG2YgL+P7OISQaC4 GX6xiVK3LAhBpjneC4jxolocSlMb/RtNEyFcITvcV9YUYNTHnjoZHKnUyCBCWETKkyn8 iZsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=db7VWCLl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qc15si11622612ejb.658.2020.08.17.14.58.36; Mon, 17 Aug 2020 14:58:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=db7VWCLl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730331AbgHQPcr (ORCPT + 99 others); Mon, 17 Aug 2020 11:32:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:47570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730088AbgHQP3X (ORCPT ); Mon, 17 Aug 2020 11:29:23 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3D5C12395B; Mon, 17 Aug 2020 15:29:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597678162; bh=1sMJ4DzHl9wjIkYM1UGBRkiU3Arytg+JDvm2TSLd80A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=db7VWCLlW/Ghrhmgn6wGlP4gyfY8sC9xVVILjnlci0B8ugsC+KcWuIvT8GsgK++WK 4iVCoeSzgxs29pfK59B4OeOnLnuPhPe5ydnwEksSe7bNZGmcMsUf1zCsqWQkj9nGT8 cHHdLNLbPojDtqx7sssMzzWJdR/Qomp/+qAGXDgI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tyler Hicks , Janne Karhunen , Casey Schaufler , Mimi Zohar , Sasha Levin Subject: [PATCH 5.8 239/464] ima: Have the LSM free its audit rule Date: Mon, 17 Aug 2020 17:13:12 +0200 Message-Id: <20200817143845.244431488@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143833.737102804@linuxfoundation.org> References: <20200817143833.737102804@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tyler Hicks [ Upstream commit 9ff8a616dfab96a4fa0ddd36190907dc68886d9b ] 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 Signed-off-by: Sasha Levin --- security/integrity/ima/ima.h | 5 +++++ security/integrity/ima/ima_policy.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index 9d94080bdad82..f0748f8ca47e9 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h @@ -404,6 +404,7 @@ static inline void ima_free_modsig(struct modsig *modsig) #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 @@ -414,6 +415,10 @@ static inline int security_filter_rule_init(u32 field, u32 op, char *rulestr, 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) { diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index e493063a3c344..236a731492d1e 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -258,7 +258,7 @@ static void ima_lsm_free_rule(struct ima_rule_entry *entry) int i; for (i = 0; i < MAX_LSM_RULES; i++) { - kfree(entry->lsm[i].rule); + security_filter_rule_free(entry->lsm[i].rule); kfree(entry->lsm[i].args_p); } kfree(entry); -- 2.25.1