Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp594838iog; Thu, 30 Jun 2022 06:43:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vWMxqgvn3hUg0TypACJymzNLR60qRbbxWKD4OwcUTbySeGgsEVtRHCxJAivQhWQztwxHs0 X-Received: by 2002:a17:90b:1a8c:b0:1ed:1afb:7a73 with SMTP id ng12-20020a17090b1a8c00b001ed1afb7a73mr10577552pjb.144.1656596599514; Thu, 30 Jun 2022 06:43:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656596599; cv=none; d=google.com; s=arc-20160816; b=jfJaHrTLg7YS9DsmXUmSXTeQ8Qy9La/pdYvi9Y8C1ogxAbmb1xg7AZ9+2wT0cLH1sC TfyLOHPwYP5+AblgaK4sZL6MeK9c57pYZK97nimXeYLg0OjFye2pirr0wcr+5W3uHve8 aI4fBQmh5lZ2W/bWGIjY/QBSRnCbeIcLLKlRD0+fQFIuMROegUn7Lo+NSQOG09b140kw oiuvM2zbieAttvWm0GXJYR9KWnaIvGKzyfmyv3YkTdxTTRoGYcNC6yJTwqNV2XitvE91 PxVHMaHIbJ4DpoEh/+IE7yRxwXFMo+fyz3jSgShPmgPpBy7RSF857N69OmNd0Dirmj07 0GbQ== 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=aJrHW1zfskt5mub94imQU6kO3Is9Gr7LgOI7ppnURQQ=; b=Sw1ss5keKvzGXQaQf4lf1W9GFnqSxokFf1aHb+4A5yo6HMFTOMd42/uyGQ0nF93tcz ZNNGoOVrUCJh87V+/Rr78Eq5pZmSFDpMHVRSwPi8RqOYeylWmttU1LVKo9nQ1nxCyBjK SwwjIVL7K5Gf2HaNpJHn8G9x6zH/zNZAistHL/xlSrAjbECvN2Ls9v8MSbZG+CKyg32s oCpqhksMx+5Jt4FsW3w6yL+T5uHNyiODJwDCZ+CaCcCiQFJJ77hIlAE/pqqtYeP+Emvy Q0KkS5+xoDGqdpKmac7HpjYP+fKp4YrQcEEGgPFpx77DBvY3/yKHzogQefB0pFgF6P6+ jv7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@zx2c4.com header.s=20210105 header.b=Gwi9lqIU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE 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 y3-20020a170902864300b001617b60e734si7180115plt.139.2022.06.30.06.43.05; Thu, 30 Jun 2022 06:43:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=Gwi9lqIU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zx2c4.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235321AbiF3Nb2 (ORCPT + 99 others); Thu, 30 Jun 2022 09:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235307AbiF3NbY (ORCPT ); Thu, 30 Jun 2022 09:31:24 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B66E340F0 for ; Thu, 30 Jun 2022 06:31:24 -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 B1C6861EA4 for ; Thu, 30 Jun 2022 13:31:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43E1BC3411E; Thu, 30 Jun 2022 13:31:22 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Gwi9lqIU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1656595880; 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=aJrHW1zfskt5mub94imQU6kO3Is9Gr7LgOI7ppnURQQ=; b=Gwi9lqIULHdxm268t463sx0i6CICCytkUmkvGgdPMucd0hpFhw98C9Z0OkhiEcr555stsc CQJUbVtBBrCQLtVtC8EsRoMW8ZUENKhMQp7EiMdpVRTbM6LIAOnp6LyHkDohyJBRTA7Ovv g+nxzXC3vPWoY4C057F7yO2ezUxNWpw= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c370565c (TLSv1.3:AEAD-AES256-GCM-SHA384:256:NO); Thu, 30 Jun 2022 13:31:20 +0000 (UTC) From: "Jason A. Donenfeld" To: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org Cc: "Jason A. Donenfeld" Subject: [PATCH v4] x86/setup: Allow passing RNG seeds via e820 setup table Date: Thu, 30 Jun 2022 15:31:06 +0200 Message-Id: <20220630133106.35970-1-Jason@zx2c4.com> In-Reply-To: <20220630120955.1937664-1-Jason@zx2c4.com> References: <20220630120955.1937664-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,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org Currently the only way x86 can get an early boot RNG seed is via EFI, which is generally always used now for physical machines, but is very rarely used in VMs, especially VMs that are optimized for starting "instantaneously", such as Firecracker's MicroVM. Here, we really want the ability for the firmware to pass a random seed, similar to what OF platforms do with the "rng-seed" property. It also would be nice for bootloaders to be able to append seeds to the kernel before launching. This patch accomplishes that by adding SETUP_RNG_SEED, similar to the other 7 SETUP_* entries that are parsed from the e820 setup table. I've verified that this works well with QEMU. Signed-off-by: Jason A. Donenfeld --- Sorry for all the churn. I keep forgetting things. I'll slow down a bit after this one. Changes v3->v4: - Zero out data after using, for forward secrecy and so that kexec doesn't reuse the data. Changes v2->v3: - Actually memmap the right area with the random bytes in it. This worked before because of page sizes, but the code wasn't right. Now it's right. Changes v1->v2: - Fix small typo of data_len -> data->len. arch/x86/include/uapi/asm/bootparam.h | 1 + arch/x86/kernel/setup.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h index bea5cdcdf532..a60676b8d1d4 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -11,6 +11,7 @@ #define SETUP_APPLE_PROPERTIES 5 #define SETUP_JAILHOUSE 6 #define SETUP_CC_BLOB 7 +#define SETUP_RNG_SEED 8 #define SETUP_INDIRECT (1<<31) diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c index bd6c6fd373ae..6c807a4ae141 100644 --- a/arch/x86/kernel/setup.c +++ b/arch/x86/kernel/setup.c @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -355,6 +356,13 @@ static void __init parse_setup_data(void) case SETUP_EFI: parse_efi_setup(pa_data, data_len); break; + case SETUP_RNG_SEED: + data = early_memremap(pa_data, data_len); + add_bootloader_randomness(data->data, data->len); + memzero_explicit(data->data, data->len); + memzero_explicit(&data->len, sizeof(data->len)); + early_memunmap(data, data_len); + break; default: break; } -- 2.35.1