From patchwork Thu Oct 20 08:39:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 616955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A274C433FE for ; Thu, 20 Oct 2022 08:40:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229978AbiJTIkr (ORCPT ); Thu, 20 Oct 2022 04:40:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230340AbiJTIkn (ORCPT ); Thu, 20 Oct 2022 04:40:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 542C4FE910; Thu, 20 Oct 2022 01:40:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 74DB0B826A1; Thu, 20 Oct 2022 08:40:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C78BFC433C1; Thu, 20 Oct 2022 08:40:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666255228; bh=+9bMSJ0X4Yjn8yLu6yBGJtoukl8NU5/yiaxkP9nsKi4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B36vHDFHBJs6hHEaHMyjxe1wh+DcvDlRFCDQYVuTjgT+acfIGU+saTpvMxdQxlk1T 8TlfBvXwLDxX+eGkk3lQjYjuPA23m9L4Jvci00/mdtEsdTJgxktNiL27Cid/EFBJU9 0jLMJOtiTlJmiHbR5a2aZ/vJo02P8LQJto6OTbwFCUfY/yR9uSgRj+KRgGXCrTioLW RgTyIjae5oL995mOMIaZYthuMfnybMAFi3/EhmRlOC20Dp9Uz6YlpiNbkcp6waw8oy 1wda+VoWOWJ8c435wgvwcqA23zJ9Rs3OgkuC6gJoyVWo+qvGG5lVnhlKMk5W0ukBKg rwn/BHMIFslLg== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Ilias Apalodimas , "Jason A . Donenfeld" , Lennart Poettering , stable@vger.kernel.org Subject: [PATCH v3 1/3] efi: random: reduce seed size to 32 bytes Date: Thu, 20 Oct 2022 10:39:08 +0200 Message-Id: <20221020083910.1902009-2-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221020083910.1902009-1-ardb@kernel.org> References: <20221020083910.1902009-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1656; i=ardb@kernel.org; h=from:subject; bh=+9bMSJ0X4Yjn8yLu6yBGJtoukl8NU5/yiaxkP9nsKi4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjUQkqg0qt7nSGhTRI40z0ewqgrZPZ4lMqOdNYP6j8 xnKM1D+JAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY1EJKgAKCRDDTyI5ktmPJENzC/ 4vYmMEMsuIj+WaTXdML+3JJw2kkRxTAZdg6xm2yFfjuqw+04pJGXHTp40sJQRHHpTbHKxIWKYA8lHF RLeEjRy5s6BQ3V2q1iJ5ttAVEsRJKmLTrzJ1dxk8DDykjW29NCDc6lDoh4Ag9JPcGIrcXc3eKrYa7A E8NnH2s3shVFZjcmPFTbYgDEj/t6IZ+tIKwknt6w2RDodnf4Vv2eyf3qfxvIkMx2aJpOp7RFM2NIlD ypGnTf38d5gXVaMtpoolIP1GFLmOUcr5UNpJ2TlmmxRxUK3qK9UKYcmt8+ZRGXgA+74MxYMCY6JmsV V4qs1FKHDN/FQRw/fCyCiZSVlMua8XxMRW7CE5RaP13ioodvUINDH/uShZGJCfMHw/TFSPEVRWfkKk 8z2Jt/b3e1d4E2kiQv/gK8aBLovalQaoJlt46n/ZmfGxrUZqKgLYJP9pa40rmZbQkgCkQ4LhXH/RJj ZaUY5yWXP2oq48UTTtNXeznwWaddk5l44tJHF5TVEnOHA= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org We no longer need at least 64 bytes of random seed to permit the early crng init to complete. The RNG is now based on Blake2s, so reduce the EFI seed size to the Blake2s hash size, which is sufficient for our purposes. While at it, drop the READ_ONCE(), which was supposed to prevent size from being evaluated after seed was unmapped. However, this cannot actually happen, so READ_ONCE() is unnecessary here. Cc: # v4.14+ Signed-off-by: Ard Biesheuvel Reviewed-by: Jason A. Donenfeld Acked-by: Ilias Apalodimas --- drivers/firmware/efi/efi.c | 2 +- include/linux/efi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 9624735f1575..a949509de62f 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -609,7 +609,7 @@ int __init efi_config_parse_tables(const efi_config_table_t *config_tables, seed = early_memremap(efi_rng_seed, sizeof(*seed)); if (seed != NULL) { - size = READ_ONCE(seed->size); + size = min(seed->size, EFI_RANDOM_SEED_SIZE); early_memunmap(seed, sizeof(*seed)); } else { pr_err("Could not map UEFI random seed!\n"); diff --git a/include/linux/efi.h b/include/linux/efi.h index da3974bf05d3..cf96f8d5f15f 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1225,7 +1225,7 @@ efi_status_t efi_random_get_seed(void); arch_efi_call_virt_teardown(); \ }) -#define EFI_RANDOM_SEED_SIZE 64U +#define EFI_RANDOM_SEED_SIZE 32U // BLAKE2S_HASH_SIZE struct linux_efi_random_seed { u32 size; From patchwork Thu Oct 20 08:39:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 617340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 664C7C4332F for ; Thu, 20 Oct 2022 08:40:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230248AbiJTIkq (ORCPT ); Thu, 20 Oct 2022 04:40:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230324AbiJTIkm (ORCPT ); Thu, 20 Oct 2022 04:40:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8D50FE92D; Thu, 20 Oct 2022 01:40:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4198BB826A6; Thu, 20 Oct 2022 08:40:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97391C4347C; Thu, 20 Oct 2022 08:40:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666255230; bh=ECHaI5zocDylFw60A6Q3tgn4qFote5nVt4SpK7yOsfU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i0SHYPCp8gTNsk1cTUAI2nGCRjiXax+LgHQ6owjjDZiyZRKa0LkdqKHJYEIwlJBmo Wn6xsBL3VUhkguPPGjNpa+xZtDqQUBpYKve4gGUMpd5H9Lhf3PQ/9gPGGYsLPbLIiT qBhZ7Fo1KMA3zK024Mu3R2JGcTX9988YJ2dJz7O6FYpwAs9mRFvkk4tpPll0+7spKe 9mMCmE46ExF0qZgWcD2FczOeByOKlIVa4/+ii0My9Fx4pNBv6QXlV6RVAr9Lp8kCGL w7dzoXS76j5NALuuoc33YQRXtdtWtseKiQQ5IFz5OfVC2yQ/F1aHczmYyZ0Zm5deKF j9if+lVyO4mZA== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Ilias Apalodimas , "Jason A . Donenfeld" , Lennart Poettering , stable@vger.kernel.org Subject: [PATCH v3 2/3] efi: random: Use 'ACPI reclaim' memory for random seed Date: Thu, 20 Oct 2022 10:39:09 +0200 Message-Id: <20221020083910.1902009-3-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221020083910.1902009-1-ardb@kernel.org> References: <20221020083910.1902009-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2101; i=ardb@kernel.org; h=from:subject; bh=ECHaI5zocDylFw60A6Q3tgn4qFote5nVt4SpK7yOsfU=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjUQkrdvptBKznc0r0FPMjTAGWvDsaxzEcM/YaWFbQ h11CwUaJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY1EJKwAKCRDDTyI5ktmPJJuTDA CjOGNUO9xGgMTRLDrkq9BJaOgtspt70o08B0jMmIMnpF4aVdzPphKS7zdmk4NEyXd1WrFm7Yf4RC0r Bk3u5SUyiYwYRmxAsn5Hx2mXLFUkNwHu4Yx55VExb7flFxfuBnuJRJ30weXQybppv9RguuQvt7wbU+ 8qsaIGDtJLp/nn5x2XTAjfoIfG0jwmA+hbG+EdF7pwvOUIJ/Wd4MmF3rKfDGNpIAfRH8vpUkdZtEbn 8im8UJ9VsjXERaSsyzJ5NmlHKT+oDmDjh/CTFp1952E26OArsxvB+Gjs/5OymSP583vlwuuQJM8eRx 9XOEGIVpf8d9ggI160/0I9RYQS97aN0SgUR6yo1/nDGWu2VsVPgjtFsLVmCvd/bs68W9PgBaGAdOIq Z2vSKRhLn20zJBTwPfFg6GQYdUtA4miXljC+TgVtSVvYikVuxBg0KFGJYnqVf4zO/W8P2WBSYIE/qW h2PMxuzjbP2neTA0xi1OyaK2owhpt00pdLesiIr28040o= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org EFI runtime services data is guaranteed to be preserved by the OS, making it a suitable candidate for the EFI random seed table, which may be passed to kexec kernels as well (after refreshing the seed), and so we need to ensure that the memory is preserved without support from the OS itself. However, runtime services data is intended for allocations that are relevant to the implementations of the runtime services themselves, and so they are unmapped from the kernel linear map, and mapped into the EFI page tables that are active while runtime service invocations are in progress. None of this is needed for the RNG seed. So let's switch to EFI 'ACPI reclaim' memory: in spite of the name, there is nothing exclusively ACPI about it, it is simply a type of allocation that carries firmware provided data which may or may not be relevant to the OS, and it is left up to the OS to decide whether to reclaim it after having consumed its contents. Given that in Linux, we never reclaim these allocations, it is a good choice for the EFI RNG seed, as the allocation is guaranteed to survive kexec reboots. One additional reason for changing this now is to align it with the upcoming recommendation for EFI bootloader provided RNG seeds, which must not use EFI runtime services code/data allocations. Cc: # v4.14+ Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/random.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c index 24aa37535372..183dc5cdb8ed 100644 --- a/drivers/firmware/efi/libstub/random.c +++ b/drivers/firmware/efi/libstub/random.c @@ -75,7 +75,7 @@ efi_status_t efi_random_get_seed(void) if (status != EFI_SUCCESS) return status; - status = efi_bs_call(allocate_pool, EFI_RUNTIME_SERVICES_DATA, + status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY, sizeof(*seed) + EFI_RANDOM_SEED_SIZE, (void **)&seed); if (status != EFI_SUCCESS) From patchwork Thu Oct 20 08:39:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 616956 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CEC5CC433FE for ; Thu, 20 Oct 2022 08:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbiJTIkp (ORCPT ); Thu, 20 Oct 2022 04:40:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230285AbiJTIkm (ORCPT ); Thu, 20 Oct 2022 04:40:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E67FFBCFC for ; Thu, 20 Oct 2022 01:40:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 317D561A7B for ; Thu, 20 Oct 2022 08:40:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 653B8C433B5; Thu, 20 Oct 2022 08:40:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666255231; bh=DidgXi01vs3QJl79fyJMKey6h/6Z2yoooMXAGEGQbow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m7LzqgqVvMu7nn9U+HYnAtm98jxrS4jEaqCs4h1wMIwew/WjzhAzGATI81nHR1rt9 n4zElTkByRzWgcoawhMwLEPp+4KFpzbRPAceg+/WMWctdu0bPcDfpk4yRfJvhcyYCH gp2OPD9Go0pvWTRbW24IDGlerOkR32xeGkYZQGN63oj+Ha+pOSSAgE78zG7Pn5Vep/ 5muDCkuM6I8jDw09hnk5I3xVeCo8sYUy2uKZwYGMcwEedUWMitxdCIMlkHfXCuBs2Y oxgK7vfMKquPVRmSH1FmRZTuqJVDiQwAZ8hq/+jX5G0dnBJ0OR3X/ahHQEXJrInmia IEt3zVFFNahcQ== From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Ard Biesheuvel , Ilias Apalodimas , "Jason A . Donenfeld" , Lennart Poettering Subject: [PATCH v3 3/3] efi: random: combine bootloader provided RNG seed with RNG protocol output Date: Thu, 20 Oct 2022 10:39:10 +0200 Message-Id: <20221020083910.1902009-4-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221020083910.1902009-1-ardb@kernel.org> References: <20221020083910.1902009-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4851; i=ardb@kernel.org; h=from:subject; bh=DidgXi01vs3QJl79fyJMKey6h/6Z2yoooMXAGEGQbow=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjUQktk5UXFUYdATXiXa5lDEJuzxwgsQagUOLcYPvL 4zN6F3OJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY1EJLQAKCRDDTyI5ktmPJH4JDA C7pruCaWEkzlKz1sBf0/C3n3u/EdIxPemexn/uXwibNGWozqWqrPX3At4F27NaTy+hXnQaLgG47TYW TxBd4FVvARI+5jl0lmJeJgv64pn1NmDbgiDy8k1DPoCX0z34Cc7JrwdIymfylHsCv4laJEAvI1ONsA Od89CIuTGb52GpR+DIWLRzKmQ2lWRRt5BFMNVH3lrtZr6HipMZD3fG6JaV+tJN4+5tyT69sRoDP1Pv HAbKB/PoEsbTK3NVeH5lO3J2Bsu04+vzaK6XaEBs80XFvGOOqI3Ab5EgyOKGIvo1Nscg4vMlSXWsDn 9QxfKo3AyfdzsWYwda0XnYavJ9dWHzMX5KDp0iyYLyTdm0V4APQ8+VB34O9Y9EmnHIBdaLRCZtpmyJ 9Yx6rt1lekD3vqr+4Ol0WJuuJaK4rgZQcx50xBOV8AgjSJxglImquIFouJOAEPwt9ggl5buMcnP89y IGCRX6frHfNHryuaqyA1FLSjlI73HCAPiClVrvwoleGS4= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Instead of blindly creating the EFI random seed configuration table if the RNG protocol is implemented and works, check whether such a EFI configuration table was provided by an earlier boot stage and if so, concatenate the existing and the new seeds, leaving it up to the core code to mix it in and credit it the way it sees fit. This can be used for, e.g., systemd-boot, to pass an additional seed to Linux in a way that can be consumed by the kernel very early. In that case, the following definitions should be used to pass the seed to the EFI stub: struct linux_efi_random_seed { u32 size; // of the 'seed' array in bytes u8 seed[]; }; The memory for the struct must be allocated as EFI_ACPI_RECLAIM_MEMORY pool memory, and the address of the struct in memory should be installed as a EFI configuration table using the following GUID: LINUX_EFI_RANDOM_SEED_TABLE_GUID 1ce1e5bc-7ceb-42f2-81e5-8aadf180f57b Note that doing so is safe even on kernels that were built without this patch applied, but the seed will simply be overwritten with a seed derived from the EFI RNG protocol, if available. The recommended seed size is 32 bytes, anything beyond that is disregarded when the seeds are concatenated. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efistub.h | 2 ++ drivers/firmware/efi/libstub/random.c | 29 ++++++++++++++++++-- include/linux/efi.h | 2 -- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/firmware/efi/libstub/efistub.h b/drivers/firmware/efi/libstub/efistub.h index a30fb5d8ef05..75280b800eee 100644 --- a/drivers/firmware/efi/libstub/efistub.h +++ b/drivers/firmware/efi/libstub/efistub.h @@ -882,6 +882,8 @@ efi_status_t efi_get_random_bytes(unsigned long size, u8 *out); efi_status_t efi_random_alloc(unsigned long size, unsigned long align, unsigned long *addr, unsigned long random_seed); +efi_status_t efi_random_get_seed(void); + efi_status_t check_platform_features(void); void *get_efi_config_table(efi_guid_t guid); diff --git a/drivers/firmware/efi/libstub/random.c b/drivers/firmware/efi/libstub/random.c index 183dc5cdb8ed..080012e837c3 100644 --- a/drivers/firmware/efi/libstub/random.c +++ b/drivers/firmware/efi/libstub/random.c @@ -67,16 +67,28 @@ efi_status_t efi_random_get_seed(void) efi_guid_t rng_proto = EFI_RNG_PROTOCOL_GUID; efi_guid_t rng_algo_raw = EFI_RNG_ALGORITHM_RAW; efi_guid_t rng_table_guid = LINUX_EFI_RANDOM_SEED_TABLE_GUID; + struct linux_efi_random_seed *prev_seed, *seed = NULL; + int prev_seed_size, seed_size = EFI_RANDOM_SEED_SIZE; efi_rng_protocol_t *rng = NULL; - struct linux_efi_random_seed *seed = NULL; efi_status_t status; status = efi_bs_call(locate_protocol, &rng_proto, NULL, (void **)&rng); if (status != EFI_SUCCESS) return status; + /* + * Check whether a seed was provided by a prior boot stage. In that + * case, instead of overwriting it, let's create a new buffer that can + * hold both, and concatenate the existing and the new seeds. + */ + prev_seed = get_efi_config_table(LINUX_EFI_RANDOM_SEED_TABLE_GUID); + if (prev_seed) { + prev_seed_size = min(prev_seed->size, EFI_RANDOM_SEED_SIZE); + seed_size += prev_seed_size; + } + status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY, - sizeof(*seed) + EFI_RANDOM_SEED_SIZE, + struct_size(seed, bits, seed_size), (void **)&seed); if (status != EFI_SUCCESS) return status; @@ -95,14 +107,25 @@ efi_status_t efi_random_get_seed(void) if (status != EFI_SUCCESS) goto err_freepool; - seed->size = EFI_RANDOM_SEED_SIZE; + seed->size = seed_size; + if (prev_seed) + memcpy(seed->bits + EFI_RANDOM_SEED_SIZE, prev_seed->bits, + prev_seed_size); + status = efi_bs_call(install_configuration_table, &rng_table_guid, seed); if (status != EFI_SUCCESS) goto err_freepool; + if (prev_seed) { + /* wipe and free the old seed if we managed to install the new one */ + memzero_explicit(prev_seed->bits, prev_seed_size); + efi_bs_call(free_pool, prev_seed); + } return EFI_SUCCESS; err_freepool: + efi_warn("Failed to obtain seed from EFI_RNG_PROTOCOL%s\n", + prev_seed ? ", retaining bootloader supplied seed only" : ""); efi_bs_call(free_pool, seed); return status; } diff --git a/include/linux/efi.h b/include/linux/efi.h index cf96f8d5f15f..69454a7ccc6f 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1172,8 +1172,6 @@ void efi_check_for_embedded_firmwares(void); static inline void efi_check_for_embedded_firmwares(void) { } #endif -efi_status_t efi_random_get_seed(void); - #define arch_efi_call_virt(p, f, args...) ((p)->f(args)) /*