| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
| 6 | 6 |
| 7 // Some headers on Android are missing cdefs: crbug.com/172337. | 7 // Some headers on Android are missing cdefs: crbug.com/172337. |
| 8 // (We can't use OS_ANDROID here since build_config.h is not included). | 8 // (We can't use OS_ANDROID here since build_config.h is not included). |
| 9 #if defined(ANDROID) | 9 #if defined(ANDROID) |
| 10 #include <sys/cdefs.h> | 10 #include <sys/cdefs.h> |
| (...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 // this range object. If it is greater or equal, it might be inside. | 881 // this range object. If it is greater or equal, it might be inside. |
| 882 Ranges::const_iterator mid = start + (stop - start) / 2; | 882 Ranges::const_iterator mid = start + (stop - start) / 2; |
| 883 | 883 |
| 884 // Sub-divide the list of ranges and continue recursively. | 884 // Sub-divide the list of ranges and continue recursively. |
| 885 Instruction* jf = AssembleJumpTable(gen, start, mid); | 885 Instruction* jf = AssembleJumpTable(gen, start, mid); |
| 886 Instruction* jt = AssembleJumpTable(gen, mid, stop); | 886 Instruction* jt = AssembleJumpTable(gen, mid, stop); |
| 887 return gen->MakeInstruction(BPF_JMP + BPF_JGE + BPF_K, mid->from, jt, jf); | 887 return gen->MakeInstruction(BPF_JMP + BPF_JGE + BPF_K, mid->from, jt, jf); |
| 888 } | 888 } |
| 889 | 889 |
| 890 Instruction* SandboxBPF::RetExpression(CodeGen* gen, const ErrorCode& err) { | 890 Instruction* SandboxBPF::RetExpression(CodeGen* gen, const ErrorCode& err) { |
| 891 if (err.error_type_ == ErrorCode::ET_COND) { | 891 switch (err.error_type()) { |
| 892 return CondExpression(gen, err); | 892 case ErrorCode::ET_COND: |
| 893 } else { | 893 return CondExpression(gen, err); |
| 894 return gen->MakeInstruction(BPF_RET + BPF_K, err); | 894 case ErrorCode::ET_SIMPLE: |
| 895 case ErrorCode::ET_TRAP: |
| 896 return gen->MakeInstruction(BPF_RET + BPF_K, err.err()); |
| 897 default: |
| 898 SANDBOX_DIE("ErrorCode is not suitable for returning from a BPF program"); |
| 895 } | 899 } |
| 896 } | 900 } |
| 897 | 901 |
| 898 Instruction* SandboxBPF::CondExpression(CodeGen* gen, const ErrorCode& cond) { | 902 Instruction* SandboxBPF::CondExpression(CodeGen* gen, const ErrorCode& cond) { |
| 899 // Sanity check that |cond| makes sense. | 903 // Sanity check that |cond| makes sense. |
| 900 if (cond.argno_ < 0 || cond.argno_ >= 6) { | 904 if (cond.argno_ < 0 || cond.argno_ >= 6) { |
| 901 SANDBOX_DIE("sandbox_bpf: invalid argument number"); | 905 SANDBOX_DIE("sandbox_bpf: invalid argument number"); |
| 902 } | 906 } |
| 903 if (cond.width_ != ErrorCode::TP_32BIT && | 907 if (cond.width_ != ErrorCode::TP_32BIT && |
| 904 cond.width_ != ErrorCode::TP_64BIT) { | 908 cond.width_ != ErrorCode::TP_64BIT) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 } | 1136 } |
| 1133 } | 1137 } |
| 1134 | 1138 |
| 1135 ErrorCode SandboxBPF::Kill(const char* msg) { | 1139 ErrorCode SandboxBPF::Kill(const char* msg) { |
| 1136 return Trap(BPFFailure, const_cast<char*>(msg)); | 1140 return Trap(BPFFailure, const_cast<char*>(msg)); |
| 1137 } | 1141 } |
| 1138 | 1142 |
| 1139 SandboxBPF::SandboxStatus SandboxBPF::status_ = STATUS_UNKNOWN; | 1143 SandboxBPF::SandboxStatus SandboxBPF::status_ = STATUS_UNKNOWN; |
| 1140 | 1144 |
| 1141 } // namespace sandbox | 1145 } // namespace sandbox |
| OLD | NEW |