Commit 14e900c7 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Ingo Molnar

efi/libstub: Avoid protocol wrapper for file I/O routines

The EFI file I/O routines built on top of the file I/O firmware
services are incompatible with mixed mode, so there is no need
to obfuscate them by using protocol wrappers whose only purpose
is to hide the mixed mode handling. So let's switch to plain
indirect calls instead.

This also means we can drop the mixed_mode aliases from the various
types involved.
Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Cc: Arvind Sankar <nivedita@alum.mit.edu>
Cc: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>
Cc: Matt Fleming <matt@codeblueprint.co.uk>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-efi@vger.kernel.org
Link: https://lkml.kernel.org/r/20191224151025.32482-15-ardb@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent afc4cc71
...@@ -370,8 +370,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, ...@@ -370,8 +370,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
efi_guid_t info_guid = EFI_FILE_INFO_ID; efi_guid_t info_guid = EFI_FILE_INFO_ID;
unsigned long info_sz; unsigned long info_sz;
status = efi_call_proto(efi_file_handle, open, fh, &h, filename_16, status = fh->open(fh, &h, filename_16, EFI_FILE_MODE_READ, 0);
EFI_FILE_MODE_READ, (u64)0);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
efi_printk(sys_table_arg, "Failed to open file: "); efi_printk(sys_table_arg, "Failed to open file: ");
efi_char16_printk(sys_table_arg, filename_16); efi_char16_printk(sys_table_arg, filename_16);
...@@ -382,8 +381,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, ...@@ -382,8 +381,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
*handle = h; *handle = h;
info_sz = 0; info_sz = 0;
status = efi_call_proto(efi_file_handle, get_info, h, &info_guid, status = h->get_info(h, &info_guid, &info_sz, NULL);
&info_sz, NULL);
if (status != EFI_BUFFER_TOO_SMALL) { if (status != EFI_BUFFER_TOO_SMALL) {
efi_printk(sys_table_arg, "Failed to get file info size\n"); efi_printk(sys_table_arg, "Failed to get file info size\n");
return status; return status;
...@@ -397,8 +395,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, ...@@ -397,8 +395,7 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
return status; return status;
} }
status = efi_call_proto(efi_file_handle, get_info, h, &info_guid, status = h->get_info(h, &info_guid, &info_sz, info);
&info_sz, info);
if (status == EFI_BUFFER_TOO_SMALL) { if (status == EFI_BUFFER_TOO_SMALL) {
efi_call_early(free_pool, info); efi_call_early(free_pool, info);
goto grow; goto grow;
...@@ -416,12 +413,12 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh, ...@@ -416,12 +413,12 @@ static efi_status_t efi_file_size(efi_system_table_t *sys_table_arg, void *__fh,
static efi_status_t efi_file_read(efi_file_handle_t *handle, static efi_status_t efi_file_read(efi_file_handle_t *handle,
unsigned long *size, void *addr) unsigned long *size, void *addr)
{ {
return efi_call_proto(efi_file_handle, read, handle, size, addr); return handle->read(handle, size, addr);
} }
static efi_status_t efi_file_close(efi_file_handle_t *handle) static efi_status_t efi_file_close(efi_file_handle_t *handle)
{ {
return efi_call_proto(efi_file_handle, close, handle); return handle->close(handle);
} }
static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
...@@ -432,7 +429,7 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, ...@@ -432,7 +429,7 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
efi_file_handle_t *fh; efi_file_handle_t *fh;
efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID; efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
efi_status_t status; efi_status_t status;
void *handle = efi_table_attr(efi_loaded_image, device_handle, image); efi_handle_t handle = image->device_handle;
status = efi_call_early(handle_protocol, handle, status = efi_call_early(handle_protocol, handle,
&fs_proto, (void **)&io); &fs_proto, (void **)&io);
...@@ -441,7 +438,7 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg, ...@@ -441,7 +438,7 @@ static efi_status_t efi_open_volume(efi_system_table_t *sys_table_arg,
return status; return status;
} }
status = efi_call_proto(efi_file_io_interface, open_volume, io, &fh); status = io->open_volume(io, &fh);
if (status != EFI_SUCCESS) if (status != EFI_SUCCESS)
efi_printk(sys_table_arg, "Failed to open volume\n"); efi_printk(sys_table_arg, "Failed to open volume\n");
else else
......
...@@ -806,10 +806,7 @@ struct efi_fdt_params { ...@@ -806,10 +806,7 @@ struct efi_fdt_params {
u32 desc_ver; u32 desc_ver;
}; };
typedef union efi_loaded_image efi_loaded_image_t; typedef struct {
union efi_loaded_image {
struct {
u32 revision; u32 revision;
efi_handle_t parent_handle; efi_handle_t parent_handle;
efi_system_table_t *system_table; efi_system_table_t *system_table;
...@@ -823,23 +820,7 @@ union efi_loaded_image { ...@@ -823,23 +820,7 @@ union efi_loaded_image {
unsigned int image_code_type; unsigned int image_code_type;
unsigned int image_data_type; unsigned int image_data_type;
efi_status_t ( __efiapi *unload)(efi_handle_t image_handle); efi_status_t ( __efiapi *unload)(efi_handle_t image_handle);
}; } efi_loaded_image_t;
struct {
u32 revision;
u32 parent_handle;
u32 system_table;
u32 device_handle;
u32 file_path;
u32 reserved;
u32 load_options_size;
u32 load_options;
u32 image_base;
__aligned_u64 image_size;
unsigned int image_code_type;
unsigned int image_data_type;
u32 unload;
} mixed_mode;
};
typedef struct { typedef struct {
u64 size; u64 size;
...@@ -852,10 +833,9 @@ typedef struct { ...@@ -852,10 +833,9 @@ typedef struct {
efi_char16_t filename[1]; efi_char16_t filename[1];
} efi_file_info_t; } efi_file_info_t;
typedef union efi_file_handle efi_file_handle_t; typedef struct efi_file_handle efi_file_handle_t;
union efi_file_handle { struct efi_file_handle {
struct {
u64 revision; u64 revision;
efi_status_t (__efiapi *open)(efi_file_handle_t *, efi_status_t (__efiapi *open)(efi_file_handle_t *,
efi_file_handle_t **, efi_file_handle_t **,
...@@ -872,34 +852,14 @@ union efi_file_handle { ...@@ -872,34 +852,14 @@ union efi_file_handle {
void *); void *);
void *set_info; void *set_info;
void *flush; void *flush;
};
struct {
u64 revision;
u32 open;
u32 close;
u32 delete;
u32 read;
u32 write;
u32 get_position;
u32 set_position;
u32 get_info;
u32 set_info;
u32 flush;
} mixed_mode;
}; };
typedef union efi_file_io_interface efi_file_io_interface_t; typedef struct efi_file_io_interface efi_file_io_interface_t;
union efi_file_io_interface { struct efi_file_io_interface {
struct {
u64 revision; u64 revision;
int (__efiapi *open_volume)(efi_file_io_interface_t *, int (__efiapi *open_volume)(efi_file_io_interface_t *,
efi_file_handle_t **); efi_file_handle_t **);
};
struct {
u64 revision;
u32 open_volume;
} mixed_mode;
}; };
#define EFI_FILE_MODE_READ 0x0000000000000001 #define EFI_FILE_MODE_READ 0x0000000000000001
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment