Skip to content

Commit 44b53f6

Browse files
Pratyush Anandctmarinas
authored andcommitted
arm64: Blacklist non-kprobe-able symbol
Add all function symbols which are called from do_debug_exception under NOKPROBE_SYMBOL, as they can not kprobed. Signed-off-by: Pratyush Anand <panand@redhat.com> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 2dd0e8d commit 44b53f6

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

arch/arm64/kernel/arm64ksyms.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <linux/uaccess.h>
2828
#include <linux/io.h>
2929
#include <linux/arm-smccc.h>
30+
#include <linux/kprobes.h>
3031

3132
#include <asm/checksum.h>
3233

@@ -68,6 +69,7 @@ EXPORT_SYMBOL(test_and_change_bit);
6869

6970
#ifdef CONFIG_FUNCTION_TRACER
7071
EXPORT_SYMBOL(_mcount);
72+
NOKPROBE_SYMBOL(_mcount);
7173
#endif
7274

7375
/* arm-smccc */

arch/arm64/kernel/debug-monitors.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ static void mdscr_write(u32 mdscr)
4949
asm volatile("msr mdscr_el1, %0" :: "r" (mdscr));
5050
local_dbg_restore(flags);
5151
}
52+
NOKPROBE_SYMBOL(mdscr_write);
5253

5354
static u32 mdscr_read(void)
5455
{
5556
u32 mdscr;
5657
asm volatile("mrs %0, mdscr_el1" : "=r" (mdscr));
5758
return mdscr;
5859
}
60+
NOKPROBE_SYMBOL(mdscr_read);
5961

6062
/*
6163
* Allow root to disable self-hosted debug from userspace.
@@ -104,6 +106,7 @@ void enable_debug_monitors(enum dbg_active_el el)
104106
mdscr_write(mdscr);
105107
}
106108
}
109+
NOKPROBE_SYMBOL(enable_debug_monitors);
107110

108111
void disable_debug_monitors(enum dbg_active_el el)
109112
{
@@ -124,6 +127,7 @@ void disable_debug_monitors(enum dbg_active_el el)
124127
mdscr_write(mdscr);
125128
}
126129
}
130+
NOKPROBE_SYMBOL(disable_debug_monitors);
127131

128132
/*
129133
* OS lock clearing.
@@ -174,6 +178,7 @@ static void set_regs_spsr_ss(struct pt_regs *regs)
174178
spsr |= DBG_SPSR_SS;
175179
regs->pstate = spsr;
176180
}
181+
NOKPROBE_SYMBOL(set_regs_spsr_ss);
177182

178183
static void clear_regs_spsr_ss(struct pt_regs *regs)
179184
{
@@ -183,6 +188,7 @@ static void clear_regs_spsr_ss(struct pt_regs *regs)
183188
spsr &= ~DBG_SPSR_SS;
184189
regs->pstate = spsr;
185190
}
191+
NOKPROBE_SYMBOL(clear_regs_spsr_ss);
186192

187193
/* EL1 Single Step Handler hooks */
188194
static LIST_HEAD(step_hook);
@@ -226,6 +232,7 @@ static int call_step_hook(struct pt_regs *regs, unsigned int esr)
226232

227233
return retval;
228234
}
235+
NOKPROBE_SYMBOL(call_step_hook);
229236

230237
static void send_user_sigtrap(int si_code)
231238
{
@@ -284,6 +291,7 @@ static int single_step_handler(unsigned long addr, unsigned int esr,
284291

285292
return 0;
286293
}
294+
NOKPROBE_SYMBOL(single_step_handler);
287295

288296
/*
289297
* Breakpoint handler is re-entrant as another breakpoint can
@@ -321,6 +329,7 @@ static int call_break_hook(struct pt_regs *regs, unsigned int esr)
321329

322330
return fn ? fn(regs, esr) : DBG_HOOK_ERROR;
323331
}
332+
NOKPROBE_SYMBOL(call_break_hook);
324333

325334
static int brk_handler(unsigned long addr, unsigned int esr,
326335
struct pt_regs *regs)
@@ -341,6 +350,7 @@ static int brk_handler(unsigned long addr, unsigned int esr,
341350

342351
return 0;
343352
}
353+
NOKPROBE_SYMBOL(brk_handler);
344354

345355
int aarch32_break_handler(struct pt_regs *regs)
346356
{
@@ -377,6 +387,7 @@ int aarch32_break_handler(struct pt_regs *regs)
377387
send_user_sigtrap(TRAP_BRKPT);
378388
return 0;
379389
}
390+
NOKPROBE_SYMBOL(aarch32_break_handler);
380391

381392
static int __init debug_traps_init(void)
382393
{
@@ -398,6 +409,7 @@ void user_rewind_single_step(struct task_struct *task)
398409
if (test_ti_thread_flag(task_thread_info(task), TIF_SINGLESTEP))
399410
set_regs_spsr_ss(task_pt_regs(task));
400411
}
412+
NOKPROBE_SYMBOL(user_rewind_single_step);
401413

402414
void user_fastforward_single_step(struct task_struct *task)
403415
{
@@ -413,28 +425,33 @@ void kernel_enable_single_step(struct pt_regs *regs)
413425
mdscr_write(mdscr_read() | DBG_MDSCR_SS);
414426
enable_debug_monitors(DBG_ACTIVE_EL1);
415427
}
428+
NOKPROBE_SYMBOL(kernel_enable_single_step);
416429

417430
void kernel_disable_single_step(void)
418431
{
419432
WARN_ON(!irqs_disabled());
420433
mdscr_write(mdscr_read() & ~DBG_MDSCR_SS);
421434
disable_debug_monitors(DBG_ACTIVE_EL1);
422435
}
436+
NOKPROBE_SYMBOL(kernel_disable_single_step);
423437

424438
int kernel_active_single_step(void)
425439
{
426440
WARN_ON(!irqs_disabled());
427441
return mdscr_read() & DBG_MDSCR_SS;
428442
}
443+
NOKPROBE_SYMBOL(kernel_active_single_step);
429444

430445
/* ptrace API */
431446
void user_enable_single_step(struct task_struct *task)
432447
{
433448
set_ti_thread_flag(task_thread_info(task), TIF_SINGLESTEP);
434449
set_regs_spsr_ss(task_pt_regs(task));
435450
}
451+
NOKPROBE_SYMBOL(user_enable_single_step);
436452

437453
void user_disable_single_step(struct task_struct *task)
438454
{
439455
clear_ti_thread_flag(task_thread_info(task), TIF_SINGLESTEP);
440456
}
457+
NOKPROBE_SYMBOL(user_disable_single_step);

arch/arm64/kernel/hw_breakpoint.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/cpu_pm.h>
2525
#include <linux/errno.h>
2626
#include <linux/hw_breakpoint.h>
27+
#include <linux/kprobes.h>
2728
#include <linux/perf_event.h>
2829
#include <linux/ptrace.h>
2930
#include <linux/smp.h>
@@ -127,6 +128,7 @@ static u64 read_wb_reg(int reg, int n)
127128

128129
return val;
129130
}
131+
NOKPROBE_SYMBOL(read_wb_reg);
130132

