/** * integrity_inode_free - called on security_inode_free * @inode: pointer to the inode * * Free the integrity information(iint) associated with an inode. */ void integrity_inode_free(struct inode *inode) { struct integrity_iint_cache *iint; if (!IS_IMA(inode)) return; write_lock(&integrity_iint_lock); iint = __integrity_iint_find(inode); rb_erase(&iint->rb_node, &integrity_iint_tree); write_unlock(&integrity_iint_lock); iint_free(iint); }
/** * ima_inode_alloc - allocate an iint associated with an inode * @inode: pointer to the inode */ int ima_inode_alloc(struct inode *inode) { struct rb_node **p; struct rb_node *new_node, *parent = NULL; struct ima_iint_cache *new_iint, *test_iint; int rc; new_iint = kmem_cache_alloc(iint_cache, GFP_NOFS); if (!new_iint) return -ENOMEM; new_iint->inode = inode; new_node = &new_iint->rb_node; mutex_lock(&inode->i_mutex); /* i_flags */ spin_lock(&ima_iint_lock); p = &ima_iint_tree.rb_node; while (*p) { parent = *p; test_iint = rb_entry(parent, struct ima_iint_cache, rb_node); rc = -EEXIST; if (inode < test_iint->inode) p = &(*p)->rb_left; else if (inode > test_iint->inode) p = &(*p)->rb_right; else goto out_err; } inode->i_flags |= S_IMA; rb_link_node(new_node, parent, p); rb_insert_color(new_node, &ima_iint_tree); spin_unlock(&ima_iint_lock); mutex_unlock(&inode->i_mutex); /* i_flags */ return 0; out_err: spin_unlock(&ima_iint_lock); mutex_unlock(&inode->i_mutex); /* i_flags */ iint_free(new_iint); return rc; }
/** * ima_inode_free - called on security_inode_free * @inode: pointer to the inode * * Free the integrity information(iint) associated with an inode. */ void ima_inode_free(struct inode *inode) { struct ima_iint_cache *iint; if (inode->i_readcount) printk(KERN_INFO "%s: readcount: %u\n", __func__, inode->i_readcount); inode->i_readcount = 0; if (!IS_IMA(inode)) return; spin_lock(&ima_iint_lock); iint = __ima_iint_find(inode); rb_erase(&iint->rb_node, &ima_iint_tree); spin_unlock(&ima_iint_lock); iint_free(iint); }