From patchwork Thu Sep 29 23:23:34 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: 12994729 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EB3A4C433FE for ; Thu, 29 Sep 2022 23:25:48 +0000 (UTC) Received: from localhost ([::1]:46244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oe2uZ-0006mo-Pi for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 19:25:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40968) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sp-0004q7-8U for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:23:59 -0400 Received: from ams.source.kernel.org ([145.40.68.75]:50434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sn-0008VD-Hd for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:23:58 -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 31759B8267F; Thu, 29 Sep 2022 23:23:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D13EC433C1; Thu, 29 Sep 2022 23:23:52 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="PDjBpkXD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664493829; 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; bh=s4iMmrVnKX4fWtisVeaMk48H8te3Kjy/7gY9G+U0Yws=; b=PDjBpkXDpT3TzvY1RJUbLEqYU6B0N2jPyu6aXkuySZM6+tsjvKuL2VGi+iBmPXZB8gb7aj WGW0jdoNHEMgrdlRIKM6fsaCx+S2UwR2RsKjTAAbORhiRpkPbKjH6r/fqNTcyVI44TkgXe 4MHrifYxMApW0WftMQYiulvE/OPAM1E= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 94819b2a (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Sep 2022 23:23:48 +0000 (UTC) From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: "Jason A. Donenfeld" , Alistair Francis , David Gibson Subject: [PATCH 1/6] device-tree: add re-randomization helper function Date: Fri, 30 Sep 2022 01:23:34 +0200 Message-Id: <20220929232339.372813-1-Jason@zx2c4.com> MIME-Version: 1.0 Received-SPF: pass client-ip=145.40.68.75; envelope-from=SRS0=kpRN=2A=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Several architectures require this functionality, so export a function for injecting a new seed into the given FDT. Cc: Alistair Francis Cc: David Gibson Signed-off-by: Jason A. Donenfeld Reviewed-by: Bin Meng --- include/sysemu/device_tree.h | 9 +++++++++ softmmu/device_tree.c | 21 +++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h index ef060a9759..d552f324b6 100644 --- a/include/sysemu/device_tree.h +++ b/include/sysemu/device_tree.h @@ -196,6 +196,15 @@ int qemu_fdt_setprop_sized_cells_from_array(void *fdt, qdt_tmp); \ }) + +/** + * qemu_fdt_randomize_seeds: + * @fdt: device tree blob + * + * Re-randomize all "rng-seed" properties with new seeds. + */ +void qemu_fdt_randomize_seeds(void *fdt); + #define FDT_PCI_RANGE_RELOCATABLE 0x80000000 #define FDT_PCI_RANGE_PREFETCHABLE 0x40000000 #define FDT_PCI_RANGE_ALIASED 0x20000000 diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index 6ca3fad285..d986c7b7b3 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -22,6 +22,7 @@ #include "qemu/option.h" #include "qemu/bswap.h" #include "qemu/cutils.h" +#include "qemu/guest-random.h" #include "sysemu/device_tree.h" #include "hw/loader.h" #include "hw/boards.h" @@ -643,3 +644,23 @@ out: g_free(propcells); return ret; } + +void qemu_fdt_randomize_seeds(void *fdt) +{ + int noffset, poffset, len; + const char *name; + uint8_t *data; + + for (noffset = fdt_next_node(fdt, 0, NULL); + noffset >= 0; + noffset = fdt_next_node(fdt, noffset, NULL)) { + for (poffset = fdt_first_property_offset(fdt, noffset); + poffset >= 0; + poffset = fdt_next_property_offset(fdt, poffset)) { + data = (uint8_t *)fdt_getprop_by_offset(fdt, poffset, &name, &len); + if (!data || strcmp(name, "rng-seed")) + continue; + qemu_guest_getrandom_nofail(data, len); + } + } +} From patchwork Thu Sep 29 23:23:35 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: 12994732 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9BB0FC433FE for ; Thu, 29 Sep 2022 23:27:43 +0000 (UTC) Received: from localhost ([::1]:58232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oe2wQ-0002Ar-PH for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 19:27:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40970) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sq-0004qn-FZ; Thu, 29 Sep 2022 19:24:00 -0400 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]:43618) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sn-0008VC-MH; Thu, 29 Sep 2022 19:24:00 -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 F2E24B825AC; Thu, 29 Sep 2022 23:23:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32C28C433D7; Thu, 29 Sep 2022 23:23:54 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="nHI+vwbn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664493833; 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=49FxQV60TFmBCPm/S/dzlRLa4PG449vmaa8+eDrLBqM=; b=nHI+vwbnrnSlY0A5detab0BPBB8qnZ9fP3geHIkXzT7TRr9bSz7zXyvosSE/H7nnT3O5xn 675CjBbRRSfWMi5pxZ4HTEiFJf88O0r8hB+3Z3DW0N4ha9lBpGU96V6GiyCuS8fkx2hGJm KjNc5fT4gJsvNwnzxt2xJkw1ocLxJxY= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 18a64c57 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Sep 2022 23:23:52 +0000 (UTC) From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: "Jason A. Donenfeld" , qemu-arm@nongnu.org Subject: [PATCH 2/6] arm: re-randomize rng-seed on reboot Date: Fri, 30 Sep 2022 01:23:35 +0200 Message-Id: <20220929232339.372813-2-Jason@zx2c4.com> In-Reply-To: <20220929232339.372813-1-Jason@zx2c4.com> References: <20220929232339.372813-1-Jason@zx2c4.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=SRS0=kpRN=2A=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Peter Maydell Cc: qemu-arm@nongnu.org Signed-off-by: Jason A. Donenfeld Reviewed-by: Bin Meng --- hw/arm/boot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index ada2717f76..6a6f4c92c2 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -683,6 +683,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo, * the DTB is copied again upon reset, even if addr points into RAM. */ rom_add_blob_fixed_as("dtb", fdt, size, addr, as); + qemu_register_reset(qemu_fdt_randomize_seeds, rom_ptr_for_as(as, addr, size)); g_free(fdt); From patchwork Thu Sep 29 23:23:36 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: 12994731 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1FE01C433FE for ; Thu, 29 Sep 2022 23:26:04 +0000 (UTC) Received: from localhost ([::1]:47302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oe2up-0007RQ-8X for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 19:26:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40972) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2st-0004vB-Bi; Thu, 29 Sep 2022 19:24:03 -0400 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]:43666) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sr-0008VU-Pr; Thu, 29 Sep 2022 19:24:03 -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 D355FB8267F; Thu, 29 Sep 2022 23:23:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDF57C433D6; Thu, 29 Sep 2022 23:23:57 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="aVj1dhMT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664493836; 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=5HftbmP2bOLL0qaTIFvjVy40wbSWxhakG63dKzx542s=; b=aVj1dhMTMWvmYJSwvkuRLjrJls62jv2kkr7ITaA2VLKhI7oOJPs73NHoQ7zrNMDSo07ufC Usk72PB3qLpEj6Zttd2l+LP1nv4nNM6RqT7bNncU33b93cHi4tOu1MuuVuzHWvjWPMOSpl 9d8PByCTY6wrTInP5PAsDXfv9ian1H8= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id c3ee3846 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Sep 2022 23:23:56 +0000 (UTC) From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: "Jason A. Donenfeld" , Palmer Dabbelt , Alistair Francis , Bin Meng , qemu-riscv@nongnu.org Subject: [PATCH 3/6] riscv: re-randomize rng-seed on reboot Date: Fri, 30 Sep 2022 01:23:36 +0200 Message-Id: <20220929232339.372813-3-Jason@zx2c4.com> In-Reply-To: <20220929232339.372813-1-Jason@zx2c4.com> References: <20220929232339.372813-1-Jason@zx2c4.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2604:1380:4601:e00::1; envelope-from=SRS0=kpRN=2A=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Palmer Dabbelt Cc: Alistair Francis Cc: Bin Meng Cc: qemu-riscv@nongnu.org Signed-off-by: Jason A. Donenfeld Reviewed-by: Bin Meng Reviewed-by: Alistair Francis --- hw/riscv/boot.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c index 1ae7596873..aaecf21543 100644 --- a/hw/riscv/boot.c +++ b/hw/riscv/boot.c @@ -30,6 +30,7 @@ #include "sysemu/device_tree.h" #include "sysemu/qtest.h" #include "sysemu/kvm.h" +#include "sysemu/reset.h" #include @@ -241,6 +242,8 @@ uint64_t riscv_load_fdt(hwaddr dram_base, uint64_t mem_size, void *fdt) rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, &address_space_memory); + qemu_register_reset(qemu_fdt_randomize_seeds, + rom_ptr_for_as(&address_space_memory, fdt_addr, fdtsize)); return fdt_addr; } From patchwork Thu Sep 29 23:23:37 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: 12994733 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BD443C433F5 for ; Thu, 29 Sep 2022 23:27:53 +0000 (UTC) Received: from localhost ([::1]:48770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oe2wa-0002Ys-R1 for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 19:27:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40974) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sv-00050V-Cf for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:24:05 -0400 Received: from dfw.source.kernel.org ([139.178.84.217]:45114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2st-0008Vm-Sn for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:24:05 -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 dfw.source.kernel.org (Postfix) with ESMTPS id ECCD1621DF; Thu, 29 Sep 2022 23:24:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E27AFC433C1; Thu, 29 Sep 2022 23:23:59 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="m95utCWK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664493839; 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=P4hQ4wkuxSrVvM7QYmUcDj4jM9oE2hTmc0xeWMOFJsg=; b=m95utCWKI//ifUzHz/Z1aYouELgmn4Duy4cmazzgClx5X2/dTdmiUkgEwFwefwKML3iO1i F6WtB+010D3+2iKkxqe8nv4fQjlHln2u7WocuqmdpDNQQc87jQRFfPwx3OohS4P+Z4Dam9 YPYtkrWikFGfrB8/dtvgTpIUBtIHAMM= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id f3d7a65f (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Sep 2022 23:23:59 +0000 (UTC) From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: "Jason A. Donenfeld" , Stafford Horne Subject: [PATCH 4/6] openrisc: re-randomize rng-seed on reboot Date: Fri, 30 Sep 2022 01:23:37 +0200 Message-Id: <20220929232339.372813-4-Jason@zx2c4.com> In-Reply-To: <20220929232339.372813-1-Jason@zx2c4.com> References: <20220929232339.372813-1-Jason@zx2c4.com> MIME-Version: 1.0 Received-SPF: pass client-ip=139.178.84.217; envelope-from=SRS0=kpRN=2A=zx2c4.com=Jason@kernel.org; helo=dfw.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Stafford Horne Signed-off-by: Jason A. Donenfeld Reviewed-by: Bin Meng --- hw/openrisc/boot.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/openrisc/boot.c b/hw/openrisc/boot.c index 128ccbcba2..8b9f11b6d8 100644 --- a/hw/openrisc/boot.c +++ b/hw/openrisc/boot.c @@ -14,6 +14,7 @@ #include "hw/openrisc/boot.h" #include "sysemu/device_tree.h" #include "sysemu/qtest.h" +#include "sysemu/reset.h" #include @@ -111,6 +112,8 @@ uint32_t openrisc_load_fdt(void *fdt, hwaddr load_start, rom_add_blob_fixed_as("fdt", fdt, fdtsize, fdt_addr, &address_space_memory); + qemu_register_reset(qemu_fdt_randomize_seeds, + rom_ptr_for_as(&address_space_memory, fdt_addr, fdtsize)); return fdt_addr; } From patchwork Thu Sep 29 23:23:38 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: 12994730 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A6647C433F5 for ; Thu, 29 Sep 2022 23:26:01 +0000 (UTC) Received: from localhost ([::1]:47300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oe2um-0007Ov-R5 for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 19:26:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60146) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sw-00052t-4R for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:24:06 -0400 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]:33692) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2su-0008W1-Lm for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:24:05 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A6A85621E5; Thu, 29 Sep 2022 23:24:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A59EBC433C1; Thu, 29 Sep 2022 23:24:02 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="Kdw/YTl0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664493841; 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=1EkhBRNs3ukPCBFv1j1L2drncesLGhbPVoE8IvVGFYU=; b=Kdw/YTl0nucpcvqxcp4GG/WwZ59B2TU+3jondRiGNn9E6SFHvuEQzRanetlU8xXuy9jJ6r GjyHFta82DBGpDJtlnL5xy8Aa5oFWw6GF8UlZY6i1lUiFlcgu6609DW8XTN6nEuIfBYVnT kzZJft5V/wsXJ+0wxideZ9sA1BSrvlw= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 099937ce (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Sep 2022 23:24:01 +0000 (UTC) From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: "Jason A. Donenfeld" , Yoshinori Sato Subject: [PATCH 5/6] rx: re-randomize rng-seed on reboot Date: Fri, 30 Sep 2022 01:23:38 +0200 Message-Id: <20220929232339.372813-5-Jason@zx2c4.com> In-Reply-To: <20220929232339.372813-1-Jason@zx2c4.com> References: <20220929232339.372813-1-Jason@zx2c4.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2604:1380:4641:c500::1; envelope-from=SRS0=kpRN=2A=zx2c4.com=Jason@kernel.org; helo=dfw.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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Yoshinori Sato Signed-off-by: Jason A. Donenfeld Reviewed-by: Bin Meng Reviewed-by: Yoshinori Sato --- hw/rx/rx-gdbsim.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c index 8ffe1b8035..198d048964 100644 --- a/hw/rx/rx-gdbsim.c +++ b/hw/rx/rx-gdbsim.c @@ -25,6 +25,7 @@ #include "hw/rx/rx62n.h" #include "sysemu/qtest.h" #include "sysemu/device_tree.h" +#include "sysemu/reset.h" #include "hw/boards.h" #include "qom/object.h" @@ -148,6 +149,8 @@ static void rx_gdbsim_init(MachineState *machine) dtb_offset = ROUND_DOWN(machine->ram_size - dtb_size, 16); rom_add_blob_fixed("dtb", dtb, dtb_size, SDRAM_BASE + dtb_offset); + qemu_register_reset(qemu_fdt_randomize_seeds, + rom_ptr(SDRAM_BASE + dtb_offset, dtb_size)); /* Set dtb address to R1 */ RX_CPU(first_cpu)->env.regs[1] = SDRAM_BASE + dtb_offset; } From patchwork Thu Sep 29 23:23:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Jason A. Donenfeld" X-Patchwork-Id: 12994734 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67C9EC433F5 for ; Thu, 29 Sep 2022 23:28:54 +0000 (UTC) Received: from localhost ([::1]:50594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oe2xZ-0004fS-Jb for qemu-devel@archiver.kernel.org; Thu, 29 Sep 2022 19:28:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2t0-0005FE-GE for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:24:10 -0400 Received: from ams.source.kernel.org ([145.40.68.75]:50554) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oe2sz-000054-1W for qemu-devel@nongnu.org; Thu, 29 Sep 2022 19:24:10 -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 338D1B825AC; Thu, 29 Sep 2022 23:24:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59CCCC433C1; Thu, 29 Sep 2022 23:24:05 +0000 (UTC) Authentication-Results: smtp.kernel.org; dkim=pass (1024-bit key) header.d=zx2c4.com header.i=@zx2c4.com header.b="RML3BmnN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zx2c4.com; s=20210105; t=1664493843; 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=1MhP1iEDR+8kGn7gSFVtgDwHMVdwP9J3Rm1XMWdjMgQ=; b=RML3BmnNxrXjCzUaXZHSc9686WpV/MGPYp+q7NLuGaEQPvUhQKDGxkznMTn9SuOSNL34rx KVkEWV45hyOQb8a1MuVbJmoh3ZiPwgEnMNOK8EHkPflKhnMY23EspczPnNSHIONYnFE92Y mhgHLHHU3ataqIReDMtYuzCU5ImRmXI= Received: by mail.zx2c4.com (ZX2C4 Mail Server) with ESMTPSA id 26abbcae (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 29 Sep 2022 23:24:03 +0000 (UTC) From: "Jason A. Donenfeld" To: qemu-devel@nongnu.org, peter.maydell@linaro.org Cc: "Jason A. Donenfeld" , Aleksandar Rikalo , Paul Burton , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH 6/6] mips: re-randomize rng-seed on reboot Date: Fri, 30 Sep 2022 01:23:39 +0200 Message-Id: <20220929232339.372813-6-Jason@zx2c4.com> In-Reply-To: <20220929232339.372813-1-Jason@zx2c4.com> References: <20220929232339.372813-1-Jason@zx2c4.com> MIME-Version: 1.0 Received-SPF: pass client-ip=145.40.68.75; envelope-from=SRS0=kpRN=2A=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+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" When the system reboots, the rng-seed that the FDT has should be re-randomized, so that the new boot gets a new seed. Since the FDT is in the ROM region at this point, we add a hook right after the ROM has been added, so that we have a pointer to that copy of the FDT. Cc: Aleksandar Rikalo Cc: Paul Burton Cc: Philippe Mathieu-Daudé Signed-off-by: Jason A. Donenfeld Reviewed-by: Bin Meng --- hw/mips/boston.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/mips/boston.c b/hw/mips/boston.c index d2ab9da1a0..a560ce0324 100644 --- a/hw/mips/boston.c +++ b/hw/mips/boston.c @@ -41,6 +41,7 @@ #include "sysemu/sysemu.h" #include "sysemu/qtest.h" #include "sysemu/runstate.h" +#include "sysemu/reset.h" #include #include "qom/object.h" @@ -810,6 +811,8 @@ static void boston_mach_init(MachineState *machine) /* Calculate real fdt size after filter */ dt_size = fdt_totalsize(dtb_load_data); rom_add_blob_fixed("dtb", dtb_load_data, dt_size, dtb_paddr); + qemu_register_reset(qemu_fdt_randomize_seeds, + rom_ptr(dtb_paddr, dt_size)); } else { /* Try to load file as FIT */ fit_err = load_fit(&boston_fit_loader, machine->kernel_filename, s);