Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4400792ybg; Mon, 21 Oct 2019 08:26:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzwCkE6yaYj4Gk3ARjYWgRWUryXCBc73Etveq2uaiaUzGWG7Kh2tww7naIbSuOsbApf2Utj X-Received: by 2002:a17:906:1be1:: with SMTP id t1mr22893837ejg.73.1571671589852; Mon, 21 Oct 2019 08:26:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571671589; cv=none; d=google.com; s=arc-20160816; b=rU6xk6DcVO6LPdtsLl+y6mug6NU1VkpyLBfpmuLqVEq6nJrWkY9f9ds3NEQeW5sEzT 1VFk0lsKk8HrtG5gyxSnGxfwRSVNaOPC/ZP4qywyeSAZ1AxQ6ceEawxiS1dzR2Q2o25U NKxMZ70PjNqjWpu0dKLfY+fpUmL38rIC+wJn+Q5csVO+Nf+u7tKGji8naUUsELIiJ2Dl H4SUs5ljMi6CB8LvpKWt59i7eL8feW4DY+Mi4CQmax7+R0ZAAg+BiBNy07ZoOWqF2Pxd anoKOZxkSUyzeUIXgsXE2x2Rhej4DDukHwnYPGLAV9Qp6bzVaksUZopW+lK5t3q5xXNd dEdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CCsbvZ28JC46guXF6O4rYjXW3fCXuWIxBOZSISvE6SU=; b=RoabXBt5h+/5JndyFrXG0bB+18JnQjAYAQ3NmWiTqaoQ/nT3o+2pet53ptNLO8oln5 ESend+e49gHswcgFtKYOOjlH7qF06DBosI5WnY28JrMfgXYPqNvzqiRNdQtcv2TXY86k /rLj5tSG5VEGPARnycblQrJKv+tOAwYLc6YoVN8WVqWmcECx9gJI2ZmveR+/OOT8tEPi oJP8MpH01VO7HFfSDnqDdds/5haUP9wp0kyj1rgsmH/VFtiQiaEht7i/MlUc7OVKxhqQ SwjuasyjJWFG995s9ay+uWrg/JTsnOgNpIK6Yeb8hNYrTOehTMZjDGEICVooSAN6/g1r YYrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DXs+Kf83; 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 s6si11084369edi.154.2019.10.21.08.26.05; Mon, 21 Oct 2019 08:26:29 -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=DXs+Kf83; 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 S1728044AbfJUPZy (ORCPT + 99 others); Mon, 21 Oct 2019 11:25:54 -0400 Received: from mail-io1-f67.google.com ([209.85.166.67]:43843 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfJUPZy (ORCPT ); Mon, 21 Oct 2019 11:25:54 -0400 Received: by mail-io1-f67.google.com with SMTP id c11so7308250iom.10; Mon, 21 Oct 2019 08:25:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=CCsbvZ28JC46guXF6O4rYjXW3fCXuWIxBOZSISvE6SU=; b=DXs+Kf83VRyzYDoF+84qUhVH6tRXNDr0QO+onaMzRs+jWfWCKba194bx2vNLFKaW23 22sPLYAevEV+a2VJniEYOih1eiUPqdK97WcmZszjQxL5LdWnj7U5uq3BXo+8HCLCz1F3 tDnfWc9UbtuyBCh/4+1kVSj09Vf2DJTCUwh2ccctfnGKrBBXRhMX4Lnm6eWFkQyzM6Hu XtL7lN4frPNmjMdsNWNhdSk2Nnu4OJTZUBBK6j4UaiKf2rGvsxkUzpLCCWCmmEEId4KE ENzpzylEoU18yDIwO0GCugDI/TQexsiI1TiYeUCy0BPV6YE/c4XH3E73H19i7IwyDscK r2+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CCsbvZ28JC46guXF6O4rYjXW3fCXuWIxBOZSISvE6SU=; b=HiCi47xgrrHOahaSzHNcce9eLXdFO0Fly+9XLjnXjI6KFlq4nUwPN/h9DoD7jn3rh/ XIjy1GeKhPqSmeSjf/2Mj9rogPC/iRdOJe3yB9/2SFbEMgByN9I6cR7OmKckCKNpRKfm dJ11xvkLYv+qkOydjCbbKqbHo3XgFfBKqnyxRBm7sVFEwS+HHwriFXKF8stYrdlSs5MB NClllg9XorCl6XK8qdS6RKLPG423Uno/2APEkhU8yP5FOqhy0oJELNsrJGuXkiT9l94C PgcbkBEKQdXemPX/KAN8Ceh59U0nRVaSGYN0i1m6qzYthIVtViMjtfME/6A7Z3Kdrc77 FYAw== X-Gm-Message-State: APjAAAXiLCSYSWWwpo12WHu8rhTKlHI6aZaCnXh1S4zdSDAfaD010DFw wRu2MX8Fu6rnW4xTLArkoCnNKNgwmO0ntrvnA+I= X-Received: by 2002:a5e:9706:: with SMTP id w6mr19915934ioj.252.1571671552835; Mon, 21 Oct 2019 08:25:52 -0700 (PDT) MIME-Version: 1.0 References: <20191017014619.26708-1-navid.emamdoost@gmail.com> <83dcacc2-a820-fe63-a1b9-1809e8f14f2f@web.de> <57b61298-cbeb-f0ff-c6ba-b8f64d5d0287@canonical.com> In-Reply-To: <57b61298-cbeb-f0ff-c6ba-b8f64d5d0287@canonical.com> From: Navid Emamdoost Date: Mon, 21 Oct 2019 10:25:41 -0500 Message-ID: Subject: Re: [PATCH] apparmor: Fix use-after-free in aa_audit_rule_init To: John Johansen Cc: Markus Elfring , linux-security-module@vger.kernel.org, kernel-janitors@vger.kernel.org, LKML , Navid Emamdoost , Kangjie Lu , Stephen McCamant , James Morris , "Serge E. Hallyn" , Tyler Hicks Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 20, 2019 at 1:51 PM John Johansen wrote: > > On 10/20/19 7:16 AM, Markus Elfring wrote: > >> =E2=80=A6 But after this release the the return statement > >> tries to access the label field of the rule which results in > >> use-after-free. Before releaseing the rule, copy errNo and return it > >> after releasing rule. > > > Navid thanks for finding this, and Markus thanks for the review > > > Please avoid a duplicate word and a typo in this change description. > > My preference would be a v2 version of the patch with the small clean-u= ps > that Markus has pointed out. John and Markus, I updated and submitted v2. > > If I don't see a v2 this week I can pull this one in and do the revisions > myself adding a little fix-up note. > > > > > =E2=80=A6 > >> +++ b/security/apparmor/audit.c > > =E2=80=A6 > >> @@ -197,8 +198,9 @@ int aa_audit_rule_init(u32 field, u32 op, char *ru= lestr, void **vrule) > >> rule->label =3D aa_label_parse(&root_ns->unconfined->label, rules= tr, > >> GFP_KERNEL, true, false); > >> if (IS_ERR(rule->label)) { > >> + err =3D rule->label; > > > > How do you think about to define the added local variable in this if br= anch directly? > > > > + int err =3D rule->label; > > > > yes, since err isn't defined or in use else where this would be preferabl= e > > >> aa_audit_rule_free(rule); > >> - return PTR_ERR(rule->label); > >> + return PTR_ERR(err); > >> } > >> > >> *vrule =3D rule; > > > > > > Regards, > > Markus > > > --=20 Thanks, Navid.