Skip to content

Commit 960a8d0

Browse files
ardbiesheuvelIngo Molnar
authored andcommitted
efi/libstub: Use stricter typing for firmware function pointers
We will soon remove another level of pointer casting, so let's make sure all type handling involving firmware calls at boot time is correct. Signed-off-by: Ard Biesheuvel <[email protected]> Cc: Arvind Sankar <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: James Morse <[email protected]> Cc: Matt Fleming <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent e8bd5dd commit 960a8d0

File tree

7 files changed

+28
-18
lines changed

7 files changed

+28
-18
lines changed

arch/x86/boot/compressed/eboot.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ preserve_pci_rom_image(efi_pci_io_protocol_t *pci, struct pci_setup_rom **__rom)
7070

7171
size = romsize + sizeof(*rom);
7272

73-
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size, &rom);
73+
status = efi_call_early(allocate_pool, EFI_LOADER_DATA, size,
74+
(void **)&rom);
7475
if (status != EFI_SUCCESS) {
7576
efi_printk(sys_table, "Failed to allocate memory for 'rom'\n");
7677
return status;
@@ -195,9 +196,9 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
195196
struct setup_data *data, *new;
196197
efi_status_t status;
197198
u32 size = 0;
198-
void *p;
199+
apple_properties_protocol_t *p;
199200

200-
status = efi_call_early(locate_protocol, &guid, NULL, &p);
201+
status = efi_call_early(locate_protocol, &guid, NULL, (void **)&p);
201202
if (status != EFI_SUCCESS)
202203
return;
203204

@@ -212,7 +213,8 @@ static void retrieve_apple_device_properties(struct boot_params *boot_params)
212213

213214
do {
214215
status = efi_call_early(allocate_pool, EFI_LOADER_DATA,
215-
size + sizeof(struct setup_data), &new);
216+
size + sizeof(struct setup_data),
217+
(void **)&new);
216218
if (status != EFI_SUCCESS) {
217219
efi_printk(sys_table, "Failed to allocate memory for 'properties'\n");
218220
return;

arch/x86/boot/compressed/eboot.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212

1313
#define DESC_TYPE_CODE_DATA (1 << 0)
1414

15-
typedef union {
15+
typedef union efi_uga_draw_protocol efi_uga_draw_protocol_t;
16+
17+
union efi_uga_draw_protocol {
1618
struct {
17-
void *get_mode;
19+
efi_status_t (*get_mode)(efi_uga_draw_protocol_t *,
20+
u32*, u32*, u32*, u32*);
1821
void *set_mode;
1922
void *blt;
2023
};
@@ -23,6 +26,6 @@ typedef union {
2326
u32 set_mode;
2427
u32 blt;
2528
} mixed_mode;
26-
} efi_uga_draw_protocol_t;
29+
};
2730

2831
#endif /* BOOT_COMPRESSED_EBOOT_H */

arch/x86/platform/efi/efi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static int __init efi_systab_init(void *phys)
385385
tmp |= systab64->con_in;
386386
efi_systab.con_out_handle = systab64->con_out_handle;
387387
tmp |= systab64->con_out_handle;
388-
efi_systab.con_out = systab64->con_out;
388+
efi_systab.con_out = (void *)(unsigned long)systab64->con_out;
389389
tmp |= systab64->con_out;
390390
efi_systab.stderr_handle = systab64->stderr_handle;
391391
tmp |= systab64->stderr_handle;
@@ -427,7 +427,7 @@ static int __init efi_systab_init(void *phys)
427427
efi_systab.con_in_handle = systab32->con_in_handle;
428428
efi_systab.con_in = systab32->con_in;
429429
efi_systab.con_out_handle = systab32->con_out_handle;
430-
efi_systab.con_out = systab32->con_out;
430+
efi_systab.con_out = (void *)(unsigned long)systab32->con_out;
431431
efi_systab.stderr_handle = systab32->stderr_handle;
432432
efi_systab.stderr = systab32->stderr;
433433
efi_systab.runtime = (void *)(unsigned long)systab32->runtime;

arch/x86/xen/efi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static efi_system_table_t efi_systab_xen __initdata = {
3131
.con_in_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
3232
.con_in = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
3333
.con_out_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
34-
.con_out = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
34+
.con_out = NULL, /* Not used under Xen. */
3535
.stderr_handle = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
3636
.stderr = EFI_INVALID_TABLE_ADDR, /* Not used under Xen. */
3737
.runtime = (efi_runtime_services_t *)EFI_INVALID_TABLE_ADDR,

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,13 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
413413
return status;
414414
}
415415

416-
static efi_status_t efi_file_read(void *handle, unsigned long *size, void *addr)
416+
static efi_status_t efi_file_read(efi_file_handle_t *handle,
417+
unsigned long *size, void *addr)
417418
{
418419
return efi_call_proto(efi_file_handle, read, handle, size, addr);
419420
}
420421

421-
static efi_status_t efi_file_close(void *handle)
422+
static efi_status_t efi_file_close(efi_file_handle_t *handle)
422423
{
423424
return efi_call_proto(efi_file_handle, close, handle);
424425
}

drivers/firmware/efi/libstub/tpm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ void efi_retrieve_tpm2_eventlog(efi_system_table_t *sys_table_arg)
6969
size_t log_size, last_entry_size;
7070
efi_bool_t truncated;
7171
int version = EFI_TCG2_EVENT_LOG_FORMAT_TCG_2;
72-
void *tcg2_protocol = NULL;
72+
efi_tcg2_protocol_t *tcg2_protocol = NULL;
7373
int final_events_size = 0;
7474

7575
status = efi_call_early(locate_protocol, &tcg2_guid, NULL,
76-
&tcg2_protocol);
76+
(void **)&tcg2_protocol);
7777
if (status != EFI_SUCCESS)
7878
return;
7979

include/linux/efi.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,11 @@ union efi_pci_io_protocol {
382382
void *allocate_buffer;
383383
void *free_buffer;
384384
void *flush;
385-
void *get_location;
385+
efi_status_t (*get_location)(efi_pci_io_protocol_t *,
386+
unsigned long *segment_nr,
387+
unsigned long *bus_nr,
388+
unsigned long *device_nr,
389+
unsigned long *function_nr);
386390
void *attributes;
387391
void *get_bar_attributes;
388392
void *set_bar_attributes;
@@ -730,6 +734,8 @@ typedef struct {
730734
u32 tables;
731735
} efi_system_table_32_t;
732736

737+
typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
738+
733739
typedef union {
734740
struct {
735741
efi_table_hdr_t hdr;
@@ -738,7 +744,7 @@ typedef union {
738744
unsigned long con_in_handle;
739745
unsigned long con_in;
740746
unsigned long con_out_handle;
741-
unsigned long con_out;
747+
efi_simple_text_output_protocol_t *con_out;
742748
unsigned long stderr_handle;
743749
unsigned long stderr;
744750
efi_runtime_services_t *runtime;
@@ -1337,8 +1343,6 @@ struct efivar_entry {
13371343
bool deleting;
13381344
};
13391345

1340-
typedef union efi_simple_text_output_protocol efi_simple_text_output_protocol_t;
1341-
13421346
union efi_simple_text_output_protocol {
13431347
struct {
13441348
void *reset;

0 commit comments

Comments
 (0)