arm: kgdb: Handle read-only text / modules
authorDoug Anderson <dianders@chromium.org>
Tue, 22 Apr 2014 22:14:51 +0000 (15:14 -0700)
committerKees Cook <keescook@chromium.org>
Thu, 16 Oct 2014 21:38:53 +0000 (14:38 -0700)
Handle the case where someone has set the text segment of the kernel
as read-only by using the newly introduced "patch" mechanism.

Signed-off-by: Doug Anderson <dianders@chromium.org>
[kees: switched structure size check to BUILD_BUG_ON (sboyd)]
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Nicolas Pitre <nico@linaro.org>
arch/arm/kernel/Makefile
arch/arm/kernel/kgdb.c

index 38ddd9f83d0e586289c56bdbf1e38a6a977ff1a7..70b730766330563121c7e354696f225e97cc7052 100644 (file)
@@ -67,7 +67,7 @@ test-kprobes-objs             += kprobes-test-arm.o
 endif
 obj-$(CONFIG_OABI_COMPAT)      += sys_oabi-compat.o
 obj-$(CONFIG_ARM_THUMBEE)      += thumbee.o
-obj-$(CONFIG_KGDB)             += kgdb.o
+obj-$(CONFIG_KGDB)             += kgdb.o patch.o
 obj-$(CONFIG_ARM_UNWIND)       += unwind.o
 obj-$(CONFIG_HAVE_TCM)         += tcm.o
 obj-$(CONFIG_OF)               += devtree.o
index a74b53c1b7dfc3566e51957b6422da290121ff93..07db2f8a1b4505b09eb4633488d7167bb695f669 100644 (file)
 #include <linux/irq.h>
 #include <linux/kdebug.h>
 #include <linux/kgdb.h>
+#include <linux/uaccess.h>
+
 #include <asm/traps.h>
 
+#include "patch.h"
+
 struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
 {
        { "r0", 4, offsetof(struct pt_regs, ARM_r0)},
@@ -244,6 +248,31 @@ void kgdb_arch_exit(void)
        unregister_die_notifier(&kgdb_notifier);
 }
 
+int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
+{
+       int err;
+
+       /* patch_text() only supports int-sized breakpoints */
+       BUILD_BUG_ON(sizeof(int) != BREAK_INSTR_SIZE);
+
+       err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
+                               BREAK_INSTR_SIZE);
+       if (err)
+               return err;
+
+       patch_text((void *)bpt->bpt_addr,
+                  *(unsigned int *)arch_kgdb_ops.gdb_bpt_instr);
+
+       return err;
+}
+
+int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
+{
+       patch_text((void *)bpt->bpt_addr, *(unsigned int *)bpt->saved_instr);
+
+       return 0;
+}
+
 /*
  * Register our undef instruction hooks with ARM undef core.
  * We regsiter a hook specifically looking for the KGB break inst