libsepol: Fix potential NULL dereference in policydb_read()
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)
Signed-off-by James Carter <[email protected]>
--- libsepol/src/policydb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/src/policydb.c +1 -1
@@ -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
Jason Zaman
AppliedQuoted 6 lines · James Carter
Since there can be gaps in the
type_val_to_structarray 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)Signed-off-by James Carter <[email protected]>
Signed-off-by Jason Zaman <[email protected]>
Thanks, applied.
Quoted 21 lines
--- libsepol/src/policydb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libsepol/src/policydb.c +1
-1@@ -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