Bug fix for AVC
PATCH 1/1 Bug fix for AVC
The attached patch fixes a bug in the AVC that can produce deadlock on SMP machines. To apply, cd lsm-2.4 (or lsm-2.5) && patch -p0 < ~/avc_lock.patch.
--
Stephen D. Smalley, NAI Labs
[email protected]
Index: security/selinux/avc.c
===================================================================
RCS file: /cvs/lsm/lsm/security/selinux/avc.c,v
retrieving revision 1.4
retrieving revision 1.5
selinux/avc.c +14 -10
@@ -218,8 +218,9 @@ {int i, chain_len, max_chain_len, slots_used;avc_node_t *node; +unsigned long flags; -spin_lock (&avc_lock); +spin_lock_irqsave (&avc_lock,flags); slots_used =0 ; max_chain_len =0 ;
@@ -237,7 +238,7 @@ } } -spin_unlock (&avc_lock); +spin_unlock_irqrestore (&avc_lock,flags);printk ("\n%s avc: %d entries and %d/%d buckets used, longest chain length %d\n" , tag, avc_cache.activeNodes, slots_used,AVC_CACHE_SLOTS , max_chain_len);
@@ -874,8 +875,9 @@ {avc_node_t *node;int i; +unsigned long flags; -spin_lock (&avc_lock); +spin_lock_irqsave (&avc_lock,flags);if (ssid ==SECSID_WILD || tsid ==SECSID_WILD ) {/* apply to all matching nodes */
@@ -897,7 +899,7 @@ } } -spin_unlock (&avc_lock); +spin_unlock_irqrestore (&avc_lock,flags);return 0 ; }
@@ -922,6 +924,7 @@avc_callback_node_t *c;access_vector_t tretained =0 , cretained =0 ;int rc; +unsigned long flags;/* * try_revoke only removes permissions from the cache
@@ -956,10 +959,10 @@ *out_retained = tretained; } -spin_lock (&avc_lock); +spin_lock_irqsave (&avc_lock,flags);if (seqno > avc_cache.latest_notif) avc_cache.latest_notif = seqno; -spin_unlock (&avc_lock); +spin_unlock_irqrestore (&avc_lock,flags);return 0 ; }
@@ -1021,10 +1024,11 @@int rc;avc_node_t *node, *tmp;int i; +unsigned long flags;avc_hash_eval ("reset" ); -spin_lock (&avc_lock); +spin_lock_irqsave (&avc_lock,flags);for (i =0 ; i <AVC_CACHE_SLOTS ; i++) { node = avc_cache.slots[i];
@@ -1044,7 +1048,7 @@ } avc_cache.lru_hint =0 ; -spin_unlock (&avc_lock); +spin_unlock_irqrestore (&avc_lock,flags);for (i =0 ; i <AVC_NSTATS ; i++) avc_cache_stats[i] =0 ;
@@ -1058,10 +1062,10 @@ } } -spin_lock (&avc_lock); +spin_lock_irqsave (&avc_lock,flags);if (seqno > avc_cache.latest_notif) avc_cache.latest_notif = seqno; -spin_unlock (&avc_lock); +spin_unlock_irqrestore (&avc_lock,flags);return 0 ; }