131133
static void write_wb_reg(int reg, int n, u64 val)
132134
{
@@ -140,6 +142,7 @@ static void write_wb_reg(int reg, int n, u64 val)
140142
}
141143
isb();
142144
}
145+
NOKPROBE_SYMBOL(write_wb_reg);
143146

144147
/*
145148
* Convert a breakpoint privilege level to the corresponding exception
@@ -157,6 +160,7 @@ static enum dbg_active_el debug_exception_level(int privilege)
157160
return -EINVAL;
158161
}
159162
}
163+
NOKPROBE_SYMBOL(debug_exception_level);
160164

161165
enum hw_breakpoint_ops {
162166
HW_BREAKPOINT_INSTALL,
@@ -575,6 +579,7 @@ static void toggle_bp_registers(int reg, enum dbg_active_el el, int enable)
575579
write_wb_reg(reg, i, ctrl);
576580
}
577581
}
582+
NOKPROBE_SYMBOL(toggle_bp_registers);
578583

579584
/*
580585
* Debug exception handlers.
@@ -654,6 +659,7 @@ static int breakpoint_handler(unsigned long unused, unsigned int esr,
654659

655660
return 0;
656661
}
662+
NOKPROBE_SYMBOL(breakpoint_handler);
657663

658664
static int watchpoint_handler(unsigned long addr, unsigned int esr,
659665
struct pt_regs *regs)
@@ -756,6 +762,7 @@ static int watchpoint_handler(unsigned long addr, unsigned int esr,
756762

757763
return 0;
758764
}
765+
NOKPROBE_SYMBOL(watchpoint_handler);
759766

760767
/*
761768
* Handle single-step exception.
@@ -813,6 +820,7 @@ int reinstall_suspended_bps(struct pt_regs *regs)
813820

814821
return !handled_exception;
815822
}
823+
NOKPROBE_SYMBOL(reinstall_suspended_bps);
816824

817825
/*
818826
* Context-switcher for restoring suspended breakpoints.

arch/arm64/kernel/kgdb.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/irq.h>
2323
#include <linux/kdebug.h>
2424
#include <linux/kgdb.h>
25+
#include <linux/kprobes.h>
2526
#include <asm/traps.h>
2627

2728
struct dbg_reg_def_t dbg_reg_def[DBG_MAX_REG_NUM] = {
@@ -230,6 +231,7 @@ static int kgdb_brk_fn(struct pt_regs *regs, unsigned int esr)
230231
kgdb_handle_exception(1, SIGTRAP, 0, regs);
231232
return 0;
232233
}
234+
NOKPROBE_SYMBOL(kgdb_brk_fn)
233235

234236
static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr)
235237
{
@@ -238,12 +240,14 @@ static int kgdb_compiled_brk_fn(struct pt_regs *regs, unsigned int esr)
238240

239241
return 0;
240242
}
243+
NOKPROBE_SYMBOL(kgdb_compiled_brk_fn);
241244

242245
static int kgdb_step_brk_fn(struct pt_regs *regs, unsigned int esr)
243246
{
244247
kgdb_handle_exception(1, SIGTRAP, 0, regs);
245248
return 0;
246249
}
250+
NOKPROBE_SYMBOL(kgdb_step_brk_fn);
247251

248252
static struct break_hook kgdb_brkpt_hook = {
249253
.esr_mask = 0xffffffff,

0 commit comments

Comments
 (0)