Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp9497ybg; Thu, 11 Jun 2020 15:33:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyb/K93zuxBGwycwuNhMusMva3CLr9ADmCUUBS/1p/V3amOFuzvCy0GMFdOitM8abZKbTE3 X-Received: by 2002:a50:ee8f:: with SMTP id f15mr9091469edr.168.1591914828385; Thu, 11 Jun 2020 15:33:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591914828; cv=none; d=google.com; s=arc-20160816; b=lLpsId7xH7bRL+0PkM+vwmpIulJHjUNqPgh0rdL2qnGPymcCLM38SLlamA8BRd2jBB m/DvJl07scWJXIbbeWrBz8OvWx6j4v0DCHDpIze7rTBGKz5Mb4vQMOhazRTieniUYWoX g1XKB5XgvHcP/jqOrauiNr9pY/ZFOsEF5dgueWh4LkBmAiUtVTjYgGek/Vkl67hXm1gH CiqBgEE97OdMwzEv3/2UMhVWSv4H9yMVfMDAzh+3CgJu4aGuVtzw5k+UlwbrPIHAZW98 YmTnkH5g1PUzEakT/s1qpNl0Z/eZrE4XFPA7JzhZFFZouGlSXtCWEYIpGQWVMZEkl153 rH9g== 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=rg7eO693EDtdOfjCTCuFIoB+iVYboUKp8O8k4ul7UBk=; b=qR88u53/PWdx7TlKv0lSeahcq0PT4WNtTgw5xVy6cejTddO4CGlMJsqmR5PIJH975+ +af1+Xvb6tDkRFRZ+4OA1FKMlWBT0UnsRgsNBvX6RcbazZV4j9y2or1wztPwNqk3ifNh KFt662Pj179twHgmsxDH+zIY7YQMXAIXzA3+EjPgcnRKBSo9+8Nu3QbnQzSNbU9rNvPC 1obr4uPUBxGknIOV5g59F/7DDtfM2CKMhorp2zICAtaL/rSSAQvDvxjJjTvngCpSaUbl 6/olYFzBi9XAK2n+DeFnse7ACYjVzmSOxO6jkcJPpyzdqzrGVDyDOBDr682E/gQF44y2 aCqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=hc1YtbB1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id mc22si2753650ejb.655.2020.06.11.15.33.26; Thu, 11 Jun 2020 15:33:48 -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=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=hc1YtbB1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726553AbgFKWax (ORCPT + 99 others); Thu, 11 Jun 2020 18:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726471AbgFKWaw (ORCPT ); Thu, 11 Jun 2020 18:30:52 -0400 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8746BC03E96F for ; Thu, 11 Jun 2020 15:30:51 -0700 (PDT) Received: by mail-ed1-x542.google.com with SMTP id s28so3002783edw.11 for ; Thu, 11 Jun 2020 15:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=rg7eO693EDtdOfjCTCuFIoB+iVYboUKp8O8k4ul7UBk=; b=hc1YtbB1KCw8ErzxRUKtDHJZkwhczsMAsWwoN5vJwBBYc7bHeCQ83qNspaTSZF+T6K RBPy0jm3a+mM5el7SdieBOcWdOie78kUClRY/FQzU8wT8uC5za/SJw1ZBLEkgJN6lEiI q4GXLpIWJH6aUxPFm5fRY5r8c49KeclPBy2ZsR5waFVXeYVrfwAS+Y8A6xoq5DF2/yFW F1f0Xo/myHiB5IyFjPhWumgq0yAOWmwUeLxJbdYtWQEqdEnuCZt2QYsTkig7HVEDfU8L jFkHwMGrVWwN768UNV8b/Uqi9Ki51wjScgV07Q+BUl5w0yh0EAtdMs5FMSvCZXKnfrgT 0oaw== 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=rg7eO693EDtdOfjCTCuFIoB+iVYboUKp8O8k4ul7UBk=; b=kh+6R548yJO3+96ddaS+byOVkuiywSVNiP/FTJWjx3lUWJ8treF+4Fq89D8QM1ZOX+ x5XXGMLgmlcCQfA/9WWERqWWy8TYbqwo6jEIVyhzTu5/EVTwoAQqBAJhETpJFDwQzK4J aw0mD3M5TftVE92NMNh5WS3XfVT9H62L79TUCt6gSV93z9YPsJmnpsqHhOxKR64vMVq3 JPZ+UDy2ioqgit9oR88BRTazHqzOLvcwlo+5RM0D2osshZJ0Q3kN4mhyxxFU/rMXwK4A iGr2AM/cq5GJ8AZDKJcYmfc2NCjBTo+xBjTyvIsukcP8chl7oR6W8yOYEXquTPClDMy4 C+3Q== X-Gm-Message-State: AOAM530urjEhT3+6fEXw6CAm+Uur7gJAfI6ZMctYm6i1lNKRd5onsvw2 eUA3d7NTLf8tWQvNxd+Km0Dl8cRAYmkR+MAdacNx X-Received: by 2002:aa7:de08:: with SMTP id h8mr8704796edv.164.1591914650074; Thu, 11 Jun 2020 15:30:50 -0700 (PDT) MIME-Version: 1.0 References: <20200611204746.6370-1-trix@redhat.com> <20200611204746.6370-2-trix@redhat.com> In-Reply-To: <20200611204746.6370-2-trix@redhat.com> From: Paul Moore Date: Thu, 11 Jun 2020 18:30:38 -0400 Message-ID: Subject: Re: [PATCH v2 1/1] selinux: fix another double free To: trix@redhat.com Cc: Stephen Smalley , Eric Paris , Ondrej Mosnacek , weiyongjun1@huawei.com, selinux@vger.kernel.org, linux-kernel@vger.kernel.org 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 On Thu, Jun 11, 2020 at 4:48 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 > earlier nodes. > > Because cond_read_node no longer does any error handling, the goto's > the error case are redundant. Instead just return the error code. > > Fixes a problem was introduced by commit > > selinux: convert cond_list to array > > Signed-off-by: Tom Rix > --- > security/selinux/ss/conditional.c | 11 +++-------- > 1 file changed, 3 insertions(+), 8 deletions(-) Hi Tom, Thanks for the patch! A few more notes, in no particular order: * There is no need to send a cover letter for just a single patch. Typically cover letters are reserved for large patchsets that require some additional explanation and/or instructions beyond the individual commit descriptions. * Thank you for including a changelog with your patch updates, but it would be helpful if you included them in the patch by using a "---" delimiter in the commit description after your signoff but before the diffstat. Here is a recent example: -> https://lore.kernel.org/selinux/20200611135303.19538-3-cgzones@googlemail.com * When referencing a patch which you are "fixing", the proper syntax is 'Fixes: <12char_commitID> (" diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c > index da94a1b4bfda..d0d6668709f0 100644 > --- a/security/selinux/ss/conditional.c > +++ b/security/selinux/ss/conditional.c > @@ -392,26 +392,21 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp) > > rc = next_entry(buf, fp, sizeof(u32) * 2); > if (rc) > - goto err; > + return rc; > > expr->expr_type = le32_to_cpu(buf[0]); > expr->bool = le32_to_cpu(buf[1]); > > if (!expr_node_isvalid(p, expr)) { > rc = -EINVAL; > - goto err; > + return rc; > } > } > > rc = cond_read_av_list(p, fp, &node->true_list, NULL); > if (rc) > - goto err; > + return rc; > rc = cond_read_av_list(p, fp, &node->false_list, &node->true_list); > - if (rc) > - goto err; > - return 0; > -err: > - cond_node_destroy(node); > return rc; > } > > -- > 2.18.1 -- paul moore www.paul-moore.com