Skip to contentSkip to conversation

libsepol/cil: Ensure that the class in a classcommon is a kernel class

PATCH In review James Carter 1 participant 3 messages Jan 13, 2022 – Feb 11, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

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
index e97a9f46..d359eca0 100644
@@ -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
#1 lore raw

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)

---
 libsepol/cil/src/cil_resolve_ast.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +5 -1
index e97a9f46..d359eca0 100644
@@ -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

#2 lore raw
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)

---
 libsepol/cil/src/cil_resolve_ast.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil_resolve_ast.c +5 -1
index e97a9f46..d359eca0 100644
@@ -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