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
commit 6254bd3 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: c7c556f ("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>
  • Loading branch information
WOnder93 authored and gregkh committed May 25, 2022
1 parent 22fb297 commit ec9fd8d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion security/selinux/ss/hashtab.c
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 ec9fd8d

Please sign in to comment.