Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3193445ybt; Mon, 22 Jun 2020 18:00:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7/N1uavrMxm5PXHnutkeQ07XaXHcDMLxJ3n/apkAR1RXm5u+mffEMgv1yviZqcJgkSkNZ X-Received: by 2002:a17:906:2a94:: with SMTP id l20mr17574068eje.224.1592874041383; Mon, 22 Jun 2020 18:00:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592874041; cv=none; d=google.com; s=arc-20160816; b=hXS5XGhCTO1zDr/pls4D2lRK+h4udlIOm5J51WMG/HgWK85sOWLQIbuR7ftLcgyzMf iGoKbwYFNDMtaUZFZjPixZHT6thMIyyO1FirJ7WgbUZfPqwHu4OacdXsqMxrWH7xvM3e KvAdjiLkj6rClcAQyC4yhzlzmSnYveiirGbqXgYuOFhJx4HD7Bb1ZBTzZfvuLGN7reJ7 BYAh1Z4xnoPhTpMV7XKHzAWtietzgo7YzAPmsye+tLwasfZRnloCYyhUfNHJhDjosanE v1Q/XTGpzhgHiM9t+iRtqwOol5O9+tw1QoxP1ksXlad4VEWXDBcwHT+YcmCLxagsG00S 6clw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:from:references:cc:to:subject:dkim-signature; bh=pzoSBVgHzCBLrlJt0oGf4p1Cu2m7OZpq/AvXD0rhxC4=; b=JajlG93Ray9KsV82FUyalMxTmcSr/LxO4F7uNbzguJY2RXittbkwF+TkSL3DyO1Ack hKWx4rj0MZy7tReoVA1Sn7J3LtOA5G+Luai8/1jj3Dy9Ku/XRB2VSFi/xjU8ZWN2R3m5 DHFayNQ4L7qmJGd5kS/YaFMBYU2GtwXrSwNtamWJOAJPM9MY0EKTQHzUeymoSZmfAhV2 u9G61kefLycF883Wovt+7O6eJSiABMj1OSxAw6+cIDNxKkVgkKbnVi7exM6SRtCe2rgg kwM9QD7o06PHNCxnjk9rETzHJdtOxu3BVpQ0Kx0xWYLFLrTwABsKY/QPpmutBDQqAell Jplg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.com header.s=s2048 header.b=RrDbxLGd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si3563611eja.291.2020.06.22.18.00.19; Mon, 22 Jun 2020 18:00:41 -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=@yahoo.com header.s=s2048 header.b=RrDbxLGd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732124AbgFWA4T (ORCPT + 99 others); Mon, 22 Jun 2020 20:56:19 -0400 Received: from sonic310-31.consmr.mail.ne1.yahoo.com ([66.163.186.212]:35071 "EHLO sonic310-31.consmr.mail.ne1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732418AbgFWA4S (ORCPT ); Mon, 22 Jun 2020 20:56:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1592873761; bh=pzoSBVgHzCBLrlJt0oGf4p1Cu2m7OZpq/AvXD0rhxC4=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From:Subject; b=RrDbxLGdSUk6U1+4EOKkXdi771FIJCTxJa+g/4R6n7qpglLY0jcCjehqVCJM6pDKAXby0deTm79/BOQHObfWFzgp3cQtXYH4mwzhLtJagECRDR61s4OkRHnvI5mXjhsNc0ndISS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MhfCzFLOcb8dZLINAragk8IsWWrHcWKYLfrv3fiq dLW8XFUXr2GNP2hoN24LVLuBtsEe_N4grVwsARQSy8MMIkOX_Ol8_KcbNtKBl9XLOwN0kGk4KhM3 _noFY7RW9pBnjNyEubg_FJBgHhPS64BVXxZ1H5nCv5rsNfgJxBgpxK1DVNP1k.z0wel1_d92NXv0 9mm44dN2QvCgeUbsvM5yXSMAy1PIEysXTvn6FFZ8mYJGyglCGPwXGDhjAe.SKuih2J0madt_vfAW 7rEhW_2stgsX8qIUQLzD6zvXl_4DFrr3glZ81uNqA.cNw_MncOH2gr93lGmM_pk9obJFg83KpmAz N8cs2c_bJF7Er9jY95IhnJIyYr8DEL.XytS5uOx16i_WiuBcM2LTZXr0WQ6VNSrvjyXpwCLmbvhn Lx9m.FVevpYUd6X2B9kCP_P_OVu20z9IT1IWluxGykCHqp6JmUg_m076nJnmOijp4b4nB_XB9NSj 8bYWZWqH8yUJDotpjyHXwx.egweJhnrzfiiy8Y..wXNrRxmhhylwlXQuRdfhBnapJ6WxZkxNIwQv NRvawWXItnyF8uzNchICRcL8tZpH2qPRYU5aVkuVyK7aA Received: from sonic.gate.mail.ne1.yahoo.com by sonic310.consmr.mail.ne1.yahoo.com with HTTP; Tue, 23 Jun 2020 00:56:01 +0000 Received: by smtp427.mail.gq1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 0ef61bdd18007080b2d4ae4c54f37684; Tue, 23 Jun 2020 00:56:00 +0000 (UTC) Subject: Re: [PATCH 01/12] ima: Have the LSM free its audit rule To: Tyler Hicks , Mimi Zohar , Dmitry Kasatkin Cc: 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 , Casey Schaufler References: <20200623003236.830149-1-tyhicks@linux.microsoft.com> <20200623003236.830149-2-tyhicks@linux.microsoft.com> From: Casey Schaufler Autocrypt: addr=casey@schaufler-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KE7Hl6WdW19BXOZ7v3jo1q6lWwcFYth esJfk3ZPPJXuBokrFH8kqnEQ9W2QgrjDX3et2WwZFLOoOCItWxT0/1QO4ikcef/E7HXQf/ij Dxf9HG2o5hOlMIAkJq/uLNMvABEBAAGJAjwEGAEIACYWIQQL720fVjJTAhDNQh44pRV8jEPI EQUCXNX0cAIbDAUJEswDAAAKCRA4pRV8jEPIEWkzEACKFUnpp+wIVHpckMfBqN8BE5dUbWJc GyQ7wXWajLtlPdw1nNw0Wrv+ob2RCT7qQlUo6GRLcvj9Fn5tR4hBvR6D3m8aR0AGHbcC62cq I7LjaSDP5j/em4oVL2SMgNTrXgE2w33JMGjAx9oBzkxmKUqprhJomPwmfDHMJ0t7y39Da724 oLPTkQDpJL1kuraM9TC5NyLe1+MyIxqM/8NujoJbWeQUgGjn9uxQAil7o/xSCjrWCP3kZDID vd5ZaHpdl8e1mTExQoKr4EWgaMjmD/a3hZ/j3KfTVNpM2cLfD/QwTMaC2fkK8ExMsz+rUl1H icmcmpptCwOSgwSpPY1Zfio6HvEJp7gmDwMgozMfwQuT9oxyFTxn1X3rn1IoYQF3P8gsziY5 qtTxy2RrgqQFm/hr8gM78RhP54UPltIE96VywviFzDZehMvuwzW//fxysIoK97Y/KBZZOQs+ /T+Bw80Pwk/dqQ8UmIt2ffHEgwCTbkSm711BejapWCfklxkMZDp16mkxSt2qZovboVjXnfuq wQ1QL4o4t1hviM7LyoflsCLnQFJh6RSBhBpKQinMJl/z0A6NYDkQi6vEGMDBWX/M2vk9Jvwa v0cEBfY3Z5oFgkh7BUORsu1V+Hn0fR/Lqq/Pyq+nTR26WzGDkolLsDr3IH0TiAVH5ZuPxyz6 abzjfg== Message-ID: <277dd210-c443-c067-e731-44ac53418fa5@schaufler-ca.com> Date: Mon, 22 Jun 2020 17:55:59 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200623003236.830149-2-tyhicks@linux.microsoft.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Mailer: WebService/1.1.16138 hermes_yahoo Apache-HttpAsyncClient/4.1.4 (Java/11.0.7) Content-Length: 2662 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/22/2020 5:32 PM, Tyler Hicks wrote: > Ask the LSM to free its audit rule rather than directly calling kfree()= =2E > 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 *m= odsig) > #ifdef CONFIG_IMA_LSM_RULES > =20 > #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. > =20 > #else > @@ -414,6 +415,11 @@ static inline int security_filter_rule_init(u32 fi= eld, u32 op, char *rulestr, > return -EINVAL; > } > =20 > +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/i= ma/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; > =20 > for (i =3D 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);