Skip to content

Commit ec6aba3

Browse files
author
Peter Zijlstra
committed
kprobes: Remove kprobe::fault_handler
The reason for kprobe::fault_handler(), as given by their comment: * We come here because instructions in the pre/post * handler caused the page_fault, this could happen * if handler tries to access user space by * copy_from_user(), get_user() etc. Let the * user-specified handler try to fix it first. Is just plain bad. Those other handlers are ran from non-preemptible context and had better use _nofault() functions. Also, there is no upstream usage of this. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Link: https://lore.kernel.org/r/20210525073213.561116662@infradead.org
1 parent 9ce4d21 commit ec6aba3

16 files changed

Lines changed: 5 additions & 172 deletions

File tree

‎Documentation/trace/kprobes.rst‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,11 @@ register_kprobe
362362
#include <linux/kprobes.h>
363363
int register_kprobe(struct kprobe *kp);
364364

365-
Sets a breakpoint at the address kp->addr. When the breakpoint is
366-
hit, Kprobes calls kp->pre_handler. After the probed instruction
367-
is single-stepped, Kprobe calls kp->post_handler. If a fault
368-
occurs during execution of kp->pre_handler or kp->post_handler,
369-
or during single-stepping of the probed instruction, Kprobes calls
370-
kp->fault_handler. Any or all handlers can be NULL. If kp->flags
371-
is set KPROBE_FLAG_DISABLED, that kp will be registered but disabled,
372-
so, its handlers aren't hit until calling enable_kprobe(kp).
365+
Sets a breakpoint at the address kp->addr. When the breakpoint is hit, Kprobes
366+
calls kp->pre_handler. After the probed instruction is single-stepped, Kprobe
367+
calls kp->post_handler. Any or all handlers can be NULL. If kp->flags is set
368+
KPROBE_FLAG_DISABLED, that kp will be registered but disabled, so, its handlers
369+
aren't hit until calling enable_kprobe(kp).
373370

374371
.. note::
375372

@@ -415,17 +412,6 @@ User's post-handler (kp->post_handler)::
415412
p and regs are as described for the pre_handler. flags always seems
416413
to be zero.
417414

418-
User's fault-handler (kp->fault_handler)::
419-
420-
#include <linux/kprobes.h>
421-
#include <linux/ptrace.h>
422-
int fault_handler(struct kprobe *p, struct pt_regs *regs, int trapnr);
423-
424-
p and regs are as described for the pre_handler. trapnr is the
425-
architecture-specific trap number associated with the fault (e.g.,
426-
on i386, 13 for a general protection fault or 14 for a page fault).
427-
Returns 1 if it successfully handled the exception.
428-
429415
register_kretprobe
430416
------------------
431417

‎arch/arc/kernel/kprobes.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,16 +323,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned long trapnr)
323323
*/
324324
kprobes_inc_nmissed_count(cur);
325325

326-
/*
327-
* We come here because instructions in the pre/post
328-
* handler caused the page_fault, this could happen
329-
* if handler tries to access user space by
330-
* copy_from_user(), get_user() etc. Let the
331-
* user-specified handler try to fix it first.
332-
*/
333-
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
334-
return 1;
335-
336326
/*
337327
* In case the user-specified fault handler returned zero,
338328
* try to fix up.

‎arch/arm/probes/kprobes/core.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
358358
*/
359359
kprobes_inc_nmissed_count(cur);
360360

361-
/*
362-
* We come here because instructions in the pre/post
363-
* handler caused the page_fault, this could happen
364-
* if handler tries to access user space by
365-
* copy_from_user(), get_user() etc. Let the
366-
* user-specified handler try to fix it.
367-
*/
368-
if (cur->fault_handler && cur->fault_handler(cur, regs, fsr))
369-
return 1;
370361
break;
371362

372363
default:

‎arch/arm64/kernel/probes/kprobes.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int fsr)
283283
*/
284284
kprobes_inc_nmissed_count(cur);
285285

