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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 public: | 92 public: |
93 ClockSystemTesterDelegate() | 93 ClockSystemTesterDelegate() |
94 : is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()) {} | 94 : is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()) {} |
95 ~ClockSystemTesterDelegate() override {} | 95 ~ClockSystemTesterDelegate() override {} |
96 | 96 |
97 scoped_ptr<sandbox::bpf_dsl::Policy> GetSandboxBPFPolicy() override { | 97 scoped_ptr<sandbox::bpf_dsl::Policy> GetSandboxBPFPolicy() override { |
98 return scoped_ptr<sandbox::bpf_dsl::Policy>(new RestrictClockIdPolicy()); | 98 return scoped_ptr<sandbox::bpf_dsl::Policy>(new RestrictClockIdPolicy()); |
99 } | 99 } |
100 void RunTestFunction() override { | 100 void RunTestFunction() override { |
101 if (is_running_on_chromeos_) { | 101 if (is_running_on_chromeos_) { |
102 CheckClock(base::TimeTicks::kClockSystemTrace); | 102 CheckClock(base::TraceTicks::kClockSystemTrace); |
103 } else { | 103 } else { |
104 struct timespec ts; | 104 struct timespec ts; |
105 // kClockSystemTrace is 11, which is CLOCK_THREAD_CPUTIME_ID of | 105 // kClockSystemTrace is 11, which is CLOCK_THREAD_CPUTIME_ID of |
106 // the init process (pid=1). If kernel supports this feature, | 106 // the init process (pid=1). If kernel supports this feature, |
107 // this may succeed even if this is not running on Chrome OS. We | 107 // this may succeed even if this is not running on Chrome OS. We |
108 // just check this clock_gettime call does not crash. | 108 // just check this clock_gettime call does not crash. |
109 clock_gettime(base::TimeTicks::kClockSystemTrace, &ts); | 109 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts); |
110 } | 110 } |
111 } | 111 } |
112 | 112 |
113 private: | 113 private: |
114 const bool is_running_on_chromeos_; | 114 const bool is_running_on_chromeos_; |
115 DISALLOW_COPY_AND_ASSIGN(ClockSystemTesterDelegate); | 115 DISALLOW_COPY_AND_ASSIGN(ClockSystemTesterDelegate); |
116 }; | 116 }; |
117 | 117 |
118 BPF_TEST_D(BPFTest, BPFTestWithDelegateClass, ClockSystemTesterDelegate); | 118 BPF_TEST_D(BPFTest, BPFTestWithDelegateClass, ClockSystemTesterDelegate); |
119 | 119 |
120 #elif defined(OS_LINUX) | 120 #elif defined(OS_LINUX) |
121 | 121 |
122 BPF_DEATH_TEST_C(ParameterRestrictions, | 122 BPF_DEATH_TEST_C(ParameterRestrictions, |
123 clock_gettime_crash_system_trace, | 123 clock_gettime_crash_system_trace, |
124 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 124 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
125 RestrictClockIdPolicy) { | 125 RestrictClockIdPolicy) { |
126 struct timespec ts; | 126 struct timespec ts; |
127 clock_gettime(base::TimeTicks::kClockSystemTrace, &ts); | 127 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts); |
128 } | 128 } |
129 | 129 |
130 #endif // defined(OS_CHROMEOS) | 130 #endif // defined(OS_CHROMEOS) |
131 | 131 |
132 #if !defined(OS_ANDROID) | 132 #if !defined(OS_ANDROID) |
133 BPF_DEATH_TEST_C(ParameterRestrictions, | 133 BPF_DEATH_TEST_C(ParameterRestrictions, |
134 clock_gettime_crash_cpu_clock, | 134 clock_gettime_crash_cpu_clock, |
135 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 135 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
136 RestrictClockIdPolicy) { | 136 RestrictClockIdPolicy) { |
137 // We can't use clock_getcpuclockid() because it's not implemented in newlib, | 137 // 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... |
264 getrusage_crash_not_self, | 264 getrusage_crash_not_self, |
265 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 265 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
266 RestrictGetrusagePolicy) { | 266 RestrictGetrusagePolicy) { |
267 struct rusage usage; | 267 struct rusage usage; |
268 getrusage(RUSAGE_CHILDREN, &usage); | 268 getrusage(RUSAGE_CHILDREN, &usage); |
269 } | 269 } |
270 | 270 |
271 } // namespace | 271 } // namespace |
272 | 272 |
273 } // namespace sandbox | 273 } // namespace sandbox |
OLD | NEW |