/* * Reserve the memory associated with the Memory Attributes configuration * table, if it exists.
*/ int __init efi_memattr_init(void)
{
efi_memory_attributes_table_t *tbl; unsignedlong size;
if (efi_mem_attr_table == EFI_INVALID_TABLE_ADDR) return 0;
tbl = early_memremap(efi_mem_attr_table, sizeof(*tbl)); if (!tbl) {
pr_err("Failed to map EFI Memory Attributes table @ 0x%lx\n",
efi_mem_attr_table); return -ENOMEM;
}
if (tbl->version > 2) {
pr_warn("Unexpected EFI Memory Attributes table version %d\n",
tbl->version); goto unmap;
}
/* * Sanity check: the Memory Attributes Table contains up to 3 entries * for each entry of type EfiRuntimeServicesCode in the EFI memory map. * So if the size of the table exceeds 3x the size of the entire EFI * memory map, there is clearly something wrong, and the table should * just be ignored altogether.
*/
size = tbl->num_entries * tbl->desc_size; if (size > 3 * efi.memmap.nr_map * efi.memmap.desc_size) {
pr_warn(FW_BUG "Corrupted EFI Memory Attributes Table detected! (version == %u, desc_size == %u, num_entries == %u)\n",
tbl->version, tbl->desc_size, tbl->num_entries); goto unmap;
}
/* * Returns a copy @out of the UEFI memory descriptor @in if it is covered * entirely by a UEFI memory map entry with matching attributes. The virtual * address of @out is set according to the matching entry that was found.
*/ staticbool entry_is_valid(const efi_memory_desc_t *in, efi_memory_desc_t *out)
{
u64 in_paddr = in->phys_addr;
u64 in_size = in->num_pages << EFI_PAGE_SHIFT;
efi_memory_desc_t *md;
*out = *in;
if (in->type != EFI_RUNTIME_SERVICES_CODE &&
in->type != EFI_RUNTIME_SERVICES_DATA) {
pr_warn("Entry type should be RuntimeServiceCode/Data\n"); returnfalse;
}
if (PAGE_SIZE > EFI_PAGE_SIZE &&
(!PAGE_ALIGNED(in->phys_addr) ||
!PAGE_ALIGNED(in->num_pages << EFI_PAGE_SHIFT))) { /* * Since arm64 may execute with page sizes of up to 64 KB, the * UEFI spec mandates that RuntimeServices memory regions must * be 64 KB aligned. We need to validate this here since we will * not be able to tighten permissions on such regions without * affecting adjacent regions.
*/
pr_warn("Entry address region misaligned\n"); returnfalse;
}
if (!(md->attribute & EFI_MEMORY_RUNTIME)) continue; if (md->virt_addr == 0 && md->phys_addr != 0) { /* no virtual mapping has been installed by the stub */ break;
}
/* * This entry covers the start of @in, check whether * it covers the end as well.
*/ if (md_paddr + md_size < in_paddr + in_size) {
pr_warn("Entry covers multiple EFI memory map regions\n"); returnfalse;
}
if (md->type != in->type) {
pr_warn("Entry type deviates from EFI memory map region type\n"); returnfalse;
}
pr_warn("No matching entry found in the EFI memory map\n"); returnfalse;
}
/* * To be called after the EFI page tables have been populated. If a memory * attributes table is available, its contents will be used to update the * mappings with tightened permissions as described by the table. * This requires the UEFI memory map to have already been populated with * virtual addresses.
*/ int __init efi_memattr_apply_permissions(struct mm_struct *mm,
efi_memattr_perm_setter fn)
{
efi_memory_attributes_table_t *tbl; bool has_bti = false; int i, ret;
if (tbl_size <= sizeof(*tbl)) return 0;
/* * We need the EFI memory map to be setup so we can use it to * lookup the virtual addresses of all entries in the of EFI * Memory Attributes table. If it isn't available, this * function should not be called.
*/ if (WARN_ON(!efi_enabled(EFI_MEMMAP))) return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.