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 51AFFC433FE for ; Mon, 7 Nov 2022 15:36:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232511AbiKGPgI (ORCPT ); Mon, 7 Nov 2022 10:36:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232555AbiKGPgH (ORCPT ); Mon, 7 Nov 2022 10:36:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C5B11C12E for ; Mon, 7 Nov 2022 07:36:06 -0800 (PST) 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 4CBD1B81215 for ; Mon, 7 Nov 2022 15:36:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40335C433B5; Mon, 7 Nov 2022 15:36:03 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="hA+JxDQ6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1667835360; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=D9vocWNXJBjlYSYi1SYn5MPKJb2/JhDTTJ5KWtoy7jY=; b=hA+JxDQ6mxS8rDVgn/HTM0pqPZtz6fltXkfA70WdmXBRL0a6FANTFP0Anmbh4zoeXnnn/g 7TCtm/FeRGq/dEhMxI5/udsNp5LZZ2I1XoFDb5rAgKkNny2O2RXBcWIl+IJTMEJwlgf9nk Cd/6siTo9lPDvfYXqWzdOrmdveA2jZY= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 8f40a478 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 7 Nov 2022 15:36:00 +0000 (UTC) From: "Jason A. Donenfeld" To: gregkh@linuxfoundation.org Cc: Ard Biesheuvel , stable@vger.kernel.org, "Jason A . Donenfeld" , Ilias Apalodimas Subject: [PATCH 4.14.y] efi: random: reduce seed size to 32 bytes Date: Mon, 7 Nov 2022 16:35:52 +0100 Message-Id: <20221107153552.21981-1-Jason@zx2c4.com> In-Reply-To: <16678349111147@kroah.com> References: <16678349111147@kroah.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Ard Biesheuvel commit 161a438d730dade2ba2b1bf8785f0759aba4ca5f upstream. 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. [stable: READ_ONCE() wasn't backported in the first place.] Cc: # v4.14+ Signed-off-by: Ard Biesheuvel Reviewed-by: Jason A. Donenfeld Acked-by: Ilias Apalodimas Signed-off-by: Jason A. Donenfeld --- 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 24365601fbbf..ed981f5e29ae 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -532,7 +532,7 @@ int __init efi_config_parse_tables(void *config_tables, int count, int sz, seed = early_memremap(efi.rng_seed, sizeof(*seed)); if (seed != NULL) { - size = 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 2c63afd68978..8b25cd2bed40 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -1607,7 +1607,7 @@ efi_status_t efi_exit_boot_services(efi_system_table_t *sys_table, void *priv, efi_exit_boot_map_processing priv_func); -#define EFI_RANDOM_SEED_SIZE 64U +#define EFI_RANDOM_SEED_SIZE 32U // BLAKE2S_HASH_SIZE struct linux_efi_random_seed { u32 size; -- 2.38.1