Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dependencies): further adopt dependencies API to ksymbols and probes #3967

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/ebpf/c/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ statfunc const char *get_device_name(struct device *dev)

#define has_prefix(p, s, n) \
({ \
int rc = 0; \
int rc = 1; \
char *pre = p, *str = s; \
_Pragma("unroll") for (int z = 0; z < n; pre++, str++, z++) \
{ \
Expand Down
47 changes: 47 additions & 0 deletions pkg/ebpf/c/tracee.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -6798,3 +6798,50 @@ int sched_process_exit_signal(struct bpf_raw_tracepoint_args *ctx)
}

// END OF Control Plane Programs

// Tests

SEC("kprobe/empty_kprobe")
int BPF_KPROBE(empty_kprobe)
{
return 0;
}

SEC("raw_tracepoint/exec_test")
int tracepoint__exec_test(struct bpf_raw_tracepoint_args *ctx)
{
// Check if test file was executed
struct linux_binprm *bprm = (struct linux_binprm *) ctx->args[2];
if (bprm == NULL)
return -1;
struct file *file = get_file_ptr_from_bprm(bprm);
void *file_path = get_path_str(__builtin_preserve_access_index(&file->f_path));
if (file_path == NULL || !has_prefix("/tmp/test", file_path, 9))
return 0;

// Submit all test events
int ret = 0;
program_data_t p = {};
if (!init_program_data(&p, ctx, NO_EVENT_SUBMIT))
return 0;

if (!evaluate_scope_filters(&p))
return 0;

if (!reset_event(p.event, EXEC_TEST))
return 0;
if (evaluate_scope_filters(&p))
ret |= events_perf_submit(&p, 0);

if (!reset_event(p.event, TEST_MISSING_KSYMBOLS))
return 0;
if (evaluate_scope_filters(&p))
ret |= events_perf_submit(&p, 0);

if (!reset_event(p.event, TEST_FAILED_ATTACH))
return 0;
if (evaluate_scope_filters(&p))
ret |= events_perf_submit(&p, 0);

return 0;
}
5 changes: 5 additions & 0 deletions pkg/ebpf/c/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ enum event_id_e
SECURITY_BPRM_CREDS_FOR_EXEC,
MAX_EVENT_ID,
NO_EVENT_SUBMIT,

// Test events IDs
EXEC_TEST = 8000,
TEST_MISSING_KSYMBOLS,
TEST_FAILED_ATTACH,
};

enum signal_event_id_e
Expand Down
4 changes: 4 additions & 0 deletions pkg/ebpf/probes/probe_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ func NewDefaultProbeGroup(module *bpf.Module, netEnabled bool) (*ProbeGroup, err
ExecuteAtFinishedARM: NewTraceProbe(KretProbe, "__arm64_sys_execveat", "trace_execute_finished"),
ExecuteFinishedCompatARM: NewTraceProbe(KretProbe, "__arm64_compat_sys_execve", "trace_execute_finished"),
ExecuteAtFinishedCompatARM: NewTraceProbe(KretProbe, "__arm64_compat_sys_execveat", "trace_execute_finished"),

TestUnavailableHook: NewTraceProbe(KProbe, "non_existing_func", "empty_kprobe"),
ExecTest: NewTraceProbe(RawTracepoint, "raw_syscalls:sched_process_exec", "tracepoint__exec_test"),
EmptyKprobe: NewTraceProbe(KProbe, "security_bprm_check", "empty_kprobe"),
}

if !netEnabled {
Expand Down
7 changes: 7 additions & 0 deletions pkg/ebpf/probes/probes.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,10 @@ const (
ExecuteFinishedCompatARM
ExecuteAtFinishedCompatARM
)

// Test probe handles
const (
TestUnavailableHook = 1000 + iota
ExecTest
EmptyKprobe
)
Loading
Loading