Commit d8db60cb authored by Paul Moore's avatar Paul Moore

selinux: ensure we cleanup the internal AVC counters on error in avc_insert()

Fix avc_insert() to call avc_node_kill() if we've already allocated
an AVC node and the code fails to insert the node in the cache.

Fixes: fa1aa143 ("selinux: extended permissions for ioctls")
Reported-by: rsiddoji@codeaurora.org
Suggested-by: default avatarStephen Smalley <sds@tycho.nsa.gov>
Acked-by: default avatarStephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent b2104ac0
...@@ -617,26 +617,25 @@ static struct avc_node *avc_insert(struct selinux_avc *avc, ...@@ -617,26 +617,25 @@ static struct avc_node *avc_insert(struct selinux_avc *avc,
struct avc_node *pos, *node = NULL; struct avc_node *pos, *node = NULL;
int hvalue; int hvalue;
unsigned long flag; unsigned long flag;
spinlock_t *lock;
struct hlist_head *head;
if (avc_latest_notif_update(avc, avd->seqno, 1)) if (avc_latest_notif_update(avc, avd->seqno, 1))
goto out; return NULL;
node = avc_alloc_node(avc); node = avc_alloc_node(avc);
if (node) { if (!node)
struct hlist_head *head; return NULL;
spinlock_t *lock;
int rc = 0;
hvalue = avc_hash(ssid, tsid, tclass);
avc_node_populate(node, ssid, tsid, tclass, avd); avc_node_populate(node, ssid, tsid, tclass, avd);
rc = avc_xperms_populate(node, xp_node); if (avc_xperms_populate(node, xp_node)) {
if (rc) { avc_node_kill(avc, node);
kmem_cache_free(avc_node_cachep, node);
return NULL; return NULL;
} }
hvalue = avc_hash(ssid, tsid, tclass);
head = &avc->avc_cache.slots[hvalue]; head = &avc->avc_cache.slots[hvalue];
lock = &avc->avc_cache.slots_lock[hvalue]; lock = &avc->avc_cache.slots_lock[hvalue];
spin_lock_irqsave(lock, flag); spin_lock_irqsave(lock, flag);
hlist_for_each_entry(pos, head, list) { hlist_for_each_entry(pos, head, list) {
if (pos->ae.ssid == ssid && if (pos->ae.ssid == ssid &&
...@@ -649,8 +648,6 @@ static struct avc_node *avc_insert(struct selinux_avc *avc, ...@@ -649,8 +648,6 @@ static struct avc_node *avc_insert(struct selinux_avc *avc,
hlist_add_head_rcu(&node->list, head); hlist_add_head_rcu(&node->list, head);
found: found:
spin_unlock_irqrestore(lock, flag); spin_unlock_irqrestore(lock, flag);
}
out:
return node; return node;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment