Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp16954rdb; Wed, 21 Feb 2024 15:24:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXax8BMs3HfS0IWFl1zImT9aH/QKOUnpcdtiWS7p3l0fBIZUBa7buIwjtKRQzRNUridW2mRSs/zH6UdOIg86GlOAxGhpa6qHQQ4ll0e9A== X-Google-Smtp-Source: AGHT+IGIY4XBEtYM6Ul1NwislnYyiTqMva7G7Oz5/pfpUN1xJs6o/dFnW2rYh72niYseUMI87Nbr X-Received: by 2002:a17:906:b191:b0:a3e:9aa3:bbd1 with SMTP id w17-20020a170906b19100b00a3e9aa3bbd1mr6247892ejy.11.1708557877973; Wed, 21 Feb 2024 15:24:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708557877; cv=pass; d=google.com; s=arc-20160816; b=iDj37YY3hT2JT2eGN6N9YLkO+dQIwZwE086NNrtqiTSDFzC6mFyxEzdVexBLfPEsX4 ypakE33sVVXWCeqkRaHa7sKVGdwO8DSBsQtprmgceTS5Fh/Vb6Ss5mltaYTqatgX5E4l QoDYZqLd03cggi+0oCr50ziLKqDlU+HFb25snAHCiqR6yjUM0aFlXKH8aHx+3MRRtlhN xQRNUjDsob1hw1Zir8T0Gew12zKcV94zCzIZDRzOZo8A2eShT+qMwD8XLoiegfFHkLlP hxpDxsw9IFKDA013EKZTjXhz74dootb4aYrcWjt7oT6ExlNw8UxwB8ANWPUm2FsDfOmw Laig== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ItKgGXMOAFrTxx4PUZkYzUZLmp00juV4oV060/I8mw0=; fh=tPhJy2YARgFkAio1DZH0BNSQbGl7tv7F/bSkCN/WaA0=; b=bpKwNrLAGY9oX6gKWXlZdFWf/O+dHsI2DUuagqqfIKzGl4Y4MzLzClOQzNY5mAqbaX s3LuHFEGBCvQ/OFdCAHQtRWjNHtIy/U/oc52PaUuAohem9f2Q2Fj4EjqzTg9NGP6wDvo +WPRb2TQHn13rBxwzOTVsFCeFrFYdn2EARTaUPMOylyQTbbjIUjBXlMKO9JD8GSu8MCS LFjAwW1GNxPErQq3l2sEjSapT5KloNcGbqrMzAqS/u7TWr7BY2+nAZYZGcPhytPewkZh yCch7GL9cfkuKaBug5f3t2c2AP4bt2d+4ajjIdNK9pNoqhRtmj8GU16tnkjC0c0gOPo9 Ms6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uo6j9C+3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75651-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id jj16-20020a170907985000b00a3ee77a885esi2158809ejc.819.2024.02.21.15.24.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 15:24:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75651-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Uo6j9C+3; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-75651-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75651-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8E08B1F2364C for ; Wed, 21 Feb 2024 23:24:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AD41F12A14C; Wed, 21 Feb 2024 23:24:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Uo6j9C+3" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADBCD56456; Wed, 21 Feb 2024 23:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708557862; cv=none; b=bXgU2jiPSdcUFeC6nq9/Qpw2zdwS/FJLxKrx6uuLARE4b7tPNzu1ossHia/rDzsD18Jq6KEDdKh2vMt4d7gmi9YN2f6ObCB66XPOC/TuHQovLxS/0uqnXl0ayOAsGAefgaBWGa5XVT5IO91FgQEbCm5wa1LCn+AjhZYSWuWVDB0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708557862; c=relaxed/simple; bh=o0pBvdU+JHgT39C/oZ43v61yIgxOBybqfEpddDffT+s=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=X4BOlSGoxPIU5l4AobN6VjfgXmiDgDv5hqQvSGx3xa3c65QB7eMHJtTkcYLfRLU51C8OKtl7CQoXmQWytOTZ3lGDbADrRJzBu7a6z7cWLzXSoKu22yv7Bsh+EH3sgF8XDOLY9T0PUdCXrIhdLSdej4i1LBDBLcf2RFXmQBwyGpE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Uo6j9C+3; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2D2A2C433B2; Wed, 21 Feb 2024 23:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708557862; bh=o0pBvdU+JHgT39C/oZ43v61yIgxOBybqfEpddDffT+s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Uo6j9C+3yRULLuhfUameeJdnFArY/DJQDmDNfb1NtvgSUoJu5xf4jfx3Gzy+QWSD9 /Ki6xXWWXFKWco2i+oBjemS298yxFH2zmONSAJcVKpgnn5ASa+vrnmQIpFxASzABp+ xoSQLSGYl7MTRjNIb7yQfurBY6V9FXK8ivBg1ovDs85Q1KUONIJVWj5xmY8Ur8JYYU fZHc/w3kaVNWAkptQF2laAOVKKd9frUPsRF+EkoYYE7i6AHxoYzxa8iLUf660a9KUD GjhfnDzRtt2+7CtEkm91mWF+v2OU9tMK+ATcehpGg8SBuGV4NPe2dcC3yYgKO2TTcg nGOx4pK29xnCA== Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d2531294faso19792401fa.2; Wed, 21 Feb 2024 15:24:22 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVyNDcEzKTTQSv5DNDzm/PrucU88RphNZGanUIZpAW4RGjDQJRoA7FJlrzpZTt4kpx2CrcO1ZAs3P9e/iVNqF1VhthsobAG+dhfnKTe7wSsSdjrnEPK160TbQEifnJ6cxMni/EG6Kb7xGz3/xfbB6BHeSGx4yzb7N1MvOkq+WCmOCrewD+AbEAMPqmnF+BWfUgQNA48h1Km3vftmz4GB/6o3gILoVIaorvMToST92829DTGtVOhqZFyPaf6tC0X4XMJ X-Gm-Message-State: AOJu0YxaIvoxLHyGYb7bxG007v0Gnu3PS5YuKWr7ng7EE0b9ZPf+wHTt YQ0yIU0PViUTWaBbYJ1dhHKJnMQTD7DbPx79iV/ma/Dee8P1mLaifevw0t3hppN3dAzc3eNCzkT vnyRwpFbEarFUMmBRf6EbMcc5eYc= X-Received: by 2002:a2e:b8c8:0:b0:2d0:c77c:b1ca with SMTP id s8-20020a2eb8c8000000b002d0c77cb1camr14950388ljp.49.1708557860236; Wed, 21 Feb 2024 15:24:20 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240214221847.2066632-1-ross.philipson@oracle.com> <20240214221847.2066632-16-ross.philipson@oracle.com> In-Reply-To: From: Ard Biesheuvel Date: Thu, 22 Feb 2024 00:24:06 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 15/15] x86: EFI stub DRTM launch support for Secure Launch To: "H. Peter Anvin" , Kees Cook Cc: ross.philipson@oracle.com, linux-kernel@vger.kernel.org, x86@kernel.org, linux-integrity@vger.kernel.org, linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, kexec@lists.infradead.org, linux-efi@vger.kernel.org, dpsmith@apertussolutions.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, mjg59@srcf.ucam.org, James.Bottomley@hansenpartnership.com, peterhuewe@gmx.de, jarkko@kernel.org, jgg@ziepe.ca, luto@amacapital.net, nivedita@alum.mit.edu, herbert@gondor.apana.org.au, davem@davemloft.net, kanth.ghatraju@oracle.com, trenchboot-devel@googlegroups.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, 21 Feb 2024 at 21:37, H. Peter Anvin wrote: > > On February 21, 2024 12:17:30 PM PST, ross.philipson@oracle.com wrote: > >On 2/15/24 1:01 AM, Ard Biesheuvel wrote: > >> On Wed, 14 Feb 2024 at 23:32, Ross Philipson wrote: > >>> > >>> This support allows the DRTM launch to be initiated after an EFI stub > >>> launch of the Linux kernel is done. This is accomplished by providing > >>> a handler to jump to when a Secure Launch is in progress. This has to= be > >>> called after the EFI stub does Exit Boot Services. > >>> > >>> Signed-off-by: Ross Philipson > >>> --- > >>> drivers/firmware/efi/libstub/x86-stub.c | 55 ++++++++++++++++++++++= +++ > >>> 1 file changed, 55 insertions(+) > >>> > >>> diff --git a/drivers/firmware/efi/libstub/x86-stub.c b/drivers/firmwa= re/efi/libstub/x86-stub.c > >>> index 0d510c9a06a4..4df2cf539194 100644 > >>> --- a/drivers/firmware/efi/libstub/x86-stub.c > >>> +++ b/drivers/firmware/efi/libstub/x86-stub.c > >>> @@ -9,6 +9,7 @@ > >>> #include > >>> #include > >>> #include > >>> +#include > >>> > >>> #include > >>> #include > >>> @@ -810,6 +811,57 @@ static efi_status_t efi_decompress_kernel(unsign= ed long *kernel_entry) > >>> return EFI_SUCCESS; > >>> } > >>> > >>> +static void efi_secure_launch(struct boot_params *boot_params) > >>> +{ > >>> + struct slr_entry_uefi_config *uefi_config; > >>> + struct slr_uefi_cfg_entry *uefi_entry; > >>> + struct slr_entry_dl_info *dlinfo; > >>> + efi_guid_t guid =3D SLR_TABLE_GUID; > >>> + struct slr_table *slrt; > >>> + u64 memmap_hi; > >>> + void *table; > >>> + u8 buf[64] =3D {0}; > >>> + > >> > >> If you add a flex array to slr_entry_uefi_config as I suggested in > >> response to the other patch, we could simplify this substantially > > > >I feel like there is some reason why we did not use flex arrays. We were= talking and we seem to remember we used to use them and someone asked us t= o remove them. We are still looking into it. But if we can go back to them,= I will take all the changes you recommended here. > > > > Linux kernel code doesn't use VLAs because of the limited stack size, and= VLAs or alloca() makes stack size tracking impossible. Although this techn= ically speaking runs in a different environment, it is easier to enforce th= e constraint globally. Flex array !=3D VLA VLAs were phased out because of this reason (and VLAISs [VLAs in structs] were phased out before that because they are a GNU extension and not supported by Clang) Today, VLAs are not supported anywhere in the kernel. Flex arrays are widely used in the kernel. A flex array is a trailing array of unspecified size in a struct that makes the entire *type* have a variable size. But that does not make them VLAs (or VLAISs) - a VLA is a stack allocated *variable* whose size is based on a function parameter. Instances of types containing flex arrays can be allocated statically, or dynamically on the heap. This is common practice in the kernel, and even supported by instrumentation to help the compiler track the runtime size and flag overruns. We are even in the process of adding compiler support to annotate struct members as carrying the number of elements in an associated flex arrays, to improve the coverage of the instrumentation. I am not asking for a VLA here, only a flex array.