Skip to content

Commit

Permalink
tetragon: Use struct generic_maps in filter_read_arg
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 5e447e3 commit d1a5b32
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 33 deletions.
6 changes: 1 addition & 5 deletions bpf/process/bpf_generic_kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ generic_kprobe_process_filter(void *ctx)
__attribute__((section("kprobe"), used)) int
generic_kprobe_filter_arg(void *ctx)
{
return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap,
(struct bpf_map_def *)&filter_map,
(struct bpf_map_def *)&kprobe_calls,
(struct bpf_map_def *)&config_map,
true);
return filter_read_arg(ctx, &maps, true);
}

__attribute__((section("kprobe"), used)) int
Expand Down
6 changes: 1 addition & 5 deletions bpf/process/bpf_generic_lsm_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ generic_lsm_process_filter(void *ctx)
__attribute__((section("lsm"), used)) int
generic_lsm_filter_arg(void *ctx)
{
return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap,
(struct bpf_map_def *)&filter_map,
(struct bpf_map_def *)&lsm_calls,
(struct bpf_map_def *)&config_map,
true);
return filter_read_arg(ctx, &maps, true);
}

__attribute__((section("lsm"), used)) int
Expand Down
6 changes: 1 addition & 5 deletions bpf/process/bpf_generic_retkprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ BPF_KRETPROBE(generic_retkprobe_event, unsigned long ret)
__attribute__((section("kprobe"), used)) int
BPF_KRETPROBE(generic_retkprobe_filter_arg)
{
return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap,
(struct bpf_map_def *)&filter_map,
(struct bpf_map_def *)&retkprobe_calls,
(struct bpf_map_def *)&config_map,
false);
return filter_read_arg(ctx, &maps, false);
}

__attribute__((section("kprobe"), used)) int
Expand Down
6 changes: 1 addition & 5 deletions bpf/process/bpf_generic_tracepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,7 @@ generic_tracepoint_filter(void *ctx)
__attribute__((section("tracepoint"), used)) int
generic_tracepoint_arg(void *ctx)
{
return filter_read_arg(ctx, (struct bpf_map_def *)&tp_heap,
(struct bpf_map_def *)&filter_map,
(struct bpf_map_def *)&tp_calls,
(struct bpf_map_def *)&config_map,
true);
return filter_read_arg(ctx, &maps, true);
}

__attribute__((section("tracepoint"), used)) int
Expand Down
6 changes: 1 addition & 5 deletions bpf/process/bpf_generic_uprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ generic_uprobe_process_filter(void *ctx)
__attribute__((section("uprobe"), used)) int
generic_uprobe_filter_arg(void *ctx)
{
return filter_read_arg(ctx, (struct bpf_map_def *)&process_call_heap,
(struct bpf_map_def *)&filter_map,
(struct bpf_map_def *)&uprobe_calls,
(struct bpf_map_def *)&config_map,
true);
return filter_read_arg(ctx, &maps, true);
}

__attribute__((section("uprobe"), used)) int
Expand Down
14 changes: 6 additions & 8 deletions bpf/process/types/basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2323,23 +2323,21 @@ do_actions(void *ctx, struct selector_action *actions, struct generic_maps *maps
}

FUNC_INLINE long
filter_read_arg(void *ctx, struct bpf_map_def *heap,
struct bpf_map_def *filter, struct bpf_map_def *tailcalls,
struct bpf_map_def *config_map, bool is_entry)
filter_read_arg(void *ctx, struct generic_maps *maps, bool is_entry)
{
struct msg_generic_kprobe *e;
int selidx, pass, zero = 0;

e = map_lookup_elem(heap, &zero);
e = map_lookup_elem(maps->heap, &zero);
if (!e)
return 0;
selidx = e->tailcall_index_selector;
pass = filter_args(e, selidx & MAX_SELECTORS_MASK, filter, is_entry);
pass = filter_args(e, selidx & MAX_SELECTORS_MASK, maps->filter, is_entry);
if (!pass) {
selidx++;
if (selidx <= MAX_SELECTORS && e->sel.active[selidx & MAX_SELECTORS_MASK]) {
e->tailcall_index_selector = selidx;
tail_call(ctx, tailcalls, TAIL_CALL_ARGS);
tail_call(ctx, maps->calls, TAIL_CALL_ARGS);
}
// reject if we did not attempt to tailcall, or if tailcall failed.
return filter_args_reject(e->func_id);
Expand All @@ -2349,10 +2347,10 @@ filter_read_arg(void *ctx, struct bpf_map_def *heap,
// otherwise pass==1 indicates using default action.
if (pass > 1) {
e->pass = pass;
tail_call(ctx, tailcalls, TAIL_CALL_ACTIONS);
tail_call(ctx, maps->calls, TAIL_CALL_ACTIONS);
}

tail_call(ctx, tailcalls, TAIL_CALL_SEND);
tail_call(ctx, maps->calls, TAIL_CALL_SEND);
return 0;
}

Expand Down

0 comments on commit d1a5b32

Please sign in to comment.