Skip to content

Commit

Permalink
measure buffer that is used (grub2 modules) GH #9
Browse files Browse the repository at this point in the history
  • Loading branch information
neusdan committed Jan 2, 2016
1 parent 847a6b2 commit 6e593ed
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
26 changes: 19 additions & 7 deletions grub-core/kern/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ grub_dl_load_file (const char *filename)
grub_file_t file = NULL;
grub_ssize_t size;
void *core = 0;
void *measureModBuf = 0;
grub_dl_t mod = 0;

grub_boot_time ("Loading module %s", filename);
Expand Down Expand Up @@ -710,10 +711,27 @@ grub_dl_load_file (const char *filename)
opens of the same device. */
grub_file_close (file);

/* Begin TCG Extension */
/* grub_dl_load_core() modifies the original buffer, so make a copy here that is measured later */
measureModBuf = grub_malloc (size);
if (! measureModBuf)
{
return 0;
}
grub_memcpy(measureModBuf, core, size);

mod = grub_dl_load_core (core, size);
grub_free (core);
if (! mod)

if (! mod) {
grub_free (measureModBuf);
return 0;
}

DEBUG_PRINT( ( "measured module: %s \n", mod->name ) );
grub_TPM_measure_buffer( measureModBuf, size, TPM_LOADED_FILES_PCR );
grub_free (measureModBuf);
/* End TCG Extension */

mod->ref_count--;
return mod;
Expand Down Expand Up @@ -754,12 +772,6 @@ grub_dl_load (const char *name)
if (grub_strcmp (mod->name, name) != 0)
grub_error (GRUB_ERR_BAD_MODULE, "mismatched names");

/* Begin TCG Extension */
if( grub_errno == GRUB_ERR_NONE ) {
grub_TPM_measure_file( filename, TPM_LOADED_FILES_PCR );
}
/* End TCG Extension */

grub_free (filename);
return mod;
}
Expand Down
1 change: 1 addition & 0 deletions grub-core/kern/i386/pc/tpm/tpm_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ grub_TPM_measure_buffer( const void* buffer, const grub_uint32_t bufferLen, cons
DEBUG_PRINT( ( "SHA1: " ) );
print_sha1( convertedResult );
DEBUG_PRINT( ( "\n" ) );
grub_sleep( 4 );
#endif

/* measure */
Expand Down
6 changes: 0 additions & 6 deletions include/grub/i386/pc/tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@

/************************* macros *************************/

#ifdef TGRUB_DEBUG
#define DEBUG_PRINT( x ) grub_printf x
#else
#define DEBUG_PRINT( x )
#endif

#define CHECK_FOR_NULL_ARGUMENT( argument ) \
if( ! argument ) { \
grub_fatal( "BAD_ARGUMENT: argument is NULL" ); \
Expand Down
8 changes: 8 additions & 0 deletions include/grub/tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
#define TPM_COMMAND_MEASUREMENT_PCR 11
#define TPM_LUKS_HEADER_MEASUREMENT_PCR 12

/************************* macros *************************/

#ifdef TGRUB_DEBUG
#define DEBUG_PRINT( x ) grub_printf x
#else
#define DEBUG_PRINT( x )
#endif

/************************* functions *************************/

/* print SHA1 hash of input */
Expand Down

0 comments on commit 6e593ed

Please sign in to comment.