summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Moore <paul@paul-moore.com>2019-03-07 10:49:40 -0500
committerPaul Moore <paul@paul-moore.com>2019-03-14 09:51:27 -0400
commitcf5d1538d243fb6f1839db70b69469d3d7e9e077 (patch)
tree4c4d87b6b26cfb30d68536f4b79f261b6116cbd9
parentc5bf78de480b32b324e0f511c88ce533ed280b37 (diff)
downloadlibseccomp-cf5d1538d243fb6f1839db70b69469d3d7e9e077.tar.gz
bpf: pass the correct accumulator state to the next level
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>
-rw-r--r--src/gen_bpf.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/gen_bpf.c b/src/gen_bpf.c
index 550f77e..9f8f5c3 100644
--- a/src/gen_bpf.c
+++ b/src/gen_bpf.c
@@ -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:
@@ -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:
@@ -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);
@@ -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);