-
I am trying to write some bpf probes that keep some sort of state required for runtime verification. I have created a pinned map so this value can be used across several bpf programs. Whenever I read the value from the #include <bcc/proto.h>
struct automaton_s {
int initial_state;
int function[4][4];
};
typedef struct automaton_s automaton_t;
BPF_STACK(automaton, automaton_t, 1);
BPF_TABLE_PINNED("hash", int, int, state_store, 1, "/sys/fs/bpf/state");
int trace_connect_v4_return(struct pt_regs *ctx)
{
int key = 0, init_val = 0;
int *curr_state;
curr_state = state_store.lookup_or_try_init(&key, &init_val);
if (!curr_state) {
bpf_trace_printk("State store is full");
return -1;
}
bpf_trace_printk("curr state: %d", *curr_state);
automaton_t aut;
if (automaton.peek(&aut) < 0) {
bpf_trace_printk("automaton init");
aut = (automaton_t) {
.initial_state = 0,
.function = {
{ 1, -1, -1, -1 },
{ -1, 2, -1, -1 },
{ -1, -1, 3, -1 },
{ -1, -1, -1, 0 }
}
};
automaton.push(&aut, BPF_EXIST);
}
int next = aut.function[*curr_state][0];
bpf_trace_printk("next val: %d", next);
state_store.update(&key, &next);
return 0;
} The error occurs whenever I try to use this The entire error message:
I have tried testing for min and max values of both
But it seems naive and does not solve the issue. I have no clue on how to proceed, any help is greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What kind of runtime verification ? |
Beta Was this translation helpful? Give feedback.
-
So, I've found the solution. It seems that I didn't properly check for the bounds of if (*curr_state < 0 || *curr_state >= 4)
return -1; |
Beta Was this translation helpful? Give feedback.
So, I've found the solution. It seems that I didn't properly check for the bounds of
*curr_state
. So the solution is to simply add the following snippet, prior to indexingaut.function
.