diff options
author | Corey Bryant <coreyb@linux.vnet.ibm.com> | 2012-04-04 16:21:29 -0400 |
---|---|---|
committer | Paul Moore <pmoore@redhat.com> | 2012-04-04 17:37:00 -0400 |
commit | f87379cb3d947ef3887c1fbd6245effc83346cb8 (patch) | |
tree | 5963fe8ba7652312a46e0f42d537ffca346a9d25 /tools | |
parent | 500ba167d2ed0464a53fbe62c2ec29937507022a (diff) | |
download | libseccomp-f87379cb3d947ef3887c1fbd6245effc83346cb8.tar.gz |
tools: fix bugs for bpf_sim seccomp_data indexing and acc tests
This patch fixes a few bugs in bpf_sim.
We were previously only storing a byte of the seccomp_data structure
in the accumulator. This is updated to store the full word of the
corresponding nr, arch, or arg in the accumulator.
Also the relational tests of the accumular value vs filter value were
backwards and fixed in this patch.
A missing break is also added in case '4' of the main switch statement.
Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Signed-off-by: Paul Moore <pmoore@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/bpf_sim.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/tools/bpf_sim.c b/tools/bpf_sim.c index 25189f7..d04b52d 100644 --- a/tools/bpf_sim.c +++ b/tools/bpf_sim.c @@ -156,7 +156,6 @@ static void bpf_execute(const struct bpf_program *prg, ip = 0; memset(&state, 0, sizeof(state)); - /* start execution */ while (ip < prg->i_cnt) { /* get the instruction and bump the ip */ ip_c = ip; @@ -165,7 +164,7 @@ static void bpf_execute(const struct bpf_program *prg, switch (bpf->code) { case BPF_LD+BPF_W+BPF_ABS: if (bpf->k < BPF_SYSCALL_MAX) - state.acc = sys_data_b[bpf->k]; + state.acc = *((uint32_t *)&sys_data_b[bpf->k]); else exit_error(ERANGE, ip_c); break; @@ -173,19 +172,19 @@ static void bpf_execute(const struct bpf_program *prg, ip += bpf->k; break; case BPF_JMP+BPF_JEQ+BPF_K: - if (bpf->k == state.acc) + if (state.acc == bpf->k) ip += bpf->jt; else ip += bpf->jf; break; case BPF_JMP+BPF_JGT+BPF_K: - if (bpf->k > state.acc) + if (state.acc > bpf->k) ip += bpf->jt; else ip += bpf->jf; break; case BPF_JMP+BPF_JGE+BPF_K: - if (bpf->k >= state.acc) + if (state.acc >= bpf->k) ip += bpf->jt; else ip += bpf->jf; @@ -272,6 +271,7 @@ int main(int argc, char *argv[]) case '4': opt_arg_flag = 1; sys_data.args[4] = strtol(optarg, NULL, 0); + break; case '5': opt_arg_flag = 1; sys_data.args[5] = strtol(optarg, NULL, 0); |