Skip to contentSkip to conversation

libsepol/cil: fix NULL pointer dereference when copying classpermission/set

PATCH In review Steve Lawrence 2 participants 2 messages Sep 9, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: fix NULL pointer dereference when copying classpermission/set

When copying classpermission or classpermissionset statements, we did not properly initialize the new structs. This would cause a segfault when one used either of these statements inside a tunableif block, e.g.

(tunableif foo
(true
(classpermissionset cps (cls (perm1 perm2))))
(false
(classpermissionset cps (cls (perm1)))))

---
 libsepol/cil/src/cil_copy_ast.c | 4 ++++
 1 file changed, 4 insertions(+)
libsepol/cil/src/cil_copy_ast.c +4 -0
index 34d8d4c..c611dbc 100644
@@ -282,6 +282,8 @@ int cil_copy_classpermission(__attribute__((unused)) struct cil_db *db, void *da
 		}
 	}
 
+	cil_classpermission_init(&new);
+
 	cil_copy_classperms_list(orig->classperms, &new->classperms);
 
 	*copy = new;
@@ -294,6 +296,8 @@ int cil_copy_classpermissionset(__attribute__((unused)) struct cil_db *db, void
 	struct cil_classpermissionset *orig = data;
 	struct cil_classpermissionset *new = NULL;
 
+	cil_classpermissionset_init(&new);
+
 	new->set_str = orig->set_str;
 
 	cil_copy_classperms_list(orig->classperms, &new->classperms);
Signature · 1 line
2.4.3
#1 lore raw
Quoted 4 lines · Steve Lawrence

When copying classpermission or classpermissionset statements, we did not properly initialize the new structs. This would cause a segfault when one used either of these statements inside a tunableif block, e.g.

Quoted 8 lines

(tunableif foo
(true
(classpermissionset cps (cls (perm1 perm2))))
(false
(classpermissionset cps (cls (perm1)))))

Thanks. Applied.

Jim

Quoted 27 lines
---
  libsepol/cil/src/cil_copy_ast.c | 4 ++++
  1 file changed, 4 insertions(+)
libsepol/cil/src/cil_copy_ast.c +4 -0
index 34d8d4c..c611dbc 100644
@@ -282,6 +282,8 @@ int cil_copy_classpermission(__attribute__((unused)) struct cil_db *db, void *da
  		}
  	}
 
+	cil_classpermission_init(&new);
+
  	cil_copy_classperms_list(orig->classperms, &new->classperms);
 
  	*copy = new;
@@ -294,6 +296,8 @@ int cil_copy_classpermissionset(__attribute__((unused)) struct cil_db *db, void
  	struct cil_classpermissionset *orig = data;
  	struct cil_classpermissionset *new = NULL;
 
+	cil_classpermissionset_init(&new);
+
  	new->set_str = orig->set_str;
 
  	cil_copy_classperms_list(orig->classperms, &new->classperms);
Signature · 2 lines
James Carter <[email protected]>
National Security Agency