Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2750831pxb; Mon, 31 Jan 2022 03:35:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJyF2YN+spGCMcMRhaRa+dMY/57OYUJgHKAKKlgacznoNdxrQgEtzthLceNSosVm9/NE3cPl X-Received: by 2002:a05:6a00:1305:: with SMTP id j5mr19799263pfu.34.1643628908146; Mon, 31 Jan 2022 03:35:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643628908; cv=none; d=google.com; s=arc-20160816; b=UK7KeTFDRXN26ojxc7A3frYXK54fCygGSBiPJVfNbGJb3VjBbkCLDS0o1YSd0yRZab v/44kyqg/4g8L/syZhNwkqCnts1Am1HAAGyvL6VWoZV8H6JziwoeNV5yiBhNpnqJLQNe vIKXnEa8z9b1VtVsqPxngj5306jWjxMrLUeZ3Lo1vu0L/bCGyKXG12EDWDs8zXNdMqWe bJOneDPr/jG3oEvKugo9aUQ6eCNpCxojj3NmUDXpu5aaC1eqFbxyYpIKFxKWGStMBGC3 19sDeyIJ9ZQ0M9gKUQT5RIoqxUv+G0XxUZj12Z9G8Pfv8d+p8zRnncVEAxW0vvB3IOmb rjvw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i+Eh88opqIqEsznXGNCa0iEdXEj8AF6KwI0Mv89OrFI=; b=IsCbWskXrEgIdf48TY24sJoesLWlLhG2SQuINoty7uFQGB0H5WnpLh+scIGNhMEdBG 5qzm4u0kd3GQfsvK78ITAAxbpeJabqsertbdZldD8PJo02HGGQJll83GEDfEF7Sd5Rgm gWOlID4MmoepB55FdpKKLH3HAzDgHvapgcUyiZOqQBEtCsAq/PGmNVLc0ubPGh8l2egU EiOE3dudqw28kas7ATZLx00CYYIzRg/oxqQ1/qBdXiGTZrXlmWMuYn4PMRXXDMo+rpa7 I1AIVVFCNS3df/QSFw4qeUKk9zacVipJcva97Uoy6RkFjbl3URy1SEb6GjmSKjz/YDvR 49qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XS7wg0RY; 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 ls11si11602226pjb.130.2022.01.31.03.34.56; Mon, 31 Jan 2022 03:35:08 -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=@redhat.com header.s=mimecast20190719 header.b=XS7wg0RY; 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 S1351165AbiA1U3V (ORCPT + 99 others); Fri, 28 Jan 2022 15:29:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:35101 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351145AbiA1U3S (ORCPT ); Fri, 28 Jan 2022 15:29:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643401758; 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: in-reply-to:in-reply-to:references:references; bh=i+Eh88opqIqEsznXGNCa0iEdXEj8AF6KwI0Mv89OrFI=; b=XS7wg0RYrYKVk0r28/WSxGySKsDxCnGGFQuRKh16Qa0mgQQLkExCKmhzwUH3dT7yELHdaz VqHFQyN6E+v8vwK2o2qabZmYsiiWXIv2aMrb1mAnJHz0qPWEIkIop+iIbefyeKxC7MzHlm wfZnqqWJHxFMgYLfVpaY7eoyJ6WKfLs= 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-532-fLX-DTyNP1qVMuwgkPEdHw-1; Fri, 28 Jan 2022 15:29:14 -0500 X-MC-Unique: fLX-DTyNP1qVMuwgkPEdHw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 961E21006AA4; Fri, 28 Jan 2022 20:29:13 +0000 (UTC) Received: from vbendel-laptop-2020.redhat.com (unknown [10.40.195.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id C04075E26B; Fri, 28 Jan 2022 20:29:11 +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 2/3] selinux: fix double free of cond_list on error paths Date: Fri, 28 Jan 2022 21:28:57 +0100 Message-Id: <20220128202858.96935-3-vbendel@redhat.com> In-Reply-To: <20220128202858.96935-1-vbendel@redhat.com> References: <20220128202858.96935-1-vbendel@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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. Signed-off-by: Vratislav Bendel --- security/selinux/ss/conditional.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/conditional.c index 1d0e5f326b62..8bc16ad3af9e 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -151,6 +151,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]); + p->cond_list_len = 0; + kfree(p->cond_list); p->cond_list = NULL; } -- 2.26.3