Skip to content

Commit 26313ec

Browse files
mogasergiuunikraft-bot
authored andcommitted
plat/common/efi: Add support for TCG's Reset Attack Mitigation
Add `Trusted Computing Group`'s `Reset Attack Mitigation` mechanism. Whenever a machine shuts down or reboots, due to lack of electric charge, the contents of RAM may dissipate after a short amount of time. However this may be enough for an attacker to quickly boot again into a custom program and dump memory contents. Thus, by using this, the OS instructs POST BIOS to overwrite memory contents before continuing to boot into the rest of the BIOS code. Since this is not really implemented in `OVMF`'s `NVRAM` variables we disable this by default. Signed-off-by: Sergiu Moga <sergiu.moga@protonmail.com> Reviewed-by: Michalis Pappas <michalis@unikraft.io> Approved-by: Razvan Deaconescu <razvand@unikraft.io> Tested-by: Unikraft CI <monkey@unikraft.io> GitHub-Closes: #909
1 parent 170a8a4 commit 26313ec

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

plat/kvm/Config.uk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,19 @@ config KVM_BOOT_EFI_STUB_DTB_FNAME
6363
string "Name of the Devicetree Blob file"
6464
default "$(UK_NAME).dtb"
6565

66+
config KVM_BOOT_EFI_STUB_RST_ATK_MITIGATION
67+
bool "TCG Reset Attack Mitigation"
68+
default n
69+
help
70+
Enable Trusted Computing Group's Reset Attack Mitigation.
71+
Whenever a machine shuts down or reboots, due to lack of
72+
electric charge, the contents of RAM may dissipate after a short
73+
amount of time. However this may be enough for an attacker to
74+
quickly boot again into a custom program and dump memory
75+
contents. Thus, by using this, the OS instructs POST BIOS to
76+
overwrite memory contents before continuing to boot into the
77+
rest of the BIOS code.
78+
6679
endif
6780

6881
choice

plat/kvm/efi.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,48 @@ static void uk_efi_exit_bs(void)
567567
uk_efi_crash("Failed to to exit Boot Services\n");
568568
}
569569

570+
/* Sect 4. of TCG Platform Reset Attack Mitigation Specification Version 1.10
571+
* Rev. 17
572+
*/
573+
static void uk_efi_reset_attack_mitigation_enable(void)
574+
{
575+
#ifdef CONFIG_KVM_BOOT_EFI_STUB_RST_ATK_MITIGATION
576+
/* The UTF-16 encoding of the "MemoryOverwriteRequestControl" string */
577+
char var_name[] = "M\0e\0m\0o\0r\0y\0O\0v\0e\0r\0w\0r\0i\0t\0e\0R\0e"
578+
"\0q\0u\0e\0s\0t\0C\0o\0n\0t\0r\0o\0l\0";
579+
uk_efi_uintn_t data_sz;
580+
uk_efi_status_t status;
581+
__u8 enable = 1;
582+
583+
status = uk_efi_rs->get_variable((__s16 *)var_name,
584+
MEMORY_ONLY_RESET_CONTROL_GUID,
585+
NULL, &data_sz, NULL);
586+
/* There is either no such variable in the firmware database, or no
587+
* variable storage is supported
588+
*/
589+
if (status == UK_EFI_UNSUPPORTED || status == UK_EFI_NOT_FOUND)
590+
return;
591+
else if (unlikely(status != UK_EFI_SUCCESS))
592+
uk_efi_crash("Failed to get MemoryOverwriteRequestControl variable\n");
593+
594+
status = uk_efi_rs->set_variable((__s16 *)var_name,
595+
MEMORY_ONLY_RESET_CONTROL_GUID,
596+
UK_EFI_VARIABLE_NON_VOLATILE |
597+
UK_EFI_VARIABLE_BOOTSERVICE_ACCESS |
598+
UK_EFI_VARIABLE_RUNTIME_ACCESS,
599+
sizeof(enable), &enable);
600+
if (unlikely(status != UK_EFI_SUCCESS))
601+
uk_efi_crash("Failed to enable reset attack mitigation\n");
602+
#endif
603+
}
604+
570605
void __uk_efi_api __noreturn uk_efi_main(uk_efi_hndl_t self_hndl,
571606
struct uk_efi_sys_tbl *sys_tbl)
572607
{
573608
uk_efi_init_vars(self_hndl, sys_tbl);
574609
uk_efi_cls();
575610
uk_efi_setup_bootinfo();
611+
uk_efi_reset_attack_mitigation_enable();
576612
uk_efi_exit_bs();
577613

578614
/* Jump to arch specific post-EFI entry */

plat/kvm/include/kvm/efi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ enum uk_efi_if_type {
4040
EFI_NATIVE_INTERFACE
4141
};
4242

43+
#define UK_EFI_VARIABLE_NON_VOLATILE 0x00000001
44+
#define UK_EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
45+
#define UK_EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
46+
#define UK_EFI_VARIABLE_HARDWARE_ERROR_RECORD 0x00000008
47+
#define UK_EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS 0x00000010
48+
#define UK_EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
49+
#define UK_EFI_VARIABLE_APPEND_WRITE 0x00000040
50+
#define UK_EFI_VARIABLE_ENHANCED_AUTHENTICATED_ACCESS 0x00000080
51+
4352
#define UK_EFI_PAGE_SHIFT 12
4453
#define UK_EFI_PAGE_SIZE (1UL << UK_EFI_PAGE_SHIFT)
4554
#define UK_EFI_PAGES_MAX (__U64_MAX >> UK_EFI_PAGE_SHIFT)

0 commit comments

Comments
 (0)