[meta-intel] [PATCH 1/2] systemd-boot: stub: use built-in RMC db only

Mikko Ylinen mikko.ylinen at linux.intel.com
Tue Feb 28 02:35:11 PST 2017


The v1 implementation that added RMC support in systemd-boot'
EFI stub openened the database file from EFI system partition.

This is a problem, e.g., with secure boot since the database
could be modified on ESP without the stub noticing it.

The v2 implementation moves to use RMC db that is built inside
the UEFI executable. With that the database cannot be modified
on the device.

Note: that also means the db becomes read-only and it cannot be
updated using the RMC utility directly on the device any more.

Fixes [YOCTO #11030].

Signed-off-by: Mikko Ylinen <mikko.ylinen at linux.intel.com>
---
 ...-kernel-command-line-fragment-in-EFI-stub.patch | 78 +++++++++++-----------
 1 file changed, 40 insertions(+), 38 deletions(-)

diff --git a/common/recipes-bsp/systemd-boot/systemd-boot/0004-sd-boot-Support-global-kernel-command-line-fragment-in-EFI-stub.patch b/common/recipes-bsp/systemd-boot/systemd-boot/0004-sd-boot-Support-global-kernel-command-line-fragment-in-EFI-stub.patch
index 7508269..fbb731d 100644
--- a/common/recipes-bsp/systemd-boot/systemd-boot/0004-sd-boot-Support-global-kernel-command-line-fragment-in-EFI-stub.patch
+++ b/common/recipes-bsp/systemd-boot/systemd-boot/0004-sd-boot-Support-global-kernel-command-line-fragment-in-EFI-stub.patch
@@ -1,6 +1,6 @@
-From 4cb9c65ea9c0eba3ba04d036dccd4a5ab3d2547b Mon Sep 17 00:00:00 2001
-From: Mikko Ylinen <mikko.ylinen at intel.com>
-Date: Fri, 27 Jan 2017 13:31:45 +0200
+From eaa8431c41a3a2379d789f0974588ed54d702f0a Mon Sep 17 00:00:00 2001
+From: Mikko Ylinen <mikko.ylinen at linux.intel.com>
+Date: Mon, 27 Feb 2017 13:38:35 +0200
 Subject: [PATCH] sd-boot: support global kernel command line in EFI stub
 
 This change integrates rmc into EFI stub and supports a
@@ -11,15 +11,19 @@ The fragment is board-specific and read from the database.
 
 Implements [YOCTO #10924].
 
+v2:
+Instead of reading the RMC db from ESP, use what's built in
+the UEFI executable. Fixes [YOCTO #11030].
+
 Upstream-status: Pending
 
-Signed-off-by: Mikko Ylinen <mikko.ylinen at intel.com>
+Signed-off-by: Mikko Ylinen <mikko.ylinen at linux.intel.com>
 ---
- src/boot/efi/stub.c | 33 +++++++++++++++++++++++++++++++++
- 1 file changed, 33 insertions(+)
+ src/boot/efi/stub.c | 31 +++++++++++++++++++++++++++++++
+ 1 file changed, 31 insertions(+)
 
 diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c
-index 1e250f34f..f3865199f 100644
+index 1e250f34f..a17e2ab66 100644
 --- a/src/boot/efi/stub.c
 +++ b/src/boot/efi/stub.c
 @@ -13,6 +13,7 @@
@@ -30,47 +34,45 @@ index 1e250f34f..f3865199f 100644
  
  #include "disk.h"
  #include "graphics.h"
-@@ -48,6 +49,9 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
-         UINTN cmdline_len;
-         CHAR16 uuid[37];
-         EFI_STATUS err;
-+        INTN len;
-+        CHAR8 *rmc_db = NULL;
-+        rmc_file_t rmc_file;
- 
-         InitializeLib(image, sys_table);
- 
-@@ -112,6 +116,35 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
+@@ -39,6 +40,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
+                 (UINT8 *)".linux",
+                 (UINT8 *)".initrd",
+                 (UINT8 *)".splash",
++                (UINT8 *)".rmc",
+                 NULL
+         };
+         UINTN addrs[ELEMENTSOF(sections)-1] = {};
+@@ -112,6 +114,35 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
  #endif
          }
  
-+        len = file_read(root_dir, L"\\rmc.db", 0, 0, &rmc_db);
-+        if (len <= 0)
-+                rmc_db = NULL;
++        if (szs[4] > 0) {
++                CHAR8 *rmc_db;
++                rmc_file_t rmc_file;
 +
-+        /* If the board has a fragment in rmc database, append it to the cmdline */
-+        if (rmc_db && !rmc_gimme_file(sys_table, rmc_db, "KBOOTPARAM", &rmc_file)) {
-+                CHAR8 *line;
-+                UINTN i = 0;
-+                UINTN j;
++                rmc_db = (CHAR8 *)(loaded_image->ImageBase + addrs[4]);
 +
-+                line = AllocatePool(rmc_file.blob_len + cmdline_len + 2);
++                if (!rmc_gimme_file(sys_table, rmc_db, "KBOOTPARAM", &rmc_file)) {
++                        CHAR8 *line;
++                        UINTN i = 0;
++                        UINTN j;
 +
-+                while (i < cmdline_len && cmdline[i] != '\0') {
-+                        line[i] = cmdline[i];
-+                        i++;
-+                }
++                        line = AllocatePool(rmc_file.blob_len + cmdline_len + 2);
 +
-+                line[i++] = ' ';
++                        while (i < cmdline_len && cmdline[i] != '\0') {
++                                line[i] = cmdline[i];
++                                i++;
++                        }
 +
-+                for (j=0; j < rmc_file.blob_len; j++)
-+                        line[i+j] = rmc_file.blob[j];
-+                line[i+j] = '\0';
++                        line[i++] = ' ';
 +
-+                cmdline = line;
-+                cmdline_len = i + j;
++                        for (j=0; j < rmc_file.blob_len; j++)
++                                line[i+j] = rmc_file.blob[j];
++                        line[i+j] = '\0';
 +
-+                FreePool(rmc_db);
++                        cmdline = line;
++                        cmdline_len = i + j;
++                }
 +        }
 +
          /* export the device path this image is started from */
-- 
2.11.0



More information about the meta-intel mailing list