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

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