Blame SOURCES/0002-libsepol-cil-Destroy-classperms-list-when-resetting-.patch

060220
From 5012fee580f5e4744166462855767949311f9154 Mon Sep 17 00:00:00 2001
060220
From: James Carter <jwcart2@gmail.com>
060220
Date: Thu, 8 Apr 2021 13:32:01 -0400
060220
Subject: [PATCH] libsepol/cil: Destroy classperms list when resetting
060220
 classpermission
060220
060220
Nicolas Iooss reports:
060220
  A few months ago, OSS-Fuzz found a crash in the CIL compiler, which
060220
  got reported as
060220
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28648 (the title
060220
  is misleading, or is caused by another issue that conflicts with the
060220
  one I report in this message). Here is a minimized CIL policy which
060220
  reproduces the issue:
060220
060220
  (class CLASS (PERM))
060220
  (classorder (CLASS))
060220
  (sid SID)
060220
  (sidorder (SID))
060220
  (user USER)
060220
  (role ROLE)
060220
  (type TYPE)
060220
  (category CAT)
060220
  (categoryorder (CAT))
060220
  (sensitivity SENS)
060220
  (sensitivityorder (SENS))
060220
  (sensitivitycategory SENS (CAT))
060220
  (allow TYPE self (CLASS (PERM)))
060220
  (roletype ROLE TYPE)
060220
  (userrole USER ROLE)
060220
  (userlevel USER (SENS))
060220
  (userrange USER ((SENS)(SENS (CAT))))
060220
  (sidcontext SID (USER ROLE TYPE ((SENS)(SENS))))
060220
060220
  (classpermission CLAPERM)
060220
060220
  (optional OPT
060220
      (roletype nonexistingrole nonexistingtype)
060220
      (classpermissionset CLAPERM (CLASS (PERM)))
060220
  )
060220
060220
  The CIL policy fuzzer (which mimics secilc built with clang Address
060220
  Sanitizer) reports:
060220
060220
  ==36541==ERROR: AddressSanitizer: heap-use-after-free on address
060220
  0x603000004f98 at pc 0x56445134c842 bp 0x7ffe2a256590 sp
060220
  0x7ffe2a256588
060220
  READ of size 8 at 0x603000004f98 thread T0
060220
      #0 0x56445134c841 in __cil_verify_classperms
060220
  /selinux/libsepol/src/../cil/src/cil_verify.c:1620:8
060220
      #1 0x56445134a43e in __cil_verify_classpermission
060220
  /selinux/libsepol/src/../cil/src/cil_verify.c:1650:9
060220
      #2 0x56445134a43e in __cil_pre_verify_helper
060220
  /selinux/libsepol/src/../cil/src/cil_verify.c:1715:8
060220
      #3 0x5644513225ac in cil_tree_walk_core
060220
  /selinux/libsepol/src/../cil/src/cil_tree.c:272:9
060220
      #4 0x564451322ab1 in cil_tree_walk
060220
  /selinux/libsepol/src/../cil/src/cil_tree.c:316:7
060220
      #5 0x5644513226af in cil_tree_walk_core
060220
  /selinux/libsepol/src/../cil/src/cil_tree.c:284:9
060220
      #6 0x564451322ab1 in cil_tree_walk
060220
  /selinux/libsepol/src/../cil/src/cil_tree.c:316:7
060220
      #7 0x5644512b88fd in cil_pre_verify
060220
  /selinux/libsepol/src/../cil/src/cil_post.c:2510:7
060220
      #8 0x5644512b88fd in cil_post_process
060220
  /selinux/libsepol/src/../cil/src/cil_post.c:2524:7
060220
      #9 0x5644511856ff in cil_compile
060220
  /selinux/libsepol/src/../cil/src/cil.c:564:7
060220
060220
The classperms list of a classpermission rule is created and filled
060220
in when classpermissionset rules are processed, so it doesn't own any
060220
part of the list and shouldn't retain any of it when it is reset.
060220
060220
Destroy the classperms list (without destroying the data in it)  when
060220
resetting a classpermission rule.
060220
060220
Reported-by: Nicolas Iooss <nicolas.iooss@m4x.org>
060220
Signed-off-by: James Carter <jwcart2@gmail.com>
060220
060220
(cherry-picked from SElinuxProject
060220
 commit:  f34d3d30c8325e4847a6b696fe7a3936a8a361f3)
060220
---
060220
 libsepol/cil/src/cil_reset_ast.c | 2 +-
060220
 1 file changed, 1 insertion(+), 1 deletion(-)
060220
060220
diff --git a/libsepol/cil/src/cil_reset_ast.c b/libsepol/cil/src/cil_reset_ast.c
060220
index 43e6b88e..73e1fcf0 100644
060220
--- a/libsepol/cil/src/cil_reset_ast.c
060220
+++ b/libsepol/cil/src/cil_reset_ast.c
060220
@@ -52,7 +52,7 @@ static void cil_reset_classpermission(struct cil_classpermission *cp)
060220
 		return;
060220
 	}
060220
 
060220
-	cil_reset_classperms_list(cp->classperms);
060220
+	cil_list_destroy(&cp->classperms, CIL_FALSE);
060220
 }
060220
 
060220
 static void cil_reset_classperms_set(struct cil_classperms_set *cp_set)
060220
-- 
060220
2.30.2
060220