Skip to content

Commit fb549c5

Browse files
committed
Merge tag 'selinux-pr-20190321' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull selinux fix from Paul Moore: "Another small SELinux fix for v5.1" * tag 'selinux-pr-20190321' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: fix NULL dereference in policydb_destroy()
2 parents 0939221 + 6a1afff commit fb549c5

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

security/selinux/ss/policydb.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,11 @@ void policydb_destroy(struct policydb *p)
828828
hashtab_map(p->range_tr, range_tr_destroy, NULL);
829829
hashtab_destroy(p->range_tr);
830830

831-
for (i = 0; i < p->p_types.nprim; i++)
832-
ebitmap_destroy(&p->type_attr_map_array[i]);
833-
kvfree(p->type_attr_map_array);
831+
if (p->type_attr_map_array) {
832+
for (i = 0; i < p->p_types.nprim; i++)
833+
ebitmap_destroy(&p->type_attr_map_array[i]);
834+
kvfree(p->type_attr_map_array);
835+
}
834836

835837
ebitmap_destroy(&p->filename_trans_ttypes);
836838
ebitmap_destroy(&p->policycaps);
@@ -2496,10 +2498,13 @@ int policydb_read(struct policydb *p, void *fp)
24962498
if (!p->type_attr_map_array)
24972499
goto bad;
24982500

2501+
/* just in case ebitmap_init() becomes more than just a memset(0): */
2502+
for (i = 0; i < p->p_types.nprim; i++)
2503+
ebitmap_init(&p->type_attr_map_array[i]);
2504+
24992505
for (i = 0; i < p->p_types.nprim; i++) {
25002506
struct ebitmap *e = &p->type_attr_map_array[i];
25012507

2502-
ebitmap_init(e);
25032508
if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
25042509
rc = ebitmap_read(e, fp);
25052510
if (rc)

0 commit comments

Comments
 (0)