Skip to content

Commit 23a4e40

Browse files
dianderskees
authored andcommitted
arm: kgdb: Handle read-only text / modules
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 <[email protected]> [kees: switched structure size check to BUILD_BUG_ON (sboyd)] Signed-off-by: Kees Cook <[email protected]> Acked-by: Nicolas Pitre <[email protected]>
1 parent 42d720d commit 23a4e40

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

arch/arm/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ test-kprobes-objs += kprobes-test-arm.o
6767
endif
6868
obj-$(CONFIG_OABI_COMPAT) += sys_oabi-compat.o
6969
obj-$(CONFIG_ARM_THUMBEE) += thumbee.o
70-
obj-$(CONFIG_KGDB) += kgdb.o
70+
obj-$(CONFIG_KGDB) += kgdb.o patch.o
7171
obj-$(CONFIG_ARM_UNWIND) += unwind.o
7272
obj-$(CONFIG_HAVE_TCM) += tcm.o
7373
obj-$(CONFIG_OF) += devtree.o

arch/arm/kernel/kgdb.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
#include <linux/irq.h>
1313
#include <linux/kdebug.h>
1414
#include <linux/kgdb.h>
15+
#include <linux/uaccess.h>
16+
1517
#include <asm/traps.h>
1618

19+
#include "patch.h"
20+
1721
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] =
1822
{
1923
{ "r0", 4, offsetof(struct pt_regs, ARM_r0)},
@@ -244,6 +248,31 @@ void kgdb_arch_exit(void)
244248
unregister_die_notifier(&kgdb_notifier);
245249
}
246250

251+
int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
252+
{
253+
int err;
254+
255+
/* patch_text() only supports int-sized breakpoints */
256+
BUILD_BUG_ON(sizeof(int) != BREAK_INSTR_SIZE);
257+
258+
err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
259+
BREAK_INSTR_SIZE);
260+
if (err)
261+
return err;
262+
263+
patch_text((void *)bpt->bpt_addr,
264+
*(unsigned int *)arch_kgdb_ops.gdb_bpt_instr);
265+
266+
return err;
267+
}
268+
269+
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
270+
{
271+
patch_text((void *)bpt->bpt_addr, *(unsigned int *)bpt->saved_instr);
272+
273+
return 0;
274+
}
275+
247276
/*
248277
* Register our undef instruction hooks with ARM undef core.
249278
* We regsiter a hook specifically looking for the KGB break inst

0 commit comments

Comments
 (0)