uefi-vars.rst 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ==============
  2. UEFI variables
  3. ==============
  4. Guest UEFI variable management
  5. ==============================
  6. The traditional approach for UEFI Variable storage in qemu guests is
  7. to work as close as possible to physical hardware. That means
  8. providing pflash as storage and leaving the management of variables
  9. and flash to the guest.
  10. Secure boot support comes with the requirement that the UEFI variable
  11. storage must be protected against direct access by the OS. All update
  12. requests must pass the sanity checks. (Parts of) the firmware must
  13. run with a higher privilege level than the OS so this can be enforced
  14. by the firmware. On x86 this has been implemented using System
  15. Management Mode (SMM) in qemu and kvm, which again is the same
  16. approach taken by physical hardware. Only privileged code running in
  17. SMM mode is allowed to access flash storage.
  18. Communication with the firmware code running in SMM mode works by
  19. serializing the requests to a shared buffer, then trapping into SMM
  20. mode via SMI. The SMM code processes the request, stores the reply in
  21. the same buffer and returns.
  22. Host UEFI variable service
  23. ==========================
  24. Instead of running the privileged code inside the guest we can run it
  25. on the host. The serialization protocol can be reused. The
  26. communication with the host uses a virtual device, which essentially
  27. configures the shared buffer location and size, and traps to the host
  28. to process the requests.
  29. The ``uefi-vars`` device implements the UEFI virtual device. It comes
  30. in ``uefi-vars-x86`` and ``uefi-vars-sysbus`` flavours. The device
  31. reimplements the handlers needed, specifically
  32. ``EfiSmmVariableProtocol`` and ``VarCheckPolicyLibMmiHandler``. It
  33. also consumes events (``EfiEndOfDxeEventGroup``,
  34. ``EfiEventReadyToBoot`` and ``EfiEventExitBootServices``).
  35. The advantage of the approach is that we do not need a special
  36. privilege level for the firmware to protect itself, i.e. it does not
  37. depend on SMM emulation on x64, which allows the removal of a bunch of
  38. complex code for SMM emulation from the linux kernel
  39. (CONFIG_KVM_SMM=n). It also allows support for secure boot on arm
  40. without implementing secure world (el3) emulation in kvm.
  41. Of course there are also downsides. The added device increases the
  42. attack surface of the host, and we are adding some code duplication
  43. because we have to reimplement some edk2 functionality in qemu.
  44. usage on x86_64
  45. ---------------
  46. .. code::
  47. qemu-system-x86_64 \
  48. -device uefi-vars-x86,jsonfile=/path/to/vars.json
  49. usage on aarch64
  50. ----------------
  51. .. code::
  52. qemu-system-aarch64 -M virt \
  53. -device uefi-vars-sysbus,jsonfile=/path/to/vars.json