x86: only modify setup_data if the boot protocol indicates safety
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.
Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?
Quoted 28 lines
--- 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
Quoted 18 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Quoted 2 lines
BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Quoted 19 lines · Jason A. Donenfeld
Quoted 18 lines · Michael S. Tsirkin
Quoted 15 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Quoted 7 lines
Quoted 2 lines
BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Signature · 1 line
MST
(cc Laszlo)
Quoted 24 lines · Michael S. Tsirkin
Quoted 22 lines · Jason A. Donenfeld
Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?
Quoted 8 lines
Quoted 4 lines
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
This does raise the question (as I mentioned before) how things like secure boot and measured boot are affected when combined with direct kernel boot: AIUI, libvirt uses direct kernel boot at guest installation time, and modifying setup_data will corrupt the image signature.
Quoted 36 lines · Ard Biesheuvel
(cc Laszlo)
Quoted 24 lines · Michael S. Tsirkin
Quoted 22 lines · Jason A. Donenfeld
Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?Quoted 8 lines
Quoted 4 lines
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Quoted 5 lines
This does raise the question (as I mentioned before) how things like secure boot and measured boot are affected when combined with direct kernel boot: AIUI, libvirt uses direct kernel boot at guest installation time, and modifying
setup_datawill corrupt the image signature.
IIUC, qemu already modifies setup_data when using direct kernel boot.
It put in logic to skip this if SEV is enabled, to avoid interfering with SEV hashes over the kernel, but there's nothing doing this more generally for non-SEV cases using UEFI. So potentially use of SecureBoot may already be impacted when using direct kernel boot. I haven't formally tested this myself though. I just saw that earlier versions of this RNG patch broke SEV hashes and later versions addressed that problem for SEV when the code was re-arranged.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 43 lines · Daniel P. Berrangé
Quoted 36 lines · Ard Biesheuvel
(cc Laszlo)
Quoted 24 lines · Michael S. Tsirkin
Quoted 22 lines · Jason A. Donenfeld
Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?Quoted 8 lines
Quoted 4 lines
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Quoted 5 lines
This does raise the question (as I mentioned before) how things like secure boot and measured boot are affected when combined with direct kernel boot: AIUI, libvirt uses direct kernel boot at guest installation time, and modifying
setup_datawill corrupt the image signature.
Quoted 6 lines
IIUC, qemu already modifies
setup_datawhen using direct kernel boot.It put in logic to skip this if SEV is enabled, to avoid interfering with SEV hashes over the kernel, but there's nothing doing this more generally for non-SEV cases using UEFI. So potentially use of SecureBoot may already be impacted when using direct kernel boot.
Yes,
https://github.com/tianocore/edk2/commit/82808b422617
Laszlo
Quoted 8 lines
I haven't formally
tested this myself though. I just saw that earlier versions of this RNG patch broke SEV hashes and later versions addressed that problem for SEV when the code was re-arranged.With regards,
Daniel
Quoted 47 lines · Laszlo Ersek
Quoted 45 lines · Daniel P. Berrangé
Quoted 36 lines · Ard Biesheuvel
(cc Laszlo)
Quoted 24 lines · Michael S. Tsirkin
Quoted 22 lines · Jason A. Donenfeld
Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?Quoted 8 lines
Quoted 4 lines
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Quoted 5 lines
This does raise the question (as I mentioned before) how things like secure boot and measured boot are affected when combined with direct kernel boot: AIUI, libvirt uses direct kernel boot at guest installation time, and modifying
setup_datawill corrupt the image signature.IIUC, qemu already modifies
setup_datawhen using direct kernel boot.
Quoted 9 lines
Quoted 4 lines
It put in logic to skip this if SEV is enabled, to avoid interfering with SEV hashes over the kernel, but there's nothing doing this more generally for non-SEV cases using UEFI. So potentially use of SecureBoot may already be impacted when using direct kernel boot.
Yes,
Ah yes, thanks for jogging my memory.
So virt-install --network already ignores secure boot failures on direct kernel boot, so this is not going to make it any worse.
Quoted 55 lines · Ard Biesheuvel
Quoted 54 lines · Laszlo Ersek
Quoted 43 lines · Daniel P. Berrangé
Quoted 36 lines · Ard Biesheuvel
(cc Laszlo)
Quoted 24 lines · Michael S. Tsirkin
Quoted 22 lines · Jason A. Donenfeld
Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?Quoted 8 lines
Quoted 4 lines
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Quoted 5 lines
This does raise the question (as I mentioned before) how things like secure boot and measured boot are affected when combined with direct kernel boot: AIUI, libvirt uses direct kernel boot at guest installation time, and modifying
setup_datawill corrupt the image signature.Quoted 6 lines
IIUC, qemu already modifies
setup_datawhen using direct kernel boot.It put in logic to skip this if SEV is enabled, to avoid interfering with SEV hashes over the kernel, but there's nothing doing this more generally for non-SEV cases using UEFI. So potentially use of SecureBoot may already be impacted when using direct kernel boot.
Yes,
Quoted 7 lines
Quoted 2 lines
Ah yes, thanks for jogging my memory.
So virt-install --network already ignores secure boot failures on direct kernel boot, so this is not going to make it any worse.
And in a cloud world this isn't too much of a problem to start with. The cloud disks images will be built offline in trusted infrastructure, so lack of SecureBoot isn't a show stopper. When later deployed to the public cloud, SecureBoot (and/or Confidential Boot) will be fully operational, where it matters most.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 23 lines · Michael S. Tsirkin
Quoted 22 lines · Jason A. Donenfeld
Quoted 20 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?
Quoted 7 lines
Quoted 4 lines
Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Sure, will do.
Jason
Quoted 27 lines · Jason A. Donenfeld
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Jason A. Donenfeld
Quoted 18 lines · Michael S. Tsirkin
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>Quoted 2 lines
BTW what does it have to do with SEV?
Is this because SEV is not going to trust the data to be random anyway?Daniel (now CC'd) pointed out in one of the previous threads that this breaks SEV, because the image hash changes.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
Jason
Oh I see. I'd add a comment maybe and definitely mention this in the commit log.
Sure, will do.
Actually, I'm wrong. This is already done implicitly below with a huge comment:
/*
* If we're starting an encrypted VM, it will be OVMF based, which uses the
* efi stub for booting and doesn't require any values to be placed in the
* kernel header. We therefore don't update the header so the hash of the
* kernel on the other side of the fw_cfg interface matches the hash of the
* file the user passed in.
*/
if (!sev_enabled()) {
memcpy(setup, header, MIN(sizeof(header), setup_size));
}
So I'll remove the SEV bit from this commit. Whoops. Glad you asked about it.
Jason
PATCH v3 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.
--- hw/i386/x86.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
hw/i386/x86.c +8 -2
@@ -1088,8 +1088,14 @@ 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. +*/ +if (protocol >=0x210 ) { +/* 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 v3 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
Re: [PATCH v3 2/2] x86: re-enable rng seeding via setup_data
Quoted 12 lines · Jason A. Donenfeld
This reverts
3824e25db1("x86: disable rng seeding viasetup_data"), but for 7.2 rather than 7.1, now that modifyingsetup_datais safe to do.Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Gerd Hoffmann via
Acked-by Gerd HoffmannQuoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.
Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
take care,
Gerd
Quoted 17 lines · Gerd Hoffmann
Quoted 5 lines · Jason A. Donenfeld
It's only safe to modify the
setup_datapointer 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.Quoted 10 lines
Cc Gerd Hoffmann <[email protected]>Cc Laurent Vivier <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Richard Henderson <[email protected]>Cc Ard Biesheuvel <[email protected]>Signed-off-by Jason A. Donenfeld <[email protected]>
Quoted 1 line
Acked-by Gerd Hoffmann <[email protected]>
Thanks for the ack. Just FYI, we should probably wait until Ard sends the kernel side of things up to Linus before committing this to QEMU.
Jason