From b7077f316694fb81c8f219f9569f1e37daf172eb Mon Sep 17 00:00:00 2001 From: Blagovest Petrov Date: Wed, 4 Nov 2026 03:03:52 +0200 Subject: [PATCH] fix(server): accept constrain statements in Bor SELinux modules The CIL allowlist for custom modules rejected constrain, the one statement that can take a permission away from the unconfined domains, which hold allow rules for everything. A module that keeps a service from being killed from a shell needs it. Constraints restructure nothing in the base policy, and a bad one is undone by removing the module. --- server/pkg/macrules/macrules.go | 11 +++++++---- server/pkg/macrules/macrules_test.go | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/server/pkg/macrules/macrules.go b/server/pkg/macrules/macrules.go index af79acab..1a9a4577 100644 --- a/server/pkg/macrules/macrules.go +++ b/server/pkg/macrules/macrules.go @@ -270,12 +270,15 @@ func IsRiskyPermissiveDomain(name string) bool { // cilAllowedStatements are the top-level CIL statements a Bor module may // use: rules, type and attribute declarations, booleans, file and port -// contexts, login mappings, and the containers CIL sources are organised -// in. Statements that restructure the base policy (classes, sids, users -// and roles, MLS, policy capabilities, kernel object contexts) are not +// contexts, login mappings, constraints, and the containers CIL sources +// are organised in. Constraints are accepted because they are the only +// way to take a permission away from the unconfined domains, which hold +// allow rules for everything; a bad one is undone by removing the module. +// Statements that restructure the base policy (classes, sids, users and +// roles, MLS, policy capabilities, kernel object contexts) are not // accepted. var cilAllowedStatements = map[string]struct{}{ - "allow": {}, "auditallow": {}, "dontaudit": {}, "neverallow": {}, + "allow": {}, "auditallow": {}, "dontaudit": {}, "neverallow": {}, "constrain": {}, "allowx": {}, "auditallowx": {}, "dontauditx": {}, "neverallowx": {}, "permissionx": {}, "type": {}, "typealias": {}, "typealiasactual": {}, "typeattribute": {}, "typeattributeset": {}, "typetransition": {}, "typechange": {}, "typemember": {}, "typebounds": {}, "typepermissive": {}, diff --git a/server/pkg/macrules/macrules_test.go b/server/pkg/macrules/macrules_test.go index fc842c3c..fe8a7bc3 100644 --- a/server/pkg/macrules/macrules_test.go +++ b/server/pkg/macrules/macrules_test.go @@ -101,6 +101,7 @@ func TestCheckCIL(t *testing.T) { "(optional corp (allow a_t b_t (file (read))))", "(block corp (type corp_t) (roletype system_r corp_t))", "(booleanif deny_ptrace (true (allow a_t b_t (process (ptrace)))))", + "(constrain (process (signal sigkill sigstop)) (or (neq t2 corp_t) (eq t1 init_t)))", } for _, v := range valid { if err := CheckCIL(v); err != nil { @@ -116,6 +117,7 @@ func TestCheckCIL(t *testing.T) { "sid": "(sid kernel)", "user": "(user corp_u)", "policycap": "(policycap open_perms)", + "mls": "(mlsconstrain (process (sigkill)) (dom h1 h2))", "nul": "(allow a_t b_t (file (read)))\x00", "unterminated": `(filecon "/opt any (system_u object_r bin_t ((s0) (s0))))`, "too big": "(" + strings.Repeat("allow a_t b_t (file (read))\n", 4000) + ")",