Skip to content

Commit 2dacab7

Browse files
Matthew Leachctmarinas
Matthew Leach
authored andcommitted
arm64: debug: make aarch32 bkpt checking endian clean
The current breakpoint instruction checking code for A32 is not endian clean. Fix this with appropriate byte-swapping when retrieving instructions. Signed-off-by: Matthew Leach <[email protected]> Reviewed-by: Will Deacon <[email protected]> Signed-off-by: Catalin Marinas <[email protected]>
1 parent 6a2e5e5 commit 2dacab7

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

arch/arm64/kernel/debug-monitors.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ static int brk_handler(unsigned long addr, unsigned int esr,
248248
int aarch32_break_handler(struct pt_regs *regs)
249249
{
250250
siginfo_t info;
251-
unsigned int instr;
251+
u32 arm_instr;
252+
u16 thumb_instr;
252253
bool bp = false;
253254
void __user *pc = (void __user *)instruction_pointer(regs);
254255

@@ -257,18 +258,21 @@ int aarch32_break_handler(struct pt_regs *regs)
257258

258259
if (compat_thumb_mode(regs)) {
259260
/* get 16-bit Thumb instruction */
260-
get_user(instr, (u16 __user *)pc);
261-
if (instr == AARCH32_BREAK_THUMB2_LO) {
261+
get_user(thumb_instr, (u16 __user *)pc);
262+
thumb_instr = le16_to_cpu(thumb_instr);
263+
if (thumb_instr == AARCH32_BREAK_THUMB2_LO) {
262264
/* get second half of 32-bit Thumb-2 instruction */
263-
get_user(instr, (u16 __user *)(pc + 2));
264-
bp = instr == AARCH32_BREAK_THUMB2_HI;
265+
get_user(thumb_instr, (u16 __user *)(pc + 2));
266+
thumb_instr = le16_to_cpu(thumb_instr);
267+
bp = thumb_instr == AARCH32_BREAK_THUMB2_HI;
265268
} else {
266-
bp = instr == AARCH32_BREAK_THUMB;
269+
bp = thumb_instr == AARCH32_BREAK_THUMB;
267270
}
268271
} else {
269272
/* 32-bit ARM instruction */
270-
get_user(instr, (u32 __user *)pc);
271-
bp = (instr & ~0xf0000000) == AARCH32_BREAK_ARM;
273+
get_user(arm_instr, (u32 __user *)pc);
274+
arm_instr = le32_to_cpu(arm_instr);
275+
bp = (arm_instr & ~0xf0000000) == AARCH32_BREAK_ARM;
272276
}
273277

274278
if (!bp)

0 commit comments

Comments
 (0)