Skip to contentSkip to conversation

libsepol/cil: do not override previous results of __cil_verify_classperms

PATCH In review Nicolas Iooss 2 participants 3 messages Jul 2, 2021 – Jul 7, 2021 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: do not override previous results of __cil_verify_classperms

When __cil_verify_map_class() verifies a classpermission, it calls __verify_map_perm_classperms() on each item. If the first item reports a failure and the next one succeeds, the failure is overwritten in map_args->rc. This is a bug which causes a NULL pointer dereference in the CIL compiler when compiling the following policy:

(sid SID)
(sidorder (SID))

(class CLASS (PERM1))
(classorder (CLASS))

(classpermission CLSPERM)
(classpermissionset CLSPERM (CLASS (PERM1)))
(classmap files (CLAMAPxx x))
(classmapping files CLAMAPxx CLSPERM)

---
 libsepol/cil/src/cil_verify.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_verify.c +5 -1
index 59397f70f2ea..8ad3dc9e114a 100644
@@ -1786,8 +1786,12 @@ static int __verify_map_perm_classperms(__attribute__((unused)) hashtab_key_t k,
 {
 	struct cil_verify_map_args *map_args = args;
 	struct cil_perm *cmp = (struct cil_perm *)d;
+	int rc;
 
-	map_args->rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &map_args->class->datum, &cmp->datum, CIL_MAP_PERM, 0, 2);
+	rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &map_args->class->datum, &cmp->datum, CIL_MAP_PERM, 0, 2);
+	if (rc != SEPOL_OK) {
+		map_args->rc = rc;
+	}
 
 	return SEPOL_OK;
 }
Signature · 1 line
2.32.0
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Nicolas Iooss

When __cil_verify_map_class() verifies a classpermission, it calls __verify_map_perm_classperms() on each item. If the first item reports a failure and the next one succeeds, the failure is overwritten in map_args->rc. This is a bug which causes a NULL pointer dereference in the CIL compiler when compiling the following policy:

(sid SID)
(sidorder (SID))

(class CLASS (PERM1))
(classorder (CLASS))

Quoted 8 lines

(classpermission CLSPERM)
(classpermissionset CLSPERM (CLASS (PERM1)))
(classmap files (CLAMAPxx x))
(classmapping files CLAMAPxx CLSPERM)

Quoted 25 lines
---
 libsepol/cil/src/cil_verify.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_verify.c +5 -2
index 59397f70f2ea..8ad3dc9e114a 100644
@@ -1786,8 +1786,12 @@ static int __verify_map_perm_classperms(__attribute__((unused)) hashtab_key_t k,
 {
        struct cil_verify_map_args *map_args = args;
        struct cil_perm *cmp = (struct cil_perm *)d;
+       int rc;
 
-       map_args->rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &map_args->class->datum, &cmp->datum, CIL_MAP_PERM, 0, 2);
+       rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &map_args->class->datum, &cmp->datum, CIL_MAP_PERM, 0, 2);
+       if (rc != SEPOL_OK) {
+               map_args->rc = rc;
+       }
 
        return SEPOL_OK;
 }
--

2.32.0

#2 lore raw
Quoted 20 lines · James Carter
Quoted 18 lines · Nicolas Iooss

When __cil_verify_map_class() verifies a classpermission, it calls __verify_map_perm_classperms() on each item. If the first item reports a failure and the next one succeeds, the failure is overwritten in map_args->rc. This is a bug which causes a NULL pointer dereference in the CIL compiler when compiling the following policy:

(sid SID)
(sidorder (SID))

(class CLASS (PERM1))
(classorder (CLASS))

(classpermission CLSPERM)
(classpermissionset CLSPERM (CLASS (PERM1)))
(classmap files (CLAMAPxx x))
(classmapping files CLAMAPxx CLSPERM)

Quoted 6 lines
Quoted 3 lines

Merged.
Thanks,
Jim

Quoted 25 lines
Quoted 25 lines
---
 libsepol/cil/src/cil_verify.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_verify.c +5 -2
index 59397f70f2ea..8ad3dc9e114a 100644
@@ -1786,8 +1786,12 @@ static int __verify_map_perm_classperms(__attribute__((unused)) hashtab_key_t k,
 {
        struct cil_verify_map_args *map_args = args;
        struct cil_perm *cmp = (struct cil_perm *)d;
+       int rc;
 
-       map_args->rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &map_args->class->datum, &cmp->datum, CIL_MAP_PERM, 0, 2);
+       rc = __cil_verify_classperms(cmp->classperms, &cmp->datum, &map_args->class->datum, &cmp->datum, CIL_MAP_PERM, 0, 2);
+       if (rc != SEPOL_OK) {
+               map_args->rc = rc;
+       }
 
        return SEPOL_OK;
 }
--

2.32.0