Skip to contentSkip to conversation

selinux: clean up avc node cache when disabling selinux

PATCH In review Thomas Liu 3 participants 5 messages Jun 24, 2009 SELinux security module

lore
Share & tools
lore

Thomas Liu

author
#0 lore raw

PATCH 1/1 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.

---

security/selinux/avc.c +6 -0
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/avc.c kernel/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);
+}
security/selinux/hooks.c +3 -0
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/hooks.c kernel/security/selinux/hooks.c
@@ -5678,6 +5678,9 @@ int selinux_disable(void)
 	selinux_disabled = 1;
 	selinux_enabled = 0;
 
+	/* Try to destroy the avc node cache */
+	avc_node_cache_free();
+
 	/* Reset security_ops to the secondary module, dummy or capability. */
 	security_ops = secondary_ops;
 
security/selinux/include/avc.h +3 -0
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/include/avc.h kernel/security/selinux/include/avc.h
@@ -134,6 +134,9 @@ void avc_dump_av(struct audit_buffer *ab
 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

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#1 lore raw
Quoted 23 lines · Thomas Liu

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.

---
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/avc.c kernel/security/selinux/avc.c

security/selinux/avc.c +6 -0
@@ -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 -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/hooks.c kernel/security/selinux/hooks.c

security/selinux/hooks.c int selinux_disable(void) · line 5682

Quoted 5 lines
security/selinux/hooks.c +2 -0
@@ -5678,6 +5678,9 @@ int selinux_disable(void)
 	selinux_disabled = 1;
 	selinux_enabled = 0;
 
+	/* Try to destroy the avc node cache */
+	avc_node_cache_free();

whoops! did you compile it?

Quoted 9 lines
security/selinux/hooks.c +1 -0
+
 	/* Reset security_ops to the secondary module, dummy or capability. */
 	security_ops = secondary_ops;
 

diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/include/avc.h kernel/security/selinux/include/avc.h

security/selinux/include/avc.h void avc_dump_av(struct audit_buffer *ab · line 142

Quoted 9 lines
security/selinux/include/avc.h +3 -0
@@ -134,6 +134,9 @@ void avc_dump_av(struct audit_buffer *ab
 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

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

author
#2 lore raw

PATCH 1/1 selinux: clean up avc node cache when disabling selinux

In reply to Thomas Liu

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.

---

security/selinux/avc.c +6 -0
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/avc.c kernel/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);
+}
security/selinux/hooks.c +3 -0
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/hooks.c kernel/security/selinux/hooks.c
@@ -5678,6 +5678,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;
 
security/selinux/include/avc.h +3 -0
diff -uprN -X kernel-vanilla/Documentation/dontdiff kernel-vanilla/security/selinux/include/avc.h kernel/security/selinux/include/avc.h
@@ -134,6 +134,9 @@ void avc_dump_av(struct audit_buffer *ab
 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

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

Acked-by on v1 1/1
#3 lore raw
Quoted 5 lines · Thomas Liu

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.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

#4 lore raw
In reply to Thomas Liu
Quoted 5 lines · Thomas Liu

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.

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next

Signature · 7 lines
James Morris
<[email protected]>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.