286-
/*
287-
* We come here because instructions in the pre/post
288-
* handler caused the page_fault, this could happen
289-
* if handler tries to access user space by
290-
* copy_from_user(), get_user() etc. Let the
291-
* user-specified handler try to fix it first.
292-
*/
293-
if (cur->fault_handler && cur->fault_handler(cur, regs, fsr))
294-
return 1;
295-
296286
/*
297287
* In case the user-specified fault handler returned
298288
* zero, try to fix up.

‎arch/csky/kernel/probes/kprobes.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int trapnr)
301301
*/
302302
kprobes_inc_nmissed_count(cur);
303303

304-
/*
305-
* We come here because instructions in the pre/post
306-
* handler caused the page_fault, this could happen
307-
* if handler tries to access user space by
308-
* copy_from_user(), get_user() etc. Let the
309-
* user-specified handler try to fix it first.
310-
*/
311-
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
312-
return 1;
313-
314304
/*
315305
* In case the user-specified fault handler returned
316306
* zero, try to fix up.

‎arch/ia64/kernel/kprobes.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -850,15 +850,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, int trapnr)
850850
*/
851851
kprobes_inc_nmissed_count(cur);
852852

853-
/*
854-
* We come here because instructions in the pre/post
855-
* handler caused the page_fault, this could happen
856-
* if handler tries to access user space by
857-
* copy_from_user(), get_user() etc. Let the
858-
* user-specified handler try to fix it first.
859-
*/
860-
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
861-
return 1;
862853
/*
863854
* In case the user-specified fault handler returned
864855
* zero, try to fix up.

‎arch/mips/kernel/kprobes.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
403403
struct kprobe *cur = kprobe_running();
404404
struct kprobe_ctlblk *kcb = get_kprobe_ctlblk();
405405

406-
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
407-
return 1;
408-
409406
if (kcb->kprobe_status & KPROBE_HIT_SS) {
410407
resume_execution(cur, regs, kcb);
411408
regs->cp0_status |= kcb->kprobe_old_SR;

‎arch/powerpc/kernel/kprobes.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -508,16 +508,6 @@ int kprobe_fault_handler(struct pt_regs *regs, int trapnr)
508508
*/
509509
kprobes_inc_nmissed_count(cur);
510510

511-
/*
512-
* We come here because instructions in the pre/post
513-
* handler caused the page_fault, this could happen
514-
* if handler tries to access user space by
515-
* copy_from_user(), get_user() etc. Let the
516-
* user-specified handler try to fix it first.
517-
*/
518-
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
519-
return 1;
520-
521511
/*
522512
* In case the user-specified fault handler returned
523513
* zero, try to fix up.

‎arch/riscv/kernel/probes/kprobes.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -283,16 +283,6 @@ int __kprobes kprobe_fault_handler(struct pt_regs *regs, unsigned int trapnr)
283283
*/
284284
kprobes_inc_nmissed_count(cur);
285285

286-
/*
287-
* We come here because instructions in the pre/post
288-
* handler caused the page_fault, this could happen
289-
* if handler tries to access user space by
290-
* copy_from_user(), get_user() etc. Let the
291-
* user-specified handler try to fix it first.
292-
*/
293-
if (cur->fault_handler && cur->fault_handler(cur, regs, trapnr))
294-
return 1;
295-
296286
/*
297287
* In case the user-specified fault handler returned
298288
* zero, try to fix up.

‎arch/s390/kernel/kprobes.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,16 +452,6 @@ static int kprobe_trap_handler(struct pt_regs *regs, int trapnr)
452452
*/
453453
kprobes_inc_nmissed_count(p);
454454

455-
/*
456-
* We come here because instructions in the pre/post
457-
* handler caused the page_fault, this could happen
458-
* if handler tries to access user space by
459-
* copy_from_user(), get_user() etc. Let the
460-
* user-specified handler try to fix it first.
461-
*/
462-
if (p->fault_handler && p->fault_handler(p, regs, trapnr))
463-
return 1;
464-
465455
/*
466456
* In case the user-specified fault handler returned
467457
* zero, try to fix up.

0 commit comments

Comments
 (0)