From patchwork Wed Nov 16 16:16:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 625284 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 A531BC4332F for ; Wed, 16 Nov 2022 16:17:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233463AbiKPQRY (ORCPT ); Wed, 16 Nov 2022 11:17:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232506AbiKPQRT (ORCPT ); Wed, 16 Nov 2022 11:17:19 -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 C6C1257B4A; Wed, 16 Nov 2022 08:17:18 -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 5D66761EA1; Wed, 16 Nov 2022 16:17:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 380C4C433C1; Wed, 16 Nov 2022 16:17:17 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="gP8ZSBvF" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1668615436; 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=T8rpk19kPkTtPMi5LUcmORLt2HUDUjWWv1DWoYLEx0I=; b=gP8ZSBvFYttV9FkdX6gi6A9SgRb4YQWPgyka74GC2aO+WXfMXjyb8bfOjzxLhH8q1nNS8p u0qnicPF58AhsnY8+ODg1ml+iE0X15khp7H6L4Ko6TuBx1+bDiXW8urDyukGhGAK+Bdc/a Y6w76zi4j/dcPbLRZd8EnDy3EyjWw9Q= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 2e2b34f2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 16 Nov 2022 16:17:15 +0000 (UTC) From: "Jason A. Donenfeld" To: linux-efi@vger.kernel.org, linux-crypto@vger.kernel.org Cc: "Jason A. Donenfeld" , Ard Biesheuvel , Lennart Poettering Subject: [PATCH RFC v1 6/6] efi: refresh non-volatile random seed when RNG is initialized Date: Wed, 16 Nov 2022 17:16:42 +0100 Message-Id: <20221116161642.1670235-7-Jason@zx2c4.com> In-Reply-To: <20221116161642.1670235-1-Jason@zx2c4.com> References: <20221116161642.1670235-1-Jason@zx2c4.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org Register a notifier so that when the RNG is initialized, the EFI variable containing the random seed can be refreshed. Signed-off-by: Jason A. Donenfeld --- drivers/firmware/efi/efi.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index a46df5d1d094..db247a52d3c2 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -337,6 +337,19 @@ static void __init efi_debugfs_init(void) static inline void efi_debugfs_init(void) {} #endif +static int refresh_nv_rng_seed(struct notifier_block *nb, unsigned long action, void *data) +{ + 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)); + return 0; +} +static struct notifier_block refresh_nv_rng_seed_nb = { .notifier_call = refresh_nv_rng_seed }; + /* * 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 +426,7 @@ static int __init efisubsys_init(void) platform_device_register_simple("efi_secret", 0, NULL, 0); #endif + notify_on_rng_initialized(&refresh_nv_rng_seed_nb); return 0; err_remove_group: