Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3255806ybt; Mon, 22 Jun 2020 20:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZjHZaBbdJzTzjXdsj5XAse9YK0chntUgM/oF5hNYA8iRDm6jkVZ8Il7jtZMG8xKhjP+4j X-Received: by 2002:a17:906:e247:: with SMTP id gq7mr18158725ejb.107.1592881603560; Mon, 22 Jun 2020 20:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592881603; cv=none; d=google.com; s=arc-20160816; b=ieuEAkLVWzKJklZ7L5ew2h15TbFY7ZXP4hYAt2ug4pRgq5a9JL/ixYdcP1JG6QxaJH q+c7Z/79sOnnm1mZJTZvr8Cd/ankM/0iHl8W2VqG5WlfsjOweUQL1doVYzntGJowqi8f 21s15EsdSDUfVtpzKDi3RAlCQklIgZz//lQkUkr9wfXRAw7hHa+4Nz3896O+kKxTEcJA xCfJm0GQdn/EbK5SJkzEilO9EgRPzKVISMV3rCANneKID+0Yvh7ldH+03hNMDT8aGOnx A3ZKXzmnVGlCxr+3yTP3SnY3kWvFITB5qgrQG6zIB6p9tCxaFKLZlspidOx8dn9EflhU apNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:dkim-filter; bh=381Z41lC2pIuRAjDOd1plbxk7DixDyCGV2sdQrwp2K8=; b=AvN7AD69tf9IWJeLB2NVLdsXpCWMjli4+muzJ0JGRCHxO6MHrAS7OUbOxx5Awvbreb MKQHO7ehgU+qZOi0M11LFyLwElszFnhCaTW9xSDYYhlKk1ZWYDQCCKg589AlsDpmTX/V YEvtkb+Vn/uM2i0ynlECNIYQMG0cc4K0OUo+mPPwjAq8FUNrTj4LgGbkeH4wZQsJW8aU eXX3YMeaS40hVzkX/hw/lbcqwpojgcEMrX0Gqi1wTd+70SkGZSjRMk41G5DpGNMIoHKK /m90ACgQIsMwNPyYDmomoZyYsyQESdUGH90+fpYw+DELhtWBbYa7Q1jPUTdnUtaeS3a1 xsQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=BF7DmQg0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds15si14429322ejc.14.2020.06.22.20.06.21; Mon, 22 Jun 2020 20:06:43 -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=@linux.microsoft.com header.s=default header.b=BF7DmQg0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732083AbgFWDE3 (ORCPT + 99 others); Mon, 22 Jun 2020 23:04:29 -0400 Received: from linux.microsoft.com ([13.77.154.182]:39466 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731820AbgFWDE2 (ORCPT ); Mon, 22 Jun 2020 23:04:28 -0400 Received: from sequoia (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id E02BB20B7192; Mon, 22 Jun 2020 20:04:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E02BB20B7192 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1592881467; bh=381Z41lC2pIuRAjDOd1plbxk7DixDyCGV2sdQrwp2K8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BF7DmQg0pl1+RSkVQ+UHXPhVzA05min9ZtgSAp4sjf9eiEZbWpW37yBlfH4Gs28JW 0qObN7Q++fObJG1IT7S2kSL/nQAK+qLRq40yPxUbGqe7qmmxL7F9H+ILgRR4jYoKUY ERX66DrDmXerBOnmTGdDXf4AQUuQjrQQAd71dIPc= Date: Mon, 22 Jun 2020 22:04:10 -0500 From: Tyler Hicks To: Casey Schaufler Cc: Mimi Zohar , Dmitry Kasatkin , James Morris , "Serge E . Hallyn" , Lakshmi Ramasubramanian , Prakhar Srivastava , linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, Janne Karhunen Subject: Re: [PATCH 01/12] ima: Have the LSM free its audit rule Message-ID: <20200623030410.GA6048@sequoia> References: <20200623003236.830149-1-tyhicks@linux.microsoft.com> <20200623003236.830149-2-tyhicks@linux.microsoft.com> <277dd210-c443-c067-e731-44ac53418fa5@schaufler-ca.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <277dd210-c443-c067-e731-44ac53418fa5@schaufler-ca.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-22 17:55:59, Casey Schaufler wrote: > On 6/22/2020 5:32 PM, Tyler Hicks wrote: > > 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 > > --- > > security/integrity/ima/ima.h | 6 ++++++ > > security/integrity/ima/ima_policy.c | 2 +- > > 2 files changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h > > index df93ac258e01..de05d7f1d3ec 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 > > In context this seems perfectly reasonable. If, however, you're > working with the LSM infrastructure this set of #defines is maddening. > The existing ones have been driving my nuts for the past few years, > so I'd like to discourage adding another. Since the security_filter_rule > functions are IMA specific they shouldn't be prefixed security_. I know > that it seems to be code churn/bikesheading, but we please change these: > > static inline int ima_filter_rule_init(.....) > { > return security_audit_rule_init(.....); > } > > and so forth. I understand if you don't want to make the change. > I have plenty of other things driving me crazy just now, so this > doesn't seem likely to push me over the edge. I'd be happy to take a stab at that as a follow-up or a 13/12 patch. I'd like to leave this one as-is for stable kernel reasons since it is straightforward and simple. Tyler > > > > > #else > > @@ -414,6 +415,11 @@ static inline int security_filter_rule_init(u32 field, u32 op, char *rulestr, > > return -EINVAL; > > } > > > > +static inline void security_filter_rule_free(void *lsmrule) > > +{ > > + return -EINVAL; > > +} > > + > > 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 e493063a3c34..236a731492d1 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);