Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1531877ybg; Thu, 11 Jun 2020 12:15:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfNxyZc638riLaet4n3Cxzmg1SClcli6OrmKKnxnElM6jT4P9awJdD5r8HFfLfiMIobQcO X-Received: by 2002:a17:906:a889:: with SMTP id ha9mr10153722ejb.429.1591902904152; Thu, 11 Jun 2020 12:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591902904; cv=none; d=google.com; s=arc-20160816; b=DC+aGFwbuaT7isALNpmbtVDM2agFXCsm7ZUVuI8pwYtKZ9GUheI1fIpG6lMenJ6PL2 L047RWMdaYLIsztIyHqeyI//8QX59VLUZjSiwe4H38bAlYiW6w+5/rzHjN17P6q7Cm1n RRbY5uyZFb7YwZYqEBa9TK9l+tUE5V7vsRT2YGSLt/StAZUtER5qaVMJPo85XRdcN2Mh bigs56Fp4SDi8Sxkh4FXaWgCh1ZRWojdMMnMVE4eFDbSEx566labBj7fKvTKYsmMgb0Z lnF/XEcJUvBA0mLHRTNIsRLF4k7KI+157o9ZqwM5HnqFyQ4tA/McwJg9o+v8RZQjD12G heuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2lc4GWkEgMW9G8vaWxd2JwQUtHL+Yw8/GWAwvra2v9I=; b=t4FtlGX8UVOlYsrwAE7HMc44q6bjWocbLmSlTnwC0SnNy+84KBb94HwxKWMXhL8mj4 y0nJ4z7ofzkrD5w3Ii+JdozWOTYE7BqYX70MPb6pdh5FbQEZR16sLGYt7EHszjXaVokS u6VOup+RnB6P0oLa9Nhl0FRs4ckl1TOVPqwU56QUDlovMDbwmrRmwuJ6h6oiMynXDydL 5Q8nZESjtdQJxgQ3D+XFecZ0ori619zklvOYwKYcniT1a6BtWyPIPpMb9+KFFFzwfZYP QGqb775tk1+jWHeUoplfMXPiXIStWr+sE0aHftjzJwFNsY9mfeTf4j4HcTTIoO3Bb8Oi lDRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cAYIVxUc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n21si2492470ejd.625.2020.06.11.12.14.41; Thu, 11 Jun 2020 12:15:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cAYIVxUc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726760AbgFKRNE (ORCPT + 99 others); Thu, 11 Jun 2020 13:13:04 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:31093 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726706AbgFKRND (ORCPT ); Thu, 11 Jun 2020 13:13:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591895582; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=2lc4GWkEgMW9G8vaWxd2JwQUtHL+Yw8/GWAwvra2v9I=; b=cAYIVxUcG/UtDI/oR8PXHEINIm7+IClhjBsNX8baR/B/FgXY84JMuRNhbdJhZDFx2/B1yR GWqyh10gSX/lPlNCE8MHtwN2/Wg0E5PrpHcH+Y54TRLKT+HDvcLIMPv11ZTRQo/fz2IYwt 25EEneWtJN/sqlCqXeQ2nHqnn96fJWo= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-365-elP6mpaWNPqVjBSEdWCzmA-1; Thu, 11 Jun 2020 13:13:01 -0400 X-MC-Unique: elP6mpaWNPqVjBSEdWCzmA-1 Received: by mail-lf1-f69.google.com with SMTP id a10so1746176lfo.23 for ; Thu, 11 Jun 2020 10:13:00 -0700 (PDT) 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; bh=2lc4GWkEgMW9G8vaWxd2JwQUtHL+Yw8/GWAwvra2v9I=; b=T/wTCCNDBTDEXfevADrObQ/+Kp6UNaW6cRkouayNvVM2UQY3/KsOgs6QoBiJXTCNKz ob0NJIK+wnsgmlVhO3kNX+TuKA5efj9dUc3xwQoSXGORP8wsc0wFeq7aUrcTkJYEIfWi EPuo/zFEqgTx66USguF0zya9y+1u+kGzpZFQXaYgw9VYbXsgg3z6Rt9wKrH31dNGZAp4 qIfixmESXU/E3paFqnl4HVBLoizd+8TAd6HjBEvYIJBkZX6Sz+YOeEhp/ZchgDmV4Sjh oDc6Vgaxq4zvtYe3Hpy8iU4BPmXIMln5B2/ofpJYiD05ToPHuhjfFo2ETCh+13iCap1y l0+A== X-Gm-Message-State: AOAM533+NrD3cCrBV8WVWxqH9RM4f9H2inHnZBvfjYUS+g7ev87dKec0 VsqOUNdcPGLa6ezQp30cLHqeCs23awXsW5BsIDyNcNeJw/+6yv1H+z9mgbiBtBxWSIwqN/cigV/ 4GFDFOJ6F0Yp3g75SiNAixEgnWXTjMiWINhs4Svcn X-Received: by 2002:a2e:960b:: with SMTP id v11mr4937663ljh.77.1591895579089; Thu, 11 Jun 2020 10:12:59 -0700 (PDT) X-Received: by 2002:a2e:960b:: with SMTP id v11mr4937654ljh.77.1591895578882; Thu, 11 Jun 2020 10:12:58 -0700 (PDT) MIME-Version: 1.0 References: <20200611155830.8941-1-trix@redhat.com> In-Reply-To: <20200611155830.8941-1-trix@redhat.com> From: Ondrej Mosnacek Date: Thu, 11 Jun 2020 19:12:47 +0200 Message-ID: Subject: Re: [PATCH] selinux: fix another double free To: Tom Rix Cc: Paul Moore , Stephen Smalley , Eric Paris , Wei Yongjun , SElinux list , Linux kernel mailing list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Tom, On Thu, Jun 11, 2020 at 5:58 PM wrote: > From: Tom Rix > > Clang static analysis reports this double free error > > security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc] > kfree(node->expr.nodes); > ^~~~~~~~~~~~~~~~~~~~~~~ > > When cond_read_node fails, it calls cond_node_destroy which frees the > node but does not poison the entry in the node list. So when it > returns to its caller cond_read_list, cond_read_list deletes the > partial list. The latest entry in the list will be deleted twice. > > So instead of freeing the node in cond_read_node, let list freeing in > code_read_list handle the freeing the problem node along with all of the the There is an extra "the" before "freeing". > earlier nodes. > > Signed-off-by: Tom Rix > --- > security/selinux/ss/conditional.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c > index da94a1b4bfda..ffb31af22f4f 100644 > --- a/security/selinux/ss/conditional.c > +++ b/security/selinux/ss/conditional.c > @@ -411,7 +411,6 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) > goto err; > return 0; > err: > - cond_node_destroy(node); > return rc; Since there is now just "return rc" in the error path, can you please replace all the gotos with plain return statements? And please also add a Fixes: tag pointing to the commit that introduced the bug (see Stephen's reply). Thanks, -- Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.