selinux: clean up avc node cache when disabling selinux
authorThomas Liu <tliu@redhat.com>
Wed, 24 Jun 2009 21:58:05 +0000 (17:58 -0400)
committerJames Morris <jmorris@namei.org>
Wed, 24 Jun 2009 22:29:16 +0000 (08:29 +1000)
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 <tliu@redhat.com>
Acked-by: Eric Paris <eparis@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
security/selinux/avc.c
security/selinux/hooks.c
security/selinux/include/avc.h

index 7823e84dbe8d22abe10e7180a3312320741e257a..236aaa2ea86d491bcf77ef50d36ea71de877af6c 100644 (file)
@@ -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);
+}
index e3b4f3083dd70e5443a0a97f2b9a596208e0531f..2081055f6783a64c88ae412b1338f53a50d7777b 100644 (file)
@@ -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;
 
index 46a940d9af6738802b0923ddb9299ea0adc6ea15..ae4c3a0e2c1ac801db6db57644018ce6cd948705 100644 (file)
@@ -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