From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1m2vKr-0005pW-Q5 for mharc-grub-devel@gnu.org; Mon, 12 Jul 2021 08:46:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2vKp-0005ft-Ai for grub-devel@gnu.org; Mon, 12 Jul 2021 08:46:55 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39348 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2vKn-0007a9-5G for grub-devel@gnu.org; Mon, 12 Jul 2021 08:46:54 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16CCY01e086665; Mon, 12 Jul 2021 08:46:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=vXsZIByUm1Od0VxKREJ+hEBRQfSbrEvJgyPKEYj9h6k=; b=IsNx9IcluBLm/k094w6cwmjxyNyQcMgbU5rdxKx8XIFXBXT1x/RJ/oJWvoq2xn4zxji0 po91v5qv3xWPdnuqoK0bu6t5RJfI4ROB+n9PuAHV3OcXNpBnzfFdV0fD/QbMdz5kRjfd kvnp5hP7b9laUnkSm3qGrCtP+odHYm1yYK+23W4uvisFT9+Ryl1CikseL/quI8dSzen2 E9HftKACT/+gOj7H9FhNvCvr/QoNPx1x5abcB284tcGj8puBIHHrVgx9+FpPPzfYH+AP YN+PPibXsN3WubjAPKU9p0jjj3AXBKSVR8zWlp+i2P5VmAOk7pp4b6tKLjog6F1IeUng Cw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 39qs10gk4v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jul 2021 08:46:48 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 16CCcGJX106494; Mon, 12 Jul 2021 08:46:48 -0400 Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0b-001b2d01.pphosted.com with ESMTP id 39qs10gk4k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jul 2021 08:46:48 -0400 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 16CCi1qb017241; Mon, 12 Jul 2021 12:46:47 GMT Received: from b01cxnp22035.gho.pok.ibm.com (b01cxnp22035.gho.pok.ibm.com [9.57.198.25]) by ppma03wdc.us.ibm.com with ESMTP id 39q36a2yha-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 12 Jul 2021 12:46:47 +0000 Received: from b01ledav004.gho.pok.ibm.com (b01ledav004.gho.pok.ibm.com [9.57.199.109]) by b01cxnp22035.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 16CCkkk934079142 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Jul 2021 12:46:47 GMT Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA10A11206B; Mon, 12 Jul 2021 12:46:46 +0000 (GMT) Received: from b01ledav004.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B58DD112069; Mon, 12 Jul 2021 12:46:46 +0000 (GMT) Received: from [9.47.158.152] (unknown [9.47.158.152]) by b01ledav004.gho.pok.ibm.com (Postfix) with ESMTP; Mon, 12 Jul 2021 12:46:46 +0000 (GMT) Subject: Re: [PATCH v2 06/22] docs/grub: Document signing grub with an appended signature To: The development of GNU GRUB , Daniel Axtens Cc: rashmica.g@gmail.com, alastair@d-silva.org, nayna@linux.ibm.com References: <20210630084031.2663622-1-dja@axtens.net> <20210630084031.2663622-7-dja@axtens.net> From: Stefan Berger Message-ID: <35badfa4-bc8f-cc17-7705-821f17092a30@linux.ibm.com> Date: Mon, 12 Jul 2021 08:46:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210630084031.2663622-7-dja@axtens.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 2e1sGVrpi1FUecqBwN4M_vs_dQKlqNiW X-Proofpoint-ORIG-GUID: tTu3U8yeImyH1Lh-w7l_ckbGT3emVfJV X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-12_07:2021-07-12, 2021-07-12 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 suspectscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 bulkscore=0 malwarescore=0 priorityscore=1501 mlxlogscore=999 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2107120099 Received-SPF: pass client-ip=148.163.158.5; envelope-from=stefanb@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-1.479, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 12 Jul 2021 12:46:55 -0000 On 6/30/21 4:40 AM, Daniel Axtens wrote: > 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 > --- > docs/grub.texi | 42 ++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/docs/grub.texi b/docs/grub.texi > index 2ffc3b417312..bed565371460 100644 > --- a/docs/grub.texi > +++ b/docs/grub.texi > @@ -6055,6 +6055,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 > Reviewed-by: Stefan Berger