libsepol/cil: Do not use original type and typeattribute datums
PATCH 1/1 libsepol/cil: Do not use original type and typeattribute datums
When compiling CIL policy using secilc's "-m" option (which allows duplicate declarations for types and type attributes), a segfault will occur if the type or type attribute being copied has already been declared. This is because a search of the symbol table is made during the copy and the original datum will be used if one is found. The original datum will be considered a duplicate when an attempt is made to add it to the symbol table. The original datum, which is still in use, will then be destroyed and a segfault will follow soon after that.
Instead, always create a new datum. When it is added the new datum will be destroyed if it is a duplicate and duplicate declarations are allowed.
--- libsepol/cil/src/cil_copy_ast.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)
libsepol/cil/src/cil_copy_ast.c +8 -24
@@ -590,20 +590,12 @@ int cil_copy_roleallow(__attribute__((unused)) struct cil_db *db, void *data, voreturn SEPOL_OK ; } -int cil_copy_type (__attribute__((unused))struct cil_db *db,void *data,void **copy,symtab_t *symtab) +int cil_copy_type (__attribute__((unused))struct cil_db *db, __attribute__((unused))void *data,void **copy, __attribute__((unused))symtab_t *symtab) { -struct cil_type *orig = data; -char *key = orig->datum.name; -struct cil_symtab_datum *datum =NULL ; +struct cil_type *new; -cil_symtab_get_datum (symtab, key, &datum); -if (datum ==NULL ) { -struct cil_type *new; -cil_type_init (&new); - *copy = new; - }else { - *copy = datum; - } +cil_type_init (&new); + *copy = new;return SEPOL_OK ; }
@@ -622,20 +614,12 @@ int cil_copy_typepermissive(__attribute__((unused)) struct cil_db *db, void *datreturn SEPOL_OK ; } -int cil_copy_typeattribute (__attribute__((unused))struct cil_db *db,void *data,void **copy,symtab_t *symtab) +int cil_copy_typeattribute (__attribute__((unused))struct cil_db *db, __attribute__((unused))void *data,void **copy, __attribute__((unused))symtab_t *symtab) { -struct cil_typeattribute *orig = data; -char *key = orig->datum.name; -struct cil_symtab_datum *datum =NULL ; +struct cil_typeattribute *new; -cil_symtab_get_datum (symtab, key, &datum); -if (datum ==NULL ) { -struct cil_typeattribute *new; -cil_typeattribute_init (&new); - *copy = new; - }else { - *copy = datum; - } +cil_typeattribute_init (&new); + *copy = new;return SEPOL_OK ; }
Signature · 1 line
2.31.1
Quoted 10 lines · James Carter
When compiling CIL policy using secilc's "-m" option (which allows duplicate declarations for types and type attributes), a segfault will occur if the type or type attribute being copied has already been declared. This is because a search of the symbol table is made during the copy and the original datum will be used if one is found. The original datum will be considered a duplicate when an attempt is made to add it to the symbol table. The original datum, which is still in use, will then be destroyed and a segfault will follow soon after that.
Quoted 6 lines
Instead, always create a new datum. When it is added the new datum will be destroyed if it is a duplicate and duplicate declarations are allowed.
Signed-off-by James Carter <[email protected]>
Quoted 60 lines
--- libsepol/cil/src/cil_copy_ast.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-)libsepol/cil/src/cil_copy_ast.c +8
-24@@ -590,20 +590,12 @@ int cil_copy_roleallow(__attribute__((unused)) struct cil_db *db, void *data, voreturn SEPOL_OK ; } -int cil_copy_type (__attribute__((unused))struct cil_db *db,void *data,void **copy,symtab_t *symtab) +int cil_copy_type (__attribute__((unused))struct cil_db *db, __attribute__((unused))void *data,void **copy, __attribute__((unused))symtab_t *symtab) { -struct cil_type *orig = data; -char *key = orig->datum.name; -struct cil_symtab_datum *datum =NULL ; +struct cil_type *new; -cil_symtab_get_datum (symtab, key, &datum); -if (datum ==NULL ) { -struct cil_type *new; -cil_type_init (&new); - *copy = new; - }else { - *copy = datum; - } +cil_type_init (&new); + *copy = new;return SEPOL_OK ; }@@ -622,20 +614,12 @@ int cil_copy_typepermissive(__attribute__((unused)) struct cil_db *db, void *datreturn SEPOL_OK ; } -int cil_copy_typeattribute (__attribute__((unused))struct cil_db *db,void *data,void **copy,symtab_t *symtab) +int cil_copy_typeattribute (__attribute__((unused))struct cil_db *db, __attribute__((unused))void *data,void **copy, __attribute__((unused))symtab_t *symtab) { -struct cil_typeattribute *orig = data; -char *key = orig->datum.name; -struct cil_symtab_datum *datum =NULL ; +struct cil_typeattribute *new; -cil_symtab_get_datum (symtab, key, &datum); -if (datum ==NULL ) { -struct cil_typeattribute *new; -cil_typeattribute_init (&new); - *copy = new; - }else { - *copy = datum; - } +cil_typeattribute_init (&new); + *copy = new;return SEPOL_OK ; }Signature · 1 line
2.31.1