diff mbox series

[1/2] x86: reset rng seed when reading cmdline, not kernel image

Message ID 20230207224847.94429-2-Jason@zx2c4.com (mailing list archive)
State New, archived
Headers show
Series x86: fix fallout from switching setup_data from kernel image to cmdline | expand

Commit Message

Jason A. Donenfeld Feb. 7, 2023, 10:48 p.m. UTC
With eac7a7791bb6 ("x86: don't let decompressed kernel image clobber
setup_data"), the rng seed setup_data is now appended to the cmdline
file rather than the kernel image file. But in the process, the code to
re-randomize the seed when selecting the image was left out. So, change
the re-randomization over to trigger when selecting the cmdline, rather
than the kernel image.

Fixes: eac7a7791bb6 ("x86: don't let decompressed kernel image clobber setup_data")
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 hw/i386/x86.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index eaff4227bd..c6d7bf6db2 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -1114,15 +1114,15 @@  void x86_load_linux(X86MachineState *x86ms,
         setup_data->len = cpu_to_le32(RNG_SEED_LENGTH);
         qemu_guest_getrandom_nofail(setup_data->data, RNG_SEED_LENGTH);
         qemu_register_reset_nosnapshotload(reset_rng_seed, setup_data);
-        fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_KERNEL_DATA, reset_rng_seed, NULL,
-                                  setup_data, kernel, kernel_size, true);
+        fw_cfg_add_bytes_callback(fw_cfg, FW_CFG_CMDLINE_DATA, reset_rng_seed, NULL,
+                                  setup_data, kernel_cmdline, cmdline_size, true);
     } else {
-        fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
+        fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline, cmdline_size);
     }
 
+    fw_cfg_add_bytes(fw_cfg, FW_CFG_KERNEL_DATA, kernel, kernel_size);
     fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_ADDR, cmdline_addr);
     fw_cfg_add_i32(fw_cfg, FW_CFG_CMDLINE_SIZE, cmdline_size);
-    fw_cfg_add_bytes(fw_cfg, FW_CFG_CMDLINE_DATA, kernel_cmdline, cmdline_size);
     sev_load_ctx.cmdline_data = (char *)kernel_cmdline;
     sev_load_ctx.cmdline_size = cmdline_size;