Skip to content

Commit

Permalink
selinux: fix memory leak in policydb_init()
Browse files Browse the repository at this point in the history
Since roles_init() adds some entries to the role hash table, we need to
destroy also its keys/values on error, otherwise we get a memory leak in
the error path.

Cc: <stable@vger.kernel.org>
Reported-by: syzbot+fee3a14d4cdf92646287@syzkaller.appspotmail.com
Fixes: 1da177e ("Linux-2.6.12-rc2")
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
Ondrej Mosnacek authored and Paul Moore committed Jul 31, 2019
1 parent acbc372 commit 4538523
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion security/selinux/ss/policydb.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
return v;
}

static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap);

/*
* Initialize a policy database structure.
*/
Expand Down Expand Up @@ -321,8 +323,10 @@ static int policydb_init(struct policydb *p)
out:
hashtab_destroy(p->filename_trans);
hashtab_destroy(p->range_tr);
for (i = 0; i < SYM_NUM; i++)
for (i = 0; i < SYM_NUM; i++) {
hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
hashtab_destroy(p->symtab[i].table);
}
return rc;
}

Expand Down

0 comments on commit 4538523

Please sign in to comment.