Skip to content

Commit 9ae2dad

Browse files
WOnder93gregkh
authored andcommitted
selinux: fix memory leak in policydb_init()
commit 4538523 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I4ee059fe10b053f469110c183d7544f489c66ba9
1 parent 0524a82 commit 9ae2dad

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

security/selinux/ss/policydb.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ static int rangetr_cmp(struct hashtab *h, const void *k1, const void *k2)
266266
return v;
267267
}
268268

269+
static int (*destroy_f[SYM_NUM]) (void *key, void *datum, void *datap);
270+
269271
/*
270272
* Initialize a policy database structure.
271273
*/
@@ -309,8 +311,10 @@ static int policydb_init(struct policydb *p)
309311
out:
310312
hashtab_destroy(p->filename_trans);
311313
hashtab_destroy(p->range_tr);
312-
for (i = 0; i < SYM_NUM; i++)
314+
for (i = 0; i < SYM_NUM; i++) {
315+
hashtab_map(p->symtab[i].table, destroy_f[i], NULL);
313316
hashtab_destroy(p->symtab[i].table);
317+
}
314318
return rc;
315319
}
316320

0 commit comments

Comments
 (0)