Skip to contentSkip to conversation

selinux: tighten type validation during policy load

PATCH Superseded Stephen Smalley 1 participant 1 message May 7 SELinux security module

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH v2 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.

---
v2 re-bases on top of selinux/dev and drops the checks covered by the merged patches from Christian.

 security/selinux/ss/policydb.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
security/selinux/ss/policydb.c +9 -3
index ead504a639e3..994c78536cc4 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: %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;
 	}
@@ -1861,6 +1866,7 @@ static int role_bounds_sanity_check(void *key, void *datum, void *datap)
 		}
 
 		upper = p->role_val_to_struct[upper->bounds - 1];
+
 		ebitmap_for_each_positive_bit(&role->types, node, bit)
 		{
 			if (ebitmap_get_bit(&upper->types, bit))
Signature · 1 line
2.54.0