IMA: convert i_readcount to atomic
Convert the inode's i_readcount from an unsigned int to atomic. Signed-off-by: Mimi Zohar <zohar@us.ibm.com> Acked-by: Eric Paris <eparis@redhat.com>
This commit is contained in:
parent
75a25637bf
commit
a68a27b6f2
|
@ -794,8 +794,7 @@ struct inode {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_IMA
|
#ifdef CONFIG_IMA
|
||||||
/* protected by i_lock */
|
atomic_t i_readcount; /* struct files open RO */
|
||||||
unsigned int i_readcount; /* struct files open RO */
|
|
||||||
#endif
|
#endif
|
||||||
atomic_t i_writecount;
|
atomic_t i_writecount;
|
||||||
#ifdef CONFIG_SECURITY
|
#ifdef CONFIG_SECURITY
|
||||||
|
|
|
@ -137,10 +137,11 @@ void ima_inode_free(struct inode *inode)
|
||||||
{
|
{
|
||||||
struct ima_iint_cache *iint;
|
struct ima_iint_cache *iint;
|
||||||
|
|
||||||
if (inode->i_readcount)
|
if (atomic_read(&inode->i_readcount))
|
||||||
printk(KERN_INFO "%s: readcount: %u\n", __func__, inode->i_readcount);
|
printk(KERN_INFO "%s: readcount: %u\n", __func__,
|
||||||
|
atomic_read(&inode->i_readcount));
|
||||||
|
|
||||||
inode->i_readcount = 0;
|
atomic_set(&inode->i_readcount, 0);
|
||||||
|
|
||||||
if (!IS_IMA(inode))
|
if (!IS_IMA(inode))
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -113,7 +113,7 @@ void ima_counts_get(struct file *file)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (mode & FMODE_WRITE) {
|
if (mode & FMODE_WRITE) {
|
||||||
if (inode->i_readcount && IS_IMA(inode))
|
if (atomic_read(&inode->i_readcount) && IS_IMA(inode))
|
||||||
send_tomtou = true;
|
send_tomtou = true;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ void ima_counts_get(struct file *file)
|
||||||
out:
|
out:
|
||||||
/* remember the vfs deals with i_writecount */
|
/* remember the vfs deals with i_writecount */
|
||||||
if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
|
if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
|
||||||
inode->i_readcount++;
|
atomic_inc(&inode->i_readcount);
|
||||||
|
|
||||||
spin_unlock(&inode->i_lock);
|
spin_unlock(&inode->i_lock);
|
||||||
|
|
||||||
|
@ -149,15 +149,16 @@ static void ima_dec_counts(struct inode *inode, struct file *file)
|
||||||
assert_spin_locked(&inode->i_lock);
|
assert_spin_locked(&inode->i_lock);
|
||||||
|
|
||||||
if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
|
if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) {
|
||||||
if (unlikely(inode->i_readcount == 0)) {
|
if (unlikely(atomic_read(&inode->i_readcount) == 0)) {
|
||||||
if (!ima_limit_imbalance(file)) {
|
if (!ima_limit_imbalance(file)) {
|
||||||
printk(KERN_INFO "%s: open/free imbalance (r:%u)\n",
|
printk(KERN_INFO "%s: open/free imbalance (r:%u)\n",
|
||||||
__func__, inode->i_readcount);
|
__func__,
|
||||||
|
atomic_read(&inode->i_readcount));
|
||||||
dump_stack();
|
dump_stack();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inode->i_readcount--;
|
atomic_dec(&inode->i_readcount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue