grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
To: grub-devel@gnu.org
Cc: dja@axtens.net, jan.setjeeilers@oracle.com,
	julian.klode@canonical.com, mate.kukri@canonical.com,
	pjones@redhat.com, msuchanek@suse.com, mlewando@redhat.com,
	stefanb@linux.ibm.com, avnish@linux.ibm.com, nayna@linux.ibm.com,
	ssrish@linux.ibm.com, Sudhakar Kuppusamy <sudhakar@linux.ibm.com>,
	sridharm@linux.ibm.com
Subject: [PATCH v8 15/20] appended signatures: Read default db keys from the ELF Note
Date: Thu, 21 Aug 2025 13:25:08 +0530	[thread overview]
Message-ID: <20250821075513.82881-16-sudhakar@linux.ibm.com> (raw)
In-Reply-To: <20250821075513.82881-1-sudhakar@linux.ibm.com>

If Secure Boot is enabled with dynamic key management mode and the
use_static_keys flag is set, then read the static keys as a db default
keys from the ELF Note and add them into the db.

Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
---
 grub-core/commands/appendedsig/appendedsig.c | 42 ++++++++++++++------
 1 file changed, 30 insertions(+), 12 deletions(-)

diff --git a/grub-core/commands/appendedsig/appendedsig.c b/grub-core/commands/appendedsig/appendedsig.c
index b6cd9af32..146017867 100644
--- a/grub-core/commands/appendedsig/appendedsig.c
+++ b/grub-core/commands/appendedsig/appendedsig.c
@@ -1200,7 +1200,8 @@ build_static_db_list (void)
   grub_err_t err;
   struct grub_module_header *header;
   struct grub_file pseudo_file;
-  struct x509_certificate *cert;
+  grub_uint8_t *cert_data = NULL;
+  grub_size_t cert_data_size = 0;
 
   FOR_MODULES (header)
     {
@@ -1216,22 +1217,25 @@ build_static_db_list (void)
       grub_dprintf ("appendedsig", "found an X.509 certificate, size=%" PRIuGRUB_UINT64_T "\n",
                     pseudo_file.size);
 
-      err = read_cert_from_file (&pseudo_file, &cert);
+      err = file_read_whole (&pseudo_file, &cert_data, &cert_data_size);
       if (err == GRUB_ERR_OUT_OF_MEMORY)
-        return;
+        break;
       else if (err != GRUB_ERR_NONE)
+        continue;
+
+      if (grub_pks_use_keystore == true)
         {
-          grub_dprintf ("appendedsig",
-                        "warning: cannot add a certificate %u to the db list\n",
-                        db.cert_entries + 1);
-          continue;
+          if (is_dbx_cert_hash (cert_data, cert_data_size) == true)
+            {
+              grub_free (cert_data);
+              continue;
+            }
         }
 
-      grub_dprintf ("appendedsig", "add a certificate CN='%s' to db\n", cert->subject);
-
-      cert->next = db.certs;
-      db.certs = cert;
-      db.cert_entries++;
+      err = add_certificate (cert_data, cert_data_size, &db, true);
+      grub_free (cert_data);
+      if (err == GRUB_ERR_OUT_OF_MEMORY)
+        break;
     }
 }
 
@@ -1248,6 +1252,20 @@ build_pks_keystore (void)
   if (err != GRUB_ERR_NONE)
     grub_printf ("warning: db list might not be fully populated\n");
 
+  if (grub_pks_keystore.use_static_keys == true)
+    {
+      grub_dprintf ("appendedsig", "db variable is not available at PKS and "
+                    "using a static keys as a default key in db list\n");
+    }
+
+  build_static_db_list ();
+  if (grub_pks_keystore.use_static_keys == false)
+    {
+      err = create_db_list ();
+      if (err != GRUB_ERR_NONE)
+        grub_dprintf ("appendedsig", "warning: db list might not be fully populated\n");
+    }
+
   err = create_dbx_list ();
   if (err != GRUB_ERR_NONE)
     grub_printf ("warning: dbx list might not be fully populated\n");
-- 
2.39.5 (Apple Git-154)


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

  parent reply	other threads:[~2025-08-21  7:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-21  7:54 [PATCH v8 00/20] Appended Signature Secure Boot Support for PowerPC Sudhakar Kuppusamy
2025-08-21  7:54 ` [PATCH v8 01/20] powerpc-ieee1275: Add support for signing GRUB with an appended signature Sudhakar Kuppusamy
2025-08-21  7:54 ` [PATCH v8 02/20] crypto: Move storage for grub_crypto_pk_* to crypto.c Sudhakar Kuppusamy
2025-08-21  7:54 ` [PATCH v8 03/20] pgp: Rename OBJ_TYPE_PUBKEY to OBJ_TYPE_GPG_PUBKEY Sudhakar Kuppusamy
2025-08-21  7:54 ` [PATCH v8 04/20] grub-install: Support embedding x509 certificates Sudhakar Kuppusamy
2025-08-21  7:54 ` [PATCH v8 05/20] appended signatures: Import GNUTLS's ASN.1 description files Sudhakar Kuppusamy
2025-08-21  7:54 ` [PATCH v8 06/20] appended signatures: Parse ASN1 node Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 07/20] appended signatures: Parse PKCS#7 signedData Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 08/20] appended signatures: Parse X.509 certificates Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 09/20] powerpc_ieee1275: Enter lockdown based on /ibm, secure-boot Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 10/20] appended signatures: Support verifying appended signatures Sudhakar Kuppusamy
2025-08-21 15:23   ` Daniel Kiper
2025-08-22 15:30     ` Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 11/20] powerpc_ieee1275: Read the db and dbx secure boot variables Sudhakar Kuppusamy
2025-08-22 18:53   ` Daniel Kiper
2025-08-23  6:53     ` Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 12/20] appended signatures: Create db and dbx lists Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 13/20] appended signatures: Using db and dbx lists for signature verification Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 14/20] powerpc_ieee1275: Introduce use_static_keys flag Sudhakar Kuppusamy
2025-08-21  7:55 ` Sudhakar Kuppusamy [this message]
2025-08-21  7:55 ` [PATCH v8 16/20] appended signatures: Introduce GRUB commands to access db and dbx Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 17/20] appended signatures: Verification tests Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 18/20] docs/grub: Document signing GRUB under UEFI Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 19/20] docs/grub: Document signing GRUB with an appended signature Sudhakar Kuppusamy
2025-08-21  7:55 ` [PATCH v8 20/20] docs/grub: Document " Sudhakar Kuppusamy

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=20250821075513.82881-16-sudhakar@linux.ibm.com \
    --to=sudhakar@linux.ibm.com \
    --cc=avnish@linux.ibm.com \
    --cc=dja@axtens.net \
    --cc=grub-devel@gnu.org \
    --cc=jan.setjeeilers@oracle.com \
    --cc=julian.klode@canonical.com \
    --cc=mate.kukri@canonical.com \
    --cc=mlewando@redhat.com \
    --cc=msuchanek@suse.com \
    --cc=nayna@linux.ibm.com \
    --cc=pjones@redhat.com \
    --cc=sridharm@linux.ibm.com \
    --cc=ssrish@linux.ibm.com \
    --cc=stefanb@linux.ibm.com \
    /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).