From patchwork Tue Jun 23 19:57:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 223161 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E464BC433DF for ; Tue, 23 Jun 2020 21:25:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3E1420738 for ; Tue, 23 Jun 2020 21:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592947537; bh=IVRB9q9/6/QXpG+dXxWFNhybvoHx+eg0H3V+4CyDGDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=MV13ZfUrj6zfJm1KehsfOrTf7USNsMkOY+2R7MHsHx9cqeAr4kqpNa1wOAQfnehOM 3ABrgIwe7oM5MHleqx6+mQVDzv8f266GgIOf5duI/ws8jsbShUJ4pv3ypgXl3hQoXT jKBAJQJp54wORLBTA4jyxbBNnn3GVhE/W3jgk6pU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389717AbgFWUSv (ORCPT ); Tue, 23 Jun 2020 16:18:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:35848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389443AbgFWUSt (ORCPT ); Tue, 23 Jun 2020 16:18:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2E9552064B; Tue, 23 Jun 2020 20:18:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1592943528; bh=IVRB9q9/6/QXpG+dXxWFNhybvoHx+eg0H3V+4CyDGDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=08KjDKszeWh7Uvwd7efC14pB4S2aICxIjZvLFsrM4LBMhXHy0OrdjsOLFani+Stdo MJn1bh0AsWtrhAM8TdhkImGO3Xc4iwmspIe4RfafSfQN61G03+QsfManyGzq09vkZU uMCIYHLTxIS5me8BaLrb6IdmX/O3WpxV32HOmgsw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , Ondrej Mosnacek , Paul Moore Subject: [PATCH 5.7 427/477] selinux: fix a double free in cond_read_node()/cond_read_list() Date: Tue, 23 Jun 2020 21:57:04 +0200 Message-Id: <20200623195427.714040921@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623195407.572062007@linuxfoundation.org> References: <20200623195407.572062007@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Tom Rix commit aa449a7965a6172a89d48844c313708962216f1f upstream. 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. Cc: stable@vger.kernel.org Fixes: 60abd3181db2 ("selinux: convert cond_list to array") Signed-off-by: Tom Rix Reviewed-by: Ondrej Mosnacek [PM: subject line tweaks] Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/ss/conditional.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -392,27 +392,19 @@ static int cond_read_node(struct policyd 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; - } + if (!expr_node_isvalid(p, expr)) + return -EINVAL; } rc = cond_read_av_list(p, fp, &node->true_list, NULL); if (rc) - goto err; - 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; + return rc; + return cond_read_av_list(p, fp, &node->false_list, &node->true_list); } int cond_read_list(struct policydb *p, void *fp)