Skip to contentSkip to conversation

checkpolicy: error out if required permission would exceed limit

PATCH Applied Christian Göttsche 3 participants 4 messages Jun 10, 2022 – Jun 21, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpolicy: error out if required permission would exceed limit

A require statement for a class permission adds that permission to the class representation for the current module. In case the resulting class would have more than the supported amount of 32 permissions assigned the resulting binary module will fail to load at link-time without an informative error message (since [1]).

Bail out if adding a permission would result in a class having more then the supported amount of 32 permissions assigned.

[1]: https://github.com/SELinuxProject/selinux/commit/97af65f69644a3233d073ae93980a0d2e51f42e1

---
 checkpolicy/module_compiler.c | 8 ++++++++
 1 file changed, 8 insertions(+)
checkpolicy/module_compiler.c +8 -0
index 129650fa..3188af89 100644
@@ -851,6 +851,14 @@ int require_class(int pass)
 				free(perm_id);
 				return -1;
 			}
+			if (datum->permissions.nprim >= PERM_SYMTAB_SIZE) {
+				yyerror2("Class %s would have too many permissions "
+					 "to fit in an access vector with permission %s",
+					 policydbp->p_class_val_to_name[datum->s.value - 1],
+					 perm_id);
+				free(perm_id);
+				return -1;
+			}
 			allocated = 1;
 			if ((perm = malloc(sizeof(*perm))) == NULL) {
 				yyerror("Out of memory!");
Signature · 1 line
2.36.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Christian Göttsche

A require statement for a class permission adds that permission to the class representation for the current module. In case the resulting class would have more than the supported amount of 32 permissions assigned the resulting binary module will fail to load at link-time without an informative error message (since [1]).

Quoted 8 lines

Bail out if adding a permission would result in a class having more then the supported amount of 32 permissions assigned.

[1]: https://github.com/SELinuxProject/selinux/commit/97af65f69644a3233d073ae93980a0d2e51f42e1

Quoted 26 lines
---
 checkpolicy/module_compiler.c | 8 ++++++++
 1 file changed, 8 insertions(+)
checkpolicy/module_compiler.c +8 -1
index 129650fa..3188af89 100644
@@ -851,6 +851,14 @@ int require_class(int pass)
                                free(perm_id);
                                return -1;
                        }
+                       if (datum->permissions.nprim >= PERM_SYMTAB_SIZE) {
+                               yyerror2("Class %s would have too many permissions "
+                                        "to fit in an access vector with permission %s",
+                                        policydbp->p_class_val_to_name[datum->s.value - 1],
+                                        perm_id);
+                               free(perm_id);
+                               return -1;
+                       }
                        allocated = 1;
                        if ((perm = malloc(sizeof(*perm))) == NULL) {
                                yyerror("Out of memory!");
--

2.36.1

#2 lore raw
Quoted 11 lines · James Carter
Quoted 8 lines · Christian Göttsche

A require statement for a class permission adds that permission to the class representation for the current module. In case the resulting class would have more than the supported amount of 32 permissions assigned the resulting binary module will fail to load at link-time without an informative error message (since [1]).

Bail out if adding a permission would result in a class having more then

s/then/than/

Quoted 36 lines
Quoted 7 lines

the supported amount of 32 permissions assigned.

[1]: https://github.com/SELinuxProject/selinux/commit/97af65f69644a3233d073ae93980a0d2e51f42e1

Quoted 26 lines
---
 checkpolicy/module_compiler.c | 8 ++++++++
 1 file changed, 8 insertions(+)
checkpolicy/module_compiler.c +8 -1
index 129650fa..3188af89 100644
@@ -851,6 +851,14 @@ int require_class(int pass)
                                free(perm_id);
                                return -1;
                        }
+                       if (datum->permissions.nprim >= PERM_SYMTAB_SIZE) {
+                               yyerror2("Class %s would have too many permissions "
+                                        "to fit in an access vector with permission %s",
+                                        policydbp->p_class_val_to_name[datum->s.value - 1],
+                                        perm_id);
+                               free(perm_id);
+                               return -1;
+                       }
                        allocated = 1;
                        if ((perm = malloc(sizeof(*perm))) == NULL) {
                                yyerror("Out of memory!");
--

2.36.1

#3 lore raw
Quoted 11 lines · Christian Göttsche
Quoted 10 lines · James Carter
Quoted 7 lines · Christian Göttsche

A require statement for a class permission adds that permission to the class representation for the current module. In case the resulting class would have more than the supported amount of 32 permissions assigned the resulting binary module will fail to load at link-time without an informative error message (since [1]).

Quoted 3 lines
Quoted 1 line
Quoted 1 line

Bail out if adding a permission would result in a class having more then

s/then/than/

Merged, thanks!

Quoted 36 lines
Quoted 36 lines
Quoted 7 lines

the supported amount of 32 permissions assigned.

[1]: https://github.com/SELinuxProject/selinux/commit/97af65f69644a3233d073ae93980a0d2e51f42e1

Quoted 26 lines
---
 checkpolicy/module_compiler.c | 8 ++++++++
 1 file changed, 8 insertions(+)
checkpolicy/module_compiler.c +8 -1
index 129650fa..3188af89 100644
@@ -851,6 +851,14 @@ int require_class(int pass)
                                free(perm_id);
                                return -1;
                        }
+                       if (datum->permissions.nprim >= PERM_SYMTAB_SIZE) {
+                               yyerror2("Class %s would have too many permissions "
+                                        "to fit in an access vector with permission %s",
+                                        policydbp->p_class_val_to_name[datum->s.value - 1],
+                                        perm_id);
+                               free(perm_id);
+                               return -1;
+                       }
                        allocated = 1;
                        if ((perm = malloc(sizeof(*perm))) == NULL) {
                                yyerror("Out of memory!");
--

2.36.1