From: sudhakar <sudhakar@linux.ibm.com>
To: Daniel Kiper <dkiper@net-space.pl>
Cc: grub-devel@gnu.org, 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, Rashmica Gupta <rashmica.g@gmail.com>
Subject: Re: [PATCH v2 01/21] powerpc-ieee1275: Add support for signing grub with an appended signature
Date: Tue, 10 Jun 2025 21:57:10 +0530 [thread overview]
Message-ID: <7b597b1cd30b22617d2d4dea1c6a3533@linux.ibm.com> (raw)
In-Reply-To: <20250522174945.quk4vabdnjirq6zd@tomti.i.net-space.pl>
Hi Daniel,
Thank you for your valuable review comments.
On 2025-05-22 23:19, Daniel Kiper wrote:
> On Thu, Mar 27, 2025 at 01:02:22AM +0530, Sudhakar Kuppusamy wrote:
>> From: Rashmica Gupta <rashmica.g@gmail.com>
>>
>> Add infrastructure to allow firmware to verify the integrity of grub
>> by use of a Linux-kernel-module-style appended signature. We initially
>> target powerpc-ieee1275, but the code should be extensible to other
>> platforms.
>>
>> Usually these signatures are appended to a file without modifying the
>> ELF file itself. (This is what the 'sign-file' tool does, for
>> example.)
>> The verifier loads the signed file from the file system and looks at
>> the
>> end of the file for the appended signature. However, on
>> powerpc-ieee1275
>> platforms, the bootloader is often stored directly in the PReP
>> partition
>> as raw bytes without a file-system. This makes determining the
>> location
>> of an appended signature more difficult.
>>
>> To address this, we add a new ELF note.
>>
>> The name field of shall be the string "Appended-Signature",
>> zero-padded
>> to 4 byte alignment. The type field shall be 0x41536967 (the ASCII
>> values
>> for the string "ASig"). It must be the final section in the ELF
>> binary.
>>
>> The description shall contain the appended signature structure as
>> defined
>> by the Linux kernel. The description will also be padded to be a
>> multiple
>> of 4 bytes. The padding shall be added before the appended signature
>> structure (not at the end) so that the final bytes of a signed ELF
>> file
>> are the appended signature magic.
>>
>> A subsequent patch documents how to create a grub core.img validly
>> signed
>> under this scheme.
>>
>> Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
>> 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>
>> ---
>> include/grub/util/install.h | 7 +++++--
>> include/grub/util/mkimage.h | 4 ++--
>> util/grub-install-common.c | 15 ++++++++++++---
>> util/grub-mkimage.c | 11 +++++++++++
>> util/grub-mkimagexx.c | 38
>> ++++++++++++++++++++++++++++++++++++-
>> util/mkimage.c | 6 +++---
>> 6 files changed, 70 insertions(+), 11 deletions(-)
>>
>> diff --git a/include/grub/util/install.h b/include/grub/util/install.h
>> index 5c0a52ca2..3aabc4285 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 }, \
>> + { "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, \
>> N_("print verbose messages."), 1 }
>>
>> @@ -132,7 +134,8 @@ enum grub_install_options {
>> GRUB_INSTALL_OPTIONS_DTB,
>> GRUB_INSTALL_OPTIONS_SBAT,
>> GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK,
>> - GRUB_INSTALL_OPTIONS_DISABLE_CLI
>> + GRUB_INSTALL_OPTIONS_DISABLE_CLI,
>> + GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE
>> };
>>
>> extern char *grub_install_source_directory;
>> @@ -192,7 +195,7 @@ grub_install_generate_image (const char *dir,
>> const char *prefix,
>> size_t npubkeys,
>> char *config_path,
>> const struct grub_install_image_target_desc *image_target,
>> - int note,
>> + int note, size_t appsig_size,
>> grub_compression_t comp, const char *dtb_file,
>> const char *sbat_path, const int disable_shim_lock,
>> const int disable_cli);
>> diff --git a/include/grub/util/mkimage.h b/include/grub/util/mkimage.h
>> index 9d74f82c5..0d40383eb 100644
>> --- a/include/grub/util/mkimage.h
>> +++ b/include/grub/util/mkimage.h
>> @@ -51,12 +51,12 @@ grub_mkimage_load_image64 (const char
>> *kernel_path,
>> const struct grub_install_image_target_desc *image_target);
>> void
>> grub_mkimage_generate_elf32 (const struct
>> grub_install_image_target_desc *image_target,
>> - int note, char *sbat, char **core_img, size_t *core_size,
>> + int note, char *sbat, size_t appsig_size, char **core_img,
>> size_t *core_size,
>> Elf32_Addr target_addr,
>> struct grub_mkimage_layout *layout);
>> void
>> grub_mkimage_generate_elf64 (const struct
>> grub_install_image_target_desc *image_target,
>> - int note, char *sbat, char **core_img, size_t *core_size,
>> + int note, char *sbat, size_t appsig_size, char **core_img,
>> size_t *core_size,
>> Elf64_Addr target_addr,
>> struct grub_mkimage_layout *layout);
>>
>> diff --git a/util/grub-install-common.c b/util/grub-install-common.c
>> index 22bccb6a3..22f0e56cb 100644
>> --- a/util/grub-install-common.c
>> +++ b/util/grub-install-common.c
>> @@ -467,10 +467,12 @@ static char *sbat;
>> static int disable_shim_lock;
>> static grub_compression_t compression;
>> static int disable_cli;
>> +static size_t appsig_size;
>>
>> int
>> grub_install_parse (int key, char *arg)
>> {
>> + const char *end;
>
> Please add empty line after this. In general separate definitions from
> the code.
>
>> switch (key)
>> {
>> case GRUB_INSTALL_OPTIONS_INSTALL_CORE_COMPRESS:
>> @@ -571,6 +573,12 @@ grub_install_parse (int key, char *arg)
>> grub_util_error (_("Unrecognized compression `%s'"), arg);
>> case GRUB_INSTALL_OPTIONS_GRUB_MKIMAGE:
>> return 1;
>> + case GRUB_INSTALL_OPTIONS_APPENDED_SIGNATURE_SIZE:
>> + grub_errno = 0;
>
> If you have enum types please use them properly...
>
> grub_errno = GRUB_ERR_NONE
>
>> + appsig_size = grub_strtol (arg, &end, 10);
>> + if (grub_errno)
>
> This check is not reliable. Good example how it should be done is in
> commit ac8a37dda (net/http: Allow use of non-standard TCP/IP ports).
>
> ... and if (grub_errno != GRUB_ERR_NONE)
>
> Please fix above mentioned issues in all patches.
>
>> + return 0;
>> + return 1;
>> default:
>> return 0;
>> }
>> @@ -683,9 +691,10 @@ grub_install_make_image_wrap_file (const char
>> *dir, const char *prefix,
>> *p = '\0';
>>
>> grub_util_info ("grub-mkimage --directory '%s' --prefix '%s'
>> --output '%s'"
>> - " --format '%s' --compression '%s'%s%s%s%s\n",
>> + " --format '%s' --compression '%s'"
>> + " --appended-signature-size %zu %s %s %s %s\n",
>> dir, prefix, outname,
>> - mkimage_target, compnames[compression],
>> + mkimage_target, compnames[compression], appsig_size,
>> note ? " --note" : "",
>> disable_shim_lock ? " --disable-shim-lock" : "",
>> disable_cli ? " --disable-cli" : "", s);
>> @@ -698,7 +707,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,
>> - note, compression, dtb, sbat,
>> + note, appsig_size, compression, dtb, sbat,
>> disable_shim_lock, disable_cli);
>> while (dc--)
>> grub_install_pop_module ();
>> diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c
>> index 547f7310f..5b6c99d83 100644
>> --- a/util/grub-mkimage.c
>> +++ b/util/grub-mkimage.c
>> @@ -84,6 +84,7 @@ static struct argp_option options[] = {
>> {"sbat", 's', N_("FILE"), 0, N_("SBAT metadata"), 0},
>> {"disable-shim-lock", GRUB_INSTALL_OPTIONS_DISABLE_SHIM_LOCK, 0, 0,
>> N_("disable shim_lock verifier"), 0},
>> {"disable-cli", GRUB_INSTALL_OPTIONS_DISABLE_CLI, 0, 0, N_("disable
>> command line interface access"), 0},
>> + {"appended-signature-size", 'S', N_("SIZE"), 0, N_("Add a note
>> segment reserving SIZE bytes for an appended signature"), 0},
>> {"verbose", 'v', 0, 0, N_("print verbose messages."), 0},
>> { 0, 0, 0, 0, 0, 0 }
>> };
>> @@ -130,6 +131,7 @@ struct arguments
>> int note;
>> int disable_shim_lock;
>> int disable_cli;
>> + size_t appsig_size;
>> const struct grub_install_image_target_desc *image_target;
>> grub_compression_t comp;
>> };
>> @@ -140,6 +142,7 @@ argp_parser (int key, char *arg, struct argp_state
>> *state)
>> /* Get the input argument from argp_parse, which we
>> know is a pointer to our arguments structure. */
>> struct arguments *arguments = state->input;
>> + const char *end;
>>
>> switch (key)
>> {
>> @@ -172,6 +175,13 @@ argp_parser (int key, char *arg, struct
>> argp_state *state)
>> arguments->note = 1;
>> break;
>>
>> + case 'S':
>> + grub_errno = 0;
>> + arguments->appsig_size = grub_strtol (arg, &end, 10);
>
> As above...
>
>> + if (grub_errno)
>
> Ditto.
>
>> + return 0;
>> + break;
>> +
>> case 'm':
>> if (arguments->memdisk)
>> free (arguments->memdisk);
>> @@ -330,6 +340,7 @@ main (int argc, char *argv[])
>> arguments.memdisk, arguments.pubkeys,
>> arguments.npubkeys, arguments.config,
>> arguments.image_target, arguments.note,
>> + arguments.appsig_size,
>> arguments.comp, arguments.dtb,
>> arguments.sbat, arguments.disable_shim_lock,
>> arguments.disable_cli);
>> diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
>> index 448862b2e..6fe348e5b 100644
>> --- a/util/grub-mkimagexx.c
>> +++ b/util/grub-mkimagexx.c
>> @@ -115,6 +115,14 @@ struct grub_sbat_note {
>> char name[ALIGN_UP(sizeof(GRUB_SBAT_NOTE_NAME), 4)];
>> };
>>
>> +#define GRUB_APPENDED_SIGNATURE_NOTE_NAME "Appended-Signature"
>> +#define GRUB_APPENDED_SIGNATURE_NOTE_TYPE 0x41536967 /* "ASig" */
>> +struct grub_appended_signature_note
>> +{
>> + Elf32_Nhdr header;
>> + char name[ALIGN_UP (sizeof (GRUB_APPENDED_SIGNATURE_NOTE_NAME),
>> 4)];
>> +};
>> +
>> static int
>> is_relocatable (const struct grub_install_image_target_desc
>> *image_target)
>> {
>> @@ -216,7 +224,7 @@ grub_arm_reloc_jump24 (grub_uint32_t *target,
>> Elf32_Addr sym_addr)
>>
>> void
>> SUFFIX (grub_mkimage_generate_elf) (const struct
>> grub_install_image_target_desc *image_target,
>> - int note, char *sbat, char **core_img, size_t *core_size,
>> + int note, char *sbat, size_t appsig_size, char **core_img,
>> size_t *core_size,
>> Elf_Addr target_addr,
>> struct grub_mkimage_layout *layout)
>> {
>> @@ -237,6 +245,12 @@ SUFFIX (grub_mkimage_generate_elf) (const struct
>> grub_install_image_target_desc
>> footer_size += ALIGN_UP (sizeof (struct grub_sbat_note) +
>> layout->sbat_size, 4);
>> }
>>
>> + if (appsig_size)
>> + {
>> + phnum++;
>> + footer_size += ALIGN_UP (sizeof (struct
>> grub_appended_signature_note) + appsig_size, 4);
>> + }
>> +
>> if (image_target->id != IMAGE_LOONGSON_ELF)
>> phnum += 2;
>>
>> @@ -527,6 +541,28 @@ SUFFIX (grub_mkimage_generate_elf) (const struct
>> grub_install_image_target_desc
>> phdr->p_filesz = grub_host_to_target32 (note_size);
>> phdr->p_memsz = 0;
>> phdr->p_offset = grub_host_to_target32 (header_size +
>> program_size + footer_offset);
>> + footer += note_size;
>> + footer_offset += note_size;
>> + }
>> +
>> + if (appsig_size)
>> + {
>> + int note_size = ALIGN_UP (sizeof (struct
>> grub_appended_signature_note) + appsig_size, 4);
>> + struct grub_appended_signature_note *note_ptr = (struct
>> grub_appended_signature_note *) footer;
>
> Again, missing empty line here...
>
>> + note_ptr->header.n_namesz = grub_host_to_target32 (sizeof
>> (GRUB_APPENDED_SIGNATURE_NOTE_NAME));
>> + /* needs to sit at the end, so we round this up and sign some
>> zero padding */
>> + note_ptr->header.n_descsz = grub_host_to_target32 (ALIGN_UP
>> (appsig_size, 4));
>> + note_ptr->header.n_type = grub_host_to_target32
>> (GRUB_APPENDED_SIGNATURE_NOTE_TYPE);
>> + strcpy (note_ptr->name, GRUB_APPENDED_SIGNATURE_NOTE_NAME);
>> + phdr++;
>> + phdr->p_type = grub_host_to_target32 (PT_NOTE);
>> + phdr->p_flags = grub_host_to_target32 (PF_R);
>> + phdr->p_align = grub_host_to_target32
>> (image_target->voidp_sizeof);
>> + phdr->p_vaddr = 0;
>> + phdr->p_paddr = 0;
>> + phdr->p_filesz = grub_host_to_target32 (note_size);
>> + phdr->p_memsz = 0;
>> + phdr->p_offset = grub_host_to_target32 (header_size +
>> program_size + footer_offset);
>> }
>>
>> {
>> diff --git a/util/mkimage.c b/util/mkimage.c
>> index b46df2909..f5c59f563 100644
>> --- a/util/mkimage.c
>> +++ b/util/mkimage.c
>> @@ -885,7 +885,7 @@ grub_install_generate_image (const char *dir,
>> const char *prefix,
>> char *memdisk_path, char **pubkey_paths,
>> size_t npubkeys, char *config_path,
>> const struct grub_install_image_target_desc *image_target,
>> - int note, grub_compression_t comp, const char *dtb_path,
>> + int note, size_t appsig_size, grub_compression_t comp, const
>> char *dtb_path,
>> const char *sbat_path, int disable_shim_lock,
>> int disable_cli)
>> {
>> @@ -1833,10 +1833,10 @@ grub_install_generate_image (const char *dir,
>> const char *prefix,
>> else
>> target_addr = image_target->link_addr;
>> if (image_target->voidp_sizeof == 4)
>> - grub_mkimage_generate_elf32 (image_target, note, sbat, &core_img,
>> &core_size,
>> + grub_mkimage_generate_elf32 (image_target, note, sbat,
>> appsig_size, &core_img, &core_size,
>> target_addr, &layout);
>> else
>> - grub_mkimage_generate_elf64 (image_target, note, sbat, &core_img,
>> &core_size,
>> + grub_mkimage_generate_elf64 (image_target, note, sbat,
>> appsig_size, &core_img, &core_size,
>> target_addr, &layout);
>
> What will happen if somebody attempts to generate PE image with
> appended
> signature? I think GRUB utils should complain then loudly.
v2 won't complain if somebody attempts to generate PE image with
appended signature.
In v3, I have added the check condition to complain loudly if somebody
attempts to generate PE image with appended signature.
Thanks,
Sudhakar Kuppusamy
> Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-06-10 16:36 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 19:32 [PATCH v2 00/21] Appended Signature Secure Boot Support for PowerPC Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 01/21] powerpc-ieee1275: Add support for signing grub with an appended signature Sudhakar Kuppusamy
2025-05-22 17:49 ` Daniel Kiper
2025-06-10 16:27 ` sudhakar [this message]
2025-03-26 19:32 ` [PATCH v2 02/21] docs/grub: Document signing grub under UEFI Sudhakar Kuppusamy
2025-05-22 17:53 ` Daniel Kiper
2025-03-26 19:32 ` [PATCH v2 03/21] docs/grub: Document signing grub with an appended signature Sudhakar Kuppusamy
2025-05-22 18:19 ` Daniel Kiper
2025-06-10 16:33 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 04/21] dl: provide a fake grub_dl_set_persistent for the emu target Sudhakar Kuppusamy
2025-05-22 18:23 ` Daniel Kiper
2025-03-26 19:32 ` [PATCH v2 05/21] pgp: factor out rsa_pad Sudhakar Kuppusamy
2025-05-22 18:31 ` Daniel Kiper
2025-03-26 19:32 ` [PATCH v2 06/21] crypto: move storage for grub_crypto_pk_* to crypto.c Sudhakar Kuppusamy
2025-05-22 18:34 ` Daniel Kiper
2025-03-26 19:32 ` [PATCH v2 07/21] grub-install: support embedding x509 certificates Sudhakar Kuppusamy
2025-05-28 15:47 ` Daniel Kiper
2025-06-10 16:22 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 08/21] appended signatures: import GNUTLS's ASN.1 description files Sudhakar Kuppusamy
2025-05-28 15:55 ` Daniel Kiper
2025-06-10 16:20 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 09/21] appended signatures: parse PKCS#7 signedData and X.509 certificates Sudhakar Kuppusamy
2025-05-28 16:44 ` Daniel Kiper
2025-06-10 16:19 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 10/21] appended signatures: support verifying appended signatures Sudhakar Kuppusamy
2025-04-15 3:46 ` Gary Lin via Grub-devel
2025-05-21 12:49 ` sudhakar
2025-05-28 17:20 ` Daniel Kiper
2025-06-10 16:18 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 11/21] appended signatures: verification tests Sudhakar Kuppusamy
2025-05-28 17:29 ` Daniel Kiper
2025-06-10 16:16 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 12/21] appended signatures: documentation Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 13/21] ieee1275: enter lockdown based on /ibm,secure-boot Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 14/21] ieee1275: Platform Keystore (PKS) Support Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 15/21] ieee1275: Read the DB and DBX secure boot variables Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 16/21] appendedsig: The creation of trusted and distrusted lists Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 17/21] appendedsig: While verifying the kernel, use " Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 18/21] powerpc_ieee1275: set use_static_keys flag Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 19/21] appendedsig: Reads the default DB keys from ELF Note Sudhakar Kuppusamy
2025-03-26 19:32 ` [PATCH v2 20/21] appendedsig: The grub command's trusted and distrusted support Sudhakar Kuppusamy
2025-04-15 8:24 ` Gary Lin via Grub-devel
2025-05-21 12:49 ` sudhakar
2025-04-17 7:43 ` Gary Lin via Grub-devel
2025-05-21 12:46 ` sudhakar
2025-03-26 19:32 ` [PATCH v2 21/21] appendedsig: documentation Sudhakar Kuppusamy
2025-05-13 14:16 ` [PATCH v2 00/21] Appended Signature Secure Boot Support for PowerPC Marta Lewandowska via Grub-devel
2025-05-20 13:50 ` sudhakar
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=7b597b1cd30b22617d2d4dea1c6a3533@linux.ibm.com \
--to=sudhakar@linux.ibm.com \
--cc=dja@axtens.net \
--cc=dkiper@net-space.pl \
--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=pjones@redhat.com \
--cc=rashmica.g@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.