x86: only modify setup_data if the boot protocol indicates safety
PATCH 1/1 x86: only modify setup_data if the boot protocol indicates safety
This reverts 3824e25db1 ("x86: disable rng seeding via setup_data"), and then makes the use of setup_data safe. It does so by checking the boot protocol version. If it's sufficient, then it means EFI boots won't crash. While we're at it, gate this on SEV too.
--- hw/i386/microvm.c | 2 +- hw/i386/pc_piix.c | 2 +- hw/i386/pc_q35.c | 2 +- hw/i386/x86.c | 11 +++++++++-- 4 files changed, 12 insertions(+), 5 deletions(-)
hw/i386/microvm.c +1 -1
@@ -332,7 +332,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)rom_set_fw (fw_cfg);if (machine->kernel_filename !=NULL ) { -x86_load_linux (x86ms, fw_cfg,0 , true, true); +x86_load_linux (x86ms, fw_cfg,0 , true, false); }if (mms->option_roms) {
hw/i386/pc_piix.c +1 -1
@@ -439,7 +439,6 @@ static void pc_i440fx_7_2_machine_options(MachineClass *m) m->alias ="pc" ; m->is_default = true; pcmc->default_cpu_version =1 ; - pcmc->legacy_no_rng_seed = true; } DEFINE_I440FX_MACHINE(v7_2, "pc-i440fx-7.2", NULL,
@@ -463,6 +462,7 @@ static void pc_i440fx_7_0_machine_options(MachineClass *m)pc_i440fx_7_1_machine_options (m); m->alias =NULL ; m->is_default = false; + pcmc->legacy_no_rng_seed = true; pcmc->enforce_amd_1tb_hole = false;compat_props_add (m->compat_props, hw_compat_7_0, hw_compat_7_0_len);compat_props_add (m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
hw/i386/pc_q35.c +1 -1
@@ -376,7 +376,6 @@ static void pc_q35_7_2_machine_options(MachineClass *m)pc_q35_machine_options (m); m->alias ="q35" ; pcmc->default_cpu_version =1 ; - pcmc->legacy_no_rng_seed = true; } DEFINE_Q35_MACHINE(v7_2, "pc-q35-7.2", NULL,
@@ -398,6 +397,7 @@ static void pc_q35_7_0_machine_options(MachineClass *m)PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_7_1_machine_options (m); m->alias =NULL ; + pcmc->legacy_no_rng_seed = true; pcmc->enforce_amd_1tb_hole = false;compat_props_add (m->compat_props, hw_compat_7_0, hw_compat_7_0_len);compat_props_add (m->compat_props, pc_compat_7_0, pc_compat_7_0_len);
hw/i386/x86.c +9 -2
@@ -1088,8 +1088,15 @@ void x86_load_linux(X86MachineState *x86ms,qemu_guest_getrandom_nofail (setup_data->data,RNG_SEED_LENGTH ); } -/* Offset 0x250 is a pointer to the first setup_data link. */ -stq_p (header +0x250 , first_setup_data); +/* +* Only modify the header if doing so won't crash EFI boot, which is the +* case only for newer boot protocols, and don't do so either if SEV is +* enabled. +*/ +if (protocol >=0x210 && !sev_enabled ()) { +/* Offset 0x250 is a pointer to the first setup_data link. */ +stq_p (header +0x250 , first_setup_data); + }/* * If we're starting an encrypted VM, it will be OVMF based, which uses the
Signature · 1 line
2.37.3
FYI, this patch depends on this one in the kernel:
https://lore.kernel.org/linux-efi/[email protected]/
Review static void pc_i440fx_7_0_machine_options(MachineClass *m) · line 463
Quoted 8 lines · Jason A. Donenfeld
This reverts
3824e25db1("x86: disable rng seeding viasetup_data"), and then makes the use ofsetup_datasafe. It does so by checking the boot protocol version. If it's sufficient, then it means EFI boots won't crash. While we're at it, gate this on SEV too.(quoted diff) +1
-0@@ -463,6 +462,7 @@ static void pc_i440fx_7_0_machine_options(MachineClass *m) + pcmc->legacy_no_rng_seed = true;
This needs go into the pc_i440fx_7_1_machine_options function, otherwise legacy_no_rng_seed gets flipped from false to true for 7.1 machine types which breaks compatibility.
Review static void pc_q35_7_0_machine_options(MachineClass *m) · line 398
Quoted 3 lines
(quoted diff) +1
-0@@ -398,6 +397,7 @@ static void pc_q35_7_0_machine_options(MachineClass *m) + pcmc->legacy_no_rng_seed = true;
Same here.
Quoted 7 lines
hw/i386/x86.c +0
-1@@ -1088,8 +1088,15 @@ void x86_load_linux(X86MachineState *x86ms,qemu_guest_getrandom_nofail (setup_data->data,RNG_SEED_LENGTH ); } -/* Offset 0x250 is a pointer to the first setup_data link. */
hw/i386/x86.c void x86_load_linux(X86MachineState *x86ms, · line 1099
Quoted 10 lines
hw/i386/x86.c +9
-1-stq_p (header +0x250 , first_setup_data); +/* +* Only modify the header if doing so won't crash EFI boot, which is the +* case only for newer boot protocols, and don't do so either if SEV is +* enabled. +*/ +if (protocol >=0x210 && !sev_enabled ()) { +/* Offset 0x250 is a pointer to the first setup_data link. */ +stq_p (header +0x250 , first_setup_data); + }
This should better go into a separate patch.
take care,
Gerd
Hi Gerd,
Quoted 15 lines · Gerd Hoffmann
Review static void pc_i440fx_7_0_machine_options(MachineClass *m) · line 463
Quoted 8 lines · Jason A. Donenfeld
This reverts
3824e25db1("x86: disable rng seeding viasetup_data"), and then makes the use ofsetup_datasafe. It does so by checking the boot protocol version. If it's sufficient, then it means EFI boots won't crash. While we're at it, gate this on SEV too.(quoted diff) +1
-0@@ -463,6 +462,7 @@ static void pc_i440fx_7_0_machine_options(MachineClass *m) + pcmc->legacy_no_rng_seed = true;This needs go into the
pc_i440fx_7_1_machine_optionsfunction, otherwiselegacy_no_rng_seedgets flipped from false to true for 7.1 machine types which breaks compatibility.
Quoted 5 lines
Review static void pc_q35_7_0_machine_options(MachineClass *m) · line 398
Quoted 3 lines
(quoted diff) +1
-0@@ -398,6 +397,7 @@ static void pc_q35_7_0_machine_options(MachineClass *m) + pcmc->legacy_no_rng_seed = true;Same here.
Oh. Okay so a "straight" revert won't do the trick, since this is (I guess?) intended for 7.2 rather than 7.1. Makes sense; will do for v2.
Quoted 7 lines
Quoted 7 lines
hw/i386/x86.c +0
-0@@ -1088,8 +1088,15 @@ void x86_load_linux(X86MachineState *x86ms,qemu_guest_getrandom_nofail (setup_data->data,RNG_SEED_LENGTH ); }
Quoted 13 lines
hw/i386/x86.c void x86_load_linux(X86MachineState *x86ms, · line 1099
Quoted 11 lines
hw/i386/x86.c +9
-2-/* Offset 0x250 is a pointer to the first setup_data link. */ -stq_p (header +0x250 , first_setup_data); +/* +* Only modify the header if doing so won't crash EFI boot, which is the +* case only for newer boot protocols, and don't do so either if SEV is +* enabled. +*/ +if (protocol >=0x210 && !sev_enabled ()) { +/* Offset 0x250 is a pointer to the first setup_data link. */ +stq_p (header +0x250 , first_setup_data); + }This should better go into a separate patch.
Alright.
Jason
PATCH v2 1/2 x86: only modify setup_data if the boot protocol indicates safety
It's only safe to modify the setup_data pointer on newer kernels where the EFI stub loader will ignore it. So condition setting that offset on the newer boot protocol version. While we're at it, gate this on SEV too. This depends on the kernel commit linked below going upstream.
--- hw/i386/x86.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
hw/i386/x86.c +9 -2
@@ -1088,8 +1088,15 @@ void x86_load_linux(X86MachineState *x86ms,qemu_guest_getrandom_nofail (setup_data->data,RNG_SEED_LENGTH ); } -/* Offset 0x250 is a pointer to the first setup_data link. */ -stq_p (header +0x250 , first_setup_data); +/* +* Only modify the header if doing so won't crash EFI boot, which is the +* case only for newer boot protocols, and don't do so either if SEV is +* enabled. +*/ +if (protocol >=0x210 && !sev_enabled ()) { +/* Offset 0x250 is a pointer to the first setup_data link. */ +stq_p (header +0x250 , first_setup_data); + }/* * If we're starting an encrypted VM, it will be OVMF based, which uses the
Signature · 1 line
2.37.3
PATCH v2 2/2 x86: re-enable rng seeding via setup_data
This reverts 3824e25db1 ("x86: disable rng seeding via setup_data"), but for 7.2 rather than 7.1, now that modifying setup_data is safe to do.
--- hw/i386/microvm.c | 2 +- hw/i386/pc_piix.c | 3 ++- hw/i386/pc_q35.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
hw/i386/microvm.c +1 -1
@@ -332,7 +332,7 @@ static void microvm_memory_init(MicrovmMachineState *mms)rom_set_fw (fw_cfg);if (machine->kernel_filename !=NULL ) { -x86_load_linux (x86ms, fw_cfg,0 , true, true); +x86_load_linux (x86ms, fw_cfg,0 , true, false); }if (mms->option_roms) {
hw/i386/pc_piix.c +2 -1
@@ -439,7 +439,6 @@ static void pc_i440fx_7_2_machine_options(MachineClass *m) m->alias ="pc" ; m->is_default = true; pcmc->default_cpu_version =1 ; - pcmc->legacy_no_rng_seed = true; } DEFINE_I440FX_MACHINE(v7_2, "pc-i440fx-7.2", NULL,
@@ -447,9 +446,11 @@ DEFINE_I440FX_MACHINE(v7_2, "pc-i440fx-7.2", NULL,static void pc_i440fx_7_1_machine_options (MachineClass *m) { +PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_i440fx_7_2_machine_options (m); m->alias =NULL ; m->is_default = false; + pcmc->legacy_no_rng_seed = true;compat_props_add (m->compat_props, hw_compat_7_1, hw_compat_7_1_len);compat_props_add (m->compat_props, pc_compat_7_1, pc_compat_7_1_len); }
hw/i386/pc_q35.c +2 -1
@@ -376,7 +376,6 @@ static void pc_q35_7_2_machine_options(MachineClass *m)pc_q35_machine_options (m); m->alias ="q35" ; pcmc->default_cpu_version =1 ; - pcmc->legacy_no_rng_seed = true; } DEFINE_Q35_MACHINE(v7_2, "pc-q35-7.2", NULL,
@@ -384,8 +383,10 @@ DEFINE_Q35_MACHINE(v7_2, "pc-q35-7.2", NULL,static void pc_q35_7_1_machine_options (MachineClass *m) { +PCMachineClass *pcmc =PC_MACHINE_CLASS (m);pc_q35_7_2_machine_options (m); m->alias =NULL ; + pcmc->legacy_no_rng_seed = true;compat_props_add (m->compat_props, hw_compat_7_1, hw_compat_7_1_len);compat_props_add (m->compat_props, pc_compat_7_1, pc_compat_7_1_len); }
Signature · 1 line
2.37.3
Quoted 12 lines · Jason A. Donenfeld
Hi Gerd,
Quoted 9 lines · Gerd Hoffmann
Quoted 6 lines · Jason A. Donenfeld
This reverts
3824e25db1("x86: disable rng seeding viasetup_data"), and then makes the use ofsetup_datasafe. It does so by checking the boot protocol version. If it's sufficient, then it means EFI boots won't crash. While we're at it, gate this on SEV too.(quoted diff) +0
-0@@ -463,6 +462,7 @@ static void pc_i440fx_7_0_machine_options(MachineClass *m)
Quoted 8 lines
Quoted 5 lines
Review static void pc_i440fx_7_0_machine_options(MachineClass *m) · line 462
Quoted 1 line
(quoted diff) +1
-0+ pcmc->legacy_no_rng_seed = true;This needs go into the
pc_i440fx_7_1_machine_optionsfunction, otherwiselegacy_no_rng_seedgets flipped from false to true for 7.1 machine types which breaks compatibility.Oh. Okay so a "straight" revert won't do the trick, since this is (I guess?) intended for 7.2 rather than 7.1. Makes sense; will do for v2.
Exactly. 7.1 is release and thus set in stone. So we'll go flip the switch for 7.2 because the feature missed the 7.1 boat.
take care,
Gerd