Skip to content

Commit

Permalink
bpf: pass the correct accumulator state to the next level
Browse files Browse the repository at this point in the history
We were mistakenly passing the wrong accumulator state (the state at
the start of the instruction block, not at the end) which was causing
us to generate unnecessary load instructions.

Signed-off-by: Paul Moore <paul@paul-moore.com>
  • Loading branch information
pcmoore committed Mar 14, 2019
1 parent c5bf78d commit cf5d153
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/gen_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,13 @@ static struct bpf_blk *_gen_bpf_node(struct bpf_state *state,
goto node_failure;
}

/* set the accumulator state at the end of the block */
/* NOTE: the accumulator end state is very critical when we are
* assembling the final state; we assume that however we leave
* this instruction block the accumulator state is represented
* by blk->acc_end, it must be kept correct */
blk->acc_end = *a_state;

/* check the accumulator against the datum */
switch (node->op) {
case SCMP_CMP_MASKED_EQ:
Expand Down Expand Up @@ -898,7 +905,6 @@ static struct bpf_blk *_gen_bpf_node(struct bpf_state *state,
goto node_failure;

blk->node = node;
blk->acc_end = *a_state;
return blk;

node_failure:
Expand Down Expand Up @@ -953,7 +959,7 @@ static struct bpf_blk *_gen_bpf_chain_lvl_res(struct bpf_state *state,
case TGT_PTR_DB:
node = (struct db_arg_chain_tree *)i_iter->jt.tgt.db;
b_new = _gen_bpf_chain(state, sys, node,
nxt_jump, &blk->acc_start);
nxt_jump, &blk->acc_end);
if (b_new == NULL)
return NULL;
i_iter->jt = _BPF_JMP_HSH(b_new->hash);
Expand All @@ -979,7 +985,7 @@ static struct bpf_blk *_gen_bpf_chain_lvl_res(struct bpf_state *state,
case TGT_PTR_DB:
node = (struct db_arg_chain_tree *)i_iter->jf.tgt.db;
b_new = _gen_bpf_chain(state, sys, node,
nxt_jump, &blk->acc_start);
nxt_jump, &blk->acc_end);
if (b_new == NULL)
return NULL;
i_iter->jf = _BPF_JMP_HSH(b_new->hash);
Expand Down

0 comments on commit cf5d153

Please sign in to comment.