Skip to content

Commit aa61888

Browse files
pchaignoKernel Patches Daemon
authored andcommitted
bpf: Populate inner oracle maps
The previous patch created the inner oracle maps, this patch simply populates them by copying the information on verifier states from aux->oracle_states to the inner array maps. After this, aux->oracle_states isn't required anymore and can be freed. Signed-off-by: Paul Chaignon <[email protected]>
1 parent cdb52e6 commit aa61888

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

kernel/bpf/oracle.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,33 @@ static struct bpf_map *create_inner_oracle_map(size_t size)
109109
return ERR_PTR(err);
110110
}
111111

112+
static int populate_oracle_inner_map(struct list_head *head, struct bpf_map *inner_map)
113+
{
114+
struct bpf_oracle_state_list *sl;
115+
struct list_head *pos, *tmp;
116+
int i = 0;
117+
118+
list_for_each_safe(pos, tmp, head) {
119+
sl = container_of(pos, struct bpf_oracle_state_list, node);
120+
inner_map->ops->map_update_elem(inner_map, &i, &sl->state, 0);
121+
i++;
122+
}
123+
124+
return 0;
125+
}
126+
127+
static void free_oracle_states(struct list_head *oracle_states)
128+
{
129+
struct bpf_oracle_state_list *sl;
130+
struct list_head *pos, *tmp;
131+
132+
list_for_each_safe(pos, tmp, oracle_states) {
133+
sl = container_of(pos, struct bpf_oracle_state_list, node);
134+
kfree(sl);
135+
}
136+
kvfree(oracle_states);
137+
}
138+
112139
struct bpf_prog *patch_oracle_check_insn(struct bpf_verifier_env *env, struct bpf_insn *insn,
113140
int i, int *cnt)
114141
{
@@ -141,6 +168,10 @@ struct bpf_prog *patch_oracle_check_insn(struct bpf_verifier_env *env, struct bp
141168
insn_buf[2] = *insn;
142169
*cnt = 3;
143170

171+
populate_oracle_inner_map(head, inner_map);
172+
free_oracle_states(aux->oracle_states);
173+
aux->oracle_states = NULL;
174+
144175
new_prog = bpf_patch_insn_data(env, i, insn_buf, *cnt);
145176
if (!new_prog)
146177
return ERR_PTR(-ENOMEM);

0 commit comments

Comments
 (0)