From 89c86576ecde504da1eeb4f4882b2189ac2f9c4a Mon Sep 17 00:00:00 2001 From: Thomas Liu Date: Wed, 24 Jun 2009 17:58:05 -0400 Subject: [PATCH] selinux: clean up avc node cache when disabling selinux Added a call to free the avc_node_cache when inside selinux_disable because it should not waste resources allocated during avc_init if SELinux is disabled and the cache will never be used. Signed-off-by: Thomas Liu Acked-by: Eric Paris Signed-off-by: James Morris --- security/selinux/avc.c | 6 ++++++ security/selinux/hooks.c | 3 +++ security/selinux/include/avc.h | 3 +++ 3 files changed, 12 insertions(+) diff --git a/security/selinux/avc.c b/security/selinux/avc.c index 7823e84..236aaa2 100644 --- a/security/selinux/avc.c +++ b/security/selinux/avc.c @@ -970,3 +970,9 @@ u32 avc_policy_seqno(void) { return avc_cache.latest_notif; } + +void avc_disable(void) +{ + if (avc_node_cachep) + kmem_cache_destroy(avc_node_cachep); +} diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index e3b4f30..2081055 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -5683,6 +5683,9 @@ int selinux_disable(void) selinux_disabled = 1; selinux_enabled = 0; + /* Try to destroy the avc node cache */ + avc_disable(); + /* Reset security_ops to the secondary module, dummy or capability. */ security_ops = secondary_ops; diff --git a/security/selinux/include/avc.h b/security/selinux/include/avc.h index 46a940d..ae4c3a0 100644 --- a/security/selinux/include/avc.h +++ b/security/selinux/include/avc.h @@ -131,6 +131,9 @@ int avc_add_callback(int (*callback)(u32 event, u32 ssid, u32 tsid, int avc_get_hash_stats(char *page); extern unsigned int avc_cache_threshold; +/* Attempt to free avc node cache */ +void avc_disable(void); + #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS DECLARE_PER_CPU(struct avc_cache_stats, avc_cache_stats); #endif -- 1.8.2.3