From nobody Mon May 13 08:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=zx2c4.com ARC-Seal: i=1; a=rsa-sha256; t=1664793572; cv=none; d=zohomail.com; s=zohoarc; b=Y9gA/NTO0HwWCx2UZiciVnV7yW+CaMFWaMWpEdCk3LQMXwV+u2qWy8zkJJZ5jQU1MlH/mu26pbRC3RuTPEFdZOinAnIwcduw9Q9/vG3NmgINkl//42RZiug77inEbJmNKFDQaCNfJtZLoUtwit10QffUAmxVnzt5bdxtLqBZpe0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1664793572; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=YWpTi6KXCYsZeLyOVNUk5wppfEu/zvy60LaU2Vg9PJI=; b=mmxFXwEix847uqBYxkhWqn8AGF5AXihpKWMsHdGHRaPK6ayV8+6obeNMzS13IR+Xrkc94KEs9SGTf5ZEgyF0LKB7BcJnwR09r1BUiCnRUSHnfEt9WhyE9VnvOXxUY60ZQCJCw4cyVdDbp3W4JLfntwapQqv1Hw8aq2hs3hJCpyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1664793572671932.4524048195677; Mon, 3 Oct 2022 03:39:32 -0700 (PDT) Received: from localhost ([::1]:37812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ofIrC-0002XS-Bs for importer@patchew.org; Mon, 03 Oct 2022 06:39:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofIoc-0000WW-65 for qemu-devel@nongnu.org; Mon, 03 Oct 2022 06:36:50 -0400 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]:45332) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ofIoZ-0002Zd-Vy for qemu-devel@nongnu.org; Mon, 03 Oct 2022 06:36:49 -0400 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 C3AC8B81049; Mon, 3 Oct 2022 10:36:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C629BC433D7; Mon, 3 Oct 2022 10:36:36 +0000 (UTC) Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 6e5db381 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 3 Oct 2022 10:36:34 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="m7aazLT6" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664793394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YWpTi6KXCYsZeLyOVNUk5wppfEu/zvy60LaU2Vg9PJI=; b=m7aazLT6O+O0spQEbFjdG58rbVYdUTRoF1v62WzPDK0B5SO4i/a8fcf9oDl/8oh60ORzky RRKdtq+VS+HyxLuSgOw7ANT3F6ARlRUlArmGgvOIxRHOvUr5lTBYb3bUpGXO0rvsClHl2J +FgZ+2FXjr2vj36gomYoIQyhvZ62pKI= From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org Cc: "Jason A. Donenfeld" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Jiaxun Yang , Aurelien Jarno Subject: [PATCH v2] mips/malta: pass RNG seed to to kernel via env var Date: Mon, 3 Oct 2022 12:36:27 +0200 Message-Id: <20221003103627.947985-1-Jason@zx2c4.com> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=SRS0=zLWo=2E=zx2c4.com=Jason@kernel.org; helo=ams.source.kernel.org X-Spam_score_int: -67 X-Spam_score: -6.8 X-Spam_bar: ------ X-Spam_report: (-6.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25, RCVD_IN_DNSWL_HI=-5, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @zx2c4.com) X-ZM-MESSAGEID: 1664793574282100001 As of the kernel commit linked below, Linux ingests an RNG seed passed from the hypervisor. So, pass this for the Malta platform, and reinitialize it on reboot too, so that it's always fresh. Cc: Philippe Mathieu-Daud=C3=A9 Cc: Jiaxun Yang Cc: Aurelien Jarno Link: https://git.kernel.org/mips/c/056a68cea01 Signed-off-by: Jason A. Donenfeld --- Changes v1->v2: - Update commit message. - No code changes. hw/mips/malta.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hw/mips/malta.c b/hw/mips/malta.c index 0e932988e0..9d793b3c17 100644 --- a/hw/mips/malta.c +++ b/hw/mips/malta.c @@ -26,6 +26,7 @@ #include "qemu/units.h" #include "qemu/bitops.h" #include "qemu/datadir.h" +#include "qemu/guest-random.h" #include "hw/clock.h" #include "hw/southbridge/piix.h" #include "hw/isa/superio.h" @@ -1017,6 +1018,17 @@ static void G_GNUC_PRINTF(3, 4) prom_set(uint32_t *p= rom_buf, int index, va_end(ap); } =20 +static void reinitialize_rng_seed(void *opaque) +{ + char *rng_seed_hex =3D opaque; + uint8_t rng_seed[32]; + + qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); + for (size_t i =3D 0; i < sizeof(rng_seed); ++i) { + sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); + } +} + /* Kernel */ static uint64_t load_kernel(void) { @@ -1028,6 +1040,8 @@ static uint64_t load_kernel(void) long prom_size; int prom_index =3D 0; uint64_t (*xlate_to_kseg0) (void *opaque, uint64_t addr); + uint8_t rng_seed[32]; + char rng_seed_hex[sizeof(rng_seed) * 2 + 1]; =20 #if TARGET_BIG_ENDIAN big_endian =3D 1; @@ -1115,9 +1129,20 @@ static uint64_t load_kernel(void) =20 prom_set(prom_buf, prom_index++, "modetty0"); prom_set(prom_buf, prom_index++, "38400n8r"); + + qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); + for (size_t i =3D 0; i < sizeof(rng_seed); ++i) { + sprintf(rng_seed_hex + i * 2, "%02x", rng_seed[i]); + } + prom_set(prom_buf, prom_index++, "rngseed"); + prom_set(prom_buf, prom_index++, "%s", rng_seed_hex); + prom_set(prom_buf, prom_index++, NULL); =20 rom_add_blob_fixed("prom", prom_buf, prom_size, ENVP_PADDR); + qemu_register_reset(reinitialize_rng_seed, + memmem(rom_ptr(ENVP_PADDR, prom_size), prom_size, + rng_seed_hex, sizeof(rng_seed_hex))); =20 g_free(prom_buf); return kernel_entry; --=20 2.37.3