Skip to content

Commit

Permalink
IMA: Add support for file reads without contents
Browse files Browse the repository at this point in the history
When the kernel_read_file LSM hook is called with contents=false, IMA
can appraise the file directly, without requiring a filled buffer. When
such a buffer is available, though, IMA can continue to use it instead
of forcing a double read here.

Signed-off-by: Scott Branden <[email protected]>
Link: https://lore.kernel.org/lkml/[email protected]/
Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: Mimi Zohar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
sbranden authored and gregkh committed Oct 5, 2020
1 parent 2039bda commit 34736da
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions security/integrity/ima/ima_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,8 @@ void ima_post_path_mknod(struct dentry *dentry)
int ima_read_file(struct file *file, enum kernel_read_file_id read_id,
bool contents)
{
/* Reject all partial reads during appraisal. */
if (!contents) {
if (ima_appraise & IMA_APPRAISE_ENFORCE)
return -EACCES;
}
enum ima_hooks func;
u32 secid;

/*
* Do devices using pre-allocated memory run the risk of the
Expand All @@ -626,7 +623,20 @@ int ima_read_file(struct file *file, enum kernel_read_file_id read_id,
* buffers? It may be desirable to include the buffer address
* in this API and walk all the dma_map_single() mappings to check.
*/
return 0;

/*
* There will be a call made to ima_post_read_file() with
* a filled buffer, so we don't need to perform an extra
* read early here.
*/
if (contents)
return 0;

/* Read entire file for all partial reads. */
func = read_idmap[read_id] ?: FILE_CHECK;
security_task_getsecid(current, &secid);
return process_measurement(file, current_cred(), secid, NULL,
0, MAY_READ, func);
}

const int read_idmap[READING_MAX_ID] = {
Expand Down

0 comments on commit 34736da

Please sign in to comment.