IMA: fix the ToMToU logic
[pandora-kernel.git] / security / integrity / ima / ima_main.c
index 60dd615..203de97 100644 (file)
@@ -112,22 +112,23 @@ void ima_counts_get(struct file *file)
        if (!ima_initialized)
                goto out;
 
-       rc = ima_must_measure(NULL, inode, MAY_READ, FILE_CHECK);
-       if (rc < 0)
-               goto out;
-
        if (mode & FMODE_WRITE) {
-               if (inode->i_readcount)
+               if (inode->i_readcount && IS_IMA(inode))
                        send_tomtou = true;
                goto out;
        }
 
+       rc = ima_must_measure(NULL, inode, MAY_READ, FILE_CHECK);
+       if (rc < 0)
+               goto out;
+
        if (atomic_read(&inode->i_writecount) > 0)
                send_writers = true;
 out:
        /* remember the vfs deals with i_writecount */
        if ((mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
                inode->i_readcount++;
+
        spin_unlock(&inode->i_lock);
 
        if (send_tomtou)