Skip to content

Commit

Permalink
tetragon: Factor generic_process_filter function
Browse files Browse the repository at this point in the history
Switch 'enter' check to '!enter' and decrease indent of the
following code, which makes the function more readable and
will ease up following changes.

There's no functional change.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed Jan 24, 2025
1 parent 5b38182 commit c92c069
Showing 1 changed file with 34 additions and 36 deletions.
70 changes: 34 additions & 36 deletions bpf/process/generic_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,59 +570,57 @@ FUNC_INLINE int generic_retkprobe(void *ctx, struct bpf_map_def *calls, unsigned
// msg_generic_hdr structure.
FUNC_INLINE int generic_process_filter(void)
{
int selectors, pass, curr, zero = 0;
struct execve_map_value *enter;
struct msg_generic_kprobe *msg;
struct msg_execve_key *current;
struct msg_selector_data *sel;
int curr, zero = 0;
bool walker = 0;
__u32 ppid;
__u32 ppid, *f;

msg = map_lookup_elem(&process_call_heap, &zero);
if (!msg)
return 0;

enter = event_find_curr(&ppid, &walker);
if (enter) {
int selectors, pass;
__u32 *f = map_lookup_elem(&filter_map, &msg->idx);
if (!enter)
return PFILTER_CURR_NOT_FOUND;

if (!f)
return PFILTER_ERROR;
f = map_lookup_elem(&filter_map, &msg->idx);
if (!f)
return PFILTER_ERROR;

sel = &msg->sel;
current = &msg->current;
sel = &msg->sel;
current = &msg->current;

curr = sel->curr;
if (curr > MAX_SELECTORS)
return process_filter_done(sel, enter, current);
curr = sel->curr;
if (curr > MAX_SELECTORS)
return process_filter_done(sel, enter, current);

selectors = f[0];
/* If no selectors accept process */
if (!selectors) {
sel->pass = true;
return process_filter_done(sel, enter, current);
}
selectors = f[0];
/* If no selectors accept process */
if (!selectors) {
sel->pass = true;
return process_filter_done(sel, enter, current);
}

/* If we get here with reference to uninitialized selector drop */
if (selectors <= curr)
return process_filter_done(sel, enter, current);

pass = selector_process_filter(f, curr, enter, msg);
if (pass) {
/* Verify lost that msg is not null here so recheck */
asm volatile("%[curr] &= 0x1f;\n"
: [curr] "+r"(curr));
sel->active[curr] = true;
sel->active[SELECTORS_ACTIVE] = true;
sel->pass |= true;
}
sel->curr++;
if (sel->curr > selectors)
return process_filter_done(sel, enter, current);
return PFILTER_CONTINUE; /* will iterate to the next selector */
/* If we get here with reference to uninitialized selector drop */
if (selectors <= curr)
return process_filter_done(sel, enter, current);

pass = selector_process_filter(f, curr, enter, msg);
if (pass) {
/* Verify lost that msg is not null here so recheck */
asm volatile("%[curr] &= 0x1f;\n"
: [curr] "+r"(curr));
sel->active[curr] = true;
sel->active[SELECTORS_ACTIVE] = true;
sel->pass |= true;
}
return PFILTER_CURR_NOT_FOUND;
sel->curr++;
if (sel->curr > selectors)
return process_filter_done(sel, enter, current);
return PFILTER_CONTINUE; /* will iterate to the next selector */
}

FUNC_INLINE int filter_args(struct msg_generic_kprobe *e, int selidx, bool is_entry)
Expand Down

0 comments on commit c92c069

Please sign in to comment.