From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
hdegoede@redhat.com, nivedita@alum.mit.edu, x86@kernel.org
Subject: [PATCH v3 3/6] efi/libstub/x86: Make loaded_image protocol handling mixed mode safe
Date: Sat, 22 Feb 2020 16:55:16 +0100 [thread overview]
Message-ID: <20200222155519.23550-4-ardb@kernel.org> (raw)
In-Reply-To: <20200222155519.23550-1-ardb@kernel.org>
Add the definitions and use the special wrapper so that the loaded_image
UEFI protocol can be safely used from mixed mode.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
drivers/firmware/efi/libstub/efi-stub-helper.c | 4 +-
drivers/firmware/efi/libstub/efistub.h | 45 ++++++++++++++------
drivers/firmware/efi/libstub/x86-stub.c | 4 +-
3 files changed, 35 insertions(+), 18 deletions(-)
diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index b1da58141a4d..9f34c7242939 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -171,8 +171,8 @@ char *efi_convert_cmdline(efi_loaded_image_t *image,
const u16 *s2;
u8 *s1 = NULL;
unsigned long cmdline_addr = 0;
- int load_options_chars = image->load_options_size / 2; /* UTF-16 */
- const u16 *options = image->load_options;
+ int load_options_chars = efi_table_attr(image, load_options_size) / 2;
+ const u16 *options = efi_table_attr(image, load_options);
int options_bytes = 0; /* UTF-8 bytes */
int options_chars = 0; /* UTF-16 chars */
efi_status_t status;
diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h
index 2e5e79edb4d7..6960e730f990 100644
--- a/drivers/firmware/efi/libstub/efistub.h
+++ b/drivers/firmware/efi/libstub/efistub.h
@@ -308,20 +308,37 @@ union efi_graphics_output_protocol {
} mixed_mode;
};
-typedef struct {
- u32 revision;
- efi_handle_t parent_handle;
- efi_system_table_t *system_table;
- efi_handle_t device_handle;
- void *file_path;
- void *reserved;
- u32 load_options_size;
- void *load_options;
- void *image_base;
- __aligned_u64 image_size;
- unsigned int image_code_type;
- unsigned int image_data_type;
- efi_status_t (__efiapi *unload)(efi_handle_t image_handle);
+typedef union {
+ struct {
+ u32 revision;
+ efi_handle_t parent_handle;
+ efi_system_table_t *system_table;
+ efi_handle_t device_handle;
+ void *file_path;
+ void *reserved;
+ u32 load_options_size;
+ void *load_options;
+ void *image_base;
+ __aligned_u64 image_size;
+ unsigned int image_code_type;
+ unsigned int image_data_type;
+ efi_status_t (__efiapi *unload)(efi_handle_t image_handle);
+ };
+ 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;
+ u32 image_code_type;
+ u32 image_data_type;
+ u32 unload;
+ } mixed_mode;
} efi_loaded_image_t;
typedef struct {
diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmware/efi/libstub/x86-stub.c
index 7d4866471f86..ce0c3caa3087 100644
--- a/drivers/firmware/efi/libstub/x86-stub.c
+++ b/drivers/firmware/efi/libstub/x86-stub.c
@@ -377,7 +377,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
return status;
}
- hdr = &((struct boot_params *)image->image_base)->hdr;
+ hdr = &((struct boot_params *)efi_table_attr(image, image_base))->hdr;
above4g = hdr->xloadflags & XLF_CAN_BE_LOADED_ABOVE_4G;
status = efi_allocate_pages(0x4000, (unsigned long *)&boot_params,
@@ -392,7 +392,7 @@ efi_status_t __efiapi efi_pe_entry(efi_handle_t handle,
hdr = &boot_params->hdr;
/* Copy the second sector to boot_params */
- memcpy(&hdr->jump, image->image_base + 512, 512);
+ memcpy(&hdr->jump, efi_table_attr(image, image_base) + 512, 512);
/*
* Fill out some of the header fields ourselves because the
--
2.17.1
next prev parent reply other threads:[~2020-02-22 15:56 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-22 15:55 [PATCH v3 0/6] efi/x86: add support for generic EFI mixed mode boot Ard Biesheuvel
2020-02-22 15:55 ` [PATCH v3 1/6] efi/x86: add headroom to decompressor BSS to account for setup block Ard Biesheuvel
2020-02-22 15:55 ` [PATCH v3 2/6] efi/x86: Drop redundant .bss section Ard Biesheuvel
2020-02-22 15:55 ` Ard Biesheuvel [this message]
2020-02-22 15:55 ` [PATCH v3 4/6] efi/libstub/x86: Use Exit() boot service to exit the stub on errors Ard Biesheuvel
2020-02-22 15:55 ` [PATCH v3 5/6] efi/x86: Implement mixed mode boot without the handover protocol Ard Biesheuvel
2020-02-22 15:55 ` [PATCH v3 6/6] efi/x86: Add true mixed mode entry point into .compat section Ard Biesheuvel
2020-03-01 17:15 ` [PATCH v3 0/6] efi/x86: add support for generic EFI mixed mode boot Arvind Sankar
2020-03-01 17:22 ` Arvind Sankar
2020-03-01 19:36 ` Ard Biesheuvel
2020-03-01 20:00 ` Arvind Sankar
2020-03-01 20:02 ` Ard Biesheuvel
2020-03-01 20:20 ` Ard Biesheuvel
2020-03-01 20:41 ` Ard Biesheuvel
2020-03-01 20:54 ` Arvind Sankar
2020-03-01 21:36 ` Ard Biesheuvel
2020-03-01 22:01 ` Arvind Sankar
2020-03-01 22:56 ` Ard Biesheuvel
2020-03-01 23:03 ` Arvind Sankar
2020-03-02 12:14 ` Ard Biesheuvel
2020-03-03 4:19 ` Arvind Sankar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200222155519.23550-4-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=hdegoede@redhat.com \
--cc=linux-efi@vger.kernel.org \
--cc=nivedita@alum.mit.edu \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).