From patchwork Wed Oct 23 13:43:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 13847123 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC1C6E56A for ; Wed, 23 Oct 2024 13:46:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691168; cv=none; b=nWgw6DFe3OLwXaKYIl+nkFtcLcicUZTvHdbd6JYUvVEfkkTKMbUM7jeQCLrU+G6xwC9wvrVYNiKsTHwX7w90Y7IxoSA9qaA2RqU+OHloDUYnJyhn1HiqpJ5aOsbH0Q4jicZbf2JEpyuf73x4fGrH1EDzz2JJbojuymHDyd6h3A0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691168; c=relaxed/simple; bh=EsxdwvQjuD7RovcvUH7WeD0PJV6yxN+jYWYrz9Z3xRI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sXiCogf/gkWTKGQ5yeRRh+qLGkNJVGMrLIAfAuk1GCMQKNIDtdoHHjYV/0cjad6R8UbgSHMNfOppmbiT28gNTG8hL2oyTkXz/de0Ket8jSMskqNESOL2ZFD3PLNjeRgF+/otP3ndImimtxfzgV+bJTEkYhKZH4W78rlvwoyW8wk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fuuSgNNs; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fuuSgNNs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729691165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kgYRaCbTdjXaFcfkOT0nR3rrB6xCp69iXBnS2UZvUh0=; b=fuuSgNNsYVmbPtJcoBhtj/0GAX1QJztmdAp2ICDRIkg9HvyhUTLTDxR2GvqQL83YUNpLSD ZtP0O7Hihd/bvoAhp2gtx8uhqOpA8LJbAElpAkcGpfyEL3CSKUsjEDxgYttBcozZaZuEme fO810NUkHXjyoRhtYxUMrBmAGsDwq4I= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-35-H155zI4BM3GUi7j7sDM-GA-1; Wed, 23 Oct 2024 09:46:04 -0400 X-MC-Unique: H155zI4BM3GUi7j7sDM-GA-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B83F1190556E for ; Wed, 23 Oct 2024 13:43:31 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.164]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 066AA19560A2 for ; Wed, 23 Oct 2024 13:43:30 +0000 (UTC) From: Vit Mojzis To: selinux@vger.kernel.org Subject: [PATCH v2 1/4] libsepol/cil: Initialize avtab_datum on declaration Date: Wed, 23 Oct 2024 15:43:15 +0200 Message-ID: <20241023134318.733305-1-vmojzis@redhat.com> In-Reply-To: References: Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 avtab_datum.xperms was not always initialized before being used. Fixes: Error: UNINIT (CWE-457): libsepol-3.7/cil/src/cil_binary.c:977:2: var_decl: Declaring variable "avtab_datum" without initializer. libsepol-3.7/cil/src/cil_binary.c:1059:3: uninit_use_in_call: Using uninitialized value "avtab_datum". Field "avtab_datum.xperms" is uninitialized when calling "__cil_cond_insert_rule". \# 1057| } \# 1058| } \# 1059|-> rc = __cil_cond_insert_rule(&pdb->te_cond_avtab, &avtab_key, &avtab_datum, cond_node, cond_flavor); \# 1060| } Error: UNINIT (CWE-457): libsepol-3.7/cil/src/cil_binary.c:1348:2: var_decl: Declaring variable "avtab_datum" without initializer. libsepol-3.7/cil/src/cil_binary.c:1384:3: uninit_use_in_call: Using uninitialized value "avtab_datum". Field "avtab_datum.xperms" is uninitialized when calling "__cil_cond_insert_rule". \# 1382| } else { \# 1383| avtab_datum.data = data; \# 1384|-> rc = __cil_cond_insert_rule(&pdb->te_cond_avtab, &avtab_key, &avtab_datum, cond_node, cond_flavor); \# 1385| } \# 1386| Signed-off-by: Vit Mojzis Acked-by: James Carter --- libsepol/cil/src/cil_binary.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libsepol/cil/src/cil_binary.c b/libsepol/cil/src/cil_binary.c index 3dec1883..3d920182 100644 --- a/libsepol/cil/src/cil_binary.c +++ b/libsepol/cil/src/cil_binary.c @@ -975,7 +975,7 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, { int rc = SEPOL_OK; avtab_key_t avtab_key; - avtab_datum_t avtab_datum; + avtab_datum_t avtab_datum = { .data = res, .xperms = NULL }; avtab_ptr_t existing; avtab_key.source_type = src; @@ -997,8 +997,6 @@ static int __cil_insert_type_rule(policydb_t *pdb, uint32_t kind, uint32_t src, goto exit; } - avtab_datum.data = res; - existing = avtab_search_node(&pdb->te_avtab, &avtab_key); if (existing) { /* Don't add duplicate type rule and warn if they conflict. @@ -1346,7 +1344,7 @@ static int __cil_insert_avrule(policydb_t *pdb, uint32_t kind, uint32_t src, uin { int rc = SEPOL_OK; avtab_key_t avtab_key; - avtab_datum_t avtab_datum; + avtab_datum_t avtab_datum = { .data = data, .xperms = NULL }; avtab_datum_t *avtab_dup = NULL; avtab_key.source_type = src; @@ -1372,7 +1370,6 @@ static int __cil_insert_avrule(policydb_t *pdb, uint32_t kind, uint32_t src, uin if (!cond_node) { avtab_dup = avtab_search(&pdb->te_avtab, &avtab_key); if (!avtab_dup) { - avtab_datum.data = data; rc = avtab_insert(&pdb->te_avtab, &avtab_key, &avtab_datum); } else { if (kind == CIL_AVRULE_DONTAUDIT) @@ -1381,7 +1378,6 @@ static int __cil_insert_avrule(policydb_t *pdb, uint32_t kind, uint32_t src, uin avtab_dup->data |= data; } } else { - avtab_datum.data = data; rc = __cil_cond_insert_rule(&pdb->te_cond_avtab, &avtab_key, &avtab_datum, cond_node, cond_flavor); } From patchwork Wed Oct 23 13:43:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 13847120 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8897A1AAE02 for ; Wed, 23 Oct 2024 13:43:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691035; cv=none; b=gXgYD7uPn7yqR1iT3ZEL3EBC56DjC//QWXLVViHjW4WjisAGPSOYqUqvRgKwwbSOqmHUQCkeAaTTcMQmV8lWsXPZj2Ve0p+w3Y8GPOjiyVqa6ru9RXtqFojmHWJX6x41khtEJ6Kc6ketggwhOyyJaCxxA5YMEoDeq0taZ0UTTUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691035; c=relaxed/simple; bh=a58WhftuYwmQhPFE68btykTXHEJ0TAPMyWbaywwjrCc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BYbtRwTDpjs7iRj7HZZOL1E8TGzJX+Gw1TrOO73WrdY85IIfqdcU6A5B9VsRkjmpCXiyRhphsH6VmMyHRvzL+7BVs3OoavYDj/p47QJdFxYwl9PkR0FFdlQNl4Uv1ResboBLctqWZD1ZA0cCJoYRX5VM8n3Lcfo1HYKq/V+f7Ck= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=I0jrLq6y; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I0jrLq6y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729691032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uDC8es8Dnm4/AG+tkdPlI3NpIOUFXCnikfcCobDEcU0=; b=I0jrLq6yGgtC55vUyll/MDBVATEUfGdwznFKKkJAkfJfHgMIk16y4VMjaZGwyoF7nVReZ5 FYdTD488Y6Kc+lvH2vpqgv+B+mBkpjMb4/CdGjCTN08zGY528VBFXBz8nczdlWknqIV4Nz ruB1mh8WQStA085bd1vv4GjIRvRUwIo= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-77-bUcv4vo4PNWiydbrvfFHIg-1; Wed, 23 Oct 2024 09:43:51 -0400 X-MC-Unique: bUcv4vo4PNWiydbrvfFHIg-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0D67C1936DAA for ; Wed, 23 Oct 2024 13:43:36 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.164]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4CC571956046 for ; Wed, 23 Oct 2024 13:43:35 +0000 (UTC) From: Vit Mojzis To: selinux@vger.kernel.org Subject: [PATCH v2 2/4] libsepol/mls: Do not destroy context on memory error Date: Wed, 23 Oct 2024 15:43:16 +0200 Message-ID: <20241023134318.733305-2-vmojzis@redhat.com> In-Reply-To: <20241023134318.733305-1-vmojzis@redhat.com> References: <20241023134318.733305-1-vmojzis@redhat.com> Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 In case of malloc error, ctx1, or ctx2 may be pointing to uninitialized space and context_destroy should not be used on it. Fixes: Error: UNINIT (CWE-457): libsepol-3.7/src/mls.c:673:2: alloc_fn: Calling "malloc" which returns uninitialized memory. libsepol-3.7/src/mls.c:673:2: assign: Assigning: "ctx1" = "malloc(64UL)", which points to uninitialized data. libsepol-3.7/src/mls.c:699:2: uninit_use_in_call: Using uninitialized value "ctx1->range.level[0].cat.node" when calling "context_destroy". \# 697| ERR(handle, "could not check if mls context %s contains %s", \# 698| mls1, mls2); \# 699|-> context_destroy(ctx1); \# 700| context_destroy(ctx2); \# 701| free(ctx1); Error: UNINIT (CWE-457): libsepol-3.7/src/mls.c:674:2: alloc_fn: Calling "malloc" which returns uninitialized memory. libsepol-3.7/src/mls.c:674:2: assign: Assigning: "ctx2" = "malloc(64UL)", which points to uninitialized data. libsepol-3.7/src/mls.c:700:2: uninit_use_in_call: Using uninitialized value "ctx2->range.level[0].cat.node" when calling "context_destroy". \# 698| mls1, mls2); \# 699| context_destroy(ctx1); \# 700|-> context_destroy(ctx2); \# 701| free(ctx1); \# 702| free(ctx2); Signed-off-by: Vit Mojzis --- libsepol/src/mls.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libsepol/src/mls.c b/libsepol/src/mls.c index 45db8920..a37405d1 100644 --- a/libsepol/src/mls.c +++ b/libsepol/src/mls.c @@ -672,8 +672,10 @@ int sepol_mls_contains(sepol_handle_t * handle, context_struct_t *ctx1 = NULL, *ctx2 = NULL; ctx1 = malloc(sizeof(context_struct_t)); ctx2 = malloc(sizeof(context_struct_t)); - if (ctx1 == NULL || ctx2 == NULL) + if (ctx1 == NULL || ctx2 == NULL){ + ERR(handle, "out of memory"); goto omem; + } context_init(ctx1); context_init(ctx2); @@ -690,16 +692,14 @@ int sepol_mls_contains(sepol_handle_t * handle, free(ctx2); return STATUS_SUCCESS; - omem: - ERR(handle, "out of memory"); - err: - ERR(handle, "could not check if mls context %s contains %s", - mls1, mls2); context_destroy(ctx1); context_destroy(ctx2); + omem: free(ctx1); free(ctx2); + ERR(handle, "could not check if mls context %s contains %s", + mls1, mls2); return STATUS_ERR; } From patchwork Wed Oct 23 13:43:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 13847122 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18C3C159583 for ; Wed, 23 Oct 2024 13:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691069; cv=none; b=bK+sBfhMs+fmcPCqn5naimLzEGVjJzqSrDwteCvYk9vqq7dh+UuhZF74fn6CWrp3oU6l5egR+EoSmiUz7GXTlzQMuKFzJNPeOnOO8SO1ThIh38HQtQB5jlg68ciM983TELXCUJcF+yf5ZLchRxP8aipKCr2KrZMK2TNZSpogAO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691069; c=relaxed/simple; bh=DygcjO+6tokGt5xkff3FmRS0BxlLIi/2fNBumvFX40s=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJm3D9VuS+jRKidv6nwkjtzOhfbr3i86kR2u6IuuWFjkxcGX+eENBrm+lyopEEk7wwUBxsOxdag1FwVDpF3NLrRKS2G9sfzjaWLg5dV55tb2qKKijJfI/uCxZiDs/SwhXI3jr+aIwTI2SMyeOe3buixNDNYUO2vfp75TxqCkGUE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XZk1d1Vy; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XZk1d1Vy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729691065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S74S1i4iajAAwohgFYQDlrvOHjBRPPxvHDMvqGaCuc0=; b=XZk1d1VyVblE8f0fdLnc/BfCx3WYvqJSr3QxIqKkiEu4+INi5ziB22gG3vdm84htjSGjMs wUceM7/LxL45pKs+cp48odZ1rv7k2TEXTTBxXWdR8YNF1RXgJxee58PzIVLYDRzOtuK735 ugF12+vBUuS4PdbNDicwKZyBQY5PvAE= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-97-naP28411M1K5AD6RpTKdjQ-1; Wed, 23 Oct 2024 09:44:23 -0400 X-MC-Unique: naP28411M1K5AD6RpTKdjQ-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D70FC1936118 for ; Wed, 23 Oct 2024 13:43:37 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.164]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1C3F719560A2 for ; Wed, 23 Oct 2024 13:43:36 +0000 (UTC) From: Vit Mojzis To: selinux@vger.kernel.org Subject: [PATCH v2 3/4] libsepol/cil/cil_post: Initialize tmp on declaration Date: Wed, 23 Oct 2024 15:43:17 +0200 Message-ID: <20241023134318.733305-3-vmojzis@redhat.com> In-Reply-To: <20241023134318.733305-1-vmojzis@redhat.com> References: <20241023134318.733305-1-vmojzis@redhat.com> Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 tmp.node was not always initialized before being used by ebitmap_destroy. Fixes: Error: UNINIT (CWE-457): libsepol-3.7/cil/src/cil_post.c:1309:2: var_decl: Declaring variable "tmp" without initializer. libsepol-3.7/cil/src/cil_post.c:1382:6: uninit_use_in_call: Using uninitialized value "tmp.node" when calling "ebitmap_destroy". \# 1380| if (rc != SEPOL_OK) { \# 1381| cil_log(CIL_INFO, "Failed to apply operator to bitmaps\n"); \# 1382|-> ebitmap_destroy(&tmp); \# 1383| goto exit; \# 1384| } Signed-off-by: Vit Mojzis --- libsepol/cil/src/cil_post.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c index ac99997f..d63a5496 100644 --- a/libsepol/cil/src/cil_post.c +++ b/libsepol/cil/src/cil_post.c @@ -1315,6 +1315,8 @@ static int __cil_expr_to_bitmap(struct cil_list *expr, ebitmap_t *out, int max, curr = expr->head; flavor = expr->flavor; + ebitmap_init(&tmp); + if (curr->flavor == CIL_OP) { enum cil_flavor op = (enum cil_flavor)(uintptr_t)curr->data; From patchwork Wed Oct 23 13:43:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vit Mojzis X-Patchwork-Id: 13847121 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A98E1AAE02 for ; Wed, 23 Oct 2024 13:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691040; cv=none; b=JVHXjif8a2O2sjxasJw72EoN41F40DwUSH20rWv+2Y+o4LHh67XlqMEtWU2fhC2m1/Azl7GW1zg5V7ipisrJZUzBAkwN1WyaBPLM9pw4qleCcIh8oZqX7MmpCf0nccERNgRAX9FwJ48vEWIYSlcFR98Bh+dEDK20jnB8U/YJmHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729691040; c=relaxed/simple; bh=+cwYIZnbNVeipG7kuWSyYqiYU9n7VBdxpU9bjyFTltI=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Mr+MHbjBRJyb3l06f4/xKvuMz6WvvoLZbgOlI/8ZaRwEVHGzlUkHsL73nmz+i1CYTfD5tkeVpOTZsyr5Ac+b31QTXbbqR36YXqnYGkrn9oPqg/yMVODc2IsO8lMcERbKAvHxgGl1sHHWBx+OEwmn7CrQjWx+z9HPOspo3DIGJgE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TetuhwH/; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TetuhwH/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729691038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jBovyVCks93imgd3Ar2i2bSgf7MjSQfEpKOKbXi7CLM=; b=TetuhwH/j5+TKHoHzzySsF98CrBQ30Ij1paS824gvxsC8sJgMNwlSw1eZHdHrlRqRHfz0B w7mj4Q5Jg0AoDd9psQBOQrOzPZVoAu03dRgY6g3grvSD4UT8AYYZfwsWyaAjE/bPDQ70DN BZOou01H0UEugtYKcdIRh2pshUDcW7I= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-681-UMTDfAveP7iy3RL68NgD9Q-1; Wed, 23 Oct 2024 09:43:56 -0400 X-MC-Unique: UMTDfAveP7iy3RL68NgD9Q-1 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 87B1919054F1 for ; Wed, 23 Oct 2024 13:43:39 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.164]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C946E19560A2 for ; Wed, 23 Oct 2024 13:43:38 +0000 (UTC) From: Vit Mojzis To: selinux@vger.kernel.org Subject: [PATCH v2 4/4] libsepol: Initialize "strs" on declaration Date: Wed, 23 Oct 2024 15:43:18 +0200 Message-ID: <20241023134318.733305-4-vmojzis@redhat.com> In-Reply-To: <20241023134318.733305-1-vmojzis@redhat.com> References: <20241023134318.733305-1-vmojzis@redhat.com> Precedence: bulk X-Mailing-List: selinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 The value of "strs" was not always initialized before being used by strs_destroy. Fixes: Error: UNINIT (CWE-457): libsepol-3.7/src/kernel_to_cil.c:1439:2: var_decl: Declaring variable "strs" without initializer. libsepol-3.7/src/kernel_to_cil.c:1487:2: uninit_use_in_call: Using uninitialized value "strs" when calling "strs_destroy". \# 1485| \# 1486| exit: \# 1487|-> strs_destroy(&strs); \# 1488| \# 1489| if (rc != 0) { Error: UNINIT (CWE-457): libsepol-3.7/src/kernel_to_conf.c:1422:2: var_decl: Declaring variable "strs" without initializer. libsepol-3.7/src/kernel_to_conf.c:1461:2: uninit_use_in_call: Using uninitialized value "strs" when calling "strs_destroy". \# 1459| \# 1460| exit: \# 1461|-> strs_destroy(&strs); \# 1462| \# 1463| if (rc != 0) { Signed-off-by: Vit Mojzis --- libsepol/src/kernel_to_cil.c | 2 +- libsepol/src/kernel_to_conf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c index 7243b3c0..2d563e7d 100644 --- a/libsepol/src/kernel_to_cil.c +++ b/libsepol/src/kernel_to_cil.c @@ -1436,7 +1436,7 @@ static int map_type_aliases_to_strs(char *key, void *data, void *args) static int write_type_alias_rules_to_cil(FILE *out, struct policydb *pdb) { type_datum_t *alias; - struct strs *strs; + struct strs *strs = NULL; char *name; char *type; unsigned i, num = 0; diff --git a/libsepol/src/kernel_to_conf.c b/libsepol/src/kernel_to_conf.c index ca91ffae..661546af 100644 --- a/libsepol/src/kernel_to_conf.c +++ b/libsepol/src/kernel_to_conf.c @@ -1419,7 +1419,7 @@ static int map_type_aliases_to_strs(char *key, void *data, void *args) static int write_type_alias_rules_to_conf(FILE *out, struct policydb *pdb) { type_datum_t *alias; - struct strs *strs; + struct strs *strs = NULL; char *name; char *type; unsigned i, num = 0;