All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Berger <stefanb@linux.ibm.com>
To: The development of GNU GRUB <grub-devel@gnu.org>,
	Daniel Axtens <dja@axtens.net>
Cc: rashmica.g@gmail.com, alastair@d-silva.org, nayna@linux.ibm.com
Subject: Re: [PATCH v2 21/22] appended signatures: documentation
Date: Mon, 19 Jul 2021 18:24:37 -0400	[thread overview]
Message-ID: <a38659f4-d8f8-50a4-a943-99546157dd4b@linux.ibm.com> (raw)
In-Reply-To: <20210630084031.2663622-22-dja@axtens.net>


On 6/30/21 4:40 AM, Daniel Axtens wrote:
> This explains how appended signatures can be used to form part of
> a secure boot chain, and documents the commands and variables
> introduced.
>
> Signed-off-by: Daniel Axtens <dja@axtens.net>

One small thing below.


>
> ---
>
> v2: fix a grammar issue, thanks Stefan Berger.
> ---
>   docs/grub.texi | 193 ++++++++++++++++++++++++++++++++++++++++++++-----
>   1 file changed, 176 insertions(+), 17 deletions(-)
>
> diff --git a/docs/grub.texi b/docs/grub.texi
> index bed565371460..02fcda11e3bd 100644
> --- a/docs/grub.texi
> +++ b/docs/grub.texi
> @@ -3209,6 +3209,7 @@ These variables have special meaning to GRUB.
>   
>   @menu
>   * biosnum::
> +* check_appended_signatures::
>   * check_signatures::
>   * chosen::
>   * cmdpath::
> @@ -3268,11 +3269,18 @@ For an alternative approach which also changes BIOS drive mappings for the
>   chain-loaded system, @pxref{drivemap}.
>   
>   
> +@node check_appended_signatures
> +@subsection check_appended_signatures
> +
> +This variable controls whether GRUB enforces appended signature validation on
> +certain loaded files. @xref{Using appended signatures}.
> +
> +
>   @node check_signatures
>   @subsection check_signatures
>   
> -This variable controls whether GRUB enforces digital signature
> -validation on loaded files. @xref{Using digital signatures}.
> +This variable controls whether GRUB enforces GPG-style digital signature
> +validation on loaded files. @xref{Using GPG-style digital signatures}.
>   
>   @node chosen
>   @subsection chosen
> @@ -3989,6 +3997,7 @@ you forget a command, you can run the command @command{help}
>   * date::                        Display or set current date and time
>   * devicetree::                  Load a device tree blob
>   * distrust::                    Remove a pubkey from trusted keys
> +* distrust_certificate::        Remove a certificate from the list of trusted certificates
>   * drivemap::                    Map a drive to another
>   * echo::                        Display a line of text
>   * eval::                        Evaluate agruments as GRUB commands
> @@ -4005,6 +4014,7 @@ you forget a command, you can run the command @command{help}
>   * keystatus::                   Check key modifier status
>   * linux::                       Load a Linux kernel
>   * linux16::                     Load a Linux kernel (16-bit mode)
> +* list_certificates::           List trusted certificates
>   * list_env::                    List variables in environment block
>   * list_trusted::                List trusted public keys
>   * load_env::                    Load variables from environment block
> @@ -4042,8 +4052,10 @@ you forget a command, you can run the command @command{help}
>   * test::                        Check file types and compare values
>   * true::                        Do nothing, successfully
>   * trust::                       Add public key to list of trusted keys
> +* trust_certificate::           Add an x509 certificate to the list of trusted certificates
>   * unset::                       Unset an environment variable
>   @comment * vbeinfo::                     List available video modes
> +* verify_appended::             Verify appended digital signature
>   * verify_detached::             Verify detached digital signature
>   * videoinfo::                   List available video modes
>   @comment * xen_*::              Xen boot commands for AArch64
> @@ -4371,9 +4383,28 @@ These keys are used to validate signatures when environment variable
>   @code{check_signatures} is set to @code{enforce}
>   (@pxref{check_signatures}), and by some invocations of
>   @command{verify_detached} (@pxref{verify_detached}).  @xref{Using
> -digital signatures}, for more information.
> +GPG-style digital signatures}, for more information.
> +@end deffn
> +
> +
> +@node distrust_certificate
> +@subsection distrust_certificate
> +
> +@deffn Command distrust_certificate cert_number
> +Remove the x509 certificate numbered @var{cert_number} from GRUB's keyring of
> +trusted x509 certificates for verifying appended signatures.
> +
> +@var{cert_number} is the certificate number as listed by
> +@command{list_certificates} (@pxref{list_certificates}).
> +
> +These certificates are used to validate appended signatures when environment
> +variable @code{check_appended_signatures} is set to @code{enforce}
> +(@pxref{check_appended_signatures}), and by @command{verify_appended}
> +(@pxref{verify_appended}). See @xref{Using appended signatures} for more
> +information.
>   @end deffn
>   
> +
>   @node drivemap
>   @subsection drivemap
>   
> @@ -4631,6 +4662,21 @@ This command is only available on x86 systems.
>   @end deffn
>   
>   
> +@node list_certificates
> +@subsection list_certificates
> +
> +@deffn Command list_certificates
> +List all x509 certificates trusted by GRUB for validating appended signatures.
> +The output is a numbered list of certificates, showing the certificate's serial
> +number and Common Name.
> +
> +The certificate number can be used as an argument to
> +@command{distrust_certificate} (@pxref{distrust_certificate}).
> +
> +See @xref{Using appended signatures} for more information.
> +@end deffn
> +
> +
>   @node list_env
>   @subsection list_env
>   
> @@ -4650,7 +4696,7 @@ The output is in GPG's v4 key fingerprint format (i.e., the output of
>   @code{gpg --fingerprint}).  The least significant four bytes (last
>   eight hexadecimal digits) can be used as an argument to
>   @command{distrust} (@pxref{distrust}).
> -@xref{Using digital signatures}, for more information about uses for
> +@xref{Using GPG-style digital signatures}, for more information about uses for
>   these keys.
>   @end deffn
>   
> @@ -4685,8 +4731,12 @@ When used with care, @option{--skip-sig} and the whitelist enable an
>   administrator to configure a system to boot only signed
>   configurations, but to allow the user to select from among multiple
>   configurations, and to enable ``one-shot'' boot attempts and
> -``savedefault'' behavior.  @xref{Using digital signatures}, for more
> +``savedefault'' behavior.  @xref{Using GPG-style digital signatures}, for more
>   information.
> +
> +Extra care should be taken when combining this command with appended signatures
> +(@pxref{Using appended signatures}), as this file is not validated by an
> +appended signature and could set @code{check_appended_signatures=no}.
>   @end deffn
>   
>   
> @@ -4982,7 +5032,7 @@ read.  It is possible to modify a digitally signed environment block
>   file from within GRUB using this command, such that its signature will
>   no longer be valid on subsequent boots.  Care should be taken in such
>   advanced configurations to avoid rendering the system
> -unbootable. @xref{Using digital signatures}, for more information.
> +unbootable. @xref{Using GPG-style digital signatures}, for more information.
>   @end deffn
>   
>   
> @@ -5382,11 +5432,31 @@ signatures when environment variable @code{check_signatures} is set to
>   must itself be properly signed.  The @option{--skip-sig} option can be
>   used to disable signature-checking when reading @var{pubkey_file}
>   itself. It is expected that @option{--skip-sig} is useful for testing
> -and manual booting. @xref{Using digital signatures}, for more
> +and manual booting. @xref{Using GPG-style digital signatures}, for more
>   information.
>   @end deffn
>   
>   
> +@node trust_certificate
> +@subsection trust_certificate
> +
> +@deffn Command trust_certificate x509_certificate
> +Read a DER-formatted x509 certificate from the file @var{x509_certificate}
> +and add it to GRUB's internal list of trusted x509 certificates. These
> +certificates are used to validate appended signatures when the environment
> +variable @code{check_appended_signatures} is set to @code{enforce}.
> +
> +Note that if @code{check_appended_signatures} is set to @code{enforce}
> +when @command{trust_certificate} is executed, then @var{x509_certificate}
> +must itself bear an appended signature. (It is not sufficient that
> +@var{x509_certificate} be signed by a trusted certificate according to the
> +x509 rules: grub does not include support for validating signatures within x509
> +certificates themselves.)
> +
> +See @xref{Using appended signatures} for more information.
> +@end deffn
> +
> +
>   @node unset
>   @subsection unset
>   
> @@ -5405,6 +5475,18 @@ only on PC BIOS platforms.
>   @end deffn
>   @end ignore
>   
> +@node verify_appended
> +@subsection verify_appended
> +
> +@deffn Command verify_appended file
> +Verifies an appended signature on @var{file} against the trusted certificates
> +known to GRUB (See @pxref{list_certificates}, @pxref{trust_certificate}, and
> +@pxref{distrust_certificate}).
> +
> +Exit code @code{$?} is set to 0 if the signature validates
> +successfully.  If validation fails, it is set to a non-zero value.
> +See @xref{Using appended signatures}, for more information.
> +@end deffn
>   
>   @node verify_detached
>   @subsection verify_detached
> @@ -5423,7 +5505,7 @@ tried.
>   
>   Exit code @code{$?} is set to 0 if the signature validates
>   successfully.  If validation fails, it is set to a non-zero value.
> -@xref{Using digital signatures}, for more information.
> +@xref{Using GPG-style digital signatures}, for more information.
>   @end deffn
>   
>   @node videoinfo
> @@ -5789,13 +5871,14 @@ environment variables and commands are listed in the same order.
>   @chapter Security
>   
>   @menu
> -* Authentication and authorisation:: Users and access control
> -* Using digital signatures::         Booting digitally signed code
> -* UEFI secure boot and shim::        Booting digitally signed PE files
> -* Secure Boot Advanced Targeting::   Embedded information for generation number based revocation
> -* Measured Boot::                    Measuring boot components
> -* Lockdown::                         Lockdown when booting on a secure setup
> -* Signing GRUB itself::              Ensuring the integrity of the GRUB core image
> +* Authentication and authorisation::   Users and access control
> +* Using GPG-style digital signatures:: Booting digitally signed code
> +* Using appended signatures::          An alternative approach to booting digitally signed code
> +* UEFI secure boot and shim::          Booting digitally signed PE files
> +* Secure Boot Advanced Targeting::     Embedded information for generation number based revocation
> +* Measured Boot::                      Measuring boot components
> +* Lockdown::                           Lockdown when booting on a secure setup
> +* Signing GRUB itself::                Ensuring the integrity of the GRUB core image
>   @end menu
>   
>   @node Authentication and authorisation
> @@ -5869,8 +5952,8 @@ generating configuration files with authentication.  You can use
>   adding @kbd{set superusers=} and @kbd{password} or @kbd{password_pbkdf2}
>   commands.
>   
> -@node Using digital signatures
> -@section Using digital signatures in GRUB
> +@node Using GPG-style digital signatures
> +@section Using GPG-style digital signatures in GRUB
>   
>   GRUB's @file{core.img} can optionally provide enforcement that all files
>   subsequently read from disk are covered by a valid digital signature.
> @@ -5953,6 +6036,82 @@ or BIOS) configuration to cause the machine to boot from a different
>   (attacker-controlled) device.  GRUB is at best only one link in a
>   secure boot chain.
>   
> +@node Using appended signatures
> +@section Using appended signatures in GRUB
> +
> +GRUB supports verifying Linux-style 'appended signatures' for secure boot.
> +Appended signatures are PKCS#7 messages containing a signature over the
> +contents of a file, plus some metadata, appended to the end of a file. A file
> +with an appended signature ends with the magic string:
> +
> +@example
> +~Module signature appended~\n
> +@end example
> +
> +where @code{\n} represents the carriage-return character, @code{0x0a}.


