Blame SOURCES/0024-libsepol-cil-Allow-permission-expressions-when-using.patch

71cd55
From 22fb6f477bf10e834ece9eff84438fcaebf7d2ec Mon Sep 17 00:00:00 2001
71cd55
From: James Carter <jwcart2@gmail.com>
71cd55
Date: Thu, 8 Apr 2021 13:32:14 -0400
71cd55
Subject: [PATCH] libsepol/cil: Allow permission expressions when using map
71cd55
 classes
71cd55
71cd55
The following policy will cause a segfault:
71cd55
  (class CLASS (PERM))
71cd55
  (class C (P1 P2 P3))
71cd55
  (classorder (CLASS C))
71cd55
  (sid SID)
71cd55
  (sidorder (SID))
71cd55
  (user USER)
71cd55
  (role ROLE)
71cd55
  (type TYPE)
71cd55
  (category CAT)
71cd55
  (categoryorder (CAT))
71cd55
  (sensitivity SENS)
71cd55
  (sensitivityorder (SENS))
71cd55
  (sensitivitycategory SENS (CAT))
71cd55
  (allow TYPE self (CLASS (PERM)))
71cd55
  (roletype ROLE TYPE)
71cd55
  (userrole USER ROLE)
71cd55
  (userlevel USER (SENS))
71cd55
  (userrange USER ((SENS)(SENS (CAT))))
71cd55
  (sidcontext SID (USER ROLE TYPE ((SENS)(SENS))))
71cd55
71cd55
  (classmap CM (PM1 PM2 PM3))
71cd55
  (classmapping CM PM1 (C (P1)))
71cd55
  (classmapping CM PM2 (C (P2)))
71cd55
  (classmapping CM PM3 (C (P3)))
71cd55
  (allow TYPE self (CM (and (all) (not PM2))))
71cd55
71cd55
The problem is that, while permission expressions are allowed for
71cd55
normal classes, map classes are expected to only have permission
71cd55
lists and no check is done to verify that only a permission list
71cd55
is being used.
71cd55
71cd55
When the above policy is parsed, the "and" and "all" are seen as
71cd55
expression operators, but when the map permissions are converted to
71cd55
normal class and permissions, the permission expression is assumed
71cd55
to be a list of datums and since the operators are not datums a
71cd55
segfault is the result.
71cd55
71cd55
There is no reason to limit map classes to only using a list of
71cd55
permissions and, in fact, it would be better to be able to use them
71cd55
in the same way normal classes are used.
71cd55
71cd55
Allow permissions expressions to be used for map classes by first
71cd55
evaluating the permission expression and then converting the
71cd55
resulting list to normal classes and permissions.
71cd55
71cd55
Signed-off-by: James Carter <jwcart2@gmail.com>
71cd55
---
71cd55
 libsepol/cil/src/cil_post.c | 4 ++++
71cd55
 1 file changed, 4 insertions(+)
71cd55
71cd55
diff --git a/libsepol/cil/src/cil_post.c b/libsepol/cil/src/cil_post.c
71cd55
index fd4758dc580e..05842b644807 100644
71cd55
--- a/libsepol/cil/src/cil_post.c
71cd55
+++ b/libsepol/cil/src/cil_post.c
71cd55
@@ -2137,6 +2137,10 @@ static int __evaluate_classperms_list(struct cil_list *classperms, struct cil_db
71cd55
 				}
71cd55
 			} else { /* MAP */
71cd55
 				struct cil_list_item *i = NULL;
71cd55
+				rc = __evaluate_classperms(cp, db);
71cd55
+				if (rc != SEPOL_OK) {
71cd55
+					goto exit;
71cd55
+				}
71cd55
 				cil_list_for_each(i, cp->perms) {
71cd55
 					struct cil_perm *cmp = i->data;
71cd55
 					rc = __evaluate_classperms_list(cmp->classperms, db);
71cd55
-- 
71cd55
2.32.0
71cd55