diff options
author | Petko Manolov <petkan@mip-labs.com> | 2016-01-03 10:36:38 -0500 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2016-01-03 13:22:38 -0500 |
commit | 6427e6c71c8b374761b661c4f355762794c171a1 (patch) | |
tree | 3648577f5c9ca834f9e634e93ea94cecae6e3245 /security | |
parent | 0112721df4edbdd07b800813300d76811572f080 (diff) |
ima: ima_write_policy() limit locking
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 <viro@ZenIV.linux.org.uk>
Signed-off-by: Petko Manolov <petkan@mip-labs.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/integrity/ima/ima_fs.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index 3caed6de610c..f355231997b4 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c | |||
@@ -261,13 +261,8 @@ static const struct file_operations ima_ascii_measurements_ops = { | |||
261 | static ssize_t ima_write_policy(struct file *file, const char __user *buf, | 261 | static ssize_t ima_write_policy(struct file *file, const char __user *buf, |
262 | size_t datalen, loff_t *ppos) | 262 | size_t datalen, loff_t *ppos) |
263 | { | 263 | { |
264 | char *data = NULL; | 264 | char *data; |
265 | ssize_t result; | 265 | ssize_t result; |
266 | int res; | ||
267 | |||
268 | res = mutex_lock_interruptible(&ima_write_mutex); | ||
269 | if (res) | ||
270 | return res; | ||
271 | 266 | ||
272 | if (datalen >= PAGE_SIZE) | 267 | if (datalen >= PAGE_SIZE) |
273 | datalen = PAGE_SIZE - 1; | 268 | datalen = PAGE_SIZE - 1; |
@@ -286,14 +281,19 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf, | |||
286 | 281 | ||
287 | result = -EFAULT; | 282 | result = -EFAULT; |
288 | if (copy_from_user(data, buf, datalen)) | 283 | if (copy_from_user(data, buf, datalen)) |
289 | goto out; | 284 | goto out_free; |
290 | 285 | ||
286 | result = mutex_lock_interruptible(&ima_write_mutex); | ||
287 | if (result < 0) | ||
288 | goto out_free; | ||
291 | result = ima_parse_add_rule(data); | 289 | result = ima_parse_add_rule(data); |
290 | mutex_unlock(&ima_write_mutex); | ||
291 | |||
292 | out_free: | ||
293 | kfree(data); | ||
292 | out: | 294 | out: |
293 | if (result < 0) | 295 | if (result < 0) |
294 | valid_policy = 0; | 296 | valid_policy = 0; |
295 | kfree(data); | ||
296 | mutex_unlock(&ima_write_mutex); | ||
297 | 297 | ||
298 | return result; | 298 | return result; |
299 | } | 299 | } |