| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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-helpers/syscall_parameters_restrictions.h" | 5 #include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sched.h> | 8 #include <sched.h> |
| 9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
| 10 #include <sys/syscall.h> | 10 #include <sys/syscall.h> |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 public: | 101 public: |
| 102 ClockSystemTesterDelegate() | 102 ClockSystemTesterDelegate() |
| 103 : is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()) {} | 103 : is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()) {} |
| 104 ~ClockSystemTesterDelegate() override {} | 104 ~ClockSystemTesterDelegate() override {} |
| 105 | 105 |
| 106 scoped_ptr<sandbox::bpf_dsl::Policy> GetSandboxBPFPolicy() override { | 106 scoped_ptr<sandbox::bpf_dsl::Policy> GetSandboxBPFPolicy() override { |
| 107 return scoped_ptr<sandbox::bpf_dsl::Policy>(new RestrictClockIdPolicy()); | 107 return scoped_ptr<sandbox::bpf_dsl::Policy>(new RestrictClockIdPolicy()); |
| 108 } | 108 } |
| 109 void RunTestFunction() override { | 109 void RunTestFunction() override { |
| 110 if (is_running_on_chromeos_) { | 110 if (is_running_on_chromeos_) { |
| 111 CheckClock(base::TimeTicks::kClockSystemTrace); | 111 CheckClock(base::TraceTicks::kClockSystemTrace); |
| 112 } else { | 112 } else { |
| 113 struct timespec ts; | 113 struct timespec ts; |
| 114 // kClockSystemTrace is 11, which is CLOCK_THREAD_CPUTIME_ID of | 114 // kClockSystemTrace is 11, which is CLOCK_THREAD_CPUTIME_ID of |
| 115 // the init process (pid=1). If kernel supports this feature, | 115 // the init process (pid=1). If kernel supports this feature, |
| 116 // this may succeed even if this is not running on Chrome OS. We | 116 // this may succeed even if this is not running on Chrome OS. We |
| 117 // just check this clock_gettime call does not crash. | 117 // just check this clock_gettime call does not crash. |
| 118 clock_gettime(base::TimeTicks::kClockSystemTrace, &ts); | 118 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 private: | 122 private: |
| 123 const bool is_running_on_chromeos_; | 123 const bool is_running_on_chromeos_; |
| 124 DISALLOW_COPY_AND_ASSIGN(ClockSystemTesterDelegate); | 124 DISALLOW_COPY_AND_ASSIGN(ClockSystemTesterDelegate); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 BPF_TEST_D(BPFTest, BPFTestWithDelegateClass, ClockSystemTesterDelegate); | 127 BPF_TEST_D(BPFTest, BPFTestWithDelegateClass, ClockSystemTesterDelegate); |
| 128 | 128 |
| 129 #elif defined(OS_LINUX) | 129 #elif defined(OS_LINUX) |
| 130 | 130 |
| 131 BPF_DEATH_TEST_C(ParameterRestrictions, | 131 BPF_DEATH_TEST_C(ParameterRestrictions, |
| 132 clock_gettime_crash_system_trace, | 132 clock_gettime_crash_system_trace, |
| 133 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 133 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 134 RestrictClockIdPolicy) { | 134 RestrictClockIdPolicy) { |
| 135 struct timespec ts; | 135 struct timespec ts; |
| 136 clock_gettime(base::TimeTicks::kClockSystemTrace, &ts); | 136 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts); |
| 137 } | 137 } |
| 138 | 138 |
| 139 #endif // defined(OS_CHROMEOS) | 139 #endif // defined(OS_CHROMEOS) |
| 140 | 140 |
| 141 #if !defined(OS_ANDROID) | 141 #if !defined(OS_ANDROID) |
| 142 BPF_DEATH_TEST_C(ParameterRestrictions, | 142 BPF_DEATH_TEST_C(ParameterRestrictions, |
| 143 clock_gettime_crash_cpu_clock, | 143 clock_gettime_crash_cpu_clock, |
| 144 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 144 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 145 RestrictClockIdPolicy) { | 145 RestrictClockIdPolicy) { |
| 146 // We can't use clock_getcpuclockid() because it's not implemented in newlib, | 146 // We can't use clock_getcpuclockid() because it's not implemented in newlib, |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 getrusage_crash_not_self, | 273 getrusage_crash_not_self, |
| 274 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 274 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 275 RestrictGetrusagePolicy) { | 275 RestrictGetrusagePolicy) { |
| 276 struct rusage usage; | 276 struct rusage usage; |
| 277 getrusage(RUSAGE_CHILDREN, &usage); | 277 getrusage(RUSAGE_CHILDREN, &usage); |
| 278 } | 278 } |
| 279 | 279 |
| 280 } // namespace | 280 } // namespace |
| 281 | 281 |
| 282 } // namespace sandbox | 282 } // namespace sandbox |
| OLD | NEW |