From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95CAEC433DF for ; Tue, 9 Jun 2020 00:32:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E639206C3 for ; Tue, 9 Jun 2020 00:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591662740; bh=szMzKWLLvKCRf1i4cCc+3mjcrWOYNZx5wYhk+zhoUZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=mSd5agKAqZDf6aJBTCyWICLjw9E+Iib023a78Dler2gkCNkxuhGQhA8dkUH+ZSS3U Z8pVT4JpncT/xkeXzVib4gtENcuNDjjhoWQXP22DutfwKykX2ipFx+xwtxaU80kVLd CxXN9j5Nrg5G76yk1+TOZLkBBl+MKHk92g6O+EWs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731150AbgFIAcT (ORCPT ); Mon, 8 Jun 2020 20:32:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:36074 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728800AbgFHXPP (ORCPT ); Mon, 8 Jun 2020 19:15:15 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9183B20659; Mon, 8 Jun 2020 23:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591658115; bh=szMzKWLLvKCRf1i4cCc+3mjcrWOYNZx5wYhk+zhoUZA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lyvfb0boWRwzuj5n1djRN2YtCRfPhEmHu9xqraW8JTIBhGNAnp4uUtKzrOEnFjwRS hnSGuH8AzzccYwWLQBNe1g9YJbGI3urjWLVKXiwJii/GJronLvDcYNbL0qWas5RIbA sRCqyOzmnWaIPIvSUM9IlYNAIoQZS+7fOzHMUnCM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Navid Emamdoost , John Johansen , Greg Kroah-Hartman , linux-security-module@vger.kernel.org Subject: [PATCH AUTOSEL 5.6 153/606] apparmor: Fix use-after-free in aa_audit_rule_init Date: Mon, 8 Jun 2020 19:04:38 -0400 Message-Id: <20200608231211.3363633-153-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200608231211.3363633-1-sashal@kernel.org> References: <20200608231211.3363633-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Navid Emamdoost commit c54d481d71c6849e044690d3960aaebc730224cc upstream. 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 Signed-off-by: John Johansen Signed-off-by: Greg Kroah-Hartman --- 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.25.1