Skip to contentSkip to conversation

selinux: tighten type validation during policy load

PATCH Applied Stephen Smalley 3 participants 6 messages May 7 – Jul 2 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v3 1/1 selinux: tighten type validation during policy load

Tighten type validation during policy load to improve robustness in the face of ill-formed policies.

---
v3 removes a spurious empty line leftover from one of the changes dropped due to Christian's patches and adds the word "type" to the error message for clarity.

 security/selinux/ss/policydb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
security/selinux/ss/policydb.c +8 -3
index ead504a639e3..ba1c9bd9e29f 100644
@@ -604,10 +604,15 @@ static int type_index(void *key, void *datum, void *datap)
 	typdatum = datum;
 	p = datap;
 
+	if (!typdatum->value || typdatum->value > p->p_types.nprim ||
+		typdatum->bounds > p->p_types.nprim) {
+		pr_err("SELinux: type %s had value %u bounds %u nprim %u\n",
+			(char *)key, typdatum->value, typdatum->bounds,
+			p->p_types.nprim);
+		return -EINVAL;
+	}
+
 	if (typdatum->primary) {
-		if (!typdatum->value || typdatum->value > p->p_types.nprim ||
-		    typdatum->bounds > p->p_types.nprim)
-			return -EINVAL;
 		p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key;
 		p->type_val_to_struct[typdatum->value - 1] = typdatum;
 	}
Signature · 1 line
2.54.0
author maintainer
#1 lore raw
Quoted 5 lines · Stephen Smalley

Tighten type validation during policy load to improve robustness in the face of ill-formed policies.

Ping.

Quoted 34 lines

---
v3 removes a spurious empty line leftover from one of the changes dropped due to Christian's patches and adds the word "type" to the error message for clarity.

 security/selinux/ss/policydb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
security/selinux/ss/policydb.c +8 -4
index ead504a639e3..ba1c9bd9e29f 100644
@@ -604,10 +604,15 @@ static int type_index(void *key, void *datum, void *datap)
        typdatum = datum;
        p = datap;
 
+       if (!typdatum->value || typdatum->value > p->p_types.nprim ||
+               typdatum->bounds > p->p_types.nprim) {
+               pr_err("SELinux: type %s had value %u bounds %u nprim %u\n",
+                       (char *)key, typdatum->value, typdatum->bounds,
+                       p->p_types.nprim);
+               return -EINVAL;
+       }
+
        if (typdatum->primary) {
-               if (!typdatum->value || typdatum->value > p->p_types.nprim ||
-                   typdatum->bounds > p->p_types.nprim)
-                       return -EINVAL;
                p->sym_val_to_name[SYM_TYPES][typdatum->value - 1] = key;
                p->type_val_to_struct[typdatum->value - 1] = typdatum;
        }
--

2.54.0

maintainer
#2 lore raw
Quoted 9 lines · Stephen Smalley
Quoted 5 lines · Stephen Smalley

Tighten type validation during policy load to improve robustness in the face of ill-formed policies.

Ping.

Pong.

Just a reminder that there are free things I dislike more than "ping" nudges. If your patch hit the lore archive and is visible in patchwork, it's on my list; if I haven't acted upon it yet it is simply because I've been busy with other higher priority things. Nudging patches like this simply steals and wastes time that could be better spent elsewhere.

There were a few of Christian's patches that weren't merged due to feedback and other concerns, but I need to go back and see if it is preferable to fixup and merge those before looking at other patches. Maybe this is good regardless, we'll see.

--
paul-moore.com

#3 lore raw
Quoted 24 lines · Paul Moore
Quoted 9 lines · Stephen Smalley
Quoted 5 lines · Stephen Smalley

Tighten type validation during policy load to improve robustness in the face of ill-formed policies.

Ping.

Pong.

Just a reminder that there are free things I dislike more than "ping" nudges. If your patch hit the lore archive and is visible in patchwork, it's on my list; if I haven't acted upon it yet it is simply because I've been busy with other higher priority things. Nudging patches like this simply steals and wastes time that could be better spent elsewhere.

Quoted 4 lines

There were a few of Christian's patches that weren't merged due to feedback and other concerns, but I need to go back and see if it is preferable to fixup and merge those before looking at other patches. Maybe this is good regardless, we'll see.

I'll try to address the comments and rebase *soon*. (Haven't found the time yet)

Quoted 7 lines

--
paul-moore.com

author maintainer
#4 lore raw
Quoted 26 lines · Christian Göttsche
Quoted 24 lines · Paul Moore
Quoted 9 lines · Stephen Smalley
Quoted 5 lines · Stephen Smalley

Tighten type validation during policy load to improve robustness in the face of ill-formed policies.

Ping.

Pong.

Just a reminder that there are free things I dislike more than "ping" nudges. If your patch hit the lore archive and is visible in patchwork, it's on my list; if I haven't acted upon it yet it is simply because I've been busy with other higher priority things. Nudging patches like this simply steals and wastes time that could be better spent elsewhere.

Quoted 6 lines
Quoted 4 lines

There were a few of Christian's patches that weren't merged due to feedback and other concerns, but I need to go back and see if it is preferable to fixup and merge those before looking at other patches. Maybe this is good regardless, we'll see.

I'll try to address the comments and rebase *soon*. (Haven't found the time yet)

Likely helpful if you can clarify whether your patches add equivalent validation; if so, I didn't see it.

maintainer Applied
#5 lore raw
In reply to Stephen Smalley
Quoted 4 lines · On May 7, 2026 Stephen Smalley <[email protected]> wrote:

Tighten type validation during policy load to improve robustness in the face of ill-formed policies.

Quoted 8 lines

---
v3 removes a spurious empty line leftover from one of the changes dropped due to Christian's patches and adds the word "type" to the error message for clarity.

 security/selinux/ss/policydb.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Merged into selinux/dev, thanks.

--
paul-moore.com