ima: move full pathname resolution to separate function
Define a new function ima_d_path(), which returns the full pathname. This function will be used further, for example, by the directory verification code. Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@intel.com> Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
This commit is contained in:
parent
ee86633174
commit
ea1046d4c5
3 changed files with 38 additions and 31 deletions
|
@ -119,6 +119,7 @@ void ima_audit_measurement(struct integrity_iint_cache *iint,
|
||||||
int ima_store_template(struct ima_template_entry *entry, int violation,
|
int ima_store_template(struct ima_template_entry *entry, int violation,
|
||||||
struct inode *inode);
|
struct inode *inode);
|
||||||
void ima_template_show(struct seq_file *m, void *e, enum ima_show_type show);
|
void ima_template_show(struct seq_file *m, void *e, enum ima_show_type show);
|
||||||
|
const char *ima_d_path(struct path *path, char **pathbuf);
|
||||||
|
|
||||||
/* rbtree tree calls to lookup, insert, delete
|
/* rbtree tree calls to lookup, insert, delete
|
||||||
* integrity data associated with an inode.
|
* integrity data associated with an inode.
|
||||||
|
|
|
@ -237,3 +237,20 @@ void ima_audit_measurement(struct integrity_iint_cache *iint,
|
||||||
|
|
||||||
iint->flags |= IMA_AUDITED;
|
iint->flags |= IMA_AUDITED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *ima_d_path(struct path *path, char **pathbuf)
|
||||||
|
{
|
||||||
|
char *pathname = NULL;
|
||||||
|
|
||||||
|
/* We will allow 11 spaces for ' (deleted)' to be appended */
|
||||||
|
*pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL);
|
||||||
|
if (*pathbuf) {
|
||||||
|
pathname = d_path(path, *pathbuf, PATH_MAX + 11);
|
||||||
|
if (IS_ERR(pathname)) {
|
||||||
|
kfree(*pathbuf);
|
||||||
|
*pathbuf = NULL;
|
||||||
|
pathname = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pathname;
|
||||||
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ static void ima_rdwr_violation_check(struct file *file)
|
||||||
fmode_t mode = file->f_mode;
|
fmode_t mode = file->f_mode;
|
||||||
int must_measure;
|
int must_measure;
|
||||||
bool send_tomtou = false, send_writers = false;
|
bool send_tomtou = false, send_writers = false;
|
||||||
unsigned char *pathname = NULL, *pathbuf = NULL;
|
char *pathbuf = NULL;
|
||||||
|
const char *pathname;
|
||||||
|
|
||||||
if (!S_ISREG(inode->i_mode) || !ima_initialized)
|
if (!S_ISREG(inode->i_mode) || !ima_initialized)
|
||||||
return;
|
return;
|
||||||
|
@ -86,22 +87,15 @@ out:
|
||||||
if (!send_tomtou && !send_writers)
|
if (!send_tomtou && !send_writers)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* We will allow 11 spaces for ' (deleted)' to be appended */
|
pathname = ima_d_path(&file->f_path, &pathbuf);
|
||||||
pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL);
|
if (!pathname || strlen(pathname) > IMA_EVENT_NAME_LEN_MAX)
|
||||||
if (pathbuf) {
|
pathname = dentry->d_name.name;
|
||||||
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)
|
if (send_tomtou)
|
||||||
ima_add_violation(inode,
|
ima_add_violation(inode, pathname,
|
||||||
!pathname ? dentry->d_name.name : pathname,
|
|
||||||
"invalid_pcr", "ToMToU");
|
"invalid_pcr", "ToMToU");
|
||||||
if (send_writers)
|
if (send_writers)
|
||||||
ima_add_violation(inode,
|
ima_add_violation(inode, pathname,
|
||||||
!pathname ? dentry->d_name.name : pathname,
|
|
||||||
"invalid_pcr", "open_writers");
|
"invalid_pcr", "open_writers");
|
||||||
kfree(pathbuf);
|
kfree(pathbuf);
|
||||||
}
|
}
|
||||||
|
@ -145,12 +139,13 @@ void ima_file_free(struct file *file)
|
||||||
ima_check_last_writer(iint, inode, file);
|
ima_check_last_writer(iint, inode, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_measurement(struct file *file, const unsigned char *filename,
|
static int process_measurement(struct file *file, const char *filename,
|
||||||
int mask, int function)
|
int mask, int function)
|
||||||
{
|
{
|
||||||
struct inode *inode = file->f_dentry->d_inode;
|
struct inode *inode = file->f_dentry->d_inode;
|
||||||
struct integrity_iint_cache *iint;
|
struct integrity_iint_cache *iint;
|
||||||
unsigned char *pathname = NULL, *pathbuf = NULL;
|
char *pathbuf = NULL;
|
||||||
|
const char *pathname = NULL;
|
||||||
int rc = -ENOMEM, action, must_appraise;
|
int rc = -ENOMEM, action, must_appraise;
|
||||||
|
|
||||||
if (!ima_initialized || !S_ISREG(inode->i_mode))
|
if (!ima_initialized || !S_ISREG(inode->i_mode))
|
||||||
|
@ -187,24 +182,18 @@ static int process_measurement(struct file *file, const unsigned char *filename,
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
if (function != BPRM_CHECK) {
|
if (function != BPRM_CHECK)
|
||||||
/* We will allow 11 spaces for ' (deleted)' to be appended */
|
pathname = ima_d_path(&file->f_path, &pathbuf);
|
||||||
pathbuf = kmalloc(PATH_MAX + 11, GFP_KERNEL);
|
|
||||||
if (pathbuf) {
|
if (!pathname)
|
||||||
pathname =
|
pathname = filename;
|
||||||
d_path(&file->f_path, pathbuf, PATH_MAX + 11);
|
|
||||||
if (IS_ERR(pathname))
|
|
||||||
pathname = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (action & IMA_MEASURE)
|
if (action & IMA_MEASURE)
|
||||||
ima_store_measurement(iint, file,
|
ima_store_measurement(iint, file, pathname);
|
||||||
!pathname ? filename : pathname);
|
|
||||||
if (action & IMA_APPRAISE)
|
if (action & IMA_APPRAISE)
|
||||||
rc = ima_appraise_measurement(iint, file,
|
rc = ima_appraise_measurement(iint, file, pathname);
|
||||||
!pathname ? filename : pathname);
|
|
||||||
if (action & IMA_AUDIT)
|
if (action & IMA_AUDIT)
|
||||||
ima_audit_measurement(iint, !pathname ? filename : pathname);
|
ima_audit_measurement(iint, pathname);
|
||||||
kfree(pathbuf);
|
kfree(pathbuf);
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&inode->i_mutex);
|
mutex_unlock(&inode->i_mutex);
|
||||||
|
|
Loading…
Add table
Reference in a new issue