]> Git Repo - J-linux.git/commitdiff
selinux: fix bad cleanup on error in hashtab_duplicate()
authorOndrej Mosnacek <[email protected]>
Tue, 17 May 2022 12:08:16 +0000 (14:08 +0200)
committerPaul Moore <[email protected]>
Tue, 17 May 2022 22:34:35 +0000 (18:34 -0400)
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: c7c556f1e81b ("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]>
security/selinux/ss/hashtab.c

index 0ae4e4e57a401ebb36f09ba59a4e7b60b9c67846..3fb8f9026e9be80dfa448212052f18d7b9f67f1c 100644 (file)
@@ -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;
 }
 
This page took 0.066067 seconds and 4 git commands to generate.