Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp3293931pxb; Fri, 4 Feb 2022 05:45:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1icpKSoR4r3QjdTfpwM+n2+a4qm1M/t+sykDXN8u4A6KXOEKEhBHD9TTCdMosC/SnuBOT X-Received: by 2002:a17:902:d50a:: with SMTP id b10mr3298585plg.41.1643982343155; Fri, 04 Feb 2022 05:45:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643982343; cv=none; d=google.com; s=arc-20160816; b=dOwohvSqq14cDYpe8Bk0C6/vzTMw5+hsRABDVDLxvf4bDhfTrIJbJuh3zDFM+PhLOp STg6qwd0XpCyfDjiw9J4NxgTjXp84AmDeGGKE3NAY3XDxZwNLNei9J/cY1x2YCkCF4Aj iK55B0X/0AGg62XElXgu/aQHiorn5MVIWcH5xehqRqgOQtSyfRVws//MpZhsO5huINbE lLmJI0g2KNhdavs5IYm8wdD2BhbaYNKiEYOO094FBnUwIL0X4FsmQcQrQ88gLdi/qxb1 3VnWWJsz+KH0bjw4BcNzWDwFOcKECS+FQjdVJRBh135HyrpVPKfzhkbvEQv2d5GH5rXw 0iMw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=f9ysAxbXC0GSfw703DH/tdETiMeXJAtzyEW9vX7rENo=; b=LEt6DntEg9U0VGo6iCSilOfl0UUxRa6qSLNgBfDYplM2fJr5TDPX6GNo7ts/e+lFRR fsX9Kws38LNTSVxjlmwxduiLG7Kdpg1K47qJruqk4fHcyEqnhIDlFWmcIswM65bYq0vH zNpfbfvLPDO5GYJGM+Qro45HXsCkkCvlRypsBwEFelftKCIFAxuSu1tjnFVskDKpN7si 05IGmfg6K3AMjaJomYaDgrTjujlZVAa0UpRVlH2cW38jLR9ZMUOM9dGDeT873XcQZA4x c0Rx87UDvkChAmle2FBJpJM1KQXfUbzbu34ZMOTtOA/6xncw1ozSl3WCKF+8IGiT2F1h ntxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J5U57MLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14si1781808pgk.382.2022.02.04.05.45.29; Fri, 04 Feb 2022 05:45:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J5U57MLY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1343902AbiBBLZf (ORCPT + 99 others); Wed, 2 Feb 2022 06:25:35 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:47876 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232773AbiBBLZd (ORCPT ); Wed, 2 Feb 2022 06:25:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643801133; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=f9ysAxbXC0GSfw703DH/tdETiMeXJAtzyEW9vX7rENo=; b=J5U57MLYfM0Q/WW0prKLDCzOZ+qDeEi8YHxmFrJ0rCHrvjIwVdm4u7y5TzP6xqhOhG2gZ8 d0e4EMnOkOar0WCoxSIIddH6Wsk+s5EqBGcoxGmllNOIA4f3Uobn63KF0jqsj52Yn9+ilI J+59Q4zrMX/haez2BJA+R2AEp790YQs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-245-t6Tzd3unPO2X-ga9Grp-sw-1; Wed, 02 Feb 2022 06:25:30 -0500 X-MC-Unique: t6Tzd3unPO2X-ga9Grp-sw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CD98086A8A0; Wed, 2 Feb 2022 11:25:28 +0000 (UTC) Received: from vbendel-laptop-2020.redhat.com (unknown [10.40.193.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF4CD7BB69; Wed, 2 Feb 2022 11:25:25 +0000 (UTC) From: vbendel@redhat.com To: paul@paul-moore.com, stephen.smalley.work@gmail.com, eparis@parisplace.org Cc: omosnace@redhat.com, selinux@vger.kernel.org, linux-kernel@vger.kernel.org, Vratislav Bendel Subject: [PATCH v2] selinux: fix double free of cond_list on error paths Date: Wed, 2 Feb 2022 12:25:11 +0100 Message-Id: <20220202112511.18010-1-vbendel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vratislav Bendel 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. Signed-off-by: Vratislav Bendel --- security/selinux/ss/conditional.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 2ec6e5cd25d9..feb206f3acb4 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -152,6 +152,8 @@ static void cond_list_destroy(struct policydb *p) 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, void *fp) return 0; err: cond_list_destroy(p); - p->cond_list = NULL; return rc; } -- 2.26.3