Skip to content

Commit 4eaef36

Browse files
kristina-martsenkogregkh
authored andcommitted
arm64: hw_breakpoint: fix watchpoint matching for tagged pointers
commit 7dcd9dd8cebe9fa626af7e2358d03a37041a70fb upstream. This backport has a few small differences from the upstream commit: - The address tag is removed in watchpoint_handler() instead of get_distance_from_watchpoint(), because 4.4 does not have commit fdfeff0f9e3d ("arm64: hw_breakpoint: Handle inexact watchpoint addresses"). - A macro is backported (untagged_addr), as it is not present in 4.4. Original patch description: When we take a watchpoint exception, the address that triggered the watchpoint is found in FAR_EL1. We compare it to the address of each configured watchpoint to see which one was hit. The configured watchpoint addresses are untagged, while the address in FAR_EL1 will have an address tag if the data access was done using a tagged address. The tag needs to be removed to compare the address to the watchpoints. Currently we don't remove it, and as a result can report the wrong watchpoint as being hit (specifically, always either the highest TTBR0 watchpoint or lowest TTBR1 watchpoint). This patch removes the tag. Fixes: d50240a ("arm64: mm: permit use of tagged pointers at EL0") Acked-by: Mark Rutland <mark.rutland@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 bc5f31d commit 4eaef36

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

arch/arm64/include/asm/uaccess.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
/*
2222
* User space memory access functions
2323
*/
24+
#include <linux/bitops.h>
2425
#include <linux/string.h>
2526
#include <linux/thread_info.h>
2627

@@ -103,6 +104,13 @@ static inline void set_fs(mm_segment_t fs)
103104
flag; \
104105
})
105106

107+
/*
108+
* When dealing with data aborts, watchpoints, or instruction traps we may end
109+
* up with a tagged userland pointer. Clear the tag to get a sane pointer to
110+
* pass on to access_ok(), for instance.
111+
*/
112+
#define untagged_addr(addr) sign_extend64(addr, 55)
113+
106114
#define access_ok(type, addr, size) __range_ok(addr, size)
107115
#define user_addr_max get_fs
108116

arch/arm64/kernel/hw_breakpoint.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <asm/traps.h>
3636
#include <asm/cputype.h>
3737
#include <asm/system_misc.h>
38+
#include <asm/uaccess.h>
3839

3940
/* Breakpoint currently in use for each BRP. */
4041
static DEFINE_PER_CPU(struct perf_event *, bp_on_reg[ARM_MAX_BRP]);
@@ -690,7 +691,7 @@ static int watchpoint_handler(unsigned long addr, unsigned int esr,
690691

691692
/* Check if the watchpoint value matches. */
692693
val = read_wb_reg(AARCH64_DBG_REG_WVR, i);
693-
if (val != (addr & ~alignment_mask))
694+
if (val != (untagged_addr(addr) & ~alignment_mask))
694695
goto unlock;
695696

696697
/* Possible match, check the byte address select to confirm. */

0 commit comments

Comments
 (0)