Skip to content

Commit

Permalink
selinux: fix bad cleanup on error in hashtab_duplicate()
Browse files Browse the repository at this point in the history
The code attempts to free the 'new' pointer using kmem_cache_free(),
which is wrong because this function isn't responsible of freeing it.
Instead, the function should free new->htable and clear the contents of
*new (to prevent double-free).

Cc: [email protected]
Fixes: c7c556f ("selinux: refactor changing booleans")
Reported-by: Wander Lairson Costa <[email protected]>
Signed-off-by: Ondrej Mosnacek <[email protected]>
Signed-off-by: Paul Moore <[email protected]>
  • Loading branch information
WOnder93 authored and pcmoore committed May 17, 2022
1 parent 42226c9 commit 6254bd3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion security/selinux/ss/hashtab.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
kmem_cache_free(hashtab_node_cachep, cur);
}
}
kmem_cache_free(hashtab_node_cachep, new);
kfree(new->htable);
memset(new, 0, sizeof(*new));
return -ENOMEM;
}

Expand Down

0 comments on commit 6254bd3

Please sign in to comment.