@@ -294,19 +294,12 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
294
294
}
295
295
296
296
break ;
297
- case KPROBE_HIT_ACTIVE :
298
- case KPROBE_HIT_SSDONE :
299
- /*
300
- * In case the user-specified fault handler returned
301
- * zero, try to fix up.
302
- */
303
- if (fixup_exception (regs ))
304
- return 1 ;
305
297
}
306
298
return 0 ;
307
299
}
308
300
309
- static void __kprobes kprobe_handler (struct pt_regs * regs )
301
+ static int __kprobes
302
+ kprobe_breakpoint_handler (struct pt_regs * regs , unsigned long esr )
310
303
{
311
304
struct kprobe * p , * cur_kprobe ;
312
305
struct kprobe_ctlblk * kcb ;
@@ -316,39 +309,44 @@ static void __kprobes kprobe_handler(struct pt_regs *regs)
316
309
cur_kprobe = kprobe_running ();
317
310
318
311
p = get_kprobe ((kprobe_opcode_t * ) addr );
312
+ if (WARN_ON_ONCE (!p )) {
313
+ /*
314
+ * Something went wrong. This BRK used an immediate reserved
315
+ * for kprobes, but we couldn't find any corresponding probe.
316
+ */
317
+ return DBG_HOOK_ERROR ;
318
+ }
319
319
320
- if (p ) {
321
- if (cur_kprobe ) {
322
- if (reenter_kprobe (p , regs , kcb ))
323
- return ;
324
- } else {
325
- /* Probe hit */
326
- set_current_kprobe (p );
327
- kcb -> kprobe_status = KPROBE_HIT_ACTIVE ;
328
-
329
- /*
330
- * If we have no pre-handler or it returned 0, we
331
- * continue with normal processing. If we have a
332
- * pre-handler and it returned non-zero, it will
333
- * modify the execution path and no need to single
334
- * stepping. Let's just reset current kprobe and exit.
335
- */
336
- if (!p -> pre_handler || !p -> pre_handler (p , regs )) {
337
- setup_singlestep (p , regs , kcb , 0 );
338
- } else
339
- reset_current_kprobe ();
340
- }
320
+ if (cur_kprobe ) {
321
+ /* Hit a kprobe inside another kprobe */
322
+ if (!reenter_kprobe (p , regs , kcb ))
323
+ return DBG_HOOK_ERROR ;
324
+ } else {
325
+ /* Probe hit */
326
+ set_current_kprobe (p );
327
+ kcb -> kprobe_status = KPROBE_HIT_ACTIVE ;
328
+
329
+ /*
330
+ * If we have no pre-handler or it returned 0, we
331
+ * continue with normal processing. If we have a
332
+ * pre-handler and it returned non-zero, it will
333
+ * modify the execution path and not need to single-step
334
+ * Let's just reset current kprobe and exit.
335
+ */
336
+ if (!p -> pre_handler || !p -> pre_handler (p , regs ))
337
+ setup_singlestep (p , regs , kcb , 0 );
338
+ else
339
+ reset_current_kprobe ();
341
340
}
342
- /*
343
- * The breakpoint instruction was removed right
344
- * after we hit it. Another cpu has removed
345
- * either a probepoint or a debugger breakpoint
346
- * at this address. In either case, no further
347
- * handling of this interrupt is appropriate.
348
- * Return back to original instruction, and continue.
349
- */
341
+
342
+ return DBG_HOOK_HANDLED ;
350
343
}
351
344
345
+ static struct break_hook kprobes_break_hook = {
346
+ .imm = KPROBES_BRK_IMM ,
347
+ .fn = kprobe_breakpoint_handler ,
348
+ };
349
+
352
350
static int __kprobes
353
351
kprobe_breakpoint_ss_handler (struct pt_regs * regs , unsigned long esr )
354
352
{
@@ -373,18 +371,6 @@ static struct break_hook kprobes_break_ss_hook = {
373
371
.fn = kprobe_breakpoint_ss_handler ,
374
372
};
375
373
376
- static int __kprobes
377
- kprobe_breakpoint_handler (struct pt_regs * regs , unsigned long esr )
378
- {
379
- kprobe_handler (regs );
380
- return DBG_HOOK_HANDLED ;
381
- }
382
-
383
- static struct break_hook kprobes_break_hook = {
384
- .imm = KPROBES_BRK_IMM ,
385
- .fn = kprobe_breakpoint_handler ,
386
- };
387
-
388
374
/*
389
375
* Provide a blacklist of symbols identifying ranges which cannot be kprobed.
390
376
* This blacklist is exposed to userspace via debugfs (kprobes/blacklist).
0 commit comments