Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4451800ybg; Mon, 21 Oct 2019 09:12:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwei8w4w5ZHHfrBvKkoRCwM27M+spwcXgtwx5CKaLty+QeCOel99zNqDsgNCqXitu9uVsJu X-Received: by 2002:a50:fa42:: with SMTP id c2mr12469345edq.112.1571674341511; Mon, 21 Oct 2019 09:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571674341; cv=none; d=google.com; s=arc-20160816; b=SxYgx+CUqoFt1RyPBbxX8fk9GJPAHgE82EwPC1GvNMW74YIAJE3PjZOSUB/4E0qNen pnH9VnAkgxqKaKdQtQCaIjqS3GS/k1TSX05K2JPylAaYA+E/L/lULYMm3I9MtiPWVWWY 95XgP+A4AcNNU6ij7JBPfjZmXaQKVjxnGSDXuYj4ILMaqKGMRR1R9ojB+AdaBehxbbaJ XTi4h1b/Afjco4rhydRuHSEYRJ/HrsRNImuuFdlW2zUTY9ZitsCJEiC6UPBImkhP/JAa CZbZ2yr0fjPOxZXs6ACaPMR7zUjv4SOGDsr7uzt3Cy8jcMyIHkkWFWJX9gu23qzrbGYg c+LA== 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=3SQ+3mQUVtoXma3a+Pyg+gOt3JZBuJGLnCuOFol0boc=; b=uZeldxcCnxzjO3AGGoZGNpem9W2K5Da5VtCxz4vVj/NJykv/GOulqzyIFUeBbRmREB K6NyY5FUO8jTT/+rllVdUazM5Sk8FPl0Z2hjX4wFWcDr8HeCgx0jUi+9R46YoC1gWGSE k1Qh5P+VOokDPeRBF5VEzme3w4Hx/y4QGxu7bIaeUm5kJsmaCAmakOoOP51w3L+2mYjq GELtntxJpPWOvR0BCf3LflX4uA8DKq/B6NYSua+bw+8BNyF2flqq6VzaIAwF7CpZpfp8 YFx9KrHVf9SWkDVGZjPEE/HRM3ksltFQLcA+GXXJrt622LZIe2If+K/WUkqm9+LmBxxP 0xoA== 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 o14si8973233ejc.405.2019.10.21.09.11.46; Mon, 21 Oct 2019 09:12:21 -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 S1729929AbfJUQIW (ORCPT + 99 others); Mon, 21 Oct 2019 12:08:22 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:38911 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729905AbfJUQIW (ORCPT ); Mon, 21 Oct 2019 12:08:22 -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 1iMaEF-0000sX-Ga; Mon, 21 Oct 2019 16:08:19 +0000 Date: Mon, 21 Oct 2019 11:08:14 -0500 From: Tyler Hicks To: Navid Emamdoost Cc: emamd001@umn.edu, smccaman@umn.edu, kjlu@umn.edu, John Johansen , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] apparmor: Fix use-after-free in aa_audit_rule_init Message-ID: <20191021160814.GC12140@elm> References: <20191021154533.GB12140@elm> <20191021160532.7719-1-navid.emamdoost@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191021160532.7719-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 11:05:31, 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") > Signed-off-by: Navid Emamdoost Reviewed-by: Tyler Hicks Thanks! Tyler > --- > Changes in v3: > -- applied Tyler Hicks recommendation on err initialization. > > 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..597732503815 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 = PTR_ERR(rule->label); > aa_audit_rule_free(rule); > - return PTR_ERR(rule->label); > + return err; > } > > *vrule = rule; > -- > 2.17.1 >