Skip to content

Commit

Permalink
Add verity hash passthrough
Browse files Browse the repository at this point in the history
Read the verity hash from the kernel binary and pass it to the running
system via the kernel command line
  • Loading branch information
Matthew Garrett authored and dm0- committed Mar 30, 2018
1 parent 250af43 commit 03b547c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions grub-core/loader/i386/efi/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <grub/lib/cmdline.h>
#include <grub/efi/efi.h>

#include "../verity-hash.h"

GRUB_MOD_LICENSE ("GPLv3+");

static grub_dl_t my_mod;
Expand Down Expand Up @@ -288,6 +290,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
linux_cmdline + sizeof (LINUX_IMAGE) - 1,
lh.cmdline_size - (sizeof (LINUX_IMAGE) - 1));

grub_pass_verity_hash(&lh, linux_cmdline);
lh.cmd_line_ptr = (grub_uint32_t)(grub_uint64_t)linux_cmdline;

handover_offset = lh.handover_offset;
Expand Down
2 changes: 2 additions & 0 deletions grub-core/loader/i386/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <grub/lib/cmdline.h>
#include <grub/linux.h>

#include "verity-hash.h"
GRUB_MOD_LICENSE ("GPLv3+");

#ifdef GRUB_MACHINE_PCBIOS
Expand Down Expand Up @@ -1018,6 +1019,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
maximal_cmdline_size
- (sizeof (LINUX_IMAGE) - 1));

grub_pass_verity_hash(&lh, linux_cmdline);
len = prot_file_size;
if (grub_file_read (file, prot_mode_mem, len) != len && !grub_errno)
grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
Expand Down
25 changes: 25 additions & 0 deletions grub-core/loader/i386/verity-hash.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define VERITY_ARG " verity.usrhash="
#define VERITY_HASH_OFFSET 0x40
#define VERITY_HASH_LENGTH 64

static inline void grub_pass_verity_hash(struct linux_kernel_header *lh,
char *cmdline)
{
char *buf = (char *)lh;
grub_size_t cmdline_len;
int i;

for (i=VERITY_HASH_OFFSET; i<VERITY_HASH_OFFSET + VERITY_HASH_LENGTH; i++)
{
if (buf[i] < '0' || buf[i] > '9') // Not a number
if (buf[i] < 'a' || buf[i] > 'f') // Not a hex letter
return;
}

grub_memcpy (cmdline + grub_strlen(cmdline), VERITY_ARG,
sizeof (VERITY_ARG));
cmdline_len = grub_strlen(cmdline);
grub_memcpy (cmdline + cmdline_len, buf + VERITY_HASH_OFFSET,
VERITY_HASH_LENGTH);
cmdline[cmdline_len + VERITY_HASH_LENGTH] = '\0';
}

0 comments on commit 03b547c

Please sign in to comment.