Skip to content

Commit

Permalink
tetragon: Use struct generic_maps in generic_retkprobe
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Dec 12, 2024
1 parent d1a5b32 commit 032092b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
8 changes: 3 additions & 5 deletions bpf/process/bpf_generic_retkprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,14 @@ static struct generic_maps maps = {
.heap = (struct bpf_map_def *)&process_call_heap,
.calls = (struct bpf_map_def *)&retkprobe_calls,
.filter = (struct bpf_map_def *)&filter_map,
.config = (struct bpf_map_def *)&config_map,
.data = (struct bpf_map_def *)data_heap_ptr,
};

__attribute__((section((MAIN)), used)) int
BPF_KRETPROBE(generic_retkprobe_event, unsigned long ret)
{
return generic_retkprobe(ctx, (struct bpf_map_def *)&process_call_heap,
(struct bpf_map_def *)&config_map,
(struct bpf_map_def *)&retkprobe_calls,
(struct bpf_map_def *)data_heap_ptr,
ret);
return generic_retkprobe(ctx, &maps, ret);
}

__attribute__((section("kprobe"), used)) int
Expand Down
16 changes: 6 additions & 10 deletions bpf/process/generic_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,7 @@ generic_process_event_and_setup(struct pt_regs *ctx, struct generic_maps *maps)
return generic_process_event(ctx, maps);
}

FUNC_INLINE int generic_retkprobe(void *ctx, struct bpf_map_def *heap,
struct bpf_map_def *config_map,
struct bpf_map_def *tailcalls,
struct bpf_map_def *data_heap,
unsigned long ret)
FUNC_INLINE int generic_retkprobe(void *ctx, struct generic_maps *maps, unsigned long ret)
{
struct execve_map_value *enter;
struct msg_generic_kprobe *e;
Expand All @@ -233,13 +229,13 @@ FUNC_INLINE int generic_retkprobe(void *ctx, struct bpf_map_def *heap,
long ty_arg, do_copy;
__u64 pid_tgid;

e = map_lookup_elem(heap, &zero);
e = map_lookup_elem(maps->heap, &zero);
if (!e)
return 0;

e->idx = get_index(ctx);

config = map_lookup_elem(config_map, &e->idx);
config = map_lookup_elem(maps->config, &e->idx);
if (!config)
return 0;

Expand All @@ -257,7 +253,7 @@ FUNC_INLINE int generic_retkprobe(void *ctx, struct bpf_map_def *heap,
ty_arg = config->argreturn;
do_copy = config->argreturncopy;
if (ty_arg) {
size += read_call_arg(ctx, e, 0, ty_arg, size, ret, 0, (struct bpf_map_def *)data_heap);
size += read_call_arg(ctx, e, 0, ty_arg, size, ret, 0, (struct bpf_map_def *)maps->data);
#ifdef __LARGE_BPF_PROG
struct socket_owner owner;

Expand All @@ -284,7 +280,7 @@ FUNC_INLINE int generic_retkprobe(void *ctx, struct bpf_map_def *heap,

switch (do_copy) {
case char_buf:
size += __copy_char_buf(ctx, size, info.ptr, ret, false, e, (struct bpf_map_def *)data_heap);
size += __copy_char_buf(ctx, size, info.ptr, ret, false, e, (struct bpf_map_def *)maps->data);
break;
case char_iovec:
size += __copy_char_iovec(size, info.ptr, info.cnt, ret, e);
Expand Down Expand Up @@ -314,7 +310,7 @@ FUNC_INLINE int generic_retkprobe(void *ctx, struct bpf_map_def *heap,
e->func_id = config->func_id;
e->common.size = size;

tail_call(ctx, tailcalls, TAIL_CALL_ARGS);
tail_call(ctx, maps->calls, TAIL_CALL_ARGS);
return 1;
}
#endif /* __GENERIC_CALLS_H__ */

0 comments on commit 032092b

Please sign in to comment.