All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] libsepol: Validate expressions do not mix tunables and booleans
@ 2026-08-20 15:41 James Carter
  2026-08-20 15:41 ` [PATCH 2/2] libsepol: Remove assertion and comment from discard_tunables() James Carter
  2026-08-20 17:04 ` [PATCH 1/2] libsepol: Validate expressions do not mix tunables and booleans Stephen Smalley
  0 siblings, 2 replies; 5+ messages in thread
From: James Carter @ 2026-08-20 15:41 UTC (permalink / raw)
  To: selinux; +Cc: stephen.smalley.work, James Carter

A conditional expression should never have a mixture of both
tunables and booleans. This is not allowed in CIL, checkpolicy,
or checkmodule and could only occur in a maliciously crafted
binary policy.

When validating the policy, validate that conditional expressions
do not contain a mixture of both tunables and booleans and exit
with an error if they do.

Signed-off-by: James Carter <jwcart2@gmail.com>
---
 libsepol/src/policydb_validate.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/libsepol/src/policydb_validate.c b/libsepol/src/policydb_validate.c
index fe8bf1cf..7d9ae3fd 100644
--- a/libsepol/src/policydb_validate.c
+++ b/libsepol/src/policydb_validate.c
@@ -1322,9 +1322,12 @@ bad:
 }
 
 static int validate_cond_expr(sepol_handle_t *handle,
-			      const struct cond_expr *expr,
+			      const struct cond_expr *expr, const policydb_t *p,
 			      const validate_t *boolean)
 {
+	cond_bool_datum_t *booldatum;
+	int booleans = 0;
+	int tunables = 0;
 	int depth = -1;
 
 	if (!expr)
@@ -1338,6 +1341,11 @@ static int validate_cond_expr(sepol_handle_t *handle,
 			if (depth >= (COND_EXPR_MAXDEPTH - 1))
 				goto bad;
 			depth++;
+			booldatum = p->bool_val_to_struct[expr->boolean - 1];
+			if (booldatum->flags & COND_BOOL_FLAGS_TUNABLE)
+				tunables++;
+			else
+				booleans++;
 			break;
 		case COND_NOT:
 			if (depth < 0)
@@ -1364,6 +1372,12 @@ static int validate_cond_expr(sepol_handle_t *handle,
 	if (depth != 0)
 		goto bad;
 
+	if (tunables && booleans) {
+		ERR(handle, "Found both tunables and booleans in the same "
+			    "conditional expression");
+		goto bad;
+	}
+
 	return 0;
 
 bad:
@@ -1375,7 +1389,8 @@ static int validate_cond_list(sepol_handle_t *handle, const cond_list_t *cond,
 			      const policydb_t *p, validate_t flavors[])
 {
 	for (; cond; cond = cond->next) {
-		if (validate_cond_expr(handle, cond->expr, &flavors[SYM_BOOLS]))
+		if (validate_cond_expr(handle, cond->expr, p,
+				       &flavors[SYM_BOOLS]))
 			goto bad;
 		if (validate_cond_av_list(handle, cond->true_list, p, flavors))
 			goto bad;
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-08-20 20:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-20 15:41 [PATCH 1/2] libsepol: Validate expressions do not mix tunables and booleans James Carter
2026-08-20 15:41 ` [PATCH 2/2] libsepol: Remove assertion and comment from discard_tunables() James Carter
2026-08-20 17:05   ` Stephen Smalley
2026-08-20 17:04 ` [PATCH 1/2] libsepol: Validate expressions do not mix tunables and booleans Stephen Smalley
2026-08-20 20:09   ` Stephen Smalley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.