Skip to content

Commit 6254bd3

Browse files
WOnder93pcmoore
authored andcommitted
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). Cc: [email protected] Fixes: c7c556f ("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]>
1 parent 42226c9 commit 6254bd3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

security/selinux/ss/hashtab.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ int hashtab_duplicate(struct hashtab *new, struct hashtab *orig,
179179
kmem_cache_free(hashtab_node_cachep, cur);
180180
}
181181
}
182-
kmem_cache_free(hashtab_node_cachep, new);
182+
kfree(new->htable);
183+
memset(new, 0, sizeof(*new));
183184
return -ENOMEM;
184185
}
185186

0 commit comments

Comments
 (0)