Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 313610
b: refs/heads/master
c: 08e1b76
h: refs/heads/master
v: v3
  • Loading branch information
Mimi Zohar committed Jul 2, 2012
1 parent 99744b2 commit 273bd7f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 659b5e76521c10331495cbd9acb7217e38ff9750
refs/heads/master: 08e1b76ae399a010c0d0916b125d75aed6961d16
4 changes: 3 additions & 1 deletion trunk/security/integrity/ima/ima_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ void ima_store_measurement(struct integrity_iint_cache *iint,
}
memset(&entry->template, 0, sizeof(entry->template));
memcpy(entry->template.digest, iint->digest, IMA_DIGEST_SIZE);
strncpy(entry->template.file_name, filename, IMA_EVENT_NAME_LEN_MAX);
strcpy(entry->template.file_name,
(strlen(filename) > IMA_EVENT_NAME_LEN_MAX) ?
file->f_dentry->d_name.name : filename);

result = ima_store_template(entry, violation, inode);
if (!result || result == -EEXIST)
Expand Down
42 changes: 36 additions & 6 deletions trunk/security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static void ima_rdwr_violation_check(struct file *file)
fmode_t mode = file->f_mode;
int rc;
bool send_tomtou = false, send_writers = false;
unsigned char *pathname = NULL, *pathbuf = NULL;

if (!S_ISREG(inode->i_mode) || !ima_initialized)
return;
Expand All @@ -75,12 +76,27 @@ static void ima_rdwr_violation_check(struct file *file)
out:
mutex_unlock(&inode->i_mutex);

if (!send_tomtou && !send_writers)
return;

/* We will allow 11 spaces for ' (deleted)' to be appended */
pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL);
if (pathbuf) {
pathname = d_path(&file->f_path, pathbuf, PATH_MAX + 11);
if (IS_ERR(pathname))
pathname = NULL;
else if (strlen(pathname) > IMA_EVENT_NAME_LEN_MAX)
pathname = NULL;
}
if (send_tomtou)
ima_add_violation(inode, dentry->d_name.name, "invalid_pcr",
"ToMToU");
ima_add_violation(inode,
!pathname ? dentry->d_name.name : pathname,
"invalid_pcr", "ToMToU");
if (send_writers)
ima_add_violation(inode, dentry->d_name.name, "invalid_pcr",
"open_writers");
ima_add_violation(inode,
!pathname ? dentry->d_name.name : pathname,
"invalid_pcr", "open_writers");
kfree(pathbuf);
}

static void ima_check_last_writer(struct integrity_iint_cache *iint,
Expand Down Expand Up @@ -123,6 +139,7 @@ static int process_measurement(struct file *file, const unsigned char *filename,
{
struct inode *inode = file->f_dentry->d_inode;
struct integrity_iint_cache *iint;
unsigned char *pathname = NULL, *pathbuf = NULL;
int rc = 0;

if (!ima_initialized || !S_ISREG(inode->i_mode))
Expand All @@ -147,8 +164,21 @@ static int process_measurement(struct file *file, const unsigned char *filename,
goto out;

rc = ima_collect_measurement(iint, file);
if (!rc)
ima_store_measurement(iint, file, filename);
if (rc != 0)
goto out;

if (function != BPRM_CHECK) {
/* We will allow 11 spaces for ' (deleted)' to be appended */
pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL);
if (pathbuf) {
pathname =
d_path(&file->f_path, pathbuf, PATH_MAX + 11);
if (IS_ERR(pathname))
pathname = NULL;
}
}
ima_store_measurement(iint, file, !pathname ? filename : pathname);
kfree(pathbuf);
out:
mutex_unlock(&iint->mutex);
return rc;
Expand Down

0 comments on commit 273bd7f

Please sign in to comment.