summaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorBill Richardson <wfrichar@chromium.org>2016-11-09 13:27:35 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-11-11 23:11:51 -0800
commit12da6c23fbb9b72bc23d870d6283cf56ae7f448c (patch)
treeeff78fc73b85cf7dcca8371119eedaedad7a8a13 /board
parent7300bc56c050d68485368d70d6dc123fbefcd6df (diff)
downloadchrome-ec-12da6c23fbb9b72bc23d870d6283cf56ae7f448c.tar.gz
Cr50: Add TPM-compliant commands for console lock
This allows custom TPM commands to be declared using the a DECLARE_VENDOR_COMMAND macro instead of the original (and still unchanged) DECLARE_EXTENSION_COMMAND macro. The new commands are nearly identical, but they are encapsulated using the vendor-specific protocols described in the TPMv2 spec. Our original extensions use a non-standard command code, and return a non-standard struct on completion, which can be confusing to standard TPM drivers and tools. Demonstrating the use of the new macros, this adds commands to obtain the state of the Cr50 restricted console lock, or to set the lock. There is intentionally no command to unlock the console. Note that this CL just adds the commands to the Cr50. We still need to provide a nice userspace utility for the AP to use. BUG=chrome-os-partner:58230 BUG=chrome-os-partner:57940 BRANCH=none TEST=make buildall; load, boot, test, and update again on Reef On Reef, I can use the trunks_send tool to send the raw TPM bytes to invoke these commands: Get the lock state: # trunks_send 80 01 00 00 00 0C 20 00 00 00 00 10 80010000000D00000000001000 The last byte 00 indicates that the lock is NOT set, so set it: # trunks_send 80 01 00 00 00 0C 20 00 00 00 00 10 80010000000C000000000011 Success. On the Cr50 console, I see it take effect: [480.080444 The console is locked] Query the state again: # trunks_send 80 01 00 00 00 0C 20 00 00 00 00 10 80010000000D00000000001001 and now the last byte 01 indicates that the console is locked. And of course the existing extension commands still work as before. In addition to uploading firmware, I can use the usb_updater from my build machine to query the running firmware version: $ ./extra/usb_updater/usb_updater -f open_device 18d1:5014 found interface 4 endpoint 5, chunk_len 64 READY ------- start Target running protocol version 5 Offsets: backup RO at 0x40000, backup RW at 0x4000 Keyids: RO 0x3716ee6b, RW 0xb93d6539 Current versions: RO 0.0.10 RW 0.0.9 $ Change-Id: I7fb1d888bf808c2ef0b2b07c782e926063cc2cc4 Signed-off-by: Bill Richardson <wfrichar@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/409692 Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'board')
-rw-r--r--board/cr50/wp.c75
1 files changed, 70 insertions, 5 deletions
diff --git a/board/cr50/wp.c b/board/cr50/wp.c
index 823abdf145..d667ecc74e 100644
--- a/board/cr50/wp.c
+++ b/board/cr50/wp.c
@@ -5,6 +5,7 @@
#include "common.h"
#include "console.h"
+#include "extension.h"
#include "gpio.h"
#include "hooks.h"
#include "nvmem.h"
@@ -49,6 +50,19 @@ static int console_restricted_state;
static int console_restricted_state = 1;
#endif
+static void lock_the_console(void)
+{
+ CPRINTS("The console is locked");
+ console_restricted_state = 1;
+}
+
+static void unlock_the_console(void)
+{
+ nvmem_wipe_or_reboot();
+ CPRINTS("TPM is erased, console is unlocked");
+ console_restricted_state = 0;
+}
+
int console_is_restricted(void)
{
return console_restricted_state;
@@ -90,9 +104,7 @@ static void unlock_sequence_is_over(void)
} else {
/* The last poke was after the final deadline, so we're done */
CPRINTS("Unlock process completed successfully");
- nvmem_wipe_or_reboot();
- console_restricted_state = 0;
- CPRINTS("TPM is erased, console is unlocked.");
+ unlock_the_console();
}
unlock_in_progress = 0;
@@ -146,6 +158,59 @@ static void start_unlock_process(int total_poking_time, int max_poke_interval)
}
/****************************************************************************/
+/* TPM vendor-specific commands */
+
+static enum vendor_cmd_rc vc_lock(enum vendor_cmd_cc code,
+ void *buf,
+ size_t input_size,
+ size_t *response_size)
+{
+ uint8_t *buffer = buf;
+
+ if (code == VENDOR_CC_GET_LOCK) {
+ /*
+ * Get the state of the console lock.
+ *
+ * Args: none
+ * Returns: one byte; true (locked) or false (unlocked)
+ */
+ if (input_size != 0) {
+ *response_size = 0;
+ return VENDOR_RC_BOGUS_ARGS;
+ }
+
+ buffer[0] = console_is_restricted() ? 0x01 : 0x00;
+ *response_size = 1;
+ return VENDOR_RC_SUCCESS;
+ }
+
+ if (code == VENDOR_CC_SET_LOCK) {
+ /*
+ * Lock the console if it isn't already. Note that there
+ * intentionally isn't an unlock command. At most, we may want
+ * to call start_unlock_process(), but we haven't yet decided.
+ *
+ * Args: none
+ * Returns: none
+ */
+ if (input_size != 0) {
+ *response_size = 0;
+ return VENDOR_RC_BOGUS_ARGS;
+ }
+
+ lock_the_console();
+ *response_size = 0;
+ return VENDOR_RC_SUCCESS;
+ }
+
+ /* I have no idea what you're talking about */
+ *response_size = 0;
+ return VENDOR_RC_NO_SUCH_COMMAND;
+}
+DECLARE_VENDOR_COMMAND(VENDOR_CC_GET_LOCK, vc_lock);
+DECLARE_VENDOR_COMMAND(VENDOR_CC_SET_LOCK, vc_lock);
+
+/****************************************************************************/
static const char warning[] = "\n\t!!! WARNING !!!\n\n"
"\tThe AP will be impolitely shut down and the TPM persistent memory\n"
"\tERASED before the console is unlocked. If this is not what you\n"
@@ -161,12 +226,12 @@ static int command_lock(int argc, char **argv)
return EC_ERROR_PARAM1;
/* Changing nothing does nothing */
- if (enabled == console_restricted_state)
+ if (enabled == console_is_restricted())
goto out;
/* Locking the console is always allowed */
if (enabled) {
- console_restricted_state = 1;
+ lock_the_console();
goto out;
}