From d87efc08c3861127e655c68bde2117642fa827da Mon Sep 17 00:00:00 2001 From: Ross Philipson Date: Fri, 13 Jan 2023 15:11:26 -0500 Subject: [PATCH] Switch to using Secure Launch Resource Table interface Signed-off-by: Ross Philipson Signed-off-by: Sergii Dmytruk --- grub-core/loader/i386/linux.c | 94 +++++++++++++++++++++++++++++- grub-core/loader/i386/slaunch.c | 87 +++++++++++++++++++++++++++ grub-core/loader/i386/txt/txt.c | 86 ++++++++++++++++++--------- grub-core/loader/multiboot.c | 2 + grub-core/loader/multiboot_elfxx.c | 1 + include/grub/i386/slaunch.h | 15 ++++- include/grub/i386/txt.h | 25 +++----- include/grub/slr_table.h | 16 ++--- 8 files changed, 270 insertions(+), 56 deletions(-) diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c index 26f183f84..c1d2eda38 100644 --- a/grub-core/loader/i386/linux.c +++ b/grub-core/loader/i386/linux.c @@ -39,6 +39,7 @@ #include #include #include +#include GRUB_MOD_LICENSE ("GPLv3+"); @@ -69,6 +70,18 @@ GRUB_MOD_LICENSE ("GPLv3+"); #define KERNEL_INFO_HEADER "LToP" #define KERNEL_INFO_MIN_SIZE_TOTAL 12 +struct linux_params_efi_info +{ + grub_uint32_t efi_signature; + grub_uint32_t efi_system_table; + grub_uint32_t efi_mem_desc_size; + grub_uint32_t efi_mem_desc_version; + grub_uint32_t efi_mmap; + grub_uint32_t efi_mmap_size; + grub_uint32_t efi_system_table_hi; + grub_uint32_t efi_mmap_hi; +}; + static grub_dl_t my_mod; static grub_size_t linux_mem_size; @@ -248,11 +261,28 @@ allocate_pages (grub_size_t prot_size, grub_size_t *align, slparams->mle_start = prot_mode_target; slparams->mle_size = prot_size; + slparams->mle_mem = prot_mode_mem; grub_dprintf ("linux", "mle_ptab_mem = %p, mle_ptab_target = %lx, mle_ptab_size = %x\n", slparams->mle_ptab_mem, (unsigned long) slparams->mle_ptab_target, (unsigned) slparams->mle_ptab_size); + if (grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, + 0xffffffff - GRUB_PAGE_SIZE, + GRUB_PAGE_SIZE, GRUB_PAGE_SIZE, + GRUB_RELOCATOR_PREFERENCE_NONE, 1)) + goto fail; + + slparams->slr_table_base = get_physical_target_address (ch); + slparams->slr_table_size = GRUB_PAGE_SIZE; + slparams->slr_table_mem = get_virtual_current_address (ch); + + grub_memset (slparams->slr_table_mem, 0, slparams->slr_table_size); + + grub_dprintf ("linux", "slr_table_base = %lx, slr_table_size = %x\n", + (unsigned long) slparams->slr_table_base, + (unsigned) slparams->slr_table_size); + if (grub_relocator_alloc_chunk_align (relocator, &ch, 0x1000000, 0xffffffff - GRUB_SLAUNCH_TPM_EVT_LOG_SIZE, GRUB_SLAUNCH_TPM_EVT_LOG_SIZE, GRUB_PAGE_SIZE, @@ -468,6 +498,60 @@ grub_linux_boot_mmap_fill (grub_uint64_t addr, grub_uint64_t size, return 0; } +static void +grub_linux_setup_slr_table (struct grub_slaunch_params *slparams) +{ + struct linux_kernel_params *boot_params = (void *) (grub_addr_t) slparams->boot_params_addr; + struct linux_params_efi_info *efi_info; + + /* A bit of work to extract the v2.08 EFI info from the linux params */ + efi_info = (void *)((grub_uint8_t *)&boot_params->v0208 + 2*sizeof(grub_uint32_t)); + + grub_slaunch_add_slrt_policy_entry (18, + GRUB_SLR_ET_BOOT_PARAMS, + /*flags=*/0, + (grub_addr_t) boot_params, + GRUB_PAGE_SIZE, + "Measured boot parameters"); + + if (boot_params->setup_data) + grub_slaunch_add_slrt_policy_entry (18, + GRUB_SLR_ET_SETUP_DATA, + GRUB_SLR_POLICY_IMPLICIT_SIZE, + boot_params->setup_data, + /*size=*/0, + "Measured Kernel setup_data"); + + /* TODO the cmdline ptr can have hi bits but for now assume always < 4G */ + grub_slaunch_add_slrt_policy_entry (18, + GRUB_SLR_ET_CMDLINE, + /*flags=*/0, + boot_params->cmd_line_ptr, + boot_params->cmdline_size, + "Measured Kernel command line"); + + if (!grub_memcmp(&efi_info->efi_signature, "EL64", sizeof(grub_uint32_t))) + { + grub_uint64_t mmap_addr = + ((grub_uint64_t) efi_info->efi_mmap_hi << 32) | efi_info->efi_mmap; + grub_slaunch_add_slrt_policy_entry (18, + GRUB_SLR_ET_UEFI_MEMMAP, + /*flags=*/0, + mmap_addr, + efi_info->efi_mmap_size, + "Measured EFI memory map"); + } + + if (boot_params->ramdisk_image) + /* TODO the initrd image and size can have hi bits but for now assume always < 4G */ + grub_slaunch_add_slrt_policy_entry (17, + GRUB_SLR_ET_RAMDISK, + /*flags=*/0, + boot_params->ramdisk_image, + boot_params->ramdisk_size, + "Measured Kernel initrd"); +} + static grub_err_t grub_linux_boot (void) { @@ -645,6 +729,9 @@ grub_linux_boot (void) grub_dprintf ("linux", "ap_wake_block = %lx, ap_wake_block_size = %lx\n", (unsigned long) slparams->ap_wake_block, (unsigned long) ap_wake_block_size); + + /* Grab the real mode target address, this is the boot params page. */ + slparams->boot_params_addr = ctx.real_mode_target; } grub_dprintf ("linux", "real_mode_mem = %p\n", @@ -673,6 +760,8 @@ grub_linux_boot (void) ctx.params->secure_boot = grub_efi_get_secureboot (); + grub_dprintf ("linux", "EFI exit boot services\n"); + err = grub_efi_finish_boot_services (&efi_mmap_size, efi_mmap_buf, NULL, &efi_desc_size, &efi_desc_version); if (err) @@ -714,13 +803,14 @@ grub_linux_boot (void) if (state.edi == SLP_INTEL_TXT) { - slparams->boot_params_addr = (grub_uint32_t) ctx.real_mode_target; - err = grub_txt_boot_prepare (slparams); if (err != GRUB_ERR_NONE) return err; + grub_linux_setup_slr_table (slparams); + grub_slaunch_finish_slr_table (); + /* Configure relocator GETSEC[SENTER] call. */ state.eax = GRUB_SMX_LEAF_SENTER; state.ebx = slparams->dce_base; diff --git a/grub-core/loader/i386/slaunch.c b/grub-core/loader/i386/slaunch.c index 093eddef8..de22d2b80 100644 --- a/grub-core/loader/i386/slaunch.c +++ b/grub-core/loader/i386/slaunch.c @@ -23,11 +23,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include GRUB_MOD_LICENSE ("GPLv3+"); @@ -38,6 +40,13 @@ static void *slaunch_module = NULL; static struct grub_slaunch_params slparams; +/* Area to collect and build SLR Table information. */ +static struct grub_slr_entry_dl_info slr_dl_info_staging; +static struct grub_slr_entry_log_info slr_log_info_staging; +static grub_uint8_t slr_policy_buf[GRUB_PAGE_SIZE]; +static struct grub_slr_entry_policy *slr_policy_staging = + (struct grub_slr_entry_policy *)slr_policy_buf; + grub_uint32_t grub_slaunch_platform_type (void) { @@ -56,6 +65,84 @@ grub_slaunch_params (void) return &slparams; } +void +grub_slaunch_init_slrt_storage (int arch) +{ + struct grub_txt_mle_header *mle_header = + (void *) ((grub_uint8_t *) slparams.mle_mem + slparams.mle_header_offset); + + /* Setup the generic bits of the SLRT. */ + grub_slr_init_table(slparams.slr_table_mem, arch, slparams.slr_table_size); + + /* Setup DCE and DLME information. */ + slr_dl_info_staging.hdr.tag = GRUB_SLR_ENTRY_DL_INFO; + slr_dl_info_staging.hdr.size = sizeof(struct grub_slr_entry_dl_info); + slr_dl_info_staging.dce_base = slparams.dce_base; + slr_dl_info_staging.dce_size = slparams.dce_size; + slr_dl_info_staging.dlme_entry = mle_header->entry_point; + + slr_log_info_staging.hdr.tag = GRUB_SLR_ENTRY_LOG_INFO; + slr_log_info_staging.hdr.size = sizeof(struct grub_slr_entry_log_info); + slr_log_info_staging.addr = slparams.tpm_evt_log_base; + slr_log_info_staging.size = slparams.tpm_evt_log_size; + slr_log_info_staging.format = + (grub_get_tpm_ver () == GRUB_TPM_20) ? + GRUB_SLR_DRTM_TPM20_LOG : GRUB_SLR_DRTM_TPM12_LOG; + + slr_policy_staging->hdr.tag = GRUB_SLR_ENTRY_DRTM_POLICY; + slr_policy_staging->hdr.size = sizeof(struct grub_slr_entry_policy); + slr_policy_staging->revision = GRUB_SLR_TABLE_REVISION; + slr_policy_staging->nr_entries = 0; + + /* The SLR table should be measured too, at least parts of it. */ + grub_slaunch_add_slrt_policy_entry (18, + GRUB_SLR_ET_SLRT, + GRUB_SLR_POLICY_IMPLICIT_SIZE, + slparams.slr_table_base, + /*size=*/0, + "Measured SLR Table"); +} + +void +grub_slaunch_add_slrt_policy_entry (grub_uint16_t pcr, + grub_uint16_t entity_type, + grub_uint16_t flags, + grub_uint64_t entity, + grub_uint64_t size, + const char *evt_info) +{ + struct grub_slr_policy_entry *entry = + (void *)((grub_uint8_t *)slr_policy_staging + + sizeof(struct grub_slr_entry_policy) + + slr_policy_staging->nr_entries*sizeof(*entry)); + + if (slr_policy_staging->hdr.size + sizeof(*entry) > sizeof(slr_policy_buf)) + grub_fatal("Not enough space for adding policy entry: %s! The buffer is full.", + evt_info); + + entry->pcr = pcr; + entry->entity_type = entity_type; + entry->flags = flags; + entry->entity = entity; + entry->size = size; + + grub_strncpy(entry->evt_info, evt_info, sizeof(entry->evt_info) - 1); + entry->evt_info[sizeof(entry->evt_info) - 1] = '\0'; + + slr_policy_staging->hdr.size += sizeof(*entry); + ++slr_policy_staging->nr_entries; +} + +void +grub_slaunch_finish_slr_table (void) +{ + struct grub_slr_table *slr_table = slparams.slr_table_mem; + + grub_slr_add_entry (slr_table, &slr_dl_info_staging.hdr); + grub_slr_add_entry (slr_table, &slr_log_info_staging.hdr); + grub_slr_add_entry (slr_table, &slr_policy_staging->hdr); +} + static grub_err_t grub_cmd_slaunch (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), diff --git a/grub-core/loader/i386/txt/txt.c b/grub-core/loader/i386/txt/txt.c index 15ba8153f..9c5424003 100644 --- a/grub-core/loader/i386/txt/txt.c +++ b/grub-core/loader/i386/txt/txt.c @@ -59,6 +59,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,8 @@ #define OS_SINIT_DATA_MIN_VER OS_SINIT_DATA_TPM_12_VER +static struct grub_slr_entry_intel_info slr_intel_info_staging = {0}; + static grub_err_t enable_smx_mode (void) { @@ -244,33 +247,39 @@ grub_txt_prepare_cpu (void) } static void -save_mtrrs (struct grub_txt_os_mle_data *os_mle_data) +save_mtrrs (struct grub_slr_txt_mtrr_state *saved_bsp_mtrrs) { grub_uint64_t i; - os_mle_data->saved_bsp_mtrrs.default_mem_type = + saved_bsp_mtrrs->default_mem_type = grub_rdmsr (GRUB_MSR_X86_MTRR_DEF_TYPE); - os_mle_data->saved_bsp_mtrrs.mtrr_vcnt = + saved_bsp_mtrrs->mtrr_vcnt = grub_rdmsr (GRUB_MSR_X86_MTRRCAP) & GRUB_MSR_X86_VCNT_MASK; - if (os_mle_data->saved_bsp_mtrrs.mtrr_vcnt > GRUB_SL_MAX_VARIABLE_MTRRS) + if (saved_bsp_mtrrs->mtrr_vcnt > GRUB_TXT_VARIABLE_MTRRS_LENGTH) { /* Print warning but continue saving what we can... */ grub_printf ("WARNING: Actual number of variable MTRRs (%" PRIuGRUB_UINT64_T ") > GRUB_SL_MAX_VARIABLE_MTRRS (%d)\n", - os_mle_data->saved_bsp_mtrrs.mtrr_vcnt, - GRUB_SL_MAX_VARIABLE_MTRRS); - os_mle_data->saved_bsp_mtrrs.mtrr_vcnt = GRUB_SL_MAX_VARIABLE_MTRRS; + saved_bsp_mtrrs->mtrr_vcnt, + GRUB_TXT_VARIABLE_MTRRS_LENGTH); + saved_bsp_mtrrs->mtrr_vcnt = GRUB_TXT_VARIABLE_MTRRS_LENGTH; } - for (i = 0; i < os_mle_data->saved_bsp_mtrrs.mtrr_vcnt; ++i) + for (i = 0; i < saved_bsp_mtrrs->mtrr_vcnt; ++i) { - os_mle_data->saved_bsp_mtrrs.mtrr_pair[i].mtrr_physmask = + saved_bsp_mtrrs->mtrr_pair[i].mtrr_physmask = grub_rdmsr (GRUB_MSR_X86_MTRR_PHYSMASK0 + i * 2); - os_mle_data->saved_bsp_mtrrs.mtrr_pair[i].mtrr_physbase = + saved_bsp_mtrrs->mtrr_pair[i].mtrr_physbase = grub_rdmsr (GRUB_MSR_X86_MTRR_PHYSBASE0 + i * 2); } + /* Zero unused array items. */ + for ( ; i < GRUB_TXT_VARIABLE_MTRRS_LENGTH; ++i) + { + saved_bsp_mtrrs->mtrr_pair[i].mtrr_physmask = 0; + saved_bsp_mtrrs->mtrr_pair[i].mtrr_physbase = 0; + } } static void @@ -535,6 +544,20 @@ grub_txt_init_tpm_event_log (void *buf, grub_size_t size) elog->next_event_offset = sizeof(*elog); } +static void +setup_txt_slrt_entry (struct grub_slaunch_params *slparams, + struct grub_txt_os_mle_data *os_mle_data) +{ + struct grub_slr_table *slr_table = slparams->slr_table_mem; + struct grub_slr_entry_hdr *txt_info; + + grub_slr_add_entry (slr_table, &slr_intel_info_staging.hdr); + + txt_info = grub_slr_next_entry_by_tag (slr_table, NULL, GRUB_SLR_ENTRY_INTEL_INFO); + os_mle_data->txt_info = (grub_addr_t) slparams->slr_table_base + + ((grub_addr_t) txt_info - (grub_addr_t) slparams->slr_table_mem); +} + static grub_err_t init_txt_heap (struct grub_slaunch_params *slparams, struct grub_txt_acm_header *sinit) { @@ -567,16 +590,20 @@ init_txt_heap (struct grub_slaunch_params *slparams, struct grub_txt_acm_header os_mle_data->version = GRUB_SL_OS_MLE_STRUCT_VERSION; os_mle_data->boot_params_addr = slparams->boot_params_addr; - os_mle_data->saved_misc_enable_msr = grub_rdmsr (GRUB_MSR_X86_MISC_ENABLE); + os_mle_data->slrt = slparams->slr_table_base; os_mle_data->ap_wake_block = slparams->ap_wake_block; os_mle_data->ap_wake_block_size = slparams->ap_wake_block_size; - os_mle_data->evtlog_addr = slparams->tpm_evt_log_base; - os_mle_data->evtlog_size = slparams->tpm_evt_log_size; + /* Setup the TXT specific SLR information */ + slr_intel_info_staging.hdr.tag = GRUB_SLR_ENTRY_INTEL_INFO; + slr_intel_info_staging.hdr.size = sizeof(struct grub_slr_entry_intel_info); + slr_intel_info_staging.saved_misc_enable_msr = + grub_rdmsr (GRUB_MSR_X86_MISC_ENABLE); + /* Save the BSPs MTRR state so post launch can restore it. */ grub_dprintf ("slaunch", "Saving MTRRs to OS MLE data\n"); - save_mtrrs (os_mle_data); + save_mtrrs (&slr_intel_info_staging.saved_bsp_mtrrs); /* OS/loader to SINIT data. */ grub_dprintf ("slaunch", "Get supported OS SINIT data version\n"); @@ -934,9 +961,10 @@ grub_err_t grub_txt_boot_prepare (struct grub_slaunch_params *slparams) { grub_err_t err; + grub_uint8_t *txt_heap; + struct grub_txt_os_mle_data *os_mle_data; struct grub_txt_mle_header *mle_header; struct grub_txt_acm_header *sinit_base; - int i; sinit_base = grub_txt_sinit_select (grub_slaunch_module ()); @@ -952,24 +980,28 @@ grub_txt_boot_prepare (struct grub_slaunch_params *slparams) grub_dprintf ("slaunch", "TXT heap successfully prepared\n"); /* Update the MLE header. */ - mle_header = (struct grub_txt_mle_header *)(grub_addr_t) (slparams->mle_start + slparams->mle_header_offset); + mle_header = + (struct grub_txt_mle_header *) ((grub_uint8_t *) slparams->mle_mem + slparams->mle_header_offset); mle_header->first_valid_page = 0; mle_header->mle_end = slparams->mle_size; slparams->dce_base = (grub_uint32_t)(grub_addr_t) sinit_base; slparams->dce_size = sinit_base->size * 4; - /* - * Access to locality 4 isn't available to software, skip it. Don't bother - * checking TPM status, we have no tools for recovering from bad state better - * than command abort, which is part of locality relinquish. Write performed - * by the following function is no-op if locality is neither active nor - * requested. - */ - for (i = 0; i < 4; ++i) - grub_tpm_relinquish_locality (i); - - grub_dprintf ("slaunch", "TPM localities relinquished\n"); + /* Setup of SLR table. */ + grub_slaunch_init_slrt_storage (GRUB_SLR_INTEL_TXT); + txt_heap = grub_txt_get_heap (); + os_mle_data = grub_txt_os_mle_data_start (txt_heap); + setup_txt_slrt_entry (slparams, os_mle_data); + grub_slaunch_add_slrt_policy_entry (18, + GRUB_SLR_ET_TXT_OS2MLE, + /*flags=*/0, + (grub_addr_t) os_mle_data, + sizeof(*os_mle_data), + "Measured TXT OS-MLE data"); + + grub_tpm_relinquish_locality (0); + grub_dprintf ("slaunch", "Relinquished TPM locality 0\n"); err = set_mtrrs_for_acmod (sinit_base); if (err) diff --git a/grub-core/loader/multiboot.c b/grub-core/loader/multiboot.c index 75413c110..47fa6faa6 100644 --- a/grub-core/loader/multiboot.c +++ b/grub-core/loader/multiboot.c @@ -179,6 +179,8 @@ normal_boot (struct grub_relocator *rel, struct grub_relocator32_state state) return; } + grub_slaunch_finish_slr_table (); + /* Configure relocator GETSEC[SENTER] call. */ state.eax = GRUB_SMX_LEAF_SENTER; state.ebx = slparams->dce_base; diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c index 47ba4c3f2..a92082533 100644 --- a/grub-core/loader/multiboot_elfxx.c +++ b/grub-core/loader/multiboot_elfxx.c @@ -164,6 +164,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) return grub_error (GRUB_ERR_BAD_OS, "Only multiboot2 supported for slaunch"); #else slparams->mle_start = mld->load_base_addr; + slparams->mle_mem = source; err = grub_relocator_alloc_chunk_align_safe (GRUB_MULTIBOOT (relocator), &ch, GRUB_MEMORY_MACHINE_UPPER_START, diff --git a/include/grub/i386/slaunch.h b/include/grub/i386/slaunch.h index f7160d5fa..6df6fa0da 100644 --- a/include/grub/i386/slaunch.h +++ b/include/grub/i386/slaunch.h @@ -35,11 +35,15 @@ struct grub_slaunch_params { grub_uint32_t boot_params_addr; + grub_uint64_t slr_table_base; + grub_uint32_t slr_table_size; + void *slr_table_mem; grub_uint32_t mle_start; grub_uint32_t mle_size; - void *mle_ptab_mem; + void *mle_mem; grub_uint64_t mle_ptab_target; grub_uint32_t mle_ptab_size; + void *mle_ptab_mem; grub_uint32_t mle_header_offset; grub_uint32_t ap_wake_block; grub_uint32_t ap_wake_block_size; @@ -53,6 +57,15 @@ extern grub_uint32_t grub_slaunch_platform_type (void); extern void *grub_slaunch_module (void); extern struct grub_slaunch_params *grub_slaunch_params (void); +extern void grub_slaunch_init_slrt_storage (int arch); +extern void grub_slaunch_add_slrt_policy_entry (grub_uint16_t pcr, + grub_uint16_t entity_type, + grub_uint16_t flags, + grub_uint64_t entity, + grub_uint64_t size, + const char *evt_info); +extern void grub_slaunch_finish_slr_table (void); + #endif /* ASM_FILE */ #endif /* GRUB_I386_SLAUNCH_H */ diff --git a/include/grub/i386/txt.h b/include/grub/i386/txt.h index 53355d511..dec4a47e2 100644 --- a/include/grub/i386/txt.h +++ b/include/grub/i386/txt.h @@ -353,32 +353,16 @@ struct grub_txt_bios_data /* GRUB SLAUNCH specific definitions OS-MLE data */ #define GRUB_SL_BOOTPARAMS_OFFSET 0x12c #define GRUB_SL_MAX_EVENT_LOG_SIZE (5*4*1024) /* 4k*5 */ -#define GRUB_SL_MAX_VARIABLE_MTRRS 32 #define GRUB_SL_OS_MLE_STRUCT_VERSION 1 -struct grub_slaunch_mtrr_pair -{ - grub_uint64_t mtrr_physbase; - grub_uint64_t mtrr_physmask; -} GRUB_PACKED; - -struct grub_slaunch_mtrr_state -{ - grub_uint64_t default_mem_type; - grub_uint64_t mtrr_vcnt; - struct grub_slaunch_mtrr_pair mtrr_pair[GRUB_SL_MAX_VARIABLE_MTRRS]; -} GRUB_PACKED; - struct grub_txt_os_mle_data { grub_uint32_t version; grub_uint32_t boot_params_addr; - grub_uint64_t saved_misc_enable_msr; - struct grub_slaunch_mtrr_state saved_bsp_mtrrs; + grub_uint32_t slrt; + grub_uint32_t txt_info; grub_uint32_t ap_wake_block; grub_uint32_t ap_wake_block_size; - grub_uint64_t evtlog_addr; - grub_uint32_t evtlog_size; grub_uint8_t mle_scratch[64]; } GRUB_PACKED; @@ -730,6 +714,11 @@ extern void grub_txt_setup_mle_ptab (struct grub_slaunch_params *slparams); extern grub_err_t grub_txt_init (void); extern void grub_txt_shutdown (void); extern void grub_txt_state_show (void); +/* + * This function doesn't finish building of SLRT. It's caller's responsibility + * to call grub_slaunch_finish_slr_table() after possibly making some + * grub_slr_add_entry() and grub_slaunch_add_slrt_policy_entry() calls. + */ extern grub_err_t grub_txt_boot_prepare (struct grub_slaunch_params *slparams); #endif diff --git a/include/grub/slr_table.h b/include/grub/slr_table.h index 2153f6b24..9e9f90ad6 100644 --- a/include/grub/slr_table.h +++ b/include/grub/slr_table.h @@ -217,9 +217,9 @@ struct grub_slr_uefi_cfg_entry } GRUB_PACKED; static inline void * -grub_slr_end_of_entrys (struct grub_slr_table *table) +grub_slr_end_of_entries (struct grub_slr_table *table) { - return (void *)(((grub_uint8_t *)table) + table->size); + return (grub_uint8_t *) table + table->size; } static inline struct grub_slr_entry_hdr * @@ -227,9 +227,9 @@ grub_slr_next_entry (struct grub_slr_table *table, struct grub_slr_entry_hdr *curr) { struct grub_slr_entry_hdr *next = (struct grub_slr_entry_hdr *) - ((grub_uint8_t *)curr + curr->size); + ((grub_uint8_t *) curr + curr->size); - if ((void *)next >= grub_slr_end_of_entrys(table)) + if ((void *)next >= grub_slr_end_of_entries (table)) return NULL; if (next->tag == GRUB_SLR_ENTRY_END) return NULL; @@ -243,7 +243,7 @@ grub_slr_next_entry_by_tag (struct grub_slr_table *table, grub_uint16_t tag) { if (!entry) /* Start from the beginning */ - entry = (struct grub_slr_entry_hdr *)(((grub_uint8_t *)table) + sizeof(*table)); + entry = (struct grub_slr_entry_hdr *)((grub_uint8_t *) table + sizeof(*table)); for ( ; ; ) { @@ -267,10 +267,10 @@ grub_slr_add_entry (struct grub_slr_table *table, if ((table->size + entry->size) > table->max_size) return -1; - grub_memcpy((grub_uint8_t *)table + table->size - sizeof(*end), entry, entry->size); + grub_memcpy ((grub_uint8_t *) table + table->size - sizeof(*end), entry, entry->size); table->size += entry->size; - end = (struct grub_slr_entry_hdr *)((grub_uint8_t *)table + table->size - sizeof(*end)); + end = (struct grub_slr_entry_hdr *)((grub_uint8_t *) table + table->size - sizeof(*end)); end->tag = GRUB_SLR_ENTRY_END; end->size = sizeof(*end); @@ -288,7 +288,7 @@ grub_slr_init_table(struct grub_slr_table *slrt, grub_uint16_t architecture, slrt->architecture = architecture; slrt->size = sizeof(*slrt) + sizeof(*end); slrt->max_size = max_size; - end = (struct grub_slr_entry_hdr *)((grub_uint8_t *)slrt + sizeof(*slrt)); + end = (struct grub_slr_entry_hdr *)((grub_uint8_t *) slrt + sizeof(*slrt)); end->tag = GRUB_SLR_ENTRY_END; end->size = sizeof(*end); }