All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/5] checkpolicy: check identifier before copying
@ 2025-01-15 13:13 Christian Göttsche
  2025-01-15 13:13 ` [PATCH 3/5] checkpolicy: remove unneeded queue_head() Christian Göttsche
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Christian Göttsche @ 2025-01-15 13:13 UTC (permalink / raw)
  To: selinux; +Cc: Christian Göttsche

From: Christian Göttsche <cgzones@googlemail.com>

Avoid calling strdup(3) with a NULL pointer, which can happen with an
invalid policy context, e.g.:

    class C
    sid S
    class C { P }
    ;
    user U roles j;
    sid S s:l:q:q:q

Fixes: 6f2b689f ("checkpolicy: Fix MLS users in optional blocks")
Reported-by: oss-fuzz (issue 390004173)
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 checkpolicy/policy_define.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/checkpolicy/policy_define.c b/checkpolicy/policy_define.c
index 2f811b67..96a481f7 100644
--- a/checkpolicy/policy_define.c
+++ b/checkpolicy/policy_define.c
@@ -4437,6 +4437,7 @@ static int parse_semantic_categories(char *id, level_datum_t * levdatum __attrib
 
 int define_user(void)
 {
+	const char *username;
 	char *id;
 	user_datum_t *usrdatum, *usr_global;
 	level_datum_t *levdatum;
@@ -4463,7 +4464,13 @@ int define_user(void)
 		return 0;
 	}
 
-	id = strdup(queue_head(id_queue));
+	username = queue_head(id_queue);
+	if (!username) {
+		yyerror("no user name");
+		return -1;
+	}
+
+	id = strdup(username);
 
 	if ((usrdatum = declare_user()) == NULL) {
 		free(id);
-- 
2.47.1


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

end of thread, other threads:[~2025-01-16 15:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-15 13:13 [PATCH 2/5] checkpolicy: check identifier before copying Christian Göttsche
2025-01-15 13:13 ` [PATCH 3/5] checkpolicy: remove unneeded queue_head() Christian Göttsche
2025-01-15 13:13 ` [PATCH 4/5] checkpolicy: do not consume unmatched identifiers Christian Göttsche
2025-01-15 13:13 ` [PATCH 5/5] checkpolicy: clear queue between parser passes Christian Göttsche
2025-01-15 13:13 ` [PATCH 1/5] libselinux: set errno in failure case Christian Göttsche
2025-01-15 20:04   ` James Carter
2025-01-16 15:59     ` Petr Lautrbach

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.