Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp588514rwb; Fri, 18 Nov 2022 05:49:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4dAQEgGohdOjLJcksByeLtHLD9PtYwck/ZPd41PcyGYSuOS1JJatuzkMbWD3/3y2ulZkVt X-Received: by 2002:a17:902:7c81:b0:186:9c32:79d9 with SMTP id y1-20020a1709027c8100b001869c3279d9mr8057980pll.47.1668779372255; Fri, 18 Nov 2022 05:49:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668779372; cv=none; d=google.com; s=arc-20160816; b=xkrEViI3dBMGX6sakFMkKtuFzsOZXT8rdHZP4mKF6GL0jgzVz3IWuqXao3D5YiEDTW 5vZ9a4u73LCao1WWY9jSTzwLorz9acS3i2UdRTxA5RuWYvXGEcu0JVGDV9uiqh47HP5i uSs3OzeIiED6BShSq0u2jLnVuqAsUgWn3NywSrKz55szo+kHi+26tkW2Ds+q0bUq9P9z qkQFDRhoflK50O3zaCTxQkRy2nTVdnmx4yAgW/n9D1bnAwXO4fXE4Na0gvfuXCmFLVu2 H4dQueC50x1vwshp8U6zSAmbdmf2j9DAHha6pRp03yQJT7tVk7TfDgDHbOaMZEtPvJ/r IeAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Nh+wKp8yEnal64w+3O1z4UzVRdj34fdKJzoeu8AGeCc=; b=I/QAarcTa1FAacQVAqPjFHhzws1SZMtvKYN2dBxn6gdGkVNSj97KW3dzhzxM59VyGI le6Su4LrxfrQIDY9piL6QpXWCRYVlZKZXRSXbMWr6KHYRIpFzhGRYbGKM+B7QD28NpZM GgHIGfTCXu7rMcvtMtH/KAAnukV8l7OWtVHcsR/TxXifBiCoDY9XTSA9n3ECcDNuQt2A H20i5q116EhNbo+wYVe5M8LoK0gSsDmn7DdVB+0QMTbPbS8Sz3MqcvjM1RvoW1gW+VSn EOMcKL6+VzOZgu/dxOLzpJiz98cFUWroSkB5Z2mEpPqQB+i42lSo5b3mdx9on0lvNY06 BDLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=RJUXvtvl; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i22-20020aa787d6000000b005726ac39d2esi3428651pfo.30.2022.11.18.05.49.17; Fri, 18 Nov 2022 05:49:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=RJUXvtvl; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242033AbiKRNey (ORCPT + 99 others); Fri, 18 Nov 2022 08:34:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242190AbiKRNeG (ORCPT ); Fri, 18 Nov 2022 08:34:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA599920A3; Fri, 18 Nov 2022 05:33: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 dfw.source.kernel.org (Postfix) with ESMTPS id 66B956250F; Fri, 18 Nov 2022 13:33:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30FE1C433C1; Fri, 18 Nov 2022 13:33:05 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="RJUXvtvl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1668778383; 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=Nh+wKp8yEnal64w+3O1z4UzVRdj34fdKJzoeu8AGeCc=; b=RJUXvtvljmI7nM8jcrYjPJSKIeKiEHKTM0jT3pZbVZlfbnEdta+WRkCwltOF8J8+FwHPvq /+3ggZVwSf20Q0cmbQyDlGNU1SSUYo70B34KakKLgRUCu7nO0a9tVhojBiu0pzZMdQ2XVj z7cfy8Phi9lOzGsdGyNKQ7R98T1JaOI= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c42b9edb (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 18 Nov 2022 13:33:03 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-efi@vger.kernel.org, linux-crypto@vger.kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH v2 5/5] efi: random: refresh non-volatile random seed when RNG is initialized Date: Fri, 18 Nov 2022 14:32:39 +0100 Message-Id: <20221118133239.2515648-6-Jason@zx2c4.com> In-Reply-To: <20221118133239.2515648-1-Jason@zx2c4.com> References: <20221118133239.2515648-1-Jason@zx2c4.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org EFI has a rather unique benefit that it has access to some limited non-volatile storage, where the kernel can store a random seed. Register a notification for when the RNG is initialized, and at that point, store a new random seed. Signed-off-by: Jason A. Donenfeld --- drivers/firmware/efi/efi.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index f12cc29bd4b8..f8edf6164833 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -337,6 +337,24 @@ static void __init efi_debugfs_init(void) static inline void efi_debugfs_init(void) {} #endif +static void refresh_nv_rng_seed(struct work_struct *work) +{ + u8 seed[EFI_RANDOM_SEED_SIZE]; + + get_random_bytes(seed, sizeof(seed)); + efi.set_variable(LINUX_EFI_RANDOM_NV_SEED_VAR, &LINUX_EFI_RANDOM_SEED_TABLE_GUID, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, sizeof(seed), seed); + memzero_explicit(seed, sizeof(seed)); +} +static int refresh_nv_rng_seed_notification(struct notifier_block *nb, unsigned long action, void *data) +{ + static DECLARE_WORK(work, refresh_nv_rng_seed); + schedule_work(&work); + return 0; +} +static struct notifier_block refresh_nv_rng_seed_nb = { .notifier_call = refresh_nv_rng_seed_notification }; + /* * We register the efi subsystem with the firmware subsystem and the * efivars subsystem with the efi subsystem, if the system was booted with @@ -413,6 +431,7 @@ static int __init efisubsys_init(void) platform_device_register_simple("efi_secret", 0, NULL, 0); #endif + execute_with_initialized_rng(&refresh_nv_rng_seed_nb); return 0; err_remove_group: -- 2.38.1