Skip to contentSkip to conversation

libsepol: log an error if we hit the max depth for __evaluate_classperms_list()

PATCH In review Stephen Smalley 2 participants 3 messages Aug 3 – Aug 4 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v2 1/1 libsepol: log an error if we hit the max depth for __evaluate_classperms_list()

Add a cil_log() statement so that we do not fail silently if we hit the max depth. While we are here, introduce a #define for the max depth and use it, and fix the comparison so that we fail immediately when the depth has already reached the limit.

---
v2 adds the missing newline to cil_log(); was confused by the fact that cil_tree_log() doesn't want one but cil_log() does.

 libsepol/cil/src/cil_post.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_post.c +6 -1
index 183b0d49..b9d5696f 100644
@@ -49,6 +49,8 @@
 #include "cil_symtab.h"
 #include "cil_deny.h"
 
+#define MAX_CLASSPERMS_DEPTH (32)
+
 #define GEN_REQUIRE_ATTR \
 	"cil_gen_require" /* Also in libsepol/src/module_to_cil.c */
 #define TYPEATTR_INFIX "_typeattr_" /* Also in libsepol/src/module_to_cil.c */
@@ -2296,8 +2298,11 @@ static int __evaluate_classperms_list(struct cil_list *classperms,
 	int rc = SEPOL_ERR;
 	struct cil_list_item *curr;
 
-	if (depth > 32)
+	if (depth >= MAX_CLASSPERMS_DEPTH) {
+		cil_log(CIL_ERR, "Exceeded max classperms depth (%u)\n",
+			MAX_CLASSPERMS_DEPTH);
 		return SEPOL_ERR;
+	}
 
 	cil_list_for_each(curr, classperms) {
 		if (curr->flavor == CIL_CLASSPERMS) {
Signature · 1 line
2.55.0
Acked-by on v2 1/1
#1 lore raw
Quoted 7 lines · Stephen Smalley

Add a cil_log() statement so that we do not fail silently if we hit the max depth. While we are here, introduce a #define for the max depth and use it, and fix the comparison so that we fail immediately when the depth has already reached the limit.

Quoted 36 lines

---
v2 adds the missing newline to cil_log(); was confused by the fact that cil_tree_log() doesn't want one but cil_log() does.

 libsepol/cil/src/cil_post.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_post.c +6 -2
index 183b0d49..b9d5696f 100644
@@ -49,6 +49,8 @@
 #include "cil_symtab.h"
 #include "cil_deny.h"
 
+#define MAX_CLASSPERMS_DEPTH (32)
+
 #define GEN_REQUIRE_ATTR \
        "cil_gen_require" /* Also in libsepol/src/module_to_cil.c */
 #define TYPEATTR_INFIX "_typeattr_" /* Also in libsepol/src/module_to_cil.c */
@@ -2296,8 +2298,11 @@ static int __evaluate_classperms_list(struct cil_list *classperms,
        int rc = SEPOL_ERR;
        struct cil_list_item *curr;
 
-       if (depth > 32)
+       if (depth >= MAX_CLASSPERMS_DEPTH) {
+               cil_log(CIL_ERR, "Exceeded max classperms depth (%u)\n",
+                       MAX_CLASSPERMS_DEPTH);
                return SEPOL_ERR;
+       }
 
        cil_list_for_each(curr, classperms) {
                if (curr->flavor == CIL_CLASSPERMS) {
--

2.55.0

author maintainer
#2 lore raw
Quoted 4 lines · James Carter
Quoted 1 line · Stephen Smalley
Quoted 8 lines
Quoted 6 lines

Add a cil_log() statement so that we do not fail silently if we hit the max depth. While we are here, introduce a #define for the max depth and use it, and fix the comparison so that we fail immediately when the depth has already reached the limit.

Merged.