linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm: ptrace: Fix mask for thumb breakpoint hook
@ 2020-03-16 12:12 Fredrik Strupe
  0 siblings, 0 replies; only message in thread
From: Fredrik Strupe @ 2020-03-16 12:12 UTC (permalink / raw)
  To: Oleg Nesterov, Russell King, linux-arm-kernel, linux-kernel

Since instr_mask in struct undef_hook is 32 bits wide, a mask with value
0xffff will essentially be extended to 0x0000ffff. This makes undefined
thumb2 instructions with the second half-word as 0xde01 generate SIGTRAPs
instead of SIGILLs.

This happens in total for 3143 instructions on my system. An example
of such an instruction is e800de01.

This patch fixes the issue by extending the mask to the full 32 bits,
such that both half-words have to be matched. This will remove all of
the accidental matchings, as 0x0000 is not a valid thumb2 prefix, while
preserving the intended thumb hook.

Signed-off-by: Fredrik Strupe <fredrik@strupe.net>
---
  arch/arm/kernel/ptrace.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
index 36718a424..f51bec0bc 100644
--- a/arch/arm/kernel/ptrace.c
+++ b/arch/arm/kernel/ptrace.c
@@ -228,9 +228,14 @@ static struct undef_hook arm_break_hook = {
  	.fn		= break_trap,
  };
  
+/*
+ * Set all bits in the instruction mask, even though the thumb
+ * instruction is only 16 bits. This is to prevent accidental
+ * matching of thumb2 instructions.
+ */
  static struct undef_hook thumb_break_hook = {
-	.instr_mask	= 0xffff,
-	.instr_val	= 0xde01,
+	.instr_mask	= 0xffffffff,
+	.instr_val	= 0x0000de01,
  	.cpsr_mask	= PSR_T_BIT,
  	.cpsr_val	= PSR_T_BIT,
  	.fn		= break_trap,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-03-16 12:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-16 12:12 [PATCH] arm: ptrace: Fix mask for thumb breakpoint hook Fredrik Strupe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).