Skip to content

Commit 4f2d99b

Browse files
keesgregkh
authored andcommitted
firmware_loader: Use security_post_load_data()
Now that security_post_load_data() is wired up, use it instead of the NULL file argument style of security_post_read_file(), and update the security_kernel_load_data() call to indicate that a security_kernel_post_load_data() call is expected. Wire up the IMA check to match earlier logic. Perhaps a generalized change to ima_post_load_data() might look something like this: return process_buffer_measurement(buf, size, kernel_load_data_id_str(load_id), read_idmap[load_id] ?: FILE_CHECK, 0, NULL); Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Mimi Zohar <zohar@linux.ibm.com> Link: https://lore.kernel.org/r/20201002173828.2099543-10-keescook@chromium.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b64fcae commit 4f2d99b

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

‎drivers/base/firmware_loader/fallback.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ static ssize_t firmware_loading_store(struct device *dev,
272272
dev_err(dev, "%s: map pages failed\n",
273273
__func__);
274274
else
275-
rc = security_kernel_post_read_file(NULL,
276-
fw_priv->data, fw_priv->size,
277-
READING_FIRMWARE);
275+
rc = security_kernel_post_load_data(fw_priv->data,
276+
fw_priv->size,
277+
LOADING_FIRMWARE, "blob");
278278

279279
/*
280280
* Same logic as fw_load_abort, only the DONE bit
@@ -613,7 +613,7 @@ static bool fw_run_sysfs_fallback(u32 opt_flags)
613613
return false;
614614

615615
/* Also permit LSMs and IMA to fail firmware sysfs fallback */
616-
ret = security_kernel_load_data(LOADING_FIRMWARE, false);
616+
ret = security_kernel_load_data(LOADING_FIRMWARE, true);
617617
if (ret < 0)
618618
return false;
619619

‎drivers/base/firmware_loader/fallback_platform.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int firmware_fallback_platform(struct fw_priv *fw_priv, u32 opt_flags)
1717
if (!(opt_flags & FW_OPT_FALLBACK_PLATFORM))
1818
return -ENOENT;
1919

20-
rc = security_kernel_load_data(LOADING_FIRMWARE, false);
20+
rc = security_kernel_load_data(LOADING_FIRMWARE, true);
2121
if (rc)
2222
return rc;
2323

@@ -27,6 +27,12 @@ int firmware_fallback_platform(struct fw_priv *fw_priv, u32 opt_flags)
2727

2828
if (fw_priv->data && size > fw_priv->allocated_size)
2929
return -ENOMEM;
30+
31+
rc = security_kernel_post_load_data((u8 *)data, size, LOADING_FIRMWARE,
32+
"platform");
33+
if (rc)
34+
return rc;
35+
3036
if (!fw_priv->data)
3137
fw_priv->data = vmalloc(size);
3238
if (!fw_priv->data)

‎security/integrity/ima/ima_main.c‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,6 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size,
648648
enum ima_hooks func;
649649
u32 secid;
650650

651-
if (!file && read_id == READING_FIRMWARE) {
652-
if ((ima_appraise & IMA_APPRAISE_FIRMWARE) &&
653-
(ima_appraise & IMA_APPRAISE_ENFORCE)) {
654-
pr_err("Prevent firmware loading_store.\n");
655-
return -EACCES; /* INTEGRITY_UNKNOWN */
656-
}
657-
return 0;
658-
}
659-
660651
/* permit signed certs */
661652
if (!file && read_id == READING_X509_CERTIFICATE)
662653
return 0;
@@ -706,7 +697,7 @@ int ima_load_data(enum kernel_load_data_id id, bool contents)
706697
}
707698
break;
708699
case LOADING_FIRMWARE:
709-
if (ima_enforce && (ima_appraise & IMA_APPRAISE_FIRMWARE)) {
700+
if (ima_enforce && (ima_appraise & IMA_APPRAISE_FIRMWARE) && !contents) {
710701
pr_err("Prevent firmware sysfs fallback loading.\n");
711702
return -EACCES; /* INTEGRITY_UNKNOWN */
712703
}
@@ -742,6 +733,15 @@ int ima_post_load_data(char *buf, loff_t size,
742733
enum kernel_load_data_id load_id,
743734
char *description)
744735
{
736+
if (load_id == LOADING_FIRMWARE) {
737+
if ((ima_appraise & IMA_APPRAISE_FIRMWARE) &&
738+
(ima_appraise & IMA_APPRAISE_ENFORCE)) {
739+
pr_err("Prevent firmware loading_store.\n");
740+
return -EACCES; /* INTEGRITY_UNKNOWN */
741+
}
742+
return 0;
743+
}
744+
745745
return 0;
746746
}
747747

0 commit comments

Comments
 (0)