Skip to content

Commit 5d9f4cf

Browse files
committed
Merge tag 'selinux-pr-20211123' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux
Pull SELinux fix from Paul Moore: "A fix to make sure things are handled correctly when an allocation fails" * tag 'selinux-pr-20211123' of git://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/selinux: selinux: fix NULL-pointer dereference when hashtab allocation fails
2 parents b735936 + dc27f3c commit 5d9f4cf

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

security/selinux/ss/hashtab.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ static u32 hashtab_compute_size(u32 nel)
3131

3232
int hashtab_init(struct hashtab *h, u32 nel_hint)
3333
{
34-
h->size = hashtab_compute_size(nel_hint);
34+
u32 size = hashtab_compute_size(nel_hint);
35+
36+
/* should already be zeroed, but better be safe */
3537
h->nel = 0;
36-
if (!h->size)
37-
return 0;
38+
h->size = 0;
39+
h->htable = NULL;
3840

39-
h->htable = kcalloc(h->size, sizeof(*h->htable), GFP_KERNEL);
40-
return h->htable ? 0 : -ENOMEM;
41+
if (size) {
42+
h->htable = kcalloc(size, sizeof(*h->htable), GFP_KERNEL);
43+
if (!h->htable)
44+
return -ENOMEM;
45+
h->size = size;
46+
}
47+
return 0;
4148
}
4249

4350
int __hashtab_insert(struct hashtab *h, struct hashtab_node **dst,

0 commit comments

Comments
 (0)