SELinux Security Module development
 help / color / mirror / Atom feed
From: James Carter <jwcart2@gmail.com>
To: selinux@vger.kernel.org
Cc: James Carter <jwcart2@gmail.com>
Subject: [PATCH 2/3] libsepol: Check for an unset sensitivity in module_to_cil
Date: Thu, 22 Jan 2026 11:06:01 -0500	[thread overview]
Message-ID: <20260122160602.65567-2-jwcart2@gmail.com> (raw)
In-Reply-To: <20260122160602.65567-1-jwcart2@gmail.com>

It is possible for a base policy to have sensitivities for user
levels and ranges that are not set if the user is used in a require
block.

Check for an unset sensitivity before using it to look up the
name of the sensitivity to prevent a memory access error.

Signed-off-by: James Carter <jwcart2@gmail.com>
---
 libsepol/src/module_to_cil.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libsepol/src/module_to_cil.c b/libsepol/src/module_to_cil.c
index 41c2b051..56ebd9c8 100644
--- a/libsepol/src/module_to_cil.c
+++ b/libsepol/src/module_to_cil.c
@@ -520,6 +520,9 @@ static int semantic_level_to_cil(struct policydb *pdb, struct mls_semantic_level
 {
 	struct mls_semantic_cat *cat;
 
+	if (level->sens == 0)
+		return -1;
+
 	cil_printf("(%s ", pdb->p_sens_val_to_name[level->sens - 1]);
 
 	if (level->cat != NULL) {
@@ -2499,6 +2502,9 @@ static int level_to_cil(struct policydb *pdb, struct mls_level *level)
 {
 	struct ebitmap *map = &level->cat;
 
+	if (level->sens == 0)
+		return -1;
+
 	cil_printf("(%s", pdb->p_sens_val_to_name[level->sens - 1]);
 
 	if (!ebitmap_is_empty(map)) {
-- 
2.52.0


  reply	other threads:[~2026-01-22 16:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-22 16:06 [PATCH 1/3] libsepol: Tighten checks on MLS range and level when validating James Carter
2026-01-22 16:06 ` James Carter [this message]
2026-01-22 16:06 ` [PATCH 3/3] libsepol: Handled required users in module_to_cil James Carter
2026-01-26  1:48 ` [PATCH 1/3] libsepol: Tighten checks on MLS range and level when validating Jason Zaman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260122160602.65567-2-jwcart2@gmail.com \
    --to=jwcart2@gmail.com \
    --cc=selinux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox