From nobody Tue Jun 30 00:47:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54152C433F5 for ; Fri, 28 Jan 2022 20:29:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232469AbiA1U3P (ORCPT ); Fri, 28 Jan 2022 15:29:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:20656 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346480AbiA1U3O (ORCPT ); Fri, 28 Jan 2022 15:29:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643401753; 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=6DOvcDg522mwUl70M+gghWC3MO+Q3R15lzpFJhyB6Lg=; b=RHtq+vuPs/vIf3KZmH263dPc+GH3BG+4ThUaY/oHncfSRfLJP+6HpJMrRqV9wZWcS8iOe2 jH75djpuCiY1lWRf88754IPISahHLQEY3Leyl0MngxvtG7u95YbJXcu0e0NebbaY2OckaT XpRFNsD1yoIhho77Sx9BJ+YsX0OlAs4= 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-434-VpDf3GJ1MNSAFPVNtyDr9w-1; Fri, 28 Jan 2022 15:29:12 -0500 X-MC-Unique: VpDf3GJ1MNSAFPVNtyDr9w-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 48A973459B; Fri, 28 Jan 2022 20:29:11 +0000 (UTC) Received: from vbendel-laptop-2020.redhat.com (unknown [10.40.195.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 765BC5E26B; Fri, 28 Jan 2022 20:29:09 +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 1/3] selinux: consistently clear cond_list on error paths Date: Fri, 28 Jan 2022 21:28:56 +0100 Message-Id: <20220128202858.96935-2-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: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Vratislav Bendel Currently there are two users of policydb->cond_list: cond_read_list() and duplicate_policydb_cond_list(). On their error path one clears ->cond_list to NULL, but the other doesn't. Make the behavior consistent by resetting ->cond_list to NULL in cond_list_destroy(), which is called by both on the error path. Signed-off-by: Vratislav Bendel Reviewed-by: Ondrej Mosnacek --- security/selinux/ss/conditional.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/condit= ional.c index 2ec6e5cd25d9..1d0e5f326b62 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -152,6 +152,7 @@ static void cond_list_destroy(struct policydb *p) for (i =3D 0; i < p->cond_list_len; i++) cond_node_destroy(&p->cond_list[i]); kfree(p->cond_list); + p->cond_list =3D NULL; } =20 void cond_policydb_destroy(struct policydb *p) @@ -441,7 +442,6 @@ int cond_read_list(struct policydb *p, void *fp) return 0; err: cond_list_destroy(p); - p->cond_list =3D NULL; return rc; } =20 --=20 2.26.3 From nobody Tue Jun 30 00:47:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26EB7C4332F for ; Fri, 28 Jan 2022 20:29:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351188AbiA1U3W (ORCPT ); Fri, 28 Jan 2022 15:29:22 -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: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Ondrej Mosnacek --- security/selinux/ss/conditional.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/condit= ional.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) =20 for (i =3D 0; i < p->cond_list_len; i++) cond_node_destroy(&p->cond_list[i]); + p->cond_list_len =3D 0; + kfree(p->cond_list); p->cond_list =3D NULL; } --=20 2.26.3 From nobody Tue Jun 30 00:47:35 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 914E6C433F5 for ; Fri, 28 Jan 2022 20:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351137AbiA1U3X (ORCPT ); Fri, 28 Jan 2022 15:29:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:24813 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351175AbiA1U3U (ORCPT ); Fri, 28 Jan 2022 15:29:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643401760; 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=tcZWR2ltT9IDLZDOmiJU7QFW5/KRxJtDJKHmdv9rpsw=; b=LIYRhzGQMO93ZX1yRXV9S93Dhbv7WokfbQT7eE2P5U26vRjWjt5x6JinzgRb8XYvfpMV0T Q3OxRQ8JuRsINc3+TbmRo44ChbqTLT/0Hx4/DYhKuQa2kQa2DtEAWsIPkSbYzWtFQDTemz dFgktNeaD/E7KpgdHe42fRaQ+uu8jW0= 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-332-DMWCd-ppN0i23JUeM4LERA-1; Fri, 28 Jan 2022 15:29:17 -0500 X-MC-Unique: DMWCd-ppN0i23JUeM4LERA-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 D4DAC190B2A0; Fri, 28 Jan 2022 20:29:15 +0000 (UTC) Received: from vbendel-laptop-2020.redhat.com (unknown [10.40.195.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4C395E26B; Fri, 28 Jan 2022 20:29:13 +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 3/3] selinux: remove duplicate cond_list clean up calls Date: Fri, 28 Jan 2022 21:28:58 +0100 Message-Id: <20220128202858.96935-4-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: quoted-printable X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Vratislav Bendel On error path from cond_read_list() and duplicate_policydb_cond_list() the *_destroy() functions get called a second time in caller functions. Remove the first calls and let the callers clean it. Suggested-by: Ondrej Mosnacek Signed-off-by: Vratislav Bendel Reviewed-by: Ondrej Mosnacek --- security/selinux/ss/conditional.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/security/selinux/ss/conditional.c b/security/selinux/ss/condit= ional.c index 8bc16ad3af9e..c333daaeceab 100644 --- a/security/selinux/ss/conditional.c +++ b/security/selinux/ss/conditional.c @@ -432,19 +432,16 @@ int cond_read_list(struct policydb *p, void *fp) =20 rc =3D avtab_alloc(&(p->te_cond_avtab), p->te_avtab.nel); if (rc) - goto err; + return rc; =20 p->cond_list_len =3D len; =20 for (i =3D 0; i < len; i++) { rc =3D cond_read_node(p, &p->cond_list[i], fp); if (rc) - goto err; + return rc; } return 0; -err: - cond_list_destroy(p); - return rc; } =20 int cond_write_bool(void *vkey, void *datum, void *ptr) @@ -643,7 +640,7 @@ static int duplicate_policydb_cond_list(struct policydb= *newp, sizeof(*newp->cond_list), GFP_KERNEL); if (!newp->cond_list) - goto error; + return -ENOMEM; =20 for (i =3D 0; i < origp->cond_list_len; i++) { struct cond_node *newn =3D &newp->cond_list[i]; @@ -656,27 +653,22 @@ static int duplicate_policydb_cond_list(struct policy= db *newp, orign->expr.len * sizeof(*orign->expr.nodes), GFP_KERNEL); if (!newn->expr.nodes) - goto error; + return -ENOMEM; =20 newn->expr.len =3D orign->expr.len; =20 rc =3D cond_dup_av_list(&newn->true_list, &orign->true_list, &newp->te_cond_avtab); if (rc) - goto error; + return rc; =20 rc =3D cond_dup_av_list(&newn->false_list, &orign->false_list, &newp->te_cond_avtab); if (rc) - goto error; + return rc; } =20 return 0; - -error: - avtab_destroy(&newp->te_cond_avtab); - cond_list_destroy(newp); - return -ENOMEM; } =20 static int cond_bools_destroy(void *key, void *datum, void *args) --=20 2.26.3