Skip to contentSkip to conversation

libsepol: Fix potential NULL dereference in policydb_read()

PATCH Applied James Carter 2 participants 2 messages Jan 22 – Jan 26 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: Fix potential NULL dereference in policydb_read()

Since there can be gaps in the type_val_to_struct array for very old policies (version < POLICYDB_VERSION_BOUNDARY), need to that it is not NULL for a particular index before using.

Reported-by oss-fuzz (issue 474424148)
---
 libsepol/src/policydb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/policydb.c +1 -1
index 6aaa18f2..9760b164 100644
@@ -4513,7 +4513,7 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
 					if (j >= p->p_types.nprim)
 						goto bad;
 
-					if (p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
+					if (p->type_val_to_struct[i] && p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
 						ERR(fp->handle, "Invalid to have type attributes associated with an attribute for a kernel policy");
 						goto bad;
 					}
Signature · 1 line
2.52.0
Applied
#1 lore raw
Quoted 6 lines · James Carter

Since there can be gaps in the type_val_to_struct array for very old policies (version < POLICYDB_VERSION_BOUNDARY), need to that it is not NULL for a particular index before using.

Reported-by oss-fuzz (issue 474424148)

Thanks, applied.

Quoted 21 lines
---
 libsepol/src/policydb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/policydb.c +1 -1
index 6aaa18f2..9760b164 100644
@@ -4513,7 +4513,7 @@ int policydb_read(policydb_t * p, struct policy_file *fp, unsigned verbose)
 					if (j >= p->p_types.nprim)
 						goto bad;
 
-					if (p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
+					if (p->type_val_to_struct[i] && p->type_val_to_struct[i]->flavor == TYPE_ATTRIB) {
 						ERR(fp->handle, "Invalid to have type attributes associated with an attribute for a kernel policy");
 						goto bad;
 					}
Signature · 1 line
2.52.0