selinux: fix NULL dereference in policydb_destroy()
authorOndrej Mosnacek <omosnace@redhat.com>
Sun, 17 Mar 2019 13:46:53 +0000 (14:46 +0100)
committerPaul Moore <paul@paul-moore.com>
Mon, 18 Mar 2019 16:19:48 +0000 (12:19 -0400)
commit6a1afffb08ce5f9fb9ccc20f7ab24846c0142984
tree960c8d62d8a57248005a8f626b79b4eb37d53dea
parent9e98c678c2d6ae3a17cb2de55d17f69dddaa231b
selinux: fix NULL dereference in policydb_destroy()

The conversion to kvmalloc() forgot to account for the possibility that
p->type_attr_map_array might be null in policydb_destroy().

Fix this by destroying its contents only if it is not NULL.

Also make sure ebitmap_init() is called on all entries before
policydb_destroy() can be called. Right now this is a no-op, because
both kvcalloc() and ebitmap_init() just zero out the whole struct, but
let's rather not rely on a specific implementation.

Reported-by: syzbot+a57b2aff60832666fc28@syzkaller.appspotmail.com
Fixes: acdf52d97f82 ("selinux: convert to kvmalloc")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Acked-by: Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: Paul Moore <paul@paul-moore.com>
security/selinux/ss/policydb.c