Skip to content

Commit 34736da

Browse files
sbrandengregkh
authored andcommitted
IMA: Add support for file reads without contents
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 <scott.branden@broadcom.com> Link: https://lore.kernel.org/lkml/20200706232309.12010-10-scott.branden@broadcom.com/ Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Link: https://lore.kernel.org/r/20201002173828.2099543-13-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2039bda commit 34736da

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎security/integrity/ima/ima_main.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -613,11 +613,8 @@ void ima_post_path_mknod(struct dentry *dentry)
613613
int ima_read_file(struct file *file, enum kernel_read_file_id read_id,
614614
bool contents)
615615
{
616-
/* Reject all partial reads during appraisal. */
617-
if (!contents) {
618-
if (ima_appraise & IMA_APPRAISE_ENFORCE)
619-
return -EACCES;
620-
}
616+
enum ima_hooks func;
617+
u32 secid;
621618

622619
/*
623620
* Do devices using pre-allocated memory run the risk of the
@@ -626,7 +623,20 @@ int ima_read_file(struct file *file, enum kernel_read_file_id read_id,
626623
* buffers? It may be desirable to include the buffer address
627624
* in this API and walk all the dma_map_single() mappings to check.
628625
*/
629-
return 0;
626+
627+
/*
628+
* There will be a call made to ima_post_read_file() with
629+
* a filled buffer, so we don't need to perform an extra
630+
* read early here.
631+
*/
632+
if (contents)
633+
return 0;
634+
635+
/* Read entire file for all partial reads. */
636+
func = read_idmap[read_id] ?: FILE_CHECK;
637+
security_task_getsecid(current, &secid);
638+
return process_measurement(file, current_cred(), secid, NULL,
639+
0, MAY_READ, func);
630640
}
631641

632642
const int read_idmap[READING_MAX_ID] = {

0 commit comments

Comments
 (0)