\n is 0xa but it's called line-feed.


> +
> +To enable appended signature verification, load the appendedsig module and an
> +x509 certificate for verification. Building the appendedsig module into the
> +core grub image is recommended.
> +
> +Certificates can be managed at boot time using the @pxref{trust_certificate},
> +@pxref{distrust_certificate} and @pxref{list_certificates} commands.
> +Certificates can also be built in to the core image using the @code{--x509}
> +parameter to @command{grub-install} or @command{grub-mkimage}.
> +
> +A file can be explictly verified using the @pxref{verify_appended} command.
> +
> +Only signatures made with the SHA-256 or SHA-512 hash algorithm are supported,
> +and only RSA signatures are supported.
> +
> +A file can be signed with the @command{sign-file} utility supplied with the
> +Linux kernel source. For example, if you have @code{signing.key} as the private
> +key and @code{certificate.der} as the x509 certificate containing the public key:
> +
> +@example
> +sign-file SHA256 signing.key certificate.der vmlinux vmlinux.signed
> +@end example
> +
> +Enforcement of signature verification is controlled by the
> +@code{check_appended_signatures} variable. Verification will only take place
> +when files are loaded if the variable is set to @code{enforce}. If a
> +certificate is built into the grub core image with the @code{--x509} parameter,
> +the variable will be automatically set to @code{enforce} when the appendedsig
> +module is loaded.
> +
> +Unlike GPG-style signatures, not all files loaded by GRUB are required to be
> +signed. Once verification is turned on, the following file types must carry
> +appended signatures:
> +
> +@enumerate
> +@item Linux, Multiboot, BSD, XNU and Plan9 kernels
> +@item Grub modules, except those built in to the core image
> +@item Any new certificate files to be trusted
> +@end enumerate
> +
> +ACPI tables and Device Tree images will not be checked for appended signatures
> +but must be verified by another mechanism such as GPG-style signatures before
> +they will be loaded.
> +
> +No attempt is made to validate any other file type. In particular,
> +chain-loaded binaries are not verified - if your platform supports
> +chain-loading and this cannot be disabled, consider an alternative secure
> +boot mechanism.
> +
> +As with GPG-style appended signatures, signature checking does @strong{not}
> +stop an attacker with console access from dropping manually to the GRUB
> +console and executing:
> +
> +@example
> +set check_appended_signatures=no
> +@end example
> +
> +Refer to the section on password-protecting GRUB (@pxref{Authentication
> +and authorisation}) for more information on preventing this.
> +
> +Additionally, special care must be taken around the @command{loadenv} command,
> +which can be used to turn off @code{check_appended_signature}.
> +
>   @node UEFI secure boot and shim
>   @section UEFI secure boot and shim support
>   


With this nit fixed: Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>




  reply	other threads:[~2021-07-19 22:24 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-30  8:40 [PATCH v2 00/22] appended signature secure boot support Daniel Axtens
2021-06-30  8:40 ` [PATCH v2 01/22] ieee1275: drop HEAP_MAX_ADDR, HEAP_MIN_SIZE Daniel Axtens
2021-07-12 12:33   ` Stefan Berger
2021-07-14 16:21   ` Daniel Kiper
2021-06-30  8:40 ` [PATCH v2 02/22] ieee1275: claim more memory Daniel Axtens
2021-07-12 12:35   ` Stefan Berger
2021-07-15 21:51   ` Daniel Kiper
2021-07-16  3:59     ` Patrick Steinhardt
2021-07-21 14:45       ` Daniel Kiper
2021-07-21 15:24         ` Stefan Berger
2021-07-22 17:11         ` Stefan Berger
2021-07-28 11:17       ` Daniel Kiper
2021-06-30  8:40 ` [PATCH v2 03/22] ieee1275: request memory with ibm, client-architecture-support Daniel Axtens
2021-07-12 12:40   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 04/22] Add suport for signing grub with an appended signature Daniel Axtens
2021-07-12 12:43   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 05/22] docs/grub: Document signing grub under UEFI Daniel Axtens
2021-07-12 12:44   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 06/22] docs/grub: Document signing grub with an appended signature Daniel Axtens
2021-07-12 12:46   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 07/22] dl: provide a fake grub_dl_set_persistent for the emu target Daniel Axtens
2021-07-12 12:48   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 08/22] pgp: factor out rsa_pad Daniel Axtens
2021-07-12 12:52   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 09/22] crypto: move storage for grub_crypto_pk_* to crypto.c Daniel Axtens
2021-07-12 12:54   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 10/22] posix_wrap: tweaks in preparation for libtasn1 Daniel Axtens
2021-07-12 12:56   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 11/22] libtasn1: import libtasn1-4.16.0 Daniel Axtens
2021-07-20 21:46   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 12/22] libtasn1: disable code not needed in grub Daniel Axtens
2021-07-20 21:47   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 13/22] libtasn1: changes for grub compatibility Daniel Axtens
2021-07-12 13:04   ` Stefan Berger
2022-04-21  6:16     ` Daniel Axtens
2021-06-30  8:40 ` [PATCH v2 14/22] libtasn1: compile into asn1 module Daniel Axtens
2021-07-12 13:05   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 15/22] test_asn1: test module for libtasn1 Daniel Axtens
2021-07-12 19:35   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 16/22] grub-install: support embedding x509 certificates Daniel Axtens
2021-07-12 20:24   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 17/22] appended signatures: import GNUTLS's ASN.1 description files Daniel Axtens
2021-07-19 21:09   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 18/22] appended signatures: parse PKCS#7 signedData and X.509 certificates Daniel Axtens
2021-07-19 22:02   ` Stefan Berger
2022-04-21  6:36     ` Daniel Axtens
2021-06-30  8:40 ` [PATCH v2 19/22] appended signatures: support verifying appended signatures Daniel Axtens
2021-07-20  1:31   ` Stefan Berger
2022-04-21  7:10     ` Daniel Axtens
2021-06-30  8:40 ` [PATCH v2 20/22] appended signatures: verification tests Daniel Axtens
2021-07-20 12:49   ` Stefan Berger
2021-06-30  8:40 ` [PATCH v2 21/22] appended signatures: documentation Daniel Axtens
2021-07-19 22:24   ` Stefan Berger [this message]
2022-04-21  7:15     ` Daniel Axtens
2021-06-30  8:40 ` [PATCH v2 22/22] ieee1275: enter lockdown based on /ibm,secure-boot Daniel Axtens
2021-07-19 22:08   ` Stefan Berger

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=a38659f4-d8f8-50a4-a943-99546157dd4b@linux.ibm.com \
    --to=stefanb@linux.ibm.com \
    --cc=alastair@d-silva.org \
    --cc=dja@axtens.net \
    --cc=grub-devel@gnu.org \
    --cc=nayna@linux.ibm.com \
    --cc=rashmica.g@gmail.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.