IMA: convert i_readcount to atomic
authorMimi Zohar <zohar@linux.vnet.ibm.com>
Tue, 2 Nov 2010 14:10:56 +0000 (10:10 -0400)
committerMimi Zohar <zohar@linux.vnet.ibm.com>
Thu, 10 Feb 2011 12:51:43 +0000 (07:51 -0500)
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>
include/linux/fs.h
security/integrity/ima/ima_iint.c
security/integrity/ima/ima_main.c

index baf3e556ff0ed3f2e9d993a53e1f3850dd0fc8d1..ef85322863b9a3cb799f676aeb156d2bc6d85d82 100644 (file)
@@ -794,8 +794,7 @@ struct inode {
 #endif
 
 #ifdef CONFIG_IMA
-       /* protected by i_lock */
-       unsigned int            i_readcount; /* struct files open RO */
+       atomic_t                i_readcount; /* struct files open RO */
 #endif
        atomic_t                i_writecount;
 #ifdef CONFIG_SECURITY
index c442e47b67853099e776c4e5b95dd3fa321183ae..f0053552fd587f710d9c7c1b56fb9c9a3344292f 100644 (file)
@@ -137,10 +137,11 @@ 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);
+       if (atomic_read(&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))
                return;
index 203de979d30565811c2da951cae458e08645d6ab..6e8cb931b8f161f61bc6fa28c652d79bccbed446 100644 (file)
@@ -113,7 +113,7 @@ void ima_counts_get(struct file *file)
                goto out;
 
        if (mode & FMODE_WRITE) {
-               if (inode->i_readcount && IS_IMA(inode))
+               if (atomic_read(&inode->i_readcount) && IS_IMA(inode))
                        send_tomtou = true;
                goto out;
        }
@@ -127,7 +127,7 @@ void ima_counts_get(struct file *file)
 out:
        /* remember the vfs deals with i_writecount */
        if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
-               inode->i_readcount++;
+               atomic_inc(&inode->i_readcount);
 
        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);
 
        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)) {
                                printk(KERN_INFO "%s: open/free imbalance (r:%u)\n",
-                                      __func__, inode->i_readcount);
+                                      __func__,
+                                      atomic_read(&inode->i_readcount));
                                dump_stack();
                        }
                        return;
                }
-               inode->i_readcount--;
+               atomic_dec(&inode->i_readcount);
        }
 }