Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nhRXe-0003CO-TH for mharc-grub-devel@gnu.org; Thu, 21 Apr 2022 03:47:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhRXK-00037G-4B for grub-devel@gnu.org; Thu, 21 Apr 2022 03:47:37 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:40684) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhRXI-00019i-Hm for grub-devel@gnu.org; Thu, 21 Apr 2022 03:47:33 -0400 Received: by mail-pf1-x434.google.com with SMTP id i24so4247519pfa.7 for ; Thu, 21 Apr 2022 00:47:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IoPmq6qVTN6AQPqK7z6MFHXrPH16OZVu0uP+i8h22e4=; b=DgK6i6jrez8k2zAGBMeVOM61F9NcuwKtAG04eiOsrrJSa2LoYRzhmzCVAzco9jpKYl Qj2jBLvjHjZrwNS/LyI0I8+mZsXfVLpC0jquhIrdf1WLpaIUqrC0o/FuM7ylsHBOCRnb y+YZAg78wWrjIVB0SIEWZ9pJ0GNI9ppH8bMKQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IoPmq6qVTN6AQPqK7z6MFHXrPH16OZVu0uP+i8h22e4=; b=LadFoFqvfcck1ChbtqSiQ9WOD5jjp1PwqPS7jqdl2rn4ccWeWrZ1ZXoRE8lM5JE1IM cLFPKaWY4EL9fppS7h9xuSWURV8MNSYh/BTN5T8asPrB1qakSEHfsJGLzfTQSiDlZilG ERUGanxIIdWn7EhpvdMu1jCoA4+DmpPubZA/J85YJr9z6jJcjptxP4t46QSFNFXt7JtG o9785FvR7wzYB2W5QXld4DMe0qy3uRSbxjHDq/HTvEVfJhzxACiBMbHLWZJOUkWXdrrR t6grXachasNK07gvBXtYq7vqH4L6TrZOgt5rpqOtWWZl2cZ+CLeeRp8rH/shKmsd7Sm8 4pdA== X-Gm-Message-State: AOAM5318NMQgo4Zt7p+BUVM07EdsQmCIhXDzHq6IWt1VPNGTzRHsQasu L2MqZcPmpT+JbKaxK+r+P+XFz55+PEhu1g== X-Google-Smtp-Source: ABdhPJw46r+Wgxjq9c04RtJuAg1bPStaE4ql0IttExCqNMMPpCRzDnVDMG/8Z9fx1ak2jDs8Hh6hUA== X-Received: by 2002:a63:82c1:0:b0:3aa:93f4:7ea5 with SMTP id w184-20020a6382c1000000b003aa93f47ea5mr774214pgd.573.1650527250457; Thu, 21 Apr 2022 00:47:30 -0700 (PDT) Received: from localhost ([2001:4479:e000:e400:4260:be14:52a8:8c94]) by smtp.gmail.com with ESMTPSA id bc11-20020a656d8b000000b0039cc4dbb295sm20971118pgb.60.2022.04.21.00.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Apr 2022 00:47:30 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: rashmica.g@gmail.com, alastair@d-silva.org, nayna@linux.ibm.com, sudhakar@linux.ibm.com, Daniel Axtens , Stefan Berger Subject: [PATCH v3 03/19] docs/grub: Document signing grub with an appended signature Date: Thu, 21 Apr 2022 17:46:58 +1000 Message-Id: <20220421074714.1561049-4-dja@axtens.net> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220421074714.1561049-1-dja@axtens.net> References: <20220421074714.1561049-1-dja@axtens.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::434; envelope-from=dja@axtens.net; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Apr 2022 07:47:38 -0000 Signing grub for firmware that verifies an appended signature is a bit fiddly. I don't want people to have to figure it out from scratch so document it here. Signed-off-by: Daniel Axtens Reviewed-by: Stefan Berger --- docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/docs/grub.texi b/docs/grub.texi index fdf2884b814f..a7f5f6cd154c 100644 --- a/docs/grub.texi +++ b/docs/grub.texi @@ -6119,6 +6119,48 @@ image works under UEFI secure boot and can maintain the secure-boot chain. It will also be necessary to enrol the public key used into a relevant firmware key database. +@section Signing GRUB with an appended signature + +The @file{core.img} itself can be signed with a Linux kernel module-style +appended signature. + +To support IEEE1275 platforms where the boot image is often loaded directly +from a disk partition rather than from a file system, the @file{core.img} +can specify the size and location of the appended signature with an ELF +note added by @command{grub-install}. + +An image can be signed this way using the @command{sign-file} command from +the Linux kernel: + +@example +@group +# grub.key is your private key and certificate.der is your public key + +# Determine the size of the appended signature. It depends on the signing +# certificate and the hash algorithm +touch empty +sign-file SHA256 grub.key certificate.der empty empty.sig +SIG_SIZE=`stat -c '%s' empty.sig` +rm empty empty.sig + +# Build a grub image with $SIG_SIZE reserved for the signature +grub-install --appended-signature-size $SIG_SIZE --modules="..." ... + +# Replace the reserved size with a signature: +# cut off the last $SIG_SIZE bytes with truncate's minus modifier +truncate -s -$SIG_SIZE /boot/grub/powerpc-ieee1275/core.elf core.elf.unsigned +# sign the trimmed file with an appended signature, restoring the correct size +sign-file SHA256 grub.key certificate.der core.elf.unsigned core.elf.signed + +# Don't forget to install the signed image as required +# (e.g. on powerpc-ieee1275, to the PReP partition) +@end group +@end example + +As with UEFI secure boot, it is necessary to build in the required modules, +or sign them separately. + + @node Platform limitations @chapter Platform limitations -- 2.32.0