diff options
author | mdempsky <mdempsky@chromium.org> | 2014-10-31 13:50:27 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-31 20:50:44 +0000 |
commit | a41c404b1c7ff173dcc51b4bf3b9ab4830af78db (patch) | |
tree | 2f49f4b1fd2ce5e566bcea8d3c3c90847af68684 /sandbox/linux/seccomp-bpf | |
parent | 76d266af1fbe05e3395f08545a6328782e749431 (diff) | |
download | chromium_src-a41c404b1c7ff173dcc51b4bf3b9ab4830af78db.zip chromium_src-a41c404b1c7ff173dcc51b4bf3b9ab4830af78db.tar.gz chromium_src-a41c404b1c7ff173dcc51b4bf3b9ab4830af78db.tar.bz2 |
sandbox: extract PrintProgram() into a separate DumpBPF class
Removes some dependencies from codegen.cc as it now only deals with
emitting programs, not with disassembling them too.
BUG=414363
Review URL: https://codereview.chromium.org/694013002
Cr-Commit-Position: refs/heads/master@{#302323}
Diffstat (limited to 'sandbox/linux/seccomp-bpf')
-rw-r--r-- | sandbox/linux/seccomp-bpf/codegen.cc | 91 | ||||
-rw-r--r-- | sandbox/linux/seccomp-bpf/codegen.h | 4 | ||||
-rw-r--r-- | sandbox/linux/seccomp-bpf/sandbox_bpf.cc | 3 |
3 files changed, 3 insertions, 95 deletions
diff --git a/sandbox/linux/seccomp-bpf/codegen.cc b/sandbox/linux/seccomp-bpf/codegen.cc index 8169840..1ee79b6 100644 --- a/sandbox/linux/seccomp-bpf/codegen.cc +++ b/sandbox/linux/seccomp-bpf/codegen.cc @@ -4,7 +4,7 @@ #include "sandbox/linux/seccomp-bpf/codegen.h" -#include <stdio.h> +#include <linux/filter.h> #include <set> @@ -12,8 +12,6 @@ #include "sandbox/linux/seccomp-bpf/basicblock.h" #include "sandbox/linux/seccomp-bpf/die.h" #include "sandbox/linux/seccomp-bpf/instruction.h" -#include "sandbox/linux/seccomp-bpf/linux_seccomp.h" -#include "sandbox/linux/seccomp-bpf/trap.h" namespace sandbox { @@ -32,93 +30,6 @@ CodeGen::~CodeGen() { } } -void CodeGen::PrintProgram(const Program& program) { - for (Program::const_iterator iter = program.begin(); iter != program.end(); - ++iter) { - int ip = (int)(iter - program.begin()); - fprintf(stderr, "%3d) ", ip); - switch (BPF_CLASS(iter->code)) { - case BPF_LD: - if (iter->code == BPF_LD + BPF_W + BPF_ABS) { - fprintf(stderr, "LOAD %d // ", (int)iter->k); - if (iter->k == offsetof(struct arch_seccomp_data, nr)) { - fprintf(stderr, "System call number\n"); - } else if (iter->k == offsetof(struct arch_seccomp_data, arch)) { - fprintf(stderr, "Architecture\n"); - } else if (iter->k == - offsetof(struct arch_seccomp_data, instruction_pointer)) { - fprintf(stderr, "Instruction pointer (LSB)\n"); - } else if (iter->k == - offsetof(struct arch_seccomp_data, instruction_pointer) + - 4) { - fprintf(stderr, "Instruction pointer (MSB)\n"); - } else if (iter->k >= offsetof(struct arch_seccomp_data, args) && - iter->k < offsetof(struct arch_seccomp_data, args) + 48 && - (iter->k - offsetof(struct arch_seccomp_data, args)) % 4 == - 0) { - fprintf( - stderr, - "Argument %d (%cSB)\n", - (int)(iter->k - offsetof(struct arch_seccomp_data, args)) / 8, - (iter->k - offsetof(struct arch_seccomp_data, args)) % 8 ? 'M' - : 'L'); - } else { - fprintf(stderr, "???\n"); - } - } else { - fprintf(stderr, "LOAD ???\n"); - } - break; - case BPF_JMP: - if (BPF_OP(iter->code) == BPF_JA) { - fprintf(stderr, "JMP %d\n", ip + iter->k + 1); - } else { - fprintf(stderr, "if A %s 0x%x; then JMP %d else JMP %d\n", - BPF_OP(iter->code) == BPF_JSET ? "&" : - BPF_OP(iter->code) == BPF_JEQ ? "==" : - BPF_OP(iter->code) == BPF_JGE ? ">=" : - BPF_OP(iter->code) == BPF_JGT ? ">" : "???", - (int)iter->k, - ip + iter->jt + 1, ip + iter->jf + 1); - } - break; - case BPF_RET: - fprintf(stderr, "RET 0x%x // ", iter->k); - if ((iter->k & SECCOMP_RET_ACTION) == SECCOMP_RET_TRAP) { - fprintf(stderr, "Trap #%d\n", iter->k & SECCOMP_RET_DATA); - } else if ((iter->k & SECCOMP_RET_ACTION) == SECCOMP_RET_ERRNO) { - fprintf(stderr, "errno = %d\n", iter->k & SECCOMP_RET_DATA); - } else if ((iter->k & SECCOMP_RET_ACTION) == SECCOMP_RET_TRACE) { - fprintf(stderr, "Trace #%d\n", iter->k & SECCOMP_RET_DATA); - } else if (iter->k == SECCOMP_RET_ALLOW) { - fprintf(stderr, "Allowed\n"); - } else { - fprintf(stderr, "???\n"); - } - break; - case BPF_ALU: - fprintf(stderr, BPF_OP(iter->code) == BPF_NEG - ? "A := -A\n" : "A := A %s 0x%x\n", - BPF_OP(iter->code) == BPF_ADD ? "+" : - BPF_OP(iter->code) == BPF_SUB ? "-" : - BPF_OP(iter->code) == BPF_MUL ? "*" : - BPF_OP(iter->code) == BPF_DIV ? "/" : - BPF_OP(iter->code) == BPF_MOD ? "%" : - BPF_OP(iter->code) == BPF_OR ? "|" : - BPF_OP(iter->code) == BPF_XOR ? "^" : - BPF_OP(iter->code) == BPF_AND ? "&" : - BPF_OP(iter->code) == BPF_LSH ? "<<" : - BPF_OP(iter->code) == BPF_RSH ? ">>" : "???", - (int)iter->k); - break; - default: - fprintf(stderr, "???\n"); - break; - } - } - return; -} - Instruction* CodeGen::MakeInstruction(uint16_t code, uint32_t k, Instruction* next) { diff --git a/sandbox/linux/seccomp-bpf/codegen.h b/sandbox/linux/seccomp-bpf/codegen.h index 817b17c..671b09e 100644 --- a/sandbox/linux/seccomp-bpf/codegen.h +++ b/sandbox/linux/seccomp-bpf/codegen.h @@ -63,10 +63,6 @@ class SANDBOX_EXPORT CodeGen { CodeGen(); ~CodeGen(); - // This is a helper method that can be used for debugging purposes. It is - // not normally called. - static void PrintProgram(const Program& program); - // Create a new instruction. Instructions form a DAG. The instruction objects // are owned by the CodeGen object. They do not need to be explicitly // deleted. diff --git a/sandbox/linux/seccomp-bpf/sandbox_bpf.cc b/sandbox/linux/seccomp-bpf/sandbox_bpf.cc index 8292ae6..d5a5d4d 100644 --- a/sandbox/linux/seccomp-bpf/sandbox_bpf.cc +++ b/sandbox/linux/seccomp-bpf/sandbox_bpf.cc @@ -29,6 +29,7 @@ #include "base/memory/scoped_ptr.h" #include "base/posix/eintr_wrapper.h" #include "sandbox/linux/bpf_dsl/bpf_dsl.h" +#include "sandbox/linux/bpf_dsl/dump_bpf.h" #include "sandbox/linux/bpf_dsl/policy.h" #include "sandbox/linux/bpf_dsl/policy_compiler.h" #include "sandbox/linux/seccomp-bpf/codegen.h" @@ -495,7 +496,7 @@ scoped_ptr<CodeGen::Program> SandboxBPF::AssembleFilter( const char* err = NULL; if (!Verifier::VerifyBPF(&compiler, *program, *policy_, &err)) { - CodeGen::PrintProgram(*program); + bpf_dsl::DumpBPF::PrintProgram(*program); SANDBOX_DIE(err); } } |