if (esr_is_data_abort(esr))
data_abort_decode(esr);
}
staticinlineunsignedlong mm_to_pgd_phys(struct mm_struct *mm)
{ /* Either init_pg_dir or swapper_pg_dir */ if (mm == &init_mm) return __pa_symbol(mm->pgd);
return (unsignedlong)virt_to_phys(mm->pgd);
}
/* * Dump out the page tables associated with 'addr' in the currently active mm.
*/ staticvoid show_pte(unsignedlong addr)
{ struct mm_struct *mm;
pgd_t *pgdp;
pgd_t pgd;
if (is_ttbr0_addr(addr)) { /* TTBR0 */
mm = current->active_mm; if (mm == &init_mm) {
pr_alert("[%016lx] user address but active_mm is swapper\n",
addr); return;
}
} elseif (is_ttbr1_addr(addr)) { /* TTBR1 */
mm = &init_mm;
} else {
pr_alert("[%016lx] address between user and kernel address ranges\n",
addr); return;
}
/* * This function sets the access flags (dirty, accessed), as well as write * permission, and only to a more permissive setting. * * It needs to cope with hardware update of the accessed/dirty state by other * agents in the system and can safely skip the __sync_icache_dcache() call as, * like __set_ptes(), the PTE is never changed from no-exec to exec here. * * Returns whether or not the PTE actually changed.
*/ int __ptep_set_access_flags(struct vm_area_struct *vma, unsignedlong address, pte_t *ptep,
pte_t entry, int dirty)
{
pteval_t old_pteval, pteval;
pte_t pte = __ptep_get(ptep);
if (pte_same(pte, entry)) return 0;
/* only preserve the access flags and write permission */
pte_val(entry) &= PTE_RDONLY | PTE_AF | PTE_WRITE | PTE_DIRTY;
/* * Setting the flags must be done atomically to avoid racing with the * hardware update of the access/dirty state. The PTE_RDONLY bit must * be set to the most permissive (lowest value) of *ptep and entry * (calculated as: a & b == ~(~a | ~b)).
*/
pte_val(entry) ^= PTE_RDONLY;
pteval = pte_val(pte); do {
old_pteval = pteval;
pteval ^= PTE_RDONLY;
pteval |= pte_val(entry);
pteval ^= PTE_RDONLY;
pteval = cmpxchg_relaxed(&pte_val(*ptep), old_pteval, pteval);
} while (pteval != old_pteval);
/* Invalidate a stale read-only entry */ if (dirty)
flush_tlb_page(vma, address); return 1;
}
/* * If we now have a valid translation, treat the translation fault as * spurious.
*/ if (!(par & SYS_PAR_EL1_F)) returntrue;
/* * If we got a different type of fault from the AT instruction, * treat the translation fault as spurious.
*/
dfsc = FIELD_GET(SYS_PAR_EL1_FST, par); return !esr_fsc_is_translation_fault(dfsc);
}
/* * Disable MTE Tag Checking on the local CPU for the current EL. * It will be done lazily on the other CPUs when they will hit a * tag fault.
*/
sysreg_clear_set(sctlr_el1, SCTLR_EL1_TCF_MASK,
SYS_FIELD_PREP_ENUM(SCTLR_EL1, TCF, NONE));
isb();
}
/* * Are we prepared to handle this kernel fault? * We are almost certainly not prepared to handle instruction faults.
*/ if (!is_el1_instruction_abort(esr) && fixup_exception(regs, esr)) return;
if (WARN_RATELIMIT(is_spurious_el1_translation_fault(addr, esr, regs), "Ignoring spurious kernel translation fault at virtual address %016lx\n", addr)) return;
if (is_el1_mte_sync_tag_check_fault(esr)) {
do_tag_recovery(addr, esr, regs);
return;
}
if (is_el1_permission_fault(addr, esr, regs)) { if (esr & ESR_ELx_WNR)
msg = "write to read-only memory"; elseif (is_el1_instruction_abort(esr))
msg = "execute from non-executable memory"; else
msg = "read from unreadable memory";
} elseif (addr < PAGE_SIZE) {
msg = "NULL pointer dereference";
} else { if (esr_fsc_is_translation_fault(esr) &&
kfence_handle_page_fault(addr, esr & ESR_ELx_WNR, regs)) return;
msg = "paging request";
}
if (efi_runtime_fixup_exception(regs, msg)) return;
/* * If the faulting address is in the kernel, we must sanitize the ESR. * From userspace's point of view, kernel-only mappings don't exist * at all, so we report them as level 0 translation faults. * (This is not quite the way that "no mapping there at all" behaves: * an alignment fault not caused by the memory type would take * precedence over translation fault for a real access to empty * space. Unfortunately we can't easily distinguish "alignment fault * not caused by memory type" from "alignment fault caused by memory * type", so we ignore this wrinkle and just return the translation * fault.)
*/ if (!is_ttbr0_addr(current->thread.fault_address)) { switch (ESR_ELx_EC(esr)) { case ESR_ELx_EC_DABT_LOW: /* * These bits provide only information about the * faulting instruction, which userspace knows already. * We explicitly clear bits which are architecturally * RES0 in case they are given meanings in future. * We always report the ESR as if the fault was taken * to EL1 and so ISV and the bits in ISS[23:14] are * clear. (In fact it always will be a fault to EL1.)
*/
esr &= ESR_ELx_EC_MASK | ESR_ELx_IL |
ESR_ELx_CM | ESR_ELx_WNR;
esr |= ESR_ELx_FSC_FAULT; break; case ESR_ELx_EC_IABT_LOW: /* * Claim a level 0 translation fault. * All other bits are architecturally RES0 for faults * reported with that DFSC value, so we clear them.
*/
esr &= ESR_ELx_EC_MASK | ESR_ELx_IL;
esr |= ESR_ELx_FSC_FAULT; break; default: /* * This should never happen (entry.S only brings us * into this code for insn and data aborts from a lower * exception level). Fail safe by not providing an ESR * context record at all.
*/
WARN(1, "ESR 0x%lx is not DABT or IABT from EL0\n", esr);
esr = 0; break;
}
}
/* * If we are in kernel mode at this point, we have no context to * handle this fault with.
*/ if (user_mode(regs)) { conststruct fault_info *inf = esr_to_fault_info(esr);
staticbool fault_from_pkey(struct vm_area_struct *vma, unsignedint mm_flags)
{ if (!system_supports_poe()) returnfalse;
/* * We do not check whether an Overlay fault has occurred because we * cannot make a decision based solely on its value: * * - If Overlay is set, a fault did occur due to POE, but it may be * spurious in those cases where we update POR_EL0 without ISB (e.g. * on context-switch). We would then need to manually check POR_EL0 * against vma_pkey(vma), which is exactly what * arch_vma_access_permitted() does. * * - If Overlay is not set, we may still need to report a pkey fault. * This is the case if an access was made within a mapping but with no * page mapped, and POR_EL0 forbids the access (according to * vma_pkey()). Such access will result in a SIGSEGV regardless * because core code checks arch_vma_access_permitted(), but in order * to report the correct error code - SEGV_PKUERR - we must handle * that case here.
*/ return !arch_vma_access_permitted(vma,
mm_flags & FAULT_FLAG_WRITE,
mm_flags & FAULT_FLAG_INSTRUCTION, false);
}
staticbool is_gcs_fault(unsignedlong esr)
{ if (!esr_is_data_abort(esr)) returnfalse;
/* * Note: not valid for EL1 DC IVAC, but we never use that such that it * should fault. EL0 cannot issue DC IVAC (undef).
*/ staticbool is_write_abort(unsignedlong esr)
{ return (esr & ESR_ELx_WNR) && !(esr & ESR_ELx_CM);
}
staticbool is_invalid_gcs_access(struct vm_area_struct *vma, u64 esr)
{ if (!system_supports_gcs()) returnfalse;
if (unlikely(is_gcs_fault(esr))) { /* GCS accesses must be performed on a GCS page */ if (!(vma->vm_flags & VM_SHADOW_STACK)) returntrue;
} elseif (unlikely(vma->vm_flags & VM_SHADOW_STACK)) { /* Only GCS operations can write to a GCS page */ return esr_is_data_abort(esr) && is_write_abort(esr);
}
/* * If we're in an interrupt or have no user context, we must not take * the fault.
*/ if (faulthandler_disabled() || !mm) goto no_context;
if (user_mode(regs))
mm_flags |= FAULT_FLAG_USER;
/* * vm_flags tells us what bits we must have in vma->vm_flags * for the fault to be benign, __do_page_fault() would check * vma->vm_flags & vm_flags and returns an error if the * intersection is empty
*/ if (is_el0_instruction_abort(esr)) { /* It was exec fault */
vm_flags = VM_EXEC;
mm_flags |= FAULT_FLAG_INSTRUCTION;
} elseif (is_gcs_fault(esr)) { /* * The GCS permission on a page implies both read and * write so always handle any GCS fault as a write fault, * we need to trigger CoW even for GCS reads.
*/
vm_flags = VM_WRITE;
mm_flags |= FAULT_FLAG_WRITE;
} elseif (is_write_abort(esr)) { /* It was write fault */
vm_flags = VM_WRITE;
mm_flags |= FAULT_FLAG_WRITE;
} else { /* It was read fault */
vm_flags = VM_READ; /* Write implies read */
vm_flags |= VM_WRITE; /* If EPAN is absent then exec implies read */ if (!alternative_has_cap_unlikely(ARM64_HAS_EPAN))
vm_flags |= VM_EXEC;
}
if (is_ttbr0_addr(addr) && is_el1_permission_fault(addr, esr, regs)) { if (is_el1_instruction_abort(esr))
die_kernel_fault("execution of user memory",
addr, esr, regs);
if (!insn_may_access_user(regs->pc, esr))
die_kernel_fault("access to user memory outside uaccess routines",
addr, esr, regs);
}
done: /* Handle the "normal" (no error) case first. */ if (likely(!(fault & VM_FAULT_ERROR))) return 0;
si_code = SEGV_MAPERR;
bad_area: /* * If we are in kernel mode at this point, we have no context to * handle this fault with.
*/ if (!user_mode(regs)) goto no_context;
if (fault & VM_FAULT_OOM) { /* * We ran out of memory, call the OOM killer, and return to * userspace (which will retry the fault, or kill us if we got * oom-killed).
*/
pagefault_out_of_memory(); return 0;
}
inf = esr_to_fault_info(esr);
set_thread_esr(addr, esr); if (fault & VM_FAULT_SIGBUS) { /* * We had some memory, but were unable to successfully fix up * this page fault.
*/
arm64_force_sig_fault(SIGBUS, BUS_ADRERR, far, inf->name);
} elseif (fault & (VM_FAULT_HWPOISON_LARGE | VM_FAULT_HWPOISON)) { unsignedint lsb;
lsb = PAGE_SHIFT; if (fault & VM_FAULT_HWPOISON_LARGE)
lsb = hstate_index_to_shift(VM_FAULT_GET_HINDEX(fault));
arm64_force_sig_mceerr(BUS_MCEERR_AR, far, lsb, inf->name);
} else { /* * The pkey value that we return to userspace can be different * from the pkey that caused the fault. * * 1. T1 : mprotect_key(foo, PAGE_SIZE, pkey=4); * 2. T1 : set POR_EL0 to deny access to pkey=4, touches, page * 3. T1 : faults... * 4. T2: mprotect_key(foo, PAGE_SIZE, pkey=5); * 5. T1 : enters fault handler, takes mmap_lock, etc... * 6. T1 : reaches here, sees vma_pkey(vma)=5, when we really * faulted on a pte with its pkey=4.
*/ /* Something tried to access memory that out of memory map */ if (si_code == SEGV_PKUERR)
arm64_force_sig_fault_pkey(far, inf->name, pkey); else
arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name);
}
if (user_mode(regs) && apei_claim_sea(regs) == 0) { /* * APEI claimed this as a firmware-first notification. * Some processing deferred to task_work before ret_to_user().
*/ return 0;
}
if (esr & ESR_ELx_FnV) {
siaddr = 0;
} else { /* * The architecture specifies that the tag bits of FAR_EL1 are * UNKNOWN for synchronous external aborts. Mask them out now * so that userspace doesn't see them.
*/
siaddr = untagged_addr(far);
}
add_taint(TAINT_MACHINE_CHECK, LOCKDEP_STILL_OK);
arm64_notify_die(inf->name, regs, inf->sig, inf->code, siaddr, esr);
return 0;
}
staticint do_tag_check_fault(unsignedlong far, unsignedlong esr, struct pt_regs *regs)
{ /* * The architecture specifies that bits 63:60 of FAR_EL1 are UNKNOWN * for tag check faults. Set them to corresponding bits in the untagged * address if ARM64_MTE_FAR isn't supported. * Otherwise, bits 63:60 of FAR_EL1 are not UNKNOWN.
*/ if (!cpus_have_cap(ARM64_MTE_FAR))
far = (__untagged_addr(far) & ~MTE_TAG_MASK) | (far & MTE_TAG_MASK);
if (!user_mode(regs))
die_kernel_fault(inf->name, addr, esr, regs);
/* * At this point we have an unrecognized fault type whose tag bits may * have been defined as UNKNOWN. Therefore we only expose the untagged * address to the signal handler.
*/
arm64_notify_die(inf->name, regs, inf->sig, inf->code, addr, esr);
}
NOKPROBE_SYMBOL(do_mem_abort);
/* * Used during anonymous page fault handling.
*/ struct folio *vma_alloc_zeroed_movable_folio(struct vm_area_struct *vma, unsignedlong vaddr)
{
gfp_t flags = GFP_HIGHUSER_MOVABLE | __GFP_ZERO;
/* * If the page is mapped with PROT_MTE, initialise the tags at the * point of allocation and page zeroing as this is usually faster than * separate DC ZVA and STGM.
*/ if (vma->vm_flags & VM_MTE)
flags |= __GFP_ZEROTAGS;
return vma_alloc_folio(flags, 0, vma, vaddr);
}
void tag_clear_highpage(struct page *page)
{ /* Newly allocated page, shouldn't have been tagged yet */
WARN_ON_ONCE(!try_page_mte_tagging(page));
mte_zero_clear_page_tags(page_address(page));
set_page_mte_tagged(page);
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
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.