Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4401419ybg; Mon, 21 Oct 2019 08:27:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqwU0MztTdUP3LSksF4YF1J2VE2v2Udewzfyi0O3BHYCMqtUg5fqFqJy52HsbBdc/mt8yja7 X-Received: by 2002:aa7:d8ca:: with SMTP id k10mr26260357eds.54.1571671623983; Mon, 21 Oct 2019 08:27:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571671623; cv=none; d=google.com; s=arc-20160816; b=pJ1kQU89aqNMjS01C0KmYqwNhYdg7jPya+tJYVXsJYQxBvxRVMWnpawGEfLifrXVAG G3BzxnGVSEfesDH/stEKtcea3yXRlmizRQWbrVhJ3KqPvnsDLKGfKZ+5Z/XbSkBu+tj9 YSpsUjhxuo7MjMKrobXFRYl3m18mVWVRc2zpfHav8qSnYDVFJH3N7gn+SAW6+QjuwVJW IVnWnWKrY01ekLuWK2GBnRuoiuGnsVjqUhX32zDC+9DI6okXi5UcfelnhQYhxecANXg4 4Aia25PpjvNmD2U6841EW1k6LGP+yQGk91L49k1F2aNnpeqAez0L9Y24Kk6unO+BGLDw xuvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=3P+aBDo0ELSsFt8nCKFHScePQc27b2VSrL87S+QPBsU=; b=Lldj6Y+X31peWPIiA6AY/CerErCl9ywQ1Kt8StAHrZ5QeGmjw14uYTyLik7HHZR4sA nvqkuDmW7mAOnjXQUGqChEtQydIuLtIGDSEaQJku6pQP5QqxLza2WX8tvl+VA61lL1wA sHSg/pr6ZzgjG/Z+BR9o5aiHBHHrHzTMu3J0GRYgee2jAwCjOjI2cjTKkt+9ElVeKAWE 6uhZkjFEy3wGf4rbQ11eykXr6+UIgVfOKX7MSfGMtD5WqJ6X3M3yqcYg8Qeo5BCV9dj3 gMHigfLDtDV1RSJJquRP5jz1yJX6/zwn6Vgb6nfcuJEPZ1pYFAwvJ1+bXbzdXMLli7uo PaHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="inbN/c7b"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si6084277edl.371.2019.10.21.08.26.40; Mon, 21 Oct 2019 08:27:03 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="inbN/c7b"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729514AbfJUPYQ (ORCPT + 99 others); Mon, 21 Oct 2019 11:24:16 -0400 Received: from mail-io1-f65.google.com ([209.85.166.65]:37833 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728052AbfJUPYQ (ORCPT ); Mon, 21 Oct 2019 11:24:16 -0400 Received: by mail-io1-f65.google.com with SMTP id 1so5047085iou.4; Mon, 21 Oct 2019 08:24:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3P+aBDo0ELSsFt8nCKFHScePQc27b2VSrL87S+QPBsU=; b=inbN/c7buo+FoE6Dk6EAnrg8ORKRrFdixSmEroAn9vkrHOGV2OF7X+KnCKCLDz1FBo Op0aI8hSOoy5A7ciprqD8+Ss8WrJY15q5EQ/YuoWkA96CyKkwV3AwVzPX3k0UDTvj/Vx oMhkhmTj1RTF9zzZwALy4yLUi/N0u+/l+weT/H81oKL2vSYCpjep5E25XQW2rbvC/qXH bI2WnZ2KrzBkf68EBgJEH6LLC5o44cfZf6a2wFWFNhs7tN5XMHPPWSzAeOa8Ltr4yl/7 DTChh4sLLiEZvmjbG/2hv0inoeTsnvW3W9acY5hFc7wyH+eyfg7P6gcQNH6ths7h1dxr ydFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3P+aBDo0ELSsFt8nCKFHScePQc27b2VSrL87S+QPBsU=; b=KNSkd3pZIPsSs0k7RERiy8QiTozoQ+rXzUMgfk/YOfw+JUJNMNTRASHZtMiASzs+QE jIiLDF1Q/kZeiRa2GUoygAxG0SRtJcgfbJ+551OA3ZMCcUnjtMLkKzNJlhEcm9QjTXtB ss3eMrStTKPnN/kizNx32ty6OTz23aH6dwKWPq8fW1nHLcmsiwqyT5ftY2M19hxvERVf qHJCTVwi4ilOQwCsO3RjWLwooT69gP1KhqhIKswfSHGlSVcWrI1vSlhDcDW47+WHsv+o 00St0aiEIcRYad3mm1nPsHheyUpzpaaC7D+pDd4eLBqKMhDK3oW/3HAGiB6CnM35mYZc no4w== X-Gm-Message-State: APjAAAXxUOBg4fNBemXT3Zl5q/uXAwIy6Te2AyOgWEsG8lYn3VLixWPC U6weM3HZwbcartC91HJYUrE= X-Received: by 2002:a5d:8185:: with SMTP id u5mr15715116ion.147.1571671453827; Mon, 21 Oct 2019 08:24:13 -0700 (PDT) Received: from cs-dulles.cs.umn.edu (cs-dulles.cs.umn.edu. [128.101.35.54]) by smtp.googlemail.com with ESMTPSA id n123sm3872105iod.62.2019.10.21.08.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 08:24:13 -0700 (PDT) From: Navid Emamdoost To: john.johansen@canonical.com Cc: emamd001@umn.edu, smccaman@umn.edu, kjlu@umn.edu, Navid Emamdoost , James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] apparmor: Fix use-after-free in aa_audit_rule_init Date: Mon, 21 Oct 2019 10:23:47 -0500 Message-Id: <20191021152348.3906-1-navid.emamdoost@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <57b61298-cbeb-f0ff-c6ba-b8f64d5d0287@canonical.com> References: <57b61298-cbeb-f0ff-c6ba-b8f64d5d0287@canonical.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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; aa_audit_rule_free(rule); - return PTR_ERR(rule->label); + return PTR_ERR(err); } *vrule = rule; -- 2.17.1