Chromium Code Reviews| 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/bpf_dsl/bpf_dsl.h" | 5 #include "sandbox/linux/bpf_dsl/bpf_dsl.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | |
| 8 #include <pthread.h> | 9 #include <pthread.h> |
| 9 #include <sched.h> | 10 #include <sched.h> |
| 10 #include <signal.h> | 11 #include <signal.h> |
| 11 #include <sys/prctl.h> | 12 #include <sys/prctl.h> |
| 12 #include <sys/ptrace.h> | 13 #include <sys/ptrace.h> |
| 13 #include <sys/syscall.h> | 14 #include <sys/syscall.h> |
| 14 #include <sys/time.h> | 15 #include <sys/time.h> |
| 15 #include <sys/types.h> | 16 #include <sys/types.h> |
| 16 #include <sys/utsname.h> | 17 #include <sys/utsname.h> |
| 17 #include <unistd.h> | 18 #include <unistd.h> |
| 18 #include <sys/socket.h> | 19 #include <sys/socket.h> |
| 19 | 20 |
| 20 #if defined(ANDROID) | 21 #if defined(ANDROID) |
| 21 // Work-around for buggy headers in Android's NDK | 22 // Work-around for buggy headers in Android's NDK |
| 22 #define __user | 23 #define __user |
| 23 #endif | 24 #endif |
| 24 #include <linux/futex.h> | 25 #include <linux/futex.h> |
| 25 | 26 |
| 26 #include "base/bind.h" | 27 #include "base/bind.h" |
| 27 #include "base/logging.h" | 28 #include "base/logging.h" |
| 28 #include "base/macros.h" | 29 #include "base/macros.h" |
| 29 #include "base/memory/scoped_ptr.h" | 30 #include "base/memory/scoped_ptr.h" |
| 30 #include "base/posix/eintr_wrapper.h" | 31 #include "base/posix/eintr_wrapper.h" |
| 31 #include "base/synchronization/waitable_event.h" | 32 #include "base/synchronization/waitable_event.h" |
| 32 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
| 33 #include "build/build_config.h" | 34 #include "build/build_config.h" |
| 34 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" | 35 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" |
| 35 #include "sandbox/linux/seccomp-bpf/die.h" | 36 #include "sandbox/linux/seccomp-bpf/die.h" |
| 36 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" | 37 #include "sandbox/linux/seccomp-bpf/linux_seccomp.h" |
| 38 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | |
| 37 #include "sandbox/linux/seccomp-bpf/syscall.h" | 39 #include "sandbox/linux/seccomp-bpf/syscall.h" |
| 38 #include "sandbox/linux/seccomp-bpf/trap.h" | 40 #include "sandbox/linux/seccomp-bpf/trap.h" |
| 39 #include "sandbox/linux/services/broker_process.h" | 41 #include "sandbox/linux/services/broker_process.h" |
| 40 #include "sandbox/linux/services/linux_syscalls.h" | 42 #include "sandbox/linux/services/linux_syscalls.h" |
| 41 #include "sandbox/linux/tests/scoped_temporary_file.h" | 43 #include "sandbox/linux/tests/scoped_temporary_file.h" |
| 42 #include "sandbox/linux/tests/unit_tests.h" | 44 #include "sandbox/linux/tests/unit_tests.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 45 #include "testing/gtest/include/gtest/gtest.h" |
| 44 | 46 |
| 45 // Workaround for Android's prctl.h file. | 47 // Workaround for Android's prctl.h file. |
| 46 #ifndef PR_GET_ENDIAN | 48 #ifndef PR_GET_ENDIAN |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 } | 209 } |
| 208 | 210 |
| 209 // A simple blacklist policy, with a SIGSYS handler | 211 // A simple blacklist policy, with a SIGSYS handler |
| 210 intptr_t EnomemHandler(const struct arch_seccomp_data& args, void* aux) { | 212 intptr_t EnomemHandler(const struct arch_seccomp_data& args, void* aux) { |
| 211 // We also check that the auxiliary data is correct | 213 // We also check that the auxiliary data is correct |
| 212 SANDBOX_ASSERT(aux); | 214 SANDBOX_ASSERT(aux); |
| 213 *(static_cast<int*>(aux)) = kExpectedReturnValue; | 215 *(static_cast<int*>(aux)) = kExpectedReturnValue; |
| 214 return -ENOMEM; | 216 return -ENOMEM; |
| 215 } | 217 } |
| 216 | 218 |
| 217 ErrorCode BlacklistNanosleepPolicySigsys(SandboxBPF* sandbox, | 219 class BlacklistNanosleepTrapPolicy : public SandboxBPFDSLPolicy { |
| 218 int sysno, | 220 public: |
| 219 int* aux) { | 221 BlacklistNanosleepTrapPolicy(int* aux) : aux_(aux) {} |
|
jln (very slow on Chromium)
2014/09/23 18:42:06
nit: explicit
mdempsky
2014/09/23 18:50:20
Done.
| |
| 220 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); | 222 virtual ~BlacklistNanosleepTrapPolicy() {} |
| 221 switch (sysno) { | 223 |
| 222 case __NR_nanosleep: | 224 virtual ResultExpr EvaluateSyscall(int sysno) const OVERRIDE { |
| 223 return sandbox->Trap(EnomemHandler, aux); | 225 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); |
| 224 default: | 226 switch (sysno) { |
| 225 return ErrorCode(ErrorCode::ERR_ALLOWED); | 227 case __NR_nanosleep: |
| 228 return Trap(EnomemHandler, aux_); | |
| 229 default: | |
| 230 return Allow(); | |
| 231 } | |
| 226 } | 232 } |
| 227 } | 233 |
| 234 private: | |
| 235 int* aux_; | |
| 236 | |
| 237 DISALLOW_COPY_AND_ASSIGN(BlacklistNanosleepTrapPolicy); | |
| 238 }; | |
| 228 | 239 |
| 229 BPF_TEST(SandboxBPF, | 240 BPF_TEST(SandboxBPF, |
| 230 BasicBlacklistWithSigsys, | 241 BasicBlacklistWithSigsys, |
| 231 BlacklistNanosleepPolicySigsys, | 242 BlacklistNanosleepTrapPolicy, |
| 232 int /* (*BPF_AUX) */) { | 243 int /* (*BPF_AUX) */) { |
| 233 // getpid() should work properly | 244 // getpid() should work properly |
| 234 errno = 0; | 245 errno = 0; |
| 235 BPF_ASSERT(syscall(__NR_getpid) > 0); | 246 BPF_ASSERT(syscall(__NR_getpid) > 0); |
| 236 BPF_ASSERT(errno == 0); | 247 BPF_ASSERT(errno == 0); |
| 237 | 248 |
| 238 // Our Auxiliary Data, should be reset by the signal handler | 249 // Our Auxiliary Data, should be reset by the signal handler |
| 239 *BPF_AUX = -1; | 250 *BPF_AUX = -1; |
| 240 const struct timespec ts = {0, 0}; | 251 const struct timespec ts = {0, 0}; |
| 241 BPF_ASSERT(syscall(__NR_nanosleep, &ts, NULL) == -1); | 252 BPF_ASSERT(syscall(__NR_nanosleep, &ts, NULL) == -1); |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 | 509 |
| 499 // Verify that within the callback function all filtering is temporarily | 510 // Verify that within the callback function all filtering is temporarily |
| 500 // disabled. | 511 // disabled. |
| 501 BPF_ASSERT(syscall(__NR_getpid) > 1); | 512 BPF_ASSERT(syscall(__NR_getpid) > 1); |
| 502 | 513 |
| 503 // Verify that we can now call the underlying system call without causing | 514 // Verify that we can now call the underlying system call without causing |
| 504 // infinite recursion. | 515 // infinite recursion. |
| 505 return SandboxBPF::ForwardSyscall(args); | 516 return SandboxBPF::ForwardSyscall(args); |
| 506 } | 517 } |
| 507 | 518 |
| 508 ErrorCode GreyListedPolicy(SandboxBPF* sandbox, int sysno, int* aux) { | 519 class GreyListedPolicy : public SandboxBPFDSLPolicy { |
| 509 // Set the global environment for unsafe traps once. | 520 public: |
| 510 if (sysno == MIN_SYSCALL) { | 521 GreyListedPolicy(int* aux) : aux_(aux) { |
|
jln (very slow on Chromium)
2014/09/23 18:42:06
Nit: explicit
mdempsky
2014/09/23 18:50:19
Done.
| |
| 522 // Set the global environment for unsafe traps once. | |
| 511 EnableUnsafeTraps(); | 523 EnableUnsafeTraps(); |
| 512 } | 524 } |
| 525 virtual ~GreyListedPolicy() {} | |
| 513 | 526 |
| 514 // Some system calls must always be allowed, if our policy wants to make | 527 virtual ResultExpr EvaluateSyscall(int sysno) const OVERRIDE { |
| 515 // use of UnsafeTrap() | 528 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); |
| 516 if (SandboxBPF::IsRequiredForUnsafeTrap(sysno)) { | 529 // Some system calls must always be allowed, if our policy wants to make |
| 517 return ErrorCode(ErrorCode::ERR_ALLOWED); | 530 // use of UnsafeTrap() |
| 518 } else if (sysno == __NR_getpid) { | 531 if (SandboxBPF::IsRequiredForUnsafeTrap(sysno)) { |
| 519 // Disallow getpid() | 532 return Allow(); |
| 520 return ErrorCode(EPERM); | 533 } else if (sysno == __NR_getpid) { |
| 521 } else if (SandboxBPF::IsValidSyscallNumber(sysno)) { | 534 // Disallow getpid() |
| 522 // Allow (and count) all other system calls. | 535 return Error(EPERM); |
| 523 return sandbox->UnsafeTrap(CountSyscalls, aux); | 536 } else { |
| 524 } else { | 537 // Allow (and count) all other system calls. |
| 525 return ErrorCode(ENOSYS); | 538 return UnsafeTrap(CountSyscalls, aux_); |
| 539 } | |
| 526 } | 540 } |
| 527 } | 541 |
| 542 private: | |
| 543 int* aux_; | |
| 544 | |
| 545 DISALLOW_COPY_AND_ASSIGN(GreyListedPolicy); | |
| 546 }; | |
| 528 | 547 |
| 529 BPF_TEST(SandboxBPF, GreyListedPolicy, GreyListedPolicy, int /* (*BPF_AUX) */) { | 548 BPF_TEST(SandboxBPF, GreyListedPolicy, GreyListedPolicy, int /* (*BPF_AUX) */) { |
| 530 BPF_ASSERT(syscall(__NR_getpid) == -1); | 549 BPF_ASSERT(syscall(__NR_getpid) == -1); |
| 531 BPF_ASSERT(errno == EPERM); | 550 BPF_ASSERT(errno == EPERM); |
| 532 BPF_ASSERT(*BPF_AUX == 0); | 551 BPF_ASSERT(*BPF_AUX == 0); |
| 533 BPF_ASSERT(syscall(__NR_geteuid) == syscall(__NR_getuid)); | 552 BPF_ASSERT(syscall(__NR_geteuid) == syscall(__NR_getuid)); |
| 534 BPF_ASSERT(*BPF_AUX == 2); | 553 BPF_ASSERT(*BPF_AUX == 2); |
| 535 char name[17] = {}; | 554 char name[17] = {}; |
| 536 BPF_ASSERT(!syscall(__NR_prctl, | 555 BPF_ASSERT(!syscall(__NR_prctl, |
| 537 PR_GET_NAME, | 556 PR_GET_NAME, |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 777 // the openat() system call. | 796 // the openat() system call. |
| 778 BPF_ASSERT(static_cast<int>(args.args[0]) == AT_FDCWD); | 797 BPF_ASSERT(static_cast<int>(args.args[0]) == AT_FDCWD); |
| 779 return broker_process->Open(reinterpret_cast<const char*>(args.args[1]), | 798 return broker_process->Open(reinterpret_cast<const char*>(args.args[1]), |
| 780 static_cast<int>(args.args[2])); | 799 static_cast<int>(args.args[2])); |
| 781 default: | 800 default: |
| 782 BPF_ASSERT(false); | 801 BPF_ASSERT(false); |
| 783 return -ENOSYS; | 802 return -ENOSYS; |
| 784 } | 803 } |
| 785 } | 804 } |
| 786 | 805 |
| 787 ErrorCode DenyOpenPolicy(SandboxBPF* sandbox, | 806 class DenyOpenPolicy : public SandboxBPFDSLPolicy { |
| 788 int sysno, | 807 public: |
| 789 InitializedOpenBroker* iob) { | 808 DenyOpenPolicy(InitializedOpenBroker* iob) : iob_(iob) {} |
|
jln (very slow on Chromium)
2014/09/23 18:42:06
nit: explicit
mdempsky
2014/09/23 18:50:19
Done.
| |
| 790 if (!SandboxBPF::IsValidSyscallNumber(sysno)) { | 809 virtual ~DenyOpenPolicy() {} |
| 791 return ErrorCode(ENOSYS); | 810 |
| 811 virtual ResultExpr EvaluateSyscall(int sysno) const OVERRIDE { | |
| 812 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); | |
| 813 | |
| 814 switch (sysno) { | |
| 815 case __NR_faccessat: | |
| 816 #if defined(__NR_access) | |
| 817 case __NR_access: | |
| 818 #endif | |
| 819 #if defined(__NR_open) | |
| 820 case __NR_open: | |
| 821 #endif | |
| 822 case __NR_openat: | |
| 823 // We get a InitializedOpenBroker class, but our trap handler wants | |
| 824 // the BrokerProcess object. | |
| 825 return Trap(BrokerOpenTrapHandler, iob_->broker_process()); | |
| 826 default: | |
| 827 return Allow(); | |
| 828 } | |
| 792 } | 829 } |
| 793 | 830 |
| 794 switch (sysno) { | 831 private: |
| 795 case __NR_faccessat: | 832 InitializedOpenBroker* iob_; |
| 796 #if defined(__NR_access) | 833 |
| 797 case __NR_access: | 834 DISALLOW_COPY_AND_ASSIGN(DenyOpenPolicy); |
| 798 #endif | 835 }; |
| 799 #if defined(__NR_open) | |
| 800 case __NR_open: | |
| 801 #endif | |
| 802 case __NR_openat: | |
| 803 // We get a InitializedOpenBroker class, but our trap handler wants | |
| 804 // the BrokerProcess object. | |
| 805 return ErrorCode( | |
| 806 sandbox->Trap(BrokerOpenTrapHandler, iob->broker_process())); | |
| 807 default: | |
| 808 return ErrorCode(ErrorCode::ERR_ALLOWED); | |
| 809 } | |
| 810 } | |
| 811 | 836 |
| 812 // We use a InitializedOpenBroker class, so that we can run unsandboxed | 837 // We use a InitializedOpenBroker class, so that we can run unsandboxed |
| 813 // code in its constructor, which is the only way to do so in a BPF_TEST. | 838 // code in its constructor, which is the only way to do so in a BPF_TEST. |
| 814 BPF_TEST(SandboxBPF, | 839 BPF_TEST(SandboxBPF, |
| 815 UseOpenBroker, | 840 UseOpenBroker, |
| 816 DenyOpenPolicy, | 841 DenyOpenPolicy, |
| 817 InitializedOpenBroker /* (*BPF_AUX) */) { | 842 InitializedOpenBroker /* (*BPF_AUX) */) { |
| 818 BPF_ASSERT(BPF_AUX->initialized()); | 843 BPF_ASSERT(BPF_AUX->initialized()); |
| 819 BrokerProcess* broker_process = BPF_AUX->broker_process(); | 844 BrokerProcess* broker_process = BPF_AUX->broker_process(); |
| 820 BPF_ASSERT(broker_process != NULL); | 845 BPF_ASSERT(broker_process != NULL); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 } | 974 } |
| 950 | 975 |
| 951 ~EqualityStressTest() { | 976 ~EqualityStressTest() { |
| 952 for (std::vector<ArgValue*>::iterator iter = arg_values_.begin(); | 977 for (std::vector<ArgValue*>::iterator iter = arg_values_.begin(); |
| 953 iter != arg_values_.end(); | 978 iter != arg_values_.end(); |
| 954 ++iter) { | 979 ++iter) { |
| 955 DeleteArgValue(*iter); | 980 DeleteArgValue(*iter); |
| 956 } | 981 } |
| 957 } | 982 } |
| 958 | 983 |
| 959 ErrorCode Policy(SandboxBPF* sandbox, int sysno) { | 984 ResultExpr Policy(int sysno) { |
| 960 if (!SandboxBPF::IsValidSyscallNumber(sysno)) { | 985 DCHECK(SandboxBPF::IsValidSyscallNumber(sysno)); |
| 961 // FIXME: we should really not have to do that in a trivial policy | 986 if (sysno < 0 || sysno >= (int)arg_values_.size() || |
| 962 return ErrorCode(ENOSYS); | 987 IsReservedSyscall(sysno)) { |
| 963 } else if (sysno < 0 || sysno >= (int)arg_values_.size() || | |
| 964 IsReservedSyscall(sysno)) { | |
| 965 // We only return ErrorCode values for the system calls that | 988 // We only return ErrorCode values for the system calls that |
| 966 // are part of our test data. Every other system call remains | 989 // are part of our test data. Every other system call remains |
| 967 // allowed. | 990 // allowed. |
| 968 return ErrorCode(ErrorCode::ERR_ALLOWED); | 991 return Allow(); |
| 969 } else { | 992 } else { |
| 970 // ToErrorCode() turns an ArgValue object into an ErrorCode that is | 993 // ToErrorCode() turns an ArgValue object into an ErrorCode that is |
| 971 // suitable for use by a sandbox policy. | 994 // suitable for use by a sandbox policy. |
| 972 return ToErrorCode(sandbox, arg_values_[sysno]); | 995 return ToErrorCode(arg_values_[sysno]); |
| 973 } | 996 } |
| 974 } | 997 } |
| 975 | 998 |
| 976 void VerifyFilter() { | 999 void VerifyFilter() { |
| 977 // Iterate over all system calls. Skip the system calls that have | 1000 // Iterate over all system calls. Skip the system calls that have |
| 978 // previously been determined as being reserved. | 1001 // previously been determined as being reserved. |
| 979 for (int sysno = 0; sysno < (int)arg_values_.size(); ++sysno) { | 1002 for (int sysno = 0; sysno < (int)arg_values_.size(); ++sysno) { |
| 980 if (!arg_values_[sysno]) { | 1003 if (!arg_values_[sysno]) { |
| 981 // Skip reserved system calls. | 1004 // Skip reserved system calls. |
| 982 continue; | 1005 continue; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1109 } | 1132 } |
| 1110 delete[] arg_value->tests; | 1133 delete[] arg_value->tests; |
| 1111 } | 1134 } |
| 1112 if (!arg_value->err) { | 1135 if (!arg_value->err) { |
| 1113 DeleteArgValue(arg_value->arg_value); | 1136 DeleteArgValue(arg_value->arg_value); |
| 1114 } | 1137 } |
| 1115 delete arg_value; | 1138 delete arg_value; |
| 1116 } | 1139 } |
| 1117 } | 1140 } |
| 1118 | 1141 |
| 1119 ErrorCode ToErrorCode(SandboxBPF* sandbox, ArgValue* arg_value) { | 1142 ResultExpr ToErrorCode(ArgValue* arg_value) { |
| 1120 // Compute the ErrorCode that should be returned, if none of our | 1143 // Compute the ResultExpr that should be returned, if none of our |
| 1121 // tests succeed (i.e. the system call parameter doesn't match any | 1144 // tests succeed (i.e. the system call parameter doesn't match any |
| 1122 // of the values in arg_value->tests[].k_value). | 1145 // of the values in arg_value->tests[].k_value). |
| 1123 ErrorCode err; | 1146 ResultExpr err; |
| 1124 if (arg_value->err) { | 1147 if (arg_value->err) { |
| 1125 // If this was a leaf node, return the errno value that we expect to | 1148 // If this was a leaf node, return the errno value that we expect to |
| 1126 // return from the BPF filter program. | 1149 // return from the BPF filter program. |
| 1127 err = ErrorCode(arg_value->err); | 1150 err = Error(arg_value->err); |
| 1128 } else { | 1151 } else { |
| 1129 // If this wasn't a leaf node yet, recursively descend into the rest | 1152 // If this wasn't a leaf node yet, recursively descend into the rest |
| 1130 // of the tree. This will end up adding a few more SandboxBPF::Cond() | 1153 // of the tree. This will end up adding a few more SandboxBPF::Cond() |
| 1131 // tests to our ErrorCode. | 1154 // tests to our ErrorCode. |
| 1132 err = ToErrorCode(sandbox, arg_value->arg_value); | 1155 err = ToErrorCode(arg_value->arg_value); |
| 1133 } | 1156 } |
| 1134 | 1157 |
| 1135 // Now, iterate over all the test cases that we want to compare against. | 1158 // Now, iterate over all the test cases that we want to compare against. |
| 1136 // This builds a chain of SandboxBPF::Cond() tests | 1159 // This builds a chain of SandboxBPF::Cond() tests |
| 1137 // (aka "if ... elif ... elif ... elif ... fi") | 1160 // (aka "if ... elif ... elif ... elif ... fi") |
| 1138 for (int n = arg_value->size; n-- > 0;) { | 1161 for (int n = arg_value->size; n-- > 0;) { |
| 1139 ErrorCode matched; | 1162 ResultExpr matched; |
| 1140 // Again, we distinguish between leaf nodes and subtrees. | 1163 // Again, we distinguish between leaf nodes and subtrees. |
| 1141 if (arg_value->tests[n].err) { | 1164 if (arg_value->tests[n].err) { |
| 1142 matched = ErrorCode(arg_value->tests[n].err); | 1165 matched = Error(arg_value->tests[n].err); |
| 1143 } else { | 1166 } else { |
| 1144 matched = ToErrorCode(sandbox, arg_value->tests[n].arg_value); | 1167 matched = ToErrorCode(arg_value->tests[n].arg_value); |
| 1145 } | 1168 } |
| 1146 // For now, all of our tests are limited to 32bit. | 1169 // For now, all of our tests are limited to 32bit. |
| 1147 // We have separate tests that check the behavior of 32bit vs. 64bit | 1170 // We have separate tests that check the behavior of 32bit vs. 64bit |
| 1148 // conditional expressions. | 1171 // conditional expressions. |
| 1149 err = sandbox->Cond(arg_value->argno, | 1172 const Arg<uint32_t> arg(arg_value->argno); |
| 1150 ErrorCode::TP_32BIT, | 1173 err = If(arg == arg_value->tests[n].k_value, matched).Else(err); |
| 1151 ErrorCode::OP_EQUAL, | |
| 1152 arg_value->tests[n].k_value, | |
| 1153 matched, | |
| 1154 err); | |
| 1155 } | 1174 } |
| 1156 return err; | 1175 return err; |
| 1157 } | 1176 } |
| 1158 | 1177 |
| 1159 void Verify(int sysno, intptr_t* args, const ArgValue& arg_value) { | 1178 void Verify(int sysno, intptr_t* args, const ArgValue& arg_value) { |
| 1160 uint32_t mismatched = 0; | 1179 uint32_t mismatched = 0; |
| 1161 // Iterate over all the k_values in arg_value.tests[] and verify that | 1180 // Iterate over all the k_values in arg_value.tests[] and verify that |
| 1162 // we see the expected return values from system calls, when we pass | 1181 // we see the expected return values from system calls, when we pass |
| 1163 // the k_value as a parameter in a system call. | 1182 // the k_value as a parameter in a system call. |
| 1164 for (int n = arg_value.size; n-- > 0;) { | 1183 for (int n = arg_value.size; n-- > 0;) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1214 // increased too much, the test will start failing. | 1233 // increased too much, the test will start failing. |
| 1215 #if defined(__aarch64__) | 1234 #if defined(__aarch64__) |
| 1216 static const int kNumTestCases = 30; | 1235 static const int kNumTestCases = 30; |
| 1217 #else | 1236 #else |
| 1218 static const int kNumTestCases = 40; | 1237 static const int kNumTestCases = 40; |
| 1219 #endif | 1238 #endif |
| 1220 static const int kMaxFanOut = 3; | 1239 static const int kMaxFanOut = 3; |
| 1221 static const int kMaxArgs = 6; | 1240 static const int kMaxArgs = 6; |
| 1222 }; | 1241 }; |
| 1223 | 1242 |
| 1224 ErrorCode EqualityStressTestPolicy(SandboxBPF* sandbox, | 1243 class EqualityStressTestPolicy : public SandboxBPFDSLPolicy { |
| 1225 int sysno, | 1244 public: |
| 1226 EqualityStressTest* aux) { | 1245 EqualityStressTestPolicy(EqualityStressTest* aux) : aux_(aux) {} |
|
jln (very slow on Chromium)
2014/09/23 18:42:06
nit: explicit
mdempsky
2014/09/23 18:50:19
Done.
| |
| 1227 DCHECK(aux); | 1246 virtual ~EqualityStressTestPolicy() {} |
| 1228 return aux->Policy(sandbox, sysno); | 1247 |
| 1229 } | 1248 virtual ResultExpr EvaluateSyscall(int sysno) const OVERRIDE { |
| 1249 return aux_->Policy(sysno); | |
| 1250 } | |
| 1251 | |
| 1252 private: | |
| 1253 EqualityStressTest* aux_; | |
| 1254 | |
| 1255 DISALLOW_COPY_AND_ASSIGN(EqualityStressTestPolicy); | |
| 1256 }; | |
| 1230 | 1257 |
| 1231 BPF_TEST(SandboxBPF, | 1258 BPF_TEST(SandboxBPF, |
| 1232 EqualityTests, | 1259 EqualityTests, |
| 1233 EqualityStressTestPolicy, | 1260 EqualityStressTestPolicy, |
| 1234 EqualityStressTest /* (*BPF_AUX) */) { | 1261 EqualityStressTest /* (*BPF_AUX) */) { |
| 1235 BPF_AUX->VerifyFilter(); | 1262 BPF_AUX->VerifyFilter(); |
| 1236 } | 1263 } |
| 1237 | 1264 |
| 1238 class EqualityArgumentWidthPolicy : public SandboxBPFDSLPolicy { | 1265 class EqualityArgumentWidthPolicy : public SandboxBPFDSLPolicy { |
| 1239 public: | 1266 public: |
| (...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2362 BPF_ASSERT_EQ(ENOSYS, errno); | 2389 BPF_ASSERT_EQ(ENOSYS, errno); |
| 2363 | 2390 |
| 2364 BPF_ASSERT_EQ(-1, syscall(__NR_setgid, 300)); | 2391 BPF_ASSERT_EQ(-1, syscall(__NR_setgid, 300)); |
| 2365 BPF_ASSERT_EQ(EPERM, errno); | 2392 BPF_ASSERT_EQ(EPERM, errno); |
| 2366 } | 2393 } |
| 2367 | 2394 |
| 2368 } // namespace | 2395 } // namespace |
| 2369 | 2396 |
| 2370 } // namespace bpf_dsl | 2397 } // namespace bpf_dsl |
| 2371 } // namespace sandbox | 2398 } // namespace sandbox |
| OLD | NEW |