Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1497195pxb; Tue, 8 Feb 2022 20:08:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWi1ZidMBVU8S4AdaQ18eSR4cJwQ5ilpCQWszb5cFEU8zMNPsjFTjlbdSXYWkgbkxJ2Hv/ X-Received: by 2002:a17:902:cacb:: with SMTP id y11mr624869pld.96.1644379726786; Tue, 08 Feb 2022 20:08:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644379726; cv=none; d=google.com; s=arc-20160816; b=XDMR+QYmlPxnD96MJ8DALwW37oK2sya0htXIKiuy/TigTXQgrSLwLU68Y6Qs5EgnnX mr2/+dGx/EK/Y/4rJ1OkXYd4YSsTCUUcRe96YfymHm/firw8W0c0HhqNzE3ccWtIJ+MY pxrLepWQ8E1C0UithI3i4IENNIUK4SAPC9rBr9J4RNzwyF+v9dQw5gpNoKfPcPwrHs2Q RWvCVvMWn4U/E8tEL/oprIgBl8bcczx89iMVWUxzJLQeQiB0M1NlHVbAV8omSiALBaUp oQS0IKu25Scv7xyzXUuV/U2+M59kJkSyRcP3KsCu1whxzep+SDmhaLuh9SjGqi3F5fBz gJRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=AWfN++Tj9gHJw45/2eS0RTrqocNwbO5VZnsATo8AgLg=; b=l/BMje190GpEDYjR0WTZ3HrfeL2p4fBMd2U4lBZeN9/wfYKxVqo51wh8bHXnXcekY7 UwRk53q6fBISSj3wxWEA+jkLziCJxWX4+t3xmrM1DAJE3ILdNA3rQ+Yp06JVjyf+0dzd vKBX9FkaPLJDixCGhYypoHdTYJxMM6rfRzFxS+q/8XEJEgFEQklNKGKWJtcuoGxBdril tenyE0dOF35QDiVSKwkfluGcegDuT4PNpTxPM7/5jM3kVx0ZOQB/1fZvxVeRdG2zTz/5 ezg/sVKLFheSfXNbRx9VSeTk1oQQsgDwolT9Zq7oz91P6JtVsH91gs0KCJ53U0EdWWIW Ds9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=slXwP7yd; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si13638827pgq.736.2022.02.08.20.08.34; Tue, 08 Feb 2022 20:08:46 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=slXwP7yd; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1391146AbiBGL6f (ORCPT + 99 others); Mon, 7 Feb 2022 06:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1385577AbiBGLcA (ORCPT ); Mon, 7 Feb 2022 06:32:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C866C03E900; Mon, 7 Feb 2022 03:30:59 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D748260B20; Mon, 7 Feb 2022 11:30:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 928EFC004E1; Mon, 7 Feb 2022 11:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233458; bh=CEnQ53IN8cOKxoel8rwqWyPAl4pA6ktgqF4J4Ryl9Jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slXwP7ydxJjdQt9SxgTnXORdEKAM4eipLco7soygARe9G+IwdIln5vevNyxrIe4Ut FWJoY+dSqcdmv2hoY8XBR3lGUqzX/GmYcsem6e21DrrNT4Y97bV4bkm0tPfejpx0NQ 8eMtBAp0fnarL1Sihrjr84MkXwO2xrWgFutCqj8Q= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vratislav Bendel , Paul Moore Subject: [PATCH 5.16 002/126] selinux: fix double free of cond_list on error paths Date: Mon, 7 Feb 2022 12:05:33 +0100 Message-Id: <20220207103804.140013578@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103804.053675072@linuxfoundation.org> References: <20220207103804.053675072@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vratislav Bendel commit 186edf7e368c40d06cf727a1ad14698ea67b74ad upstream. On error path from cond_read_list() and duplicate_policydb_cond_list() the cond_list_destroy() gets called a second time in caller functions, resulting in NULL pointer deref. Fix this by resetting the cond_list_len to 0 in cond_list_destroy(), making subsequent calls a noop. Also consistently reset the cond_list pointer to NULL after freeing. Cc: stable@vger.kernel.org Signed-off-by: Vratislav Bendel [PM: fix line lengths in the description] Signed-off-by: Paul Moore Signed-off-by: Greg Kroah-Hartman --- security/selinux/ss/conditional.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -152,6 +152,8 @@ static void cond_list_destroy(struct pol for (i = 0; i < p->cond_list_len; i++) cond_node_destroy(&p->cond_list[i]); kfree(p->cond_list); + p->cond_list = NULL; + p->cond_list_len = 0; } void cond_policydb_destroy(struct policydb *p) @@ -441,7 +443,6 @@ int cond_read_list(struct policydb *p, v return 0; err: cond_list_destroy(p); - p->cond_list = NULL; return rc; }