From 422617f069c8a167cf05148c69046fb4279d1243 Mon Sep 17 00:00:00 2001 From: Daniel Neus Date: Sat, 2 Jan 2016 00:04:20 +0100 Subject: [PATCH] improve fix for GH #28 (measuring of compressed files) --- README.md | 2 - grub-core/kern/file.c | 72 --------------------------- grub-core/kern/i386/pc/tpm/tpm_kern.c | 6 ++- include/grub/file.h | 9 ---- 4 files changed, 4 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index a857a7799..1e9cece4d 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,6 @@ support to GRUB2. * grub-core/kern/dl.c * grub-core/kern/i386/pc/tpm/tpm_kern.c * grub-core/kern/sha1.c -* grub-core/kern/file.c * grub-core/disk/cryptodisk.c * grub-core/disk/luks.c * grub-core/loader/linux.c @@ -276,7 +275,6 @@ support to GRUB2. * include/grub/i386/pc/tpm.h * include/grub/tpm.h * include/grub/sha1.h -* include/grub/file.h * util/mkimage.c ## 3. Thanks diff --git a/grub-core/kern/file.c b/grub-core/kern/file.c index 47ca74aa7..668f8930b 100644 --- a/grub-core/kern/file.c +++ b/grub-core/kern/file.c @@ -143,78 +143,6 @@ grub_file_open (const char *name) return 0; } - -/* Begin TCG extension */ -grub_file_t -grub_file_open_nofilter (const char *name) -{ - grub_device_t device = 0; - grub_file_t file = 0; - char *device_name; - const char *file_name; - - device_name = grub_file_get_device_name (name); - if (grub_errno) - goto fail; - - /* Get the file part of NAME. */ - file_name = (name[0] == '(') ? grub_strchr (name, ')') : NULL; - if (file_name) - file_name++; - else - file_name = name; - - device = grub_device_open (device_name); - grub_free (device_name); - if (! device) - goto fail; - - file = (grub_file_t) grub_zalloc (sizeof (*file)); - if (! file) - goto fail; - - file->device = device; - - /* In case of relative pathnames and non-Unix systems (like Windows) - * name of host files may not start with `/'. Blocklists for host files - * are meaningless as well (for a start, host disk does not allow any direct - * access - it is just a marker). So skip host disk in this case. - */ - if (device->disk && file_name[0] != '/' -#if defined(GRUB_UTIL) || defined(GRUB_MACHINE_EMU) - && grub_strcmp (device->disk->name, "host") -#endif - ) - /* This is a block list. */ - file->fs = &grub_fs_blocklist; - else - { - file->fs = grub_fs_probe (device); - if (! file->fs) - goto fail; - } - - if ((file->fs->open) (file, file_name) != GRUB_ERR_NONE) - goto fail; - - file->name = grub_strdup (name); - grub_errno = GRUB_ERR_NONE; - - return file; - - fail: - if (device) - grub_device_close (device); - - /* if (net) grub_net_close (net); */ - - grub_free (file); - - return 0; -} -/* End TCG extension CUSTOM */ - - grub_disk_read_hook_t grub_file_progress_hook; grub_ssize_t diff --git a/grub-core/kern/i386/pc/tpm/tpm_kern.c b/grub-core/kern/i386/pc/tpm/tpm_kern.c index 00714bad5..147baa0e3 100644 --- a/grub-core/kern/i386/pc/tpm/tpm_kern.c +++ b/grub-core/kern/i386/pc/tpm/tpm_kern.c @@ -255,7 +255,7 @@ grub_TPM_measure_string( const char* string ) { DEBUG_PRINT( ( "SHA1: " ) ); print_sha1( convertedResult ); DEBUG_PRINT( ( "\n" ) ); - grub_sleep( 5 ); + grub_sleep( 4 ); #endif /* measure */ @@ -269,7 +269,9 @@ grub_TPM_measure_file( const char* filename, const unsigned long index ) { CHECK_FOR_NULL_ARGUMENT( filename ) /* open file 'raw' (without any pre-processing filters) */ - grub_file_t file = grub_file_open_nofilter( filename ); + grub_file_filter_disable_compression (); + grub_file_t file = grub_file_open( filename ); + if( ! file ) { grub_print_error(); grub_fatal( "grub_TPM_measureFile: grub_file_open failed." ); diff --git a/include/grub/file.h b/include/grub/file.h index 053659635..25f395eeb 100644 --- a/include/grub/file.h +++ b/include/grub/file.h @@ -133,15 +133,6 @@ char *EXPORT_FUNC(grub_file_get_device_name) (const char *name); grub_file_t EXPORT_FUNC(grub_file_open) (const char *name); -/* Begin TCG extension */ - -/* Used for TPM file measurement */ -/* grub_file_open is not suited for measurement because it does not necessarily return the same file that is stored on disk */ -/* For example it decompresses compressed files automatically */ -grub_file_t EXPORT_FUNC(grub_file_open_nofilter) (const char *name); - -/* End TCG extension */ - grub_ssize_t EXPORT_FUNC(grub_file_read) (grub_file_t file, void *buf, grub_size_t len); grub_off_t EXPORT_FUNC(grub_file_seek) (grub_file_t file, grub_off_t offset);