Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change save/restore nvram data logic #887

Merged
merged 7 commits into from Apr 3, 2024

Conversation

antonios-f
Copy link
Contributor

Save NVRAM data not only if BiosType is Q35_SECURE_BOOT Also save if Q35_OVMF because it also includes EFI boot variables With Q35_OVMF we unable to boot non-fallback bootloaders in place different from /EFI/BOOT/BOOT.EFI

To check this it needed to:

  1. Run VM with installed Linux (it doesn't matter what distro) 2) Add a bootloader via efibbotmgr
    efibootmgr -c -d -L "Some Linux" -l \EFI\\grubx64.efi
  2. Look at created efi boot variable
    efibootmgr -v
    It's present
  3. Shutdown VM
  4. Run it again
  5. Check efi boot variables again
    efibootmgr -v
  6. We got non bootable VM if fallback bootloader is broken or boot default esp/EFI/BOOT/BOOT.EFI
    otherwise

Save NVRAM data not only if BiosType is Q35_SECURE_BOOT
Also save if Q35_OVMF because it also includes EFI boot variables
With Q35_OVMF we unable to boot non-fallback bootloaders
in place different from <esp>/EFI/BOOT/BOOT<arch>.EFI

To check this it needed to:
1) Run VM with installed Linux (it doesn't matter what distro)
2) Add a bootloader via efibbotmgr
   efibootmgr -c -d <boot device> -L "Some Linux" -l \\EFI\\<somevendor>\\grubx64.efi
3) Look at created efi boot variable
   efibootmgr -v
   It's present
4) Shutdown VM
5) Run it again
6) Check efi boot variables again
   efibootmgr -v
7) We got non bootable VM if fallback bootloader is broken or boot default esp/EFI/BOOT/BOOT<arch>.EFI
   otherwise

Signed-off-by: Anton Fadeev <anton.fadeev@red-soft.ru>
@mz-pdm
Copy link
Member

mz-pdm commented Nov 27, 2023

The idea looks OK to me, IIRC there are no inherent limitations when keeping NVRAM data. It adds some Vdsm traffic and other machinery, even if the EFI variables are not modified I think, but this doesn't differ from using secure boot.

One thing I suggest to check with this patch is whether the NVRAM data is deleted when switching the VM to secure boot and back. Should it be deleted or not?

@antonios-f
Copy link
Contributor Author

antonios-f commented Nov 27, 2023

NVRAM data will be deleted when switching the VM from secure boot, by this trigger

CREATE OR REPLACE FUNCTION remove_nvram_data ()
RETURNS TRIGGER AS $$
BEGIN
    IF OLD.bios_type = 4 AND NEW.bios_type != 4 THEN
        DELETE FROM vm_nvram_data
        WHERE vm_id = OLD.vm_guid;
    END IF;
    RETURN NEW;
END;$$
LANGUAGE plpgsql;

CREATE TRIGGER remove_nvram_data_on_update AFTER
UPDATE
    ON vm_static
FOR EACH ROW
EXECUTE FUNCTION remove_nvram_data();

When switching from Uefi to Secure Boot it will be not deleted.

@mz-pdm
Copy link
Member

mz-pdm commented Nov 27, 2023

Now the question is whether it's good to delete the NVRAM data when switching from secure boot. I'd say it's on the safe side -- deleting any possible secrets stored there. It will delete the other EFI variables too though but one shouldn't switch an installed VM from secure boot without a good reason so it doesn't look like a big problem. Do you agree?

@antonios-f
Copy link
Contributor Author

I think yes.

@barpavel barpavel self-requested a review November 27, 2023 14:26
@smelamud
Copy link
Member

CREATE OR REPLACE FUNCTION remove_nvram_data ()
RETURNS TRIGGER AS $$
BEGIN
IF OLD.bios_type = 4 AND NEW.bios_type != 4 THEN

Since now bios_type = 3 can also contain NVRAM data. So, if I understand correctly, switching from it should also delete the data.

Copy link
Member

@smelamud smelamud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just need to check the stored procedures again, as mentioned above.

Copy link
Member

@mz-pdm mz-pdm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me and I think we agreed on the behavior regarding data deletion on BIOS switching.

@smelamud
Copy link
Member

@mz-pdm With this patch, NVRAM data will be available with BIOS type Q35_OVMF (bios_type = 3). But remove_nvram_data will not delete it when switching bios_type from 3 to 2, for example. While it is deleted when switching from 4 to 2. Correct me, if I'm wrong.

@mz-pdm
Copy link
Member

mz-pdm commented Nov 28, 2023

@smelamud Ah, I see your point now. Do you think it should be deleted in such a case? There is some reason to delete it when switching from secure boot (due to possible presence of secrets, not to keep them around unnecessarily). Perhaps as a general cleanup in other situations? A related question would be whether there is a confirmation dialog for the given deletion that should be updated too.

@smelamud
Copy link
Member

@mz-pdm Yes, as a general cleanup, I think. And the confirmation dialog should be shown, because BIOS type change may be unintentional.

@antonios-f
Copy link
Contributor Author

The confirmation dialog was added, as you described. Please look at this.

Copy link
Member

@barpavel barpavel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, some minor suggestions, up to you.

@antonios-f
Copy link
Contributor Author

Everything has been fixed as posted. Please look at this.

@barpavel
Copy link
Member

Everything has been fixed as posted. Please look at this.

Except 2 small suggestions as a follow-up of the previous code review, LGTM.

@barpavel barpavel self-requested a review March 26, 2024 12:16
Copy link
Member

@barpavel barpavel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My comments were addressed, LGTM.
But suggest to wait for more approvals.

@sandrobonazzola
Copy link
Member

Hi, looks like DCO test is failing, can you please follow instructions on https://github.com/oVirt/ovirt-engine/pull/887/checks?check_run_id=23100801322 for signing off your commits?

antonios-f and others added 2 commits March 26, 2024 18:00
Fix typo in method name.
isUEFI -> isUefi

Signed-off-by: Anton Fadeev <anton.fadeev@red-soft.ru>
…nd added a condition in the Remove_nvram_data function

When changing the chipset from the Q35 chipset with UEFI SecureBoot to any other and with a Q35 chipset with UEFI, a Q35 chipset with BIOS, or an I440FX chipset with BIOS, the nvram is cleared. A window based on the ConfirmationModel has been added to notify the user about clearing NVRAM when changing the BIOS type

Signed-off-by: Mochalin Nikolay <mochalin.nikolay2017@yandex.ru>
@antonios-f antonios-f force-pushed the master-nvram_uefi branch 2 times, most recently from eb7c064 to 0541272 Compare March 26, 2024 15:06
Mochalin Nikolay added 2 commits March 26, 2024 18:07
Signed-off-by: Mochalin Nikolay <nikolay.mochalin@red-soft.ru>
Signed-off-by: Mochalin Nikolay <nikolay.mochalin@red-soft.ru>
@antonios-f antonios-f force-pushed the master-nvram_uefi branch 2 times, most recently from c0d6729 to 857772b Compare March 26, 2024 15:11
@antonios-f
Copy link
Contributor Author

All done. Please look at this.

@sandrobonazzola
Copy link
Member

Build fails on:

Error:  Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project uicommonweb: Compilation failure: Compilation failure: 
Error:  /github/home/rpmbuild/BUILD/ovirt-engine-4.5.5/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java:[799,112] illegal start of expression
Error:  /github/home/rpmbuild/BUILD/ovirt-engine-4.5.5/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java:[800,117] ';' expected
Error:  /github/home/rpmbuild/BUILD/ovirt-engine-4.5.5/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/VmListModel.java:[807,15] 'else' without 'if'

Signed-off-by: Anton Fadeev <anton.fadeev@red-soft.ru>
@antonios-f
Copy link
Contributor Author

I'm sorry. already fixed

Signed-off-by: Anton Fadeev <anton.fadeev@red-soft.ru>
Copy link
Member

@smelamud smelamud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@sandrobonazzola
Copy link
Member

/ost

1 similar comment
@sandrobonazzola
Copy link
Member

/ost

@sandrobonazzola
Copy link
Member

/ost

Copy link
Member

@sandrobonazzola sandrobonazzola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OST passed, merging based on previous approvals

@sandrobonazzola sandrobonazzola merged commit 943a244 into oVirt:master Apr 3, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants