Skip to content

Commit

Permalink
ima: ima_write_policy() limit locking
Browse files Browse the repository at this point in the history
There is no need to hold the ima_write_mutex for so long.  We only need it
around ima_parse_add_rule().

Changelog:
- The return path now takes into account failed kmalloc() call.

Reported-by: Al Viro <[email protected]>
Signed-off-by: Petko Manolov <[email protected]>
Signed-off-by: Mimi Zohar <[email protected]>
  • Loading branch information
Petko Manolov authored and Mimi Zohar committed Jan 3, 2016
1 parent 0112721 commit 6427e6c
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions security/integrity/ima/ima_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,8 @@ static const struct file_operations ima_ascii_measurements_ops = {
static ssize_t ima_write_policy(struct file *file, const char __user *buf,
size_t datalen, loff_t *ppos)
{
char *data = NULL;
char *data;
ssize_t result;
int res;

res = mutex_lock_interruptible(&ima_write_mutex);
if (res)
return res;

if (datalen >= PAGE_SIZE)
datalen = PAGE_SIZE - 1;
Expand All @@ -286,14 +281,19 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,

result = -EFAULT;
if (copy_from_user(data, buf, datalen))
goto out;
goto out_free;

result = mutex_lock_interruptible(&ima_write_mutex);
if (result < 0)
goto out_free;
result = ima_parse_add_rule(data);
mutex_unlock(&ima_write_mutex);

out_free:
kfree(data);
out:
if (result < 0)
valid_policy = 0;
kfree(data);
mutex_unlock(&ima_write_mutex);

return result;
}
Expand Down

0 comments on commit 6427e6c

Please sign in to comment.