Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2267790ybt; Tue, 16 Jun 2020 01:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5SEAYgbUAXWh7rkHESbDnL74n7wBW8xZOhA+nsh+CSqTwNpDy2dFdBvq+IgEJckhRDTfZ X-Received: by 2002:a17:906:1b1b:: with SMTP id o27mr1554034ejg.264.1592295364782; Tue, 16 Jun 2020 01:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592295364; cv=none; d=google.com; s=arc-20160816; b=qtU0sJvmxx/QqB/HeQEmmOXnEckP/W3zOK6NYugFCjWhumjuvBeTZdn+fzHTp8ZENU Z/xp/1ZIX31y9rrVdLxO92ZM5tlPC6+7l0XsjB61/wpUqbbEWB6MBfGG7J84kvYKS7I1 n4QJmz9aFW8vMv3o0yxKILNZkIj1uuvVoaNPX8YEkinU6gYQME//PzxsKY0aM0S40mre J5PIjAJysi8+VwNTCEnscMiS6MgYTE7wuAJT/ZNOY4bHT0vuWIHdyGv3sU5pZ65ziKdL zsKifqydpK7JDT1cHyFJsRryE4MwLRRXvD+wtgiAAT+Q5K6qNEAPwt3U5j6ZmNNNfnJa 8fEg== 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=cJezEl7pEpz0+81cqj9YoCVXqx3lyo7ppqkURJNiPRo=; b=Kf8TZ0YyEBvc6p7TNflZMqDYYh7BDCw9zdEev5yNsiIpGyUqd9aykCG53b/nZ97YC5 EukyNWnZfIGZwuXcgF/IW6tAvUQ04dmWwCR8Y6qxHzs/DBoJ36Vs6e2FwN87YJ0G0hdx ootK08mUAi5jdfay7qO4FDEI4ixuKlU8btNKqrfX02Py4Xtjusx3cfopOEgGBgo9AiOC IQvGr73M0MhwYxZQOacL+igvnflV22RGwztlDS9ANDPoojTh72vxE1IL7u49rr+0SRIH OYsl2L7IKa9NB5DJcD32WdQJ+f6LD7zSF3Bq9pFB4064xi6Y01AT5GQIwzMiEiYxtqOn aYdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JqXuL1Yf; 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 e2si9793792edy.212.2020.06.16.01.15.42; Tue, 16 Jun 2020 01:16: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=JqXuL1Yf; 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 S1727770AbgFPIN3 (ORCPT + 99 others); Tue, 16 Jun 2020 04:13:29 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:29004 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726773AbgFPIN2 (ORCPT ); Tue, 16 Jun 2020 04:13:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592295206; 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=cJezEl7pEpz0+81cqj9YoCVXqx3lyo7ppqkURJNiPRo=; b=JqXuL1YfJzUmSCwtMI+CNs6dKnJ19jS4E0cLvML0PFSxi7bFlBjBBAsuFgjRga3rmGl7Pi b2MsMBGId71SZMzr6lUW6dgF+7vgSuI674VZZHvmuqMrQB5OzwUQHXU4Xrwjn13N6gQHCC D0KLA8/MojQwd14z8EuDpkHUgV8Y3Qs= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-355-mWrUITMXN-WAVGeMaHm6mg-1; Tue, 16 Jun 2020 04:13:21 -0400 X-MC-Unique: mWrUITMXN-WAVGeMaHm6mg-1 Received: by mail-lf1-f72.google.com with SMTP id l1so6017899lfj.3 for ; Tue, 16 Jun 2020 01:13:21 -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=cJezEl7pEpz0+81cqj9YoCVXqx3lyo7ppqkURJNiPRo=; b=OlvAGh82n8+VCyIY/Lv9Y2uVDXNeHFhMsxQVbHS0S6nDWny5S4SqT8S3PmER21dqog 8QzvXVsn24Gn7Bi3yhUZhZkWjSo4fL99EozFFiwRwhUU8RRKu7TUtU0uIiQp7aWWy9iT 9B1iCtVvvNO9C3IsojGTYOyebLMPOxYrfOBtrRiYqJ7W5lYXdMyclI6ZLhdihiSaQOp+ ucj+VLOvOvfEIoO9JJFOUFcxBURgQJaRKvv/CYPs9b5W8qhLx0WFzpVYkPMlE1UuBq10 ecMlHZ3yS+SeF4sxW6NPAdVztUMmZWH/XTUlhDX0bfqZwui5HbjX5Heu/yzEBL7fscb9 Yq+A== X-Gm-Message-State: AOAM532Ei+GRYquwFlqKVi3NkG8MN310W+uknxMkRltZvjEdtPc56wZY mM0ZALqa4gRO63yz6PiqrTrW1Gui4aGhR9p6yvO4uisOG5FJob21eoe38dc+U6YbBepbTQb+Rba v3aPN9UYPFgC2sYwjIduNG9/H5c9j6OraxjEu6qVd X-Received: by 2002:a05:651c:288:: with SMTP id b8mr847620ljo.337.1592295200157; Tue, 16 Jun 2020 01:13:20 -0700 (PDT) X-Received: by 2002:a05:651c:288:: with SMTP id b8mr847599ljo.337.1592295199705; Tue, 16 Jun 2020 01:13:19 -0700 (PDT) MIME-Version: 1.0 References: <20200615204548.9230-1-trix@redhat.com> In-Reply-To: <20200615204548.9230-1-trix@redhat.com> From: Ondrej Mosnacek Date: Tue, 16 Jun 2020 10:13:08 +0200 Message-ID: Subject: Re: [PATCH v3] 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 On Mon, Jun 15, 2020 at 10:46 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: 60abd3181db2 ("selinux: convert cond_list to array") > > Signed-off-by: Tom Rix Reviewed-by: Ondrej Mosnacek Thanks! -- Ondrej Mosnacek Software Engineer, Platform Security - SELinux kernel Red Hat, Inc.