From: sudhakar <sudhakar@linux.ibm.com>
To: Gary Lin <glin@suse.com>
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, nayna@linux.ibm.com,
ltcgcw@linux.vnet.ibm.com, ssrish@linux.ibm.com
Subject: Re: [PATCH v2 20/21] appendedsig: The grub command's trusted and distrusted support
Date: Wed, 21 May 2025 18:16:11 +0530 [thread overview]
Message-ID: <6223565dc31bb4497ff10ad663616847@linux.ibm.com> (raw)
In-Reply-To: <k7hmynwo2jkvo5cnglatvwqwzon5k2bvmaxzarp42mwdzkbhch@crp7wuiln4j7>
Hi Gary Lin,
Thank you so much for a review!. I wil fix the bug in the code mentioned
by you.
Thanks,
Sudhakar Kuppusmay
On 2025-04-17 13:13, Gary Lin wrote:
> On Thu, Mar 27, 2025 at 01:02:41AM +0530, Sudhakar Kuppusamy wrote:
>> To support the following trusted and distrusted commands
>>
>> 1. trusted_list:
>> It will show the list of trusted certificates and binary
>> hashes
>> 2. distrusted_list:
>> It will show the list of distrusted certificates and
>> binary/certificate hashes
>> 3. trusted_certificate:
>> It will add the trusted certificate to the trusted list
> There are a few bugs in grub_cmd_distrusted_cert().
>
>> 4. trusted_signature:
>> It will add the certificate/binary hash to the trusted list
>> 5. distrusted_certificate:
>> It will remove the trusted certificate from trsuted list
>> 6. distrusted_signature:
>> It will add the certificate/binary hash to the distrsuted list
>>
>> Note:-
>> The addition/deletion of trusted certificates and binary hashes
>> are not allowed in grub command prompt while secure boot is enabled.
>>
>> Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
>> Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
>> ---
>> grub-core/commands/appendedsig/appendedsig.c | 518
>> +++++++++++++------
>> 1 file changed, 351 insertions(+), 167 deletions(-)
>>
>> diff --git a/grub-core/commands/appendedsig/appendedsig.c
>> b/grub-core/commands/appendedsig/appendedsig.c
>> index 5631f0ab4..6f665aab2 100644
>> --- a/grub-core/commands/appendedsig/appendedsig.c
>> +++ b/grub-core/commands/appendedsig/appendedsig.c
>> @@ -117,6 +117,36 @@ static enum
>
> ----->8-----
>
>> +
>> +static grub_err_t
>> +grub_cmd_distrusted_cert (grub_command_t cmd __attribute__((unused)),
>> int argc, char **args)
>> +{
>> + grub_size_t cert_num = 0, i = 1;
>> + struct x509_certificate *current_cert = db.keys;
>> + struct x509_certificate *previous_cert = db.keys;
>> +
>> + if (argc != 1)
>> + {
>> + grub_printf (N_("trusted certificate number is expected\n"
>> + "Example:\n\tdistrusted_certificate
>> <CERT_NUMER>\n"));
>> + return GRUB_ERR_BAD_ARGUMENT;
>> + }
>> +
>> + if (check_sigs == check_sigs_forced)
>> + {
>> + grub_printf ("Warning: since secure boot is enabled, "
>> + "removing of trusted certificate is not
>> permitted!\n");
>> + return grub_errno;
>> + }
>> +
>> + cert_num = grub_strtoul (args[0], NULL, 10);
>> + if (cert_num < 1)
>> + return grub_error (GRUB_ERR_BAD_ARGUMENT,
>> + N_("trusted certificate number should to begin
>> with 1"));
>> +
>> + if (cert_num > db.key_entries)
>> + return grub_error (GRUB_ERR_BAD_ARGUMENT,
>> + N_("trusted certificate number should not
>> exceed %" PRIuGRUB_SIZE ""),
>> + db.key_entries);
>> + else if (cert_num < db.key_entries)
>> + return grub_error (GRUB_ERR_BAD_ARGUMENT,
>> + N_("there is no certificate on the trusted
>> list. so, not permitted"));
> The 'else if' looks wrong since it's totally fine to have a cert number
> smaller than db.key_entries. Per the error message, it should be
> 'db.key_entries == 0'.
>
>> +
>> + for (i = 1; i < db.key_entries; i++)
> It has to be 'i <= db.key_entries'. Otherwise, the last certificate in
> the list is always ignored.
>
>> + {
>> + if (cert_num == 1)
>> {
>> - grub_printf ("%02x:", cert->serial[i]);
>> + previous_cert = current_cert->next;
> Changing 'previous_cert' here won't affect 'db.keys', so the next user
> of 'db.keys' will get 'current_cert' instead of 'current_cert->next',
> and this leads to crash. I'd suggest to add:
>
> db.keys = current_cert->next;
>
>> + break;
>> + }
>> + else if (cert_num == i)
>> + {
>> + previous_cert->next = current_cert->next;
>> + break;
>> }
>> - grub_printf ("%02x\n", cert->serial[cert->serial_len - 1]);
>>
>> - grub_printf ("\tCN: %s\n\n", cert->subject);
>> - cert_num++;
>> + previous_cert = current_cert;
>> + current_cert = current_cert->next;
>> }
>>
>> + certificate_release (current_cert);
>> + grub_free (current_cert);
>> +
> 'db.key_entries' wasn't updated in the whole function.
>
> db.key_entries--;
>
>> return GRUB_ERR_NONE;
>> }
>>
>
> Cheers,
>
> Gary Lin
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-05-21 12:47 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
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 [this message]
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=6223565dc31bb4497ff10ad663616847@linux.ibm.com \
--to=sudhakar@linux.ibm.com \
--cc=dja@axtens.net \
--cc=glin@suse.com \
--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 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.