Skip to content

Commit

Permalink
selinux: clean up avc node cache when disabling selinux
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Liu authored and James Morris committed Jun 24, 2009
1 parent a893a84 commit 89c8657
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions security/selinux/avc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions security/selinux/include/avc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 89c8657

Please sign in to comment.