Skip to content

Commit 5c17a8d

Browse files
committed
perf: use kprobe for ptrace
1 parent 59bfe01 commit 5c17a8d

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

pkg/ebpf/c/common/arch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ statfunc struct pt_regs *get_current_task_pt_regs(void)
127127
#define SYSCALL_FCHDIR 81
128128
#define SYSCALL_FCHMOD 91
129129
#define SYSCALL_FCHOWN 93
130+
#define SYSCALL_PTRACE 101
130131
#define SYSCALL_FSTATFS 138
131132
#define SYSCALL_READAHEAD 187
132133
#define SYSCALL_FSETXATTR 190
@@ -275,6 +276,7 @@ statfunc struct pt_regs *get_current_task_pt_regs(void)
275276
#define SYSCALL_DUP3 24
276277
#define SYSCALL_PREADV 69
277278
#define SYSCALL_PWRITEV 70
279+
#define SYSCALL_PTRACE 117
278280
#define SYSCALL_PERF_EVENT_OPEN 241
279281
#define SYSCALL_RECVMMSG 243
280282
#define SYSCALL_NAME_TO_HANDLE_AT 264

pkg/ebpf/c/tracee.bpf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ int trace_sys_exit(struct bpf_raw_tracepoint_args *ctx)
358358
return 0;
359359
}
360360

361+
// macros for syscall kprobes
362+
TRACE_SYSCALL(ptrace, SYSCALL_PTRACE)
363+
361364
SEC("raw_tracepoint/sys_execve")
362365
int syscall__execve_enter(void *ctx)
363366
{

pkg/ebpf/probes/probe_group.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ func NewDefaultProbeGroup(module *bpf.Module, netEnabled bool) (*ProbeGroup, err
224224
ExecuteAtFinishedCompatARM: NewTraceProbe(KretProbe, "__arm64_compat_sys_execveat", "trace_execute_finished"),
225225
SecurityTaskSetrlimit: NewTraceProbe(KProbe, "security_task_setrlimit", "trace_security_task_setrlimit"),
226226
SecuritySettime64: NewTraceProbe(KProbe, "security_settime64", "trace_security_settime64"),
227+
Ptrace: NewTraceProbe(SyscallEnter, "ptrace", "trace_ptrace"),
228+
PtraceRet: NewTraceProbe(SyscallExit, "ptrace", "trace_ret_ptrace"),
227229

228230
TestUnavailableHook: NewTraceProbe(KProbe, "non_existing_func", "empty_kprobe"),
229231
ExecTest: NewTraceProbe(RawTracepoint, "raw_syscalls:sched_process_exec", "tracepoint__exec_test"),

pkg/ebpf/probes/probes.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ const (
150150
ExecuteAtFinishedCompatARM
151151
SecurityTaskSetrlimit
152152
SecuritySettime64
153+
Ptrace
154+
PtraceRet
153155
)
154156

155157
// Test probe handles

pkg/events/core.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,14 +2690,8 @@ var CoreEvents = map[ID]Definition{
26902690
},
26912691
dependencies: Dependencies{
26922692
probes: []Probe{
2693-
{handle: probes.SyscallEnter__Internal, required: true},
2694-
{handle: probes.SyscallExit__Internal, required: true},
2695-
},
2696-
tailCalls: []TailCall{
2697-
{"sys_enter_init_tail", "sys_enter_init", []uint32{uint32(Ptrace)}},
2698-
{"sys_enter_submit_tail", "sys_enter_submit", []uint32{uint32(Ptrace)}},
2699-
{"sys_exit_init_tail", "sys_exit_init", []uint32{uint32(Ptrace)}},
2700-
{"sys_exit_submit_tail", "sys_exit_submit", []uint32{uint32(Ptrace)}},
2693+
{handle: probes.Ptrace, required: true},
2694+
{handle: probes.PtraceRet, required: true},
27012695
},
27022696
},
27032697
},

0 commit comments

Comments
 (0)