]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
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)
committerStefan Bader <stefan.bader@canonical.com>
Wed, 10 Aug 2022 07:22:33 +0000 (09:22 +0200)
BugLink: https://bugs.launchpad.net/bugs/1981375
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>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
security/selinux/ss/hashtab.c

index a91fb0ed00de392e7e9bbf849c42767f3c48f17b..298098bb9c06d52aa051eb360cb2c06ed2eb7f7c 100644 (file)
@@ -178,7 +178,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;
 }