8e6824ec91
We add patches to fix CVEs for grub instead of upgrading because grub2/grub-efi is ported from yocto for secure boot bringing up. The patches for CVE-2022-28736 have conflicts with the patches for secure boot. So refer to below link to fix this CVE: (1) https://patchwork.yoctoproject.org/project/oe-core/patch/ 20221207034254.58292-1-xiangyu.chen@eng.windriver.com/ (2)https://github.com/jiazhang0/meta-secure-core/pull/257 The special patches for grub-efi are from layers meta-lat and meta-secure-core of yocto upstream, which are based on the patches for grub-efi in oe-core layer (including CVE patches). We used to mix all the patches together. Now we will move the patches from meta-lat and meta-secure-core to the end of sequence for applying patches, so that we can keep align with yocto upstream and make it easier to maintain the grub here. Since there are many patches involved here, we don't change the number in patches' name in case confusion is caused if we rename many files. Below commits are added for the CVE: <loader/efi/chainloader: Simplify the loader state> <commands/boot: Add API to pass context to loader> <loader/efi/chainloader: Use grub_loader_set_ex()> Below patches for secure boot are adapted for conflicts with above: secure-core/0009 <efi: chainloader: port shim to grub> secure-core/0010 <efi: chainloader: use shim to load and verify an image> secure-core/0012 <efi: chainloader: take care of unload undershim> All of them are aligned with upstream and no changes here. Test plan: - PASS: build grub2/grub-efi. - PASS: build-image and install and boot up on lab/qemu. - PASS: check that the "stx.N" version number is right for both bios(grub2 ver) and uefi(grub-efi ver) boot. - PASS: the tests are done on lab with secure boot disabled and enabled. Closes-Bug: #2034119 Signed-off-by: Li Zhou <li.zhou@windriver.com> Change-Id: I9a37cd8b804b238407f8ac6528f087a2eb0cf2de
130 lines
4.0 KiB
Diff
130 lines
4.0 KiB
Diff
From 1469983ebb9674753ad333d37087fb8cb20e1dce Mon Sep 17 00:00:00 2001
|
|
From: Chris Coulson <chris.coulson@canonical.com>
|
|
Date: Tue, 5 Apr 2022 10:02:04 +0100
|
|
Subject: [PATCH] loader/efi/chainloader: Simplify the loader state
|
|
|
|
The chainloader command retains the source buffer and device path passed
|
|
to LoadImage(), requiring the unload hook passed to grub_loader_set() to
|
|
free them. It isn't required to retain this state though - they aren't
|
|
required by StartImage() or anything else in the boot hook, so clean them
|
|
up before grub_cmd_chainloader() finishes.
|
|
|
|
Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
|
|
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
|
Upstream-Status: Backport
|
|
|
|
Reference to upstream patch:
|
|
https://git.savannah.gnu.org/cgit/grub.git/commit/?id=1469983ebb9674753ad333d37087fb8cb20e1dce
|
|
|
|
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
|
|
---
|
|
grub-core/loader/efi/chainloader.c | 38 +++++++++++++++++-------------
|
|
1 file changed, 21 insertions(+), 17 deletions(-)
|
|
|
|
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
|
|
index 2bd80f4db..d1602c89b 100644
|
|
--- a/grub-core/loader/efi/chainloader.c
|
|
+++ b/grub-core/loader/efi/chainloader.c
|
|
@@ -44,25 +44,20 @@ GRUB_MOD_LICENSE ("GPLv3+");
|
|
|
|
static grub_dl_t my_mod;
|
|
|
|
-static grub_efi_physical_address_t address;
|
|
-static grub_efi_uintn_t pages;
|
|
-static grub_efi_device_path_t *file_path;
|
|
static grub_efi_handle_t image_handle;
|
|
-static grub_efi_char16_t *cmdline;
|
|
|
|
static grub_err_t
|
|
grub_chainloader_unload (void)
|
|
{
|
|
+ grub_efi_loaded_image_t *loaded_image;
|
|
grub_efi_boot_services_t *b;
|
|
|
|
+ loaded_image = grub_efi_get_loaded_image (image_handle);
|
|
+ if (loaded_image != NULL)
|
|
+ grub_free (loaded_image->load_options);
|
|
+
|
|
b = grub_efi_system_table->boot_services;
|
|
efi_call_1 (b->unload_image, image_handle);
|
|
- efi_call_2 (b->free_pages, address, pages);
|
|
-
|
|
- grub_free (file_path);
|
|
- grub_free (cmdline);
|
|
- cmdline = 0;
|
|
- file_path = 0;
|
|
|
|
grub_dl_unref (my_mod);
|
|
return GRUB_ERR_NONE;
|
|
@@ -140,7 +135,7 @@ make_file_path (grub_efi_device_path_t *dp, const char *filename)
|
|
char *dir_start;
|
|
char *dir_end;
|
|
grub_size_t size;
|
|
- grub_efi_device_path_t *d;
|
|
+ grub_efi_device_path_t *d, *file_path;
|
|
|
|
dir_start = grub_strchr (filename, ')');
|
|
if (! dir_start)
|
|
@@ -222,11 +217,14 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
|
grub_efi_status_t status;
|
|
grub_efi_boot_services_t *b;
|
|
grub_device_t dev = 0;
|
|
- grub_efi_device_path_t *dp = 0;
|
|
+ grub_efi_device_path_t *dp = NULL, *file_path = NULL;
|
|
grub_efi_loaded_image_t *loaded_image;
|
|
char *filename;
|
|
void *boot_image = 0;
|
|
grub_efi_handle_t dev_handle = 0;
|
|
+ grub_efi_physical_address_t address = 0;
|
|
+ grub_efi_uintn_t pages = 0;
|
|
+ grub_efi_char16_t *cmdline = NULL;
|
|
|
|
if (argc == 0)
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
|
|
@@ -234,11 +232,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
|
|
|
grub_dl_ref (my_mod);
|
|
|
|
- /* Initialize some global variables. */
|
|
- address = 0;
|
|
- image_handle = 0;
|
|
- file_path = 0;
|
|
-
|
|
b = grub_efi_system_table->boot_services;
|
|
|
|
file = grub_file_open (filename, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE);
|
|
@@ -408,6 +401,10 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
|
grub_file_close (file);
|
|
grub_device_close (dev);
|
|
|
|
+ /* We're finished with the source image buffer and file path now. */
|
|
+ efi_call_2 (b->free_pages, address, pages);
|
|
+ grub_free (file_path);
|
|
+
|
|
grub_loader_set (grub_chainloader_boot, grub_chainloader_unload, 0);
|
|
return 0;
|
|
|
|
@@ -419,11 +416,18 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
|
|
if (file)
|
|
grub_file_close (file);
|
|
|
|
+ grub_free (cmdline);
|
|
grub_free (file_path);
|
|
|
|
if (address)
|
|
efi_call_2 (b->free_pages, address, pages);
|
|
|
|
+ if (image_handle != NULL)
|
|
+ {
|
|
+ efi_call_1 (b->unload_image, image_handle);
|
|
+ image_handle = NULL;
|
|
+ }
|
|
+
|
|
grub_dl_unref (my_mod);
|
|
|
|
return grub_errno;
|
|
--
|
|
2.34.1
|
|
|