selinux: fix bad cleanup on error in hashtab_duplicate()
authorOndrej Mosnacek <omosnace@redhat.com>
Tue, 17 May 2022 12:08:16 +0000 (14:08 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 25 May 2022 07:17:55 +0000 (09:17 +0200)
commitb42e5e3a84ddbcbb104d7c69003aac806cdcdf26
treed48864c67207762a65bf1f7ce73fae06cf99c01f
parent3ee8e109c3c316073a3e0f83ec0769c7ee8a7375
selinux: fix bad cleanup on error in hashtab_duplicate()

commit 6254bd3db316c9ccb3b05caa8b438be63245466f upstream.

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: stable@vger.kernel.org
Fixes: c7c556f1e81b ("selinux: refactor changing booleans")
Reported-by: Wander Lairson Costa <wander@redhat.com>
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>
security/selinux/ss/hashtab.c