From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
To: grub-devel@gnu.org
Cc: jan.setjeeilers@oracle.com, julian.klode@canonical.com,
mate.kukri@canonical.com, pjones@redhat.com, msuchanek@suse.com,
mlewando@redhat.com, nayna@linux.ibm.com,
ltcgcw@linux.vnet.ibm.com, ssrish@linux.ibm.com,
stefanb@linux.ibm.com, avnish@linux.ibm.com,
Sudhakar Kuppusamy <sudhakar@linux.ibm.com>,
dja@axtens.net, "Alastair D'Silva" <alastair@d-silva.org>,
Daniel Kiper <daniel.kiper@oracle.com>
Subject: [PATCH v4 07/23] grub-install: Support embedding x509 certificates
Date: Wed, 9 Jul 2025 17:15:24 +0530 [thread overview]
Message-ID: <20250709114540.58608-8-sudhakar@linux.ibm.com> (raw)
In-Reply-To: <20250709114540.58608-1-sudhakar@linux.ibm.com>
To support verification of appended signatures, we need a way to
embed the necessary public keys. Existing appended signature schemes
in the Linux kernel use X.509 certificates, so allow certificates to
be embedded in the GRUB core image in the same way as PGP keys.
Signed-off-by: Alastair D'Silva <alastair@d-silva.org>
Signed-off-by: Daniel Axtens <dja@axtens.net>
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>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
include/grub/kernel.h | 1 +
include/grub/util/install.h | 3 +++
util/grub-install-common.c | 19 +++++++++++++++++-
util/grub-mkimage.c | 12 +++++++++++-
util/mkimage.c | 39 ++++++++++++++++++++++++++++++++++++-
5 files changed, 71 insertions(+), 3 deletions(-)
diff --git a/include/grub/kernel.h b/include/grub/kernel.h
index 885289f5d..9f3e2031f 100644
--- a/include/grub/kernel.h
+++ b/include/grub/kernel.h
@@ -29,6 +29,7 @@ enum
OBJ_TYPE_CONFIG,
OBJ_TYPE_PREFIX,
OBJ_TYPE_GPG_PUBKEY,
+ OBJ_TYPE_X509_PUBKEY,
OBJ_TYPE_DTB,
OBJ_TYPE_DISABLE_SHIM_LOCK,
OBJ_TYPE_DISABLE_CLI
diff --git a/include/grub/util/install.h b/include/grub/util/install.h
index 5b6e645ca..d64e194e3 100644
--- a/include/grub/util/install.h
+++ b/include/grub/util/install.h
@@ -69,6 +69,8 @@
N_("disable shim_lock verifier"), 0 }, \
{ "disable-cli", GRUB_INSTALL_OPTIONS_DISABLE_CLI, 0, 0, \
N_("disabled command line interface access"), 0 }, \
+ { "x509key", 'x', N_("FILE"), 0, \
+ N_("embed FILE as an x509 certificate for appended signature checking"), 0}, \
{ "appended-signature-size", GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE, \
"SIZE", 0, N_("Add a note segment reserving SIZE bytes for an appended signature"), 1}, \
{ "verbose", 'v', 0, 0, \
@@ -196,6 +198,7 @@ grub_install_generate_image (const char *dir, const char *prefix,
const char *outname, char *mods[],
char *memdisk_path, char **pubkey_paths,
size_t npubkeys,
+ char **x509key_paths, size_t nx509keys,
char *config_path,
const struct grub_install_image_target_desc *image_target,
int note, size_t appsig_size,
diff --git a/util/grub-install-common.c b/util/grub-install-common.c
index 94afebd52..6e7bba5b4 100644
--- a/util/grub-install-common.c
+++ b/util/grub-install-common.c
@@ -463,6 +463,8 @@ handle_install_list (struct install_list *il, const char *val,
static char **pubkeys;
static size_t npubkeys;
+static char **x509keys;
+static size_t nx509keys;
static char *sbat;
static int disable_shim_lock;
static grub_compression_t compression;
@@ -511,6 +513,10 @@ grub_install_parse (int key, char *arg)
case GRUB_INSTALL_OPTIONS_DISABLE_CLI:
disable_cli = 1;
return 1;
+ case 'x':
+ x509keys = xrealloc (x509keys, sizeof (x509keys[0]) * (nx509keys + 1));
+ x509keys[nx509keys++] = xstrdup (arg);
+ return 1;
case GRUB_INSTALL_OPTIONS_VERBOSITY:
verbosity++;
@@ -649,6 +655,9 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
for (pk = pubkeys; pk < pubkeys + npubkeys; pk++)
slen += sizeof (" --pubkey ''") + grub_strlen (*pk);
+ for (pk = x509keys; pk < x509keys + nx509keys; pk++)
+ slen += sizeof (" --x509key ''") + grub_strlen (*pk);
+
for (md = modules.entries; *md; md++)
slen += sizeof (" ''") + grub_strlen (*md);
@@ -689,6 +698,14 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
*p++ = '\'';
}
+ for (pk = x509keys; pk < x509keys + nx509keys; pk++)
+ {
+ p = grub_stpcpy (p, "--x509key '");
+ p = grub_stpcpy (p, *pk);
+ *p++ = '\'';
+ *p++ = ' ';
+ }
+
for (md = modules.entries; *md; md++)
{
*p++ = ' ';
@@ -715,7 +732,7 @@ grub_install_make_image_wrap_file (const char *dir, const char *prefix,
grub_install_generate_image (dir, prefix, fp, outname,
modules.entries, memdisk_path,
- pubkeys, npubkeys, config_path, tgt,
+ pubkeys, npubkeys, x509keys, nx509keys, config_path, tgt,
note, appsig_size, compression, dtb, sbat,
disable_shim_lock, disable_cli);
while (dc--)
diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c
index 0b14a9360..b6f1f219e 100644
--- a/util/grub-mkimage.c
+++ b/util/grub-mkimage.c
@@ -76,6 +76,7 @@ static struct argp_option options[] = {
{"config", 'c', N_("FILE"), 0, N_("embed FILE as an early config"), 0},
/* TRANSLATORS: "embed" is a verb (command description). "*/
{"pubkey", 'k', N_("FILE"), 0, N_("embed FILE as public key for PGP signature checking"), 0},
+ {"x509key", 'x', N_("FILE"), 0, N_("embed FILE as an x509 certificate for appended signature checking"), 0},
/* TRANSLATORS: NOTE is a name of segment. */
{"note", 'n', 0, 0, N_("add NOTE segment for CHRP IEEE1275"), 0},
{"output", 'o', N_("FILE"), 0, N_("output a generated image to FILE [default=stdout]"), 0},
@@ -125,6 +126,8 @@ struct arguments
char *dtb;
char **pubkeys;
size_t npubkeys;
+ char **x509keys;
+ size_t nx509keys;
char *font;
char *config;
char *sbat;
@@ -216,6 +219,12 @@ argp_parser (int key, char *arg, struct argp_state *state)
arguments->pubkeys[arguments->npubkeys++] = xstrdup (arg);
break;
+ case 'x':
+ arguments->x509keys = xrealloc (arguments->x509keys,
+ sizeof (arguments->x509keys[0]) * (arguments->nx509keys + 1));
+ arguments->x509keys[arguments->nx509keys++] = xstrdup (arg);
+ break;
+
case 'c':
if (arguments->config)
free (arguments->config);
@@ -346,7 +355,8 @@ main (int argc, char *argv[])
grub_install_generate_image (arguments.dir, arguments.prefix, fp,
arguments.output, arguments.modules,
arguments.memdisk, arguments.pubkeys,
- arguments.npubkeys, arguments.config,
+ arguments.npubkeys, arguments.x509keys,
+ arguments.nx509keys, arguments.config,
arguments.image_target, arguments.note,
arguments.appsig_size,
arguments.comp, arguments.dtb,
diff --git a/util/mkimage.c b/util/mkimage.c
index 61c4e78e2..f364a5718 100644
--- a/util/mkimage.c
+++ b/util/mkimage.c
@@ -883,7 +883,7 @@ void
grub_install_generate_image (const char *dir, const char *prefix,
FILE *out, const char *outname, char *mods[],
char *memdisk_path, char **pubkey_paths,
- size_t npubkeys, char *config_path,
+ size_t npubkeys, char **x509key_paths, size_t nx509keys, char *config_path,
const struct grub_install_image_target_desc *image_target,
int note, size_t appsig_size, grub_compression_t comp, const char *dtb_path,
const char *sbat_path, int disable_shim_lock,
@@ -929,6 +929,24 @@ grub_install_generate_image (const char *dir, const char *prefix,
}
}
+ if (nx509keys != 0 && image_target->id != IMAGE_PPC)
+ grub_util_error (_("x509 public key can be support only to appended signature"
+ " with powerpc-ieee1275 images"));
+
+ {
+ size_t i;
+
+ for (i = 0; i < nx509keys; i++)
+ {
+ size_t curs;
+
+ curs = ALIGN_ADDR (grub_util_get_image_size (x509key_paths[i]));
+ grub_util_info ("the size of x509 public key %u is 0x%" GRUB_HOST_PRIxLONG_LONG,
+ (unsigned) i, (unsigned long long) curs);
+ total_module_size += curs + sizeof (struct grub_module_header);
+ }
+ }
+
if (memdisk_path)
{
memdisk_size = ALIGN_UP(grub_util_get_image_size (memdisk_path), 512);
@@ -1065,6 +1083,25 @@ grub_install_generate_image (const char *dir, const char *prefix,
}
}
+ {
+ size_t i;
+
+ for (i = 0; i < nx509keys; i++)
+ {
+ size_t curs;
+ struct grub_module_header *header;
+
+ curs = grub_util_get_image_size (x509key_paths[i]);
+ header = (struct grub_module_header *) (kernel_img + offset);
+ header->type = grub_host_to_target32 (OBJ_TYPE_X509_PUBKEY);
+ header->size = grub_host_to_target32 (curs + sizeof (*header));
+
+ offset += sizeof (*header);
+ grub_util_load_image (x509key_paths[i], kernel_img + offset);
+ offset += ALIGN_ADDR (curs);
+ }
+ }
+
if (memdisk_path)
{
struct grub_module_header *header;
--
2.39.5 (Apple Git-154)
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-07-09 11:49 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 11:45 [PATCH v4 00/23] Appended Signature Secure Boot Support for PowerPC Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 01/23] powerpc-ieee1275: Add support for signing GRUB with an appended signature Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 02/23] docs/grub: Document signing GRUB under UEFI Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 03/23] docs/grub: Document signing GRUB with an appended signature Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 04/23] pgp: Factor out rsa_pad Sudhakar Kuppusamy
2025-07-24 8:55 ` Gary Lin via Grub-devel
2025-07-31 12:01 ` Sudhakar Kuppusamy
2025-08-01 1:24 ` Gary Lin via Grub-devel
2025-07-09 11:45 ` [PATCH v4 05/23] crypto: Move storage for grub_crypto_pk_* to crypto.c Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 06/23] pgp: Rename OBJ_TYPE_PUBKEY to OBJ_TYPE_GPG_PUBKEY Sudhakar Kuppusamy
2025-07-09 11:45 ` Sudhakar Kuppusamy [this message]
2025-07-09 11:45 ` [PATCH v4 08/23] appended signatures: Import GNUTLS's ASN.1 description files Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 09/23] appended signatures: Parse ASN1 node Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 10/23] appended signatures: Parse PKCS#7 signedData Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 11/23] appended signatures: Parse X.509 certificates Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 12/23] appended signatures: Support verifying appended signatures Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 13/23] appended signatures: Verification tests Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 14/23] appended signatures: Documentation Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 15/23] ieee1275: Enter lockdown based on /ibm,secure-boot Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 16/23] ieee1275: Read the DB and DBX secure boot variables Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 17/23] appendedsig: create db and dbx lists Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 18/23] appendedsig: verify the kernel using " Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 19/23] powerpc_ieee1275: Introduce use_static_keys flag Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 20/23] appendedsig: Read default DB keys from the ELF Note Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 21/23] appendedsig: Introduce GRUB commands to access db and dbx Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 22/23] appendedsig: Documentation Sudhakar Kuppusamy
2025-07-09 11:45 ` [PATCH v4 23/23] appendedsig test: Replace the certificate number with an x.509 certificate 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=20250709114540.58608-8-sudhakar@linux.ibm.com \
--to=sudhakar@linux.ibm.com \
--cc=alastair@d-silva.org \
--cc=avnish@linux.ibm.com \
--cc=daniel.kiper@oracle.com \
--cc=dja@axtens.net \
--cc=grub-devel@gnu.org \
--cc=jan.setjeeilers@oracle.com \
--cc=julian.klode@canonical.com \
--cc=ltcgcw@linux.vnet.ibm.com \
--cc=mate.kukri@canonical.com \
--cc=mlewando@redhat.com \
--cc=msuchanek@suse.com \
--cc=nayna@linux.ibm.com \
--cc=pjones@redhat.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).