Skip to content

Commit 3ccf695

Browse files
kristina-martsenkogregkh
authored andcommitted
arm64: entry: improve data abort handling of tagged pointers
commit 276e93279a630657fff4b086ba14c95955912dfa upstream. This backport has a minor difference from the upstream commit: it adds the asm-uaccess.h file, which is not present in 4.4, because 4.4 does not have commit b4b8664d291a ("arm64: don't pull uaccess.h into *.S"). Original patch description: 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") Reviewed-by: Dave Martin <Dave.Martin@arm.com> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Kristina Martsenko <kristina.martsenko@arm.com> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4eaef36 commit 3ccf695

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef __ASM_ASM_UACCESS_H
2+
#define __ASM_ASM_UACCESS_H
3+
4+
/*
5+
* Remove the address tag from a virtual address, if present.
6+
*/
7+
.macro clear_address_tag, dst, addr
8+
tst \addr, #(1 << 55)
9+
bic \dst, \addr, #(0xff << 56)
10+
csel \dst, \dst, \addr, eq
11+
.endm
12+
13+
#endif

arch/arm64/kernel/entry.S

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <asm/esr.h>
3030
#include <asm/memory.h>
3131
#include <asm/thread_info.h>
32+
#include <asm/asm-uaccess.h>
3233
#include <asm/unistd.h>
3334

3435
/*
@@ -316,12 +317,13 @@ el1_da:
316317
/*
317318
* Data abort handling
318319
*/
319-
mrs x0, far_el1
320+
mrs x3, far_el1
320321
enable_dbg
321322
// re-enable interrupts if they were enabled in the aborted context
322323
tbnz x23, #7, 1f // PSR_I_BIT
323324
enable_irq
324325
1:
326+
clear_address_tag x0, x3
325327
mov x2, sp // struct pt_regs
326328
bl do_mem_abort
327329

@@ -483,7 +485,7 @@ el0_da:
483485
// enable interrupts before calling the main handler
484486
enable_dbg_and_irq
485487
ct_user_exit
486-
bic x0, x26, #(0xff << 56)
488+
clear_address_tag x0, x26
487489
mov x1, x25
488490
mov x2, sp
489491
bl do_mem_abort

0 commit comments

Comments
 (0)