Skip to contentSkip to conversation

libsepol/cil: Check that sym_index is within bounds

PATCH In review Vit Mojzis 2 participants 3 messages Jul 23, 2024 – Aug 14, 2024 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 libsepol/cil: Check that sym_index is within bounds

Make sure sym_index is within the bounds of symtab array before using it to index the array.

Fixes:
Error: OVERRUN (CWE-119):
libsepol-3.6/cil/src/cil_resolve_ast.c:3157: assignment: Assigning: "sym_index" = "CIL_SYM_UNKNOWN".
libsepol-3.6/cil/src/cil_resolve_ast.c:3189: overrun-call: Overrunning callee's array of size 19 by passing argument "sym_index" (which evaluates to 20) in call to "cil_resolve_name".

  \# 3187|                   switch (curr->flavor) {
  \# 3188|                   case CIL_STRING:
  \# 3189|->                         rc = cil_resolve_name(parent, curr->data, sym_index, db, &res_datum);
  \# 3190|                           if (rc != SEPOL_OK) {
  \# 3191|                                   goto exit;
---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -1
index 427a320c..da8863c4 100644
@@ -4291,7 +4291,7 @@ int cil_resolve_name_keep_aliases(struct cil_tree_node *ast_node, char *name, en
 	int rc = SEPOL_ERR;
 	struct cil_tree_node *node = NULL;
 
-	if (name == NULL) {
+	if (name == NULL || sym_index >= CIL_SYM_NUM) {
 		cil_log(CIL_ERR, "Invalid call to cil_resolve_name\n");
 		goto exit;
 	}
Signature · 1 line
2.43.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Vit Mojzis

Make sure sym_index is within the bounds of symtab array before using it to index the array.

Fixes:
Error: OVERRUN (CWE-119):
libsepol-3.6/cil/src/cil_resolve_ast.c:3157: assignment: Assigning: "sym_index" = "CIL_SYM_UNKNOWN".
libsepol-3.6/cil/src/cil_resolve_ast.c:3189: overrun-call: Overrunning callee's array of size 19 by passing argument "sym_index" (which evaluates to 20) in call to "cil_resolve_name".

Quoted 7 lines
  \# 3187|                   switch (curr->flavor) {
  \# 3188|                   case CIL_STRING:
  \# 3189|->                         rc = cil_resolve_name(parent, curr->data, sym_index, db, &res_datum);
  \# 3190|                           if (rc != SEPOL_OK) {
  \# 3191|                                   goto exit;
Quoted 21 lines
---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -2
index 427a320c..da8863c4 100644
@@ -4291,7 +4291,7 @@ int cil_resolve_name_keep_aliases(struct cil_tree_node *ast_node, char *name, en
        int rc = SEPOL_ERR;
        struct cil_tree_node *node = NULL;
 
-       if (name == NULL) {
+       if (name == NULL || sym_index >= CIL_SYM_NUM) {
                cil_log(CIL_ERR, "Invalid call to cil_resolve_name\n");
                goto exit;
        }
--

2.43.0

#2 lore raw
Quoted 16 lines · James Carter
Quoted 14 lines · Vit Mojzis

Make sure sym_index is within the bounds of symtab array before using it to index the array.

Fixes:
Error: OVERRUN (CWE-119):
libsepol-3.6/cil/src/cil_resolve_ast.c:3157: assignment: Assigning: "sym_index" = "CIL_SYM_UNKNOWN".
libsepol-3.6/cil/src/cil_resolve_ast.c:3189: overrun-call: Overrunning callee's array of size 19 by passing argument "sym_index" (which evaluates to 20) in call to "cil_resolve_name".

  \# 3187|                   switch (curr->flavor) {
  \# 3188|                   case CIL_STRING:
  \# 3189|->                         rc = cil_resolve_name(parent, curr->data, sym_index, db, &res_datum);
  \# 3190|                           if (rc != SEPOL_OK) {
  \# 3191|                                   goto exit;
Quoted 4 lines
Quoted 1 line

Merged.
Thanks,
Jim

Quoted 21 lines
Quoted 21 lines
---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -2
index 427a320c..da8863c4 100644
@@ -4291,7 +4291,7 @@ int cil_resolve_name_keep_aliases(struct cil_tree_node *ast_node, char *name, en
        int rc = SEPOL_ERR;
        struct cil_tree_node *node = NULL;
 
-       if (name == NULL) {
+       if (name == NULL || sym_index >= CIL_SYM_NUM) {
                cil_log(CIL_ERR, "Invalid call to cil_resolve_name\n");
                goto exit;
        }
--

2.43.0