Skip to contentSkip to conversation

libsepol: cil_policy: check at least one perm exists in a classperm

PATCH In review Rahul Sandhu 2 participants 3 messages May 31 – Jun 2 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: cil_policy: check at least one perm exists in a classperm

Kernel policy language does not support an empty list of permissions, { }. CIL expressions may collapse to nothing, so ensure that we only emit a permission list if at least one permission exists.

---
 libsepol/cil/src/cil_policy.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/cil/src/cil_policy.c +6 -0
index ca73bd28..e618ab13 100644
@@ -653,6 +653,12 @@ static void cil_classperms_to_string(struct cil_classperms *classperms, struct c
 	size_t len = 0;
 	char *new, *curr;
 
+	/* cil classperms are expressions, and hence may collapse to none. As an empty
+	   list of permissions, { }, is not valid in kernel policy language, make sure
+	   we only emit something if at least one permission exists.  */
+	if (cil_list_is_empty(classperms->perms))
+		return;
+
 	len += strlen(DATUM(classperms->class)->fqn) + 1;
 	cil_list_for_each(i1, classperms->perms) {
 		len += strlen(DATUM(i1->data)->fqn) + 1;
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Rahul Sandhu

Kernel policy language does not support an empty list of permissions, { }. CIL expressions may collapse to nothing, so ensure that we only emit a permission list if at least one permission exists.

Quoted 24 lines
---
 libsepol/cil/src/cil_policy.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/cil/src/cil_policy.c +6 -1
index ca73bd28..e618ab13 100644
@@ -653,6 +653,12 @@ static void cil_classperms_to_string(struct cil_classperms *classperms, struct c
        size_t len = 0;
        char *new, *curr;
 
+       /* cil classperms are expressions, and hence may collapse to none. As an empty
+          list of permissions, { }, is not valid in kernel policy language, make sure
+          we only emit something if at least one permission exists.  */
+       if (cil_list_is_empty(classperms->perms))
+               return;
+
        len += strlen(DATUM(classperms->class)->fqn) + 1;
        cil_list_for_each(i1, classperms->perms) {
                len += strlen(DATUM(i1->data)->fqn) + 1;
--

2.54.0

#2 lore raw
Quoted 11 lines · James Carter
Quoted 6 lines · Rahul Sandhu

Kernel policy language does not support an empty list of permissions, { }. CIL expressions may collapse to nothing, so ensure that we only emit a permission list if at least one permission exists.

Merged.
Thanks,
Jim

Quoted 24 lines
Quoted 24 lines
---
 libsepol/cil/src/cil_policy.c | 6 ++++++
 1 file changed, 6 insertions(+)
libsepol/cil/src/cil_policy.c +6 -1
index ca73bd28..e618ab13 100644
@@ -653,6 +653,12 @@ static void cil_classperms_to_string(struct cil_classperms *classperms, struct c
        size_t len = 0;
        char *new, *curr;
 
+       /* cil classperms are expressions, and hence may collapse to none. As an empty
+          list of permissions, { }, is not valid in kernel policy language, make sure
+          we only emit something if at least one permission exists.  */
+       if (cil_list_is_empty(classperms->perms))
+               return;
+
        len += strlen(DATUM(classperms->class)->fqn) + 1;
        cil_list_for_each(i1, classperms->perms) {
                len += strlen(DATUM(i1->data)->fqn) + 1;
--

2.54.0