Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4422703ybg; Mon, 21 Oct 2019 08:47:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDV/sLkfQE1Bzu0jYZQYlhLOm7CAkwebk11sIGB6kEmknIBOlGEYheJUv75xwRXr5X9DXm X-Received: by 2002:a17:906:e2c4:: with SMTP id gr4mr7675886ejb.260.1571672820790; Mon, 21 Oct 2019 08:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571672820; cv=none; d=google.com; s=arc-20160816; b=Gb8TwG/PCrjivVf69Jtq10LBOHL9gyQ+67v/qQQN7bqTi5FRmMFeQGvvFjdPynCurs RmdkyZ2uhRfGlWBiHbJzKW9u5hH5toZu/YnmZ0B0V3Vwr8+WFhbJAmH2eZep7C8Nvy0K Ah/yrRAwCcUvS+17GqNrcu+YVjDzzs55NjvUm0veBOsW5IxTGY44opC1jE6nmS9jdkKa lGNdq8VRG3LWiES7TSgo1a+6a9tr6NSMLJDalWp8ntQM5/9sBcmrqFGxm92r5tjEyGYi oR/m+L5wRe0Vxqv5gyjnUz0lTboN0WmXd5l1Nhd8ytSSe5Am/STwlcTU4HWLAuD1XKuX +klg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=PrO5LeUBLFMgyg2KLUQA5iO3Mo73ZAY8/3ak6BuOVHI=; b=GB7N1yamxg47RBOtydmycB21n3Qgyy2OMOVYe0TxwO0fleFoq4o9AqKETh0W9ReCQt 6dzsjE5d8p96v9u1qRIIyx+VSCdyMcOGX9JyvkzRpqK7cCjaqcuakr4wZnxarynISSiX n21Siq9Ieal5O4VQVhInFW9qFtYog0UX2t1u17+ynvAq4nKlbWGCbHshJZbNzlR499TQ IHKk8u8FtZEJQcfCVdBjJeIU0GtgztSB+KPW+KZLDxMRLzDalJr1UcjvIbUTec5nzc4+ 5998lBNeRdb5MvlkdYqLmGDyDQ+9J72iBI8At4JMK+Sb6Av7uW6F9gYrgk8o7ztrXWBb ZTAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8si9071427eju.333.2019.10.21.08.46.37; Mon, 21 Oct 2019 08:47:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729737AbfJUPpo (ORCPT + 99 others); Mon, 21 Oct 2019 11:45:44 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:37835 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfJUPpn (ORCPT ); Mon, 21 Oct 2019 11:45:43 -0400 Received: from 162-237-133-238.lightspeed.rcsntx.sbcglobal.net ([162.237.133.238] helo=elm) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1iMZsI-0001pK-3G; Mon, 21 Oct 2019 15:45:38 +0000 Date: Mon, 21 Oct 2019 10:45:34 -0500 From: Tyler Hicks To: Navid Emamdoost Cc: john.johansen@canonical.com, emamd001@umn.edu, smccaman@umn.edu, kjlu@umn.edu, James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] apparmor: Fix use-after-free in aa_audit_rule_init Message-ID: <20191021154533.GB12140@elm> References: <57b61298-cbeb-f0ff-c6ba-b8f64d5d0287@canonical.com> <20191021152348.3906-1-navid.emamdoost@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191021152348.3906-1-navid.emamdoost@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-10-21 10:23:47, Navid Emamdoost wrote: > In the implementation of aa_audit_rule_init(), when aa_label_parse() > fails the allocated memory for rule is released using > aa_audit_rule_free(). But after this release, the return statement > tries to access the label field of the rule which results in > use-after-free. Before releasing the rule, copy errNo and return it > after release. > > Fixes: 52e8c38001d8 ("apparmor: Fix memory leak of rule on error exit path") Ugh! I'm not sure what I was thinking when I authored that patch. :/ > Signed-off-by: Navid Emamdoost > --- > Changes in v2: > -- Fix typo in description > -- move err definition inside the if statement. > > security/apparmor/audit.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c > index 5a98661a8b46..334065302fb6 100644 > --- a/security/apparmor/audit.c > +++ b/security/apparmor/audit.c > @@ -197,8 +197,9 @@ int aa_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule) > rule->label = aa_label_parse(&root_ns->unconfined->label, rulestr, > GFP_KERNEL, true, false); > if (IS_ERR(rule->label)) { > + int err = rule->label; Since rule->label is a pointer, I'd like to see this: int err = PTR_ERR(rule->label); > aa_audit_rule_free(rule); > - return PTR_ERR(rule->label); > + return PTR_ERR(err); This line would change to: return err; Tyler > } > > *vrule = rule; > -- > 2.17.1 >