Skip to content

Commit

Permalink
ima: prevent unnecessary policy checking
Browse files Browse the repository at this point in the history
ima_rdwr_violation_check is called for every file openning.
The function checks the policy even when violation condition
is not met. It causes unnecessary policy checking.

This patch does policy checking only if violation condition is met.

Changelog:
- check writecount is greater than zero (Mimi)

Signed-off-by: Dmitry Kasatkin <[email protected]>
Signed-off-by: Mimi Zohar <[email protected]>
  • Loading branch information
Dmitry Kasatkin authored and Mimi Zohar committed Jun 12, 2014
1 parent 3e38df5 commit b882fae
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ static void ima_rdwr_violation_check(struct file *file)
{
struct inode *inode = file_inode(file);
fmode_t mode = file->f_mode;
int must_measure;
bool send_tomtou = false, send_writers = false;
char *pathbuf = NULL;
const char *pathname;
Expand All @@ -94,16 +93,12 @@ static void ima_rdwr_violation_check(struct file *file)
if (mode & FMODE_WRITE) {
if (atomic_read(&inode->i_readcount) && IS_IMA(inode))
send_tomtou = true;
goto out;
} else {
if ((atomic_read(&inode->i_writecount) > 0) &&
ima_must_measure(inode, MAY_READ, FILE_CHECK))
send_writers = true;
}

must_measure = ima_must_measure(inode, MAY_READ, FILE_CHECK);
if (!must_measure)
goto out;

if (atomic_read(&inode->i_writecount) > 0)
send_writers = true;
out:
mutex_unlock(&inode->i_mutex);

if (!send_tomtou && !send_writers)
Expand Down

0 comments on commit b882fae

Please sign in to comment.