|
|
8631a2 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
8631a2 |
From: Matthew Garrett <mjg59@srcf.ucam.org>
|
|
|
8631a2 |
Date: Mon, 10 Aug 2015 15:27:12 -0700
|
|
|
8631a2 |
Subject: [PATCH] Measure commands
|
|
|
8631a2 |
|
|
|
8631a2 |
Measure each command executed by grub, which includes script execution.
|
|
|
8631a2 |
---
|
|
|
8631a2 |
grub-core/script/execute.c | 25 +++++++++++++++++++++++--
|
|
|
8631a2 |
include/grub/tpm.h | 1 +
|
|
|
8631a2 |
2 files changed, 24 insertions(+), 2 deletions(-)
|
|
|
8631a2 |
|
|
|
8631a2 |
diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
|
|
|
f6e916 |
index cf6cd6601..9ae04a051 100644
|
|
|
8631a2 |
--- a/grub-core/script/execute.c
|
|
|
8631a2 |
+++ b/grub-core/script/execute.c
|
|
|
8631a2 |
@@ -30,6 +30,7 @@
|
|
|
8631a2 |
#ifdef GRUB_MACHINE_IEEE1275
|
|
|
8631a2 |
#include <grub/ieee1275/ieee1275.h>
|
|
|
8631a2 |
#endif
|
|
|
8631a2 |
+#include <grub/tpm.h>
|
|
|
8631a2 |
|
|
|
8631a2 |
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
|
|
|
8631a2 |
is sizeof (int) * 3, and one extra for a possible -ve sign. */
|
|
|
8631a2 |
@@ -967,8 +968,9 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|
|
8631a2 |
grub_err_t ret = 0;
|
|
|
8631a2 |
grub_script_function_t func = 0;
|
|
|
8631a2 |
char errnobuf[18];
|
|
|
8631a2 |
- char *cmdname;
|
|
|
8631a2 |
- int argc;
|
|
|
8631a2 |
+ char *cmdname, *cmdstring;
|
|
|
8631a2 |
+ int argc, offset = 0, cmdlen = 0;
|
|
|
8631a2 |
+ unsigned int i;
|
|
|
8631a2 |
char **args;
|
|
|
8631a2 |
int invert;
|
|
|
8631a2 |
struct grub_script_argv argv = { 0, 0, 0 };
|
|
|
8631a2 |
@@ -977,6 +979,25 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|
|
8631a2 |
if (grub_script_arglist_to_argv (cmdline->arglist, &argv) || ! argv.args[0])
|
|
|
8631a2 |
return grub_errno;
|
|
|
8631a2 |
|
|
|
8631a2 |
+ for (i = 0; i < argv.argc; i++) {
|
|
|
8631a2 |
+ cmdlen += grub_strlen (argv.args[i]) + 1;
|
|
|
8631a2 |
+ }
|
|
|
8631a2 |
+
|
|
|
8631a2 |
+ cmdstring = grub_malloc (cmdlen);
|
|
|
8631a2 |
+ if (!cmdstring)
|
|
|
8631a2 |
+ {
|
|
|
8631a2 |
+ return grub_error (GRUB_ERR_OUT_OF_MEMORY,
|
|
|
8631a2 |
+ N_("cannot allocate command buffer"));
|
|
|
8631a2 |
+ }
|
|
|
8631a2 |
+
|
|
|
8631a2 |
+ for (i = 0; i < argv.argc; i++) {
|
|
|
8631a2 |
+ offset += grub_snprintf (cmdstring + offset, cmdlen - offset, "%s ",
|
|
|
8631a2 |
+ argv.args[i]);
|
|
|
8631a2 |
+ }
|
|
|
8631a2 |
+ cmdstring[cmdlen-1]= '\0';
|
|
|
8631a2 |
+ grub_tpm_measure ((unsigned char *)cmdstring, cmdlen, GRUB_COMMAND_PCR,
|
|
|
8631a2 |
+ cmdstring);
|
|
|
8631a2 |
+ grub_free(cmdstring);
|
|
|
8631a2 |
invert = 0;
|
|
|
8631a2 |
argc = argv.argc - 1;
|
|
|
8631a2 |
args = argv.args + 1;
|
|
|
8631a2 |
diff --git a/include/grub/tpm.h b/include/grub/tpm.h
|
|
|
f6e916 |
index 40d3cf65b..7fc9d77d2 100644
|
|
|
8631a2 |
--- a/include/grub/tpm.h
|
|
|
8631a2 |
+++ b/include/grub/tpm.h
|
|
|
8631a2 |
@@ -30,6 +30,7 @@
|
|
|
8631a2 |
#define GRUB_KERNEL_PCR 10
|
|
|
8631a2 |
#define GRUB_INITRD_PCR 11
|
|
|
8631a2 |
#define GRUB_CMDLINE_PCR 12
|
|
|
8631a2 |
+#define GRUB_COMMAND_PCR 13
|
|
|
8631a2 |
|
|
|
8631a2 |
#define TPM_TAG_RQU_COMMAND 0x00C1
|
|
|
8631a2 |
#define TPM_ORD_Extend 0x14
|