selinux: fix bad cleanup on error in hashtab_duplicate()
PATCH 1/1 selinux: fix bad cleanup on error in hashtab_duplicate()
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).
Fixes c7c556f1e81b ("selinux: refactor changing booleans")
Reported-by Wander Lairson Costa <[email protected]>
Signed-off-by Ondrej Mosnacek <[email protected]>
--- security/selinux/ss/hashtab.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/selinux/ss/hashtab.c +2 -1
@@ -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 ; }
Signature · 1 line
2.36.1
Paul Moore
maintainerQuoted 6 lines · Ondrej Mosnacek
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 freenew->htableand clear the contents of *new (to prevent double-free).
Quoted 6 lines
Fixes c7c556f1e81b ("selinux: refactor changing booleans")Reported-by Wander Lairson Costa <[email protected]>Signed-off-by Ondrej Mosnacek <[email protected]>--- security/selinux/ss/hashtab.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Good catch, merged into selinux/stable-5.18 and I'll plan on sending this to Linus tomorrow once the tests finish running.
Signature · 1 line
paul-moore.com