Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1mkigu-0002UX-Rb for mharc-grub-devel@gnu.org; Wed, 10 Nov 2021 03:10:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mkigs-0002Qt-52 for grub-devel@gnu.org; Wed, 10 Nov 2021 03:10:42 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:25522 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 1mkigo-0006ds-MC for grub-devel@gnu.org; Wed, 10 Nov 2021 03:10:40 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1AA805el018518; Wed, 10 Nov 2021 08:10:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=zD/feQQoDb6FtY5mqJ1R8dBWLads4ziqyVinUfx8i5Q=; b=VHxa2E/WTPKttP9EfrxTRCQYIfTmWzkZtAVt7SPm8BV5yyPEoxHtoyB2KKzgQon5cN4O xu1xnkdw3hA1oYVmndJnZVC44qKiOe65ufvayKfolkH7W0yaGdLYmi3I2lAZVrf2OqxW zYWFriJ5RmBO8RPyiHF92mdNuIAX4+BRc8Reu1VRnfKEBAoWNOYOaTrdXLPajcCSCjt9 xKRzIyORydsk/uPg1dbHn1SlsU4mGnvhECe7eR84EJ38VksWViLJc5nhNK0nCIgLALDj UdbsRg6shkT3EPZmZmGv5CnKHsRJjtxr0LgJxszrKshs50T/nkOZ52hd2SNgrDxTs3O3 eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3c862bmjx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Nov 2021 08:10:33 +0000 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1AA80Xta002157; Wed, 10 Nov 2021 08:10:33 GMT Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0b-001b2d01.pphosted.com with ESMTP id 3c862bmjwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Nov 2021 08:10:33 +0000 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1AA89VFb011315; Wed, 10 Nov 2021 08:10:32 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma05wdc.us.ibm.com with ESMTP id 3c5hbc3cm1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 10 Nov 2021 08:10:32 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1AA8APPs38207862 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Nov 2021 08:10:25 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 848C87805F; Wed, 10 Nov 2021 08:10:25 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B69EF78060; Wed, 10 Nov 2021 08:10:21 +0000 (GMT) Received: from [9.160.77.174] (unknown [9.160.77.174]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 10 Nov 2021 08:10:21 +0000 (GMT) Message-ID: Date: Wed, 10 Nov 2021 10:10:20 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: [RESEND v3 3/3] efi: Add API for retrieving the EFI secret for cryptodisk Content-Language: en-US To: James Bottomley , grub-devel@gnu.org Cc: thomas.lendacky@amd.com, ashish.kalra@amd.com, brijesh.singh@amd.com, david.kaplan@amd.com, jon.grimm@amd.com, tobin@ibm.com, frankeh@us.ibm.com, "Dr . David Alan Gilbert" , Dov.Murik1@il.ibm.com, Javier Martinez Canillas , Dov Murik References: <20211109135356.10695-1-jejb@linux.ibm.com> <20211109135356.10695-4-jejb@linux.ibm.com> From: Dov Murik In-Reply-To: <20211109135356.10695-4-jejb@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UPH5PbkWwsM8QD7HnFurWHPQXSxCB_MV X-Proofpoint-ORIG-GUID: BfB4ET6Ef3CW4yOLbUPgQePMcNSbafGY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-10_02,2021-11-08_02,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 mlxscore=0 malwarescore=0 bulkscore=0 adultscore=0 spamscore=0 priorityscore=1501 impostorscore=0 phishscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111100043 Received-SPF: pass client-ip=148.163.158.5; envelope-from=dovmurik@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-1.678, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=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.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Nov 2021 08:10:42 -0000 On 09/11/2021 15:53, James Bottomley wrote: > This module is designed to provide an efisecret command which > interrogates the EFI configuration table to find the location of the > confidential computing secret and tries to register the secret with > the cryptodisk. > > The secret is stored in a boot allocated area, usually a page in size. > The layout of the secret injection area is a header > > |GRUB_EFI_SECRET_TABLE_HEADER_GUID|len| > > with entries of the form > > |guid|len|data| > > the guid corresponding to the disk encryption passphrase is > GRUB_EFI_DISKPASSWD_GUID and data must be a zero terminated string. > To get a high entropy string that doesn't need large numbers of > iterations, use a base64 encoding of 33 bytes of random data. > > Signed-off-by: James Bottomley > > --- > > v2: use callback to print failure message and destroy secret > v3: change to generic naming to use for TDX and SEV and use new mechanism > v4: review fixes > --- > grub-core/Makefile.core.def | 8 +++ > grub-core/disk/efi/efisecret.c | 125 +++++++++++++++++++++++++++++++++ > include/grub/efi/api.h | 15 ++++ > 3 files changed, 148 insertions(+) > create mode 100644 grub-core/disk/efi/efisecret.c > > diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def > index 8022e1c0a..6293ddaa5 100644 > --- a/grub-core/Makefile.core.def > +++ b/grub-core/Makefile.core.def > @@ -788,6 +788,14 @@ module = { > enable = efi; > }; > > +module = { > + name = efisecret; > + > + common = disk/efi/efisecret.c; > + > + enable = efi; > +}; > + > module = { > name = lsefimmap; > > diff --git a/grub-core/disk/efi/efisecret.c b/grub-core/disk/efi/efisecret.c > new file mode 100644 > index 000000000..a8d1f39fc > --- /dev/null > +++ b/grub-core/disk/efi/efisecret.c > @@ -0,0 +1,125 @@ > +#include > +#include > +#include > +#include > +#include > +#include > + > +GRUB_MOD_LICENSE ("GPLv3+"); > + > +static grub_efi_packed_guid_t secret_guid = GRUB_EFI_SECRET_TABLE_GUID; > +static grub_efi_packed_guid_t tableheader_guid = GRUB_EFI_SECRET_TABLE_HEADER_GUID; > +static grub_efi_packed_guid_t diskpasswd_guid = GRUB_EFI_DISKPASSWD_GUID; > + > +struct efi_secret { > + grub_uint64_t base; > + grub_uint64_t size; > +}; > + > +struct secret_header { > + grub_efi_packed_guid_t guid; > + grub_uint32_t len; > +}; > + > +struct secret_entry { > + grub_efi_packed_guid_t guid; > + grub_uint32_t len; > + char data[0]; > +}; > + > +static grub_err_t > +grub_efi_secret_put (const char *arg __attribute__((unused)), int have_it, > + char **ptr) > +{ > + struct secret_entry *e = (struct secret_entry *)(*ptr - (long)&((struct secret_entry *)0)->data); Maybe clearer (not tested): struct secret_entry *e = (struct secret_entry *)(*ptr - offsetof(struct secret_entry, data)); > + > + /* destroy the secret */ > + grub_memset (e, 0, e->len); This destroys the GUID field (good), the secret data (good), but also the len field. Without the correct length value it will be impossible to scan the GUIDed secrets table after the erased entry. If the luks passphrase is the only secret, then there's no problem. But if the OS wants to use other secrets from this table, I suggest erasing only e->guid and e->data. -Dov > + *ptr = NULL; > + > + if (have_it) > + return GRUB_ERR_NONE; > + > + return grub_error (GRUB_ERR_ACCESS_DENIED, "EFI secret failed to unlock any volumes"); > +} > + [snip]