libsepol/cil: Ensure that the class in a classcommon is a kernel class
PATCH 1/1 libsepol/cil: Ensure that the class in a classcommon is a kernel class
Map classes use the same struct as kernel classes, but only the kernel class uses the pointer to a common class. When resolving a classcommon, make sure that the class that is found is a kernel class and not a map class. If not, then return an error.
Found by oss-fuzz (#43209)
--- libsepol/cil/src/cil_resolve_ast.c | 5 +++++ 1 file changed, 5 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +5 -0
@@ -754,6 +754,11 @@ int cil_resolve_classcommon(struct cil_tree_node *current, void *extra_args)if (rc !=SEPOL_OK ) { goto exit; } +if (NODE (class_datum)->flavor !=CIL_CLASS ) { +cil_log (CIL_ERR ,"Class %s is not a kernel class and cannot be associated with common %s\n" , clscom->class_str, clscom->common_str); + rc =SEPOL_ERR ; + goto exit; + } rc =cil_resolve_name (current, clscom->common_str,CIL_SYM_COMMONS , extra_args, &common_datum);if (rc !=SEPOL_OK ) {
Signature · 1 line
2.31.1
I also plan on merging this patch at the end of the week. Jim
Quoted 32 lines · James Carter
Map classes use the same struct as kernel classes, but only the kernel class uses the pointer to a common class. When resolving a classcommon, make sure that the class that is found is a kernel class and not a map class. If not, then return an error.
Found by oss-fuzz (#43209)
Signed-off-by James Carter <[email protected]>--- libsepol/cil/src/cil_resolve_ast.c | 5 +++++ 1 file changed, 5 insertions(+)libsepol/cil/src/cil_resolve_ast.c +5
-1@@ -754,6 +754,11 @@ int cil_resolve_classcommon(struct cil_tree_node *current, void *extra_args)if (rc !=SEPOL_OK ) { goto exit; } +if (NODE (class_datum)->flavor !=CIL_CLASS ) { +cil_log (CIL_ERR ,"Class %s is not a kernel class and cannot be associated with common %s\n" , clscom->class_str, clscom->common_str); + rc =SEPOL_ERR ; + goto exit; + } rc =cil_resolve_name (current, clscom->common_str,CIL_SYM_COMMONS , extra_args, &common_datum);if (rc !=SEPOL_OK ) { --2.31.1
Quoted 4 lines · James Carter
I also plan on merging this patch at the end of the week. Jim
This patch has now been merged.
Jim
Quoted 34 lines · James Carter
Quoted 32 lines
Map classes use the same struct as kernel classes, but only the kernel class uses the pointer to a common class. When resolving a classcommon, make sure that the class that is found is a kernel class and not a map class. If not, then return an error.
Found by oss-fuzz (#43209)
Signed-off-by James Carter <[email protected]>--- libsepol/cil/src/cil_resolve_ast.c | 5 +++++ 1 file changed, 5 insertions(+)libsepol/cil/src/cil_resolve_ast.c +5
-1@@ -754,6 +754,11 @@ int cil_resolve_classcommon(struct cil_tree_node *current, void *extra_args)if (rc !=SEPOL_OK ) { goto exit; } +if (NODE (class_datum)->flavor !=CIL_CLASS ) { +cil_log (CIL_ERR ,"Class %s is not a kernel class and cannot be associated with common %s\n" , clscom->class_str, clscom->common_str); + rc =SEPOL_ERR ; + goto exit; + } rc =cil_resolve_name (current, clscom->common_str,CIL_SYM_COMMONS , extra_args, &common_datum);if (rc !=SEPOL_OK ) { --2.31.1