Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5842582rwb; Tue, 22 Nov 2022 05:45:23 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Oa9GzYGjJK/7qBEPR0GvcHJI8DCfwZDUZYP1y7ogIYKzzt4/Dop6CaK+NI9Y4SqRQAk8G X-Received: by 2002:a17:906:34d5:b0:7ae:b9fc:8668 with SMTP id h21-20020a17090634d500b007aeb9fc8668mr18450286ejb.257.1669124723632; Tue, 22 Nov 2022 05:45:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669124723; cv=none; d=google.com; s=arc-20160816; b=luJNqwD6sHwSTL5Li4gRH1geqH14sx9uQJ9G6i837EopGv83bzsxs2/RUsABzzoWq9 QhWs57YAu/8mNzjC0/Fi3XBv5EGPC0vWxSQlxp8dQ2oGGXRmxfiaQ1xDLsfXsU+pm79A ZNRXaHkTqADZui8z0vbKBXgRj/PIXUfO2IIyBqe04fu1zOLpy2AIX62Pxaa+RJrZCJs1 ZCzUDCLu+CvgalPqTMHEt/2YSuz3owzquFXVK5mSRIwTTOxv0X0UR4rLGCgYCaAEetOu 3wX5WhOjfpiJ5oTgZjkuFBpWjidFwlKSREEuyf/1YQyZHJTM2HOJqo/JhF7C5bWR/qI4 JIhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=fjebeaZzpZ3mnnrpIEV5KuYwXGEdCE+EQK5GE1APKW4=; b=j6dzTGwnpRJ9OCkG9sS/lDkJT4SbIu8laQCKgUN/jB8KBmnaw1NPGL+xG1QpiZpm+v R7KVGqZqZP8mtrbnnB6mBSW8HJzKUJLQU+RMEhMHwGjmaoMIiVHEjTpjVe+a+sxzdxyg VKKUfCtUX4cux2vNlsaFQMXv2q4+PH7YMncNnpxtcabnaXcSuVRqRJpKEgJO/aqdemhj mL17g1VNAjvu2b+4Co6tdMPPZQu/EFpm0KzCoAnFMuFjg5z6wr/yvOtSXLbT9xdBioW4 F4uRp1Jl2SDCMEBIXsxhozXS2uvB9Y9wiW5EqeLgUFV6UyaHnOou4MYHcF7VV3sJpUDn E74g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dPtI3XTf; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb17-20020a170907161100b007b790c183d5si3993955ejc.260.2022.11.22.05.44.57; Tue, 22 Nov 2022 05:45:23 -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=@kernel.org header.s=k20201202 header.b=dPtI3XTf; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233714AbiKVNj4 (ORCPT + 99 others); Tue, 22 Nov 2022 08:39:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233836AbiKVNjw (ORCPT ); Tue, 22 Nov 2022 08:39:52 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD3B59FE6; Tue, 22 Nov 2022 05:39:51 -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 A9EA7B819ED; Tue, 22 Nov 2022 13:39:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 557BEC43470; Tue, 22 Nov 2022 13:39:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669124388; bh=bAhkPmpXqz2tFgI523IWjd0wI9fHjPVBJ+d3LM6chXU=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=dPtI3XTfZ+GXeh7ghtt9lRdvV7euOHLo5WUTqNWNmfdOgx9PJ4ID1AmZ6CPEoAvET 8OpbOactRW1fKwcfflpIEtWAOqQoXaX0NZ7YefNP6CDij2VsRXSXGDEUSTKMwtZyBu Ed1Tewc8Mq0vP3zLkj0FpQ9ojKlEFz0BpUgeUZ7yKQbBOOyHc6rbFtkhdL9Urta8un 4TRwLtcbHZtBnJp+diJayiETtHWVL9eD6nmuyXoXoWzKIiJzdGECNLcO4SwZlO2K// drZhox4NOBsAg9V3DXEs/TdUA0aqxACv16zmFN2g9I3SiB41sEiJGSeZRAwmIyVioy kFAl9C/luuqBg== Received: by mail-lf1-f42.google.com with SMTP id g12so23632788lfh.3; Tue, 22 Nov 2022 05:39:48 -0800 (PST) X-Gm-Message-State: ANoB5plicwdItKEI33M8wqXHHWSJjHOUkDWif4C9ULh5JvNM8uREWydY 9ZNN8P5wNZDlw4zHoBdNZkUX120KdJRRPxJ7xvI= X-Received: by 2002:a05:6512:3c89:b0:4a2:bfd2:b218 with SMTP id h9-20020a0565123c8900b004a2bfd2b218mr7757722lfv.228.1669124386229; Tue, 22 Nov 2022 05:39:46 -0800 (PST) MIME-Version: 1.0 References: <20221118133239.2515648-1-Jason@zx2c4.com> <20221118133239.2515648-6-Jason@zx2c4.com> In-Reply-To: <20221118133239.2515648-6-Jason@zx2c4.com> From: Ard Biesheuvel Date: Tue, 22 Nov 2022 14:39:34 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 5/5] efi: random: refresh non-volatile random seed when RNG is initialized To: "Jason A. Donenfeld" Cc: linux-efi@vger.kernel.org, linux-crypto@vger.kernel.org, patches@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On Fri, 18 Nov 2022 at 14:34, Jason A. Donenfeld wrote: > > 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(+) > Not sure why I don't see v3 in my inbox. In any case, Reviewed-by: Ard Biesheuvel for this patch, or the one with the varname wide string literal used in place instead of via a CPP macro. > 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 >