diff mbox series

[v2,1/4] libsepol/cil: Initialize avtab_datum on declaration

Message ID 20241023134318.733305-1-vmojzis@redhat.com (mailing list archive)
State Accepted
Commit 0dac9813e1ea
Headers show
Series [v2,1/4] libsepol/cil: Initialize avtab_datum on declaration | expand

Commit Message

Vit Mojzis Oct. 23, 2024, 1:43 p.m. UTC
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 <vmojzis@redhat.com>
---
 libsepol/cil/src/cil_binary.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

James Carter Oct. 23, 2024, 7:10 p.m. UTC | #1
On Wed, Oct 23, 2024 at 9:46 AM Vit Mojzis <vmojzis@redhat.com> wrote:
>
> 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 <vmojzis@redhat.com>

For these four patches:
Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  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);
>         }
>
> --
> 2.47.0
>
>
James Carter Oct. 30, 2024, 1:15 p.m. UTC | #2
On Wed, Oct 23, 2024 at 3:10 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Wed, Oct 23, 2024 at 9:46 AM Vit Mojzis <vmojzis@redhat.com> wrote:
> >
> > 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 <vmojzis@redhat.com>
>
> For these four patches:
> Acked-by: James Carter <jwcart2@gmail.com>
>

These four patches have been merged.
Thanks,
Jim

> > ---
> >  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);
> >         }
> >
> > --
> > 2.47.0
> >
> >
diff mbox series

Patch

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);
 	}