Skip to content

Commit 276e932

Browse files
kristina-martsenkoctmarinas
authored andcommitted
arm64: entry: improve data abort handling of tagged pointers
When handling a data abort from EL0, we currently zero the top byte of the faulting address, as we assume the address is a TTBR0 address, which may contain a non-zero address tag. However, the address may be a TTBR1 address, in which case we should not zero the top byte. This patch fixes that. The effect is that the full TTBR1 address is passed to the task's signal handler (or printed out in the kernel log). When handling a data abort from EL1, we leave the faulting address intact, as we assume it's either a TTBR1 address or a TTBR0 address with tag 0x00. This is true as far as I'm aware, we don't seem to access a tagged TTBR0 address anywhere in the kernel. Regardless, it's easy to forget about address tags, and code added in the future may not always remember to remove tags from addresses before accessing them. So add tag handling to the EL1 data abort handler as well. This also makes it consistent with the EL0 data abort handler. Fixes: d50240a ("arm64: mm: permit use of tagged pointers at EL0") Cc: <[email protected]> # 3.12.x- Reviewed-by: Dave Martin <[email protected]> Acked-by: Will Deacon <[email protected]> Signed-off-by: Kristina Martsenko <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 7dcd9dd commit 276e932

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

arch/arm64/include/asm/asm-uaccess.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,13 @@ alternative_if ARM64_ALT_PAN_NOT_UAO
6262
alternative_else_nop_endif
6363
.endm
6464

65+
/*
66+
* Remove the address tag from a virtual address, if present.
67+
*/
68+
.macro clear_address_tag, dst, addr
69+
tst \addr, #(1 << 55)
70+
bic \dst, \addr, #(0xff << 56)
71+
csel \dst, \dst, \addr, eq
72+
.endm
73+
6574
#endif

arch/arm64/kernel/entry.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,13 @@ el1_da:
428428
/*
429429
* Data abort handling
430430
*/
431-
mrs x0, far_el1
431+
mrs x3, far_el1
432432
enable_dbg
433433
// re-enable interrupts if they were enabled in the aborted context
434434
tbnz x23, #7, 1f // PSR_I_BIT
435435
enable_irq
436436
1:
437+
clear_address_tag x0, x3
437438
mov x2, sp // struct pt_regs
438439
bl do_mem_abort
439440

@@ -594,7 +595,7 @@ el0_da:
594595
// enable interrupts before calling the main handler
595596
enable_dbg_and_irq
596597
ct_user_exit
597-
bic x0, x26, #(0xff << 56)
598+
clear_address_tag x0, x26
598599
mov x1, x25
599600
mov x2, sp
600601
bl do_mem_abort

0 commit comments

Comments
 (0)