Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(832)

Side by Side Diff: sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc

Issue 1424323002: Removes support for using the system clock on ChromeOS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit test Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 85 }
86 86
87 BPF_DEATH_TEST_C(ParameterRestrictions, 87 BPF_DEATH_TEST_C(ParameterRestrictions,
88 clock_gettime_crash_monotonic_raw, 88 clock_gettime_crash_monotonic_raw,
89 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), 89 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()),
90 RestrictClockIdPolicy) { 90 RestrictClockIdPolicy) {
91 struct timespec ts; 91 struct timespec ts;
92 clock_gettime(CLOCK_MONOTONIC_RAW, &ts); 92 clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
93 } 93 }
94 94
95 #if defined(OS_CHROMEOS) 95 #if defined(OS_LINUX)
96
97 // A custom BPF tester delegate to run IsRunningOnChromeOS() before
98 // the sandbox is enabled because we cannot run it with non-SFI BPF
99 // sandbox enabled.
100 class ClockSystemTesterDelegate : public sandbox::BPFTesterDelegate {
101 public:
102 ClockSystemTesterDelegate()
103 : is_running_on_chromeos_(base::SysInfo::IsRunningOnChromeOS()) {}
104 ~ClockSystemTesterDelegate() override {}
105
106 scoped_ptr<sandbox::bpf_dsl::Policy> GetSandboxBPFPolicy() override {
107 return scoped_ptr<sandbox::bpf_dsl::Policy>(new RestrictClockIdPolicy());
108 }
109 void RunTestFunction() override {
110 if (is_running_on_chromeos_) {
111 CheckClock(base::TraceTicks::kClockSystemTrace);
112 } else {
113 struct timespec ts;
114 // kClockSystemTrace is 11, which is CLOCK_THREAD_CPUTIME_ID of
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
117 // just check this clock_gettime call does not crash.
118 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts);
119 }
120 }
121
122 private:
123 const bool is_running_on_chromeos_;
124 DISALLOW_COPY_AND_ASSIGN(ClockSystemTesterDelegate);
125 };
126
127 BPF_TEST_D(BPFTest, BPFTestWithDelegateClass, ClockSystemTesterDelegate);
128
129 #elif defined(OS_LINUX)
130 96
131 BPF_DEATH_TEST_C(ParameterRestrictions, 97 BPF_DEATH_TEST_C(ParameterRestrictions,
132 clock_gettime_crash_system_trace, 98 clock_gettime_crash_system_trace,
133 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), 99 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()),
134 RestrictClockIdPolicy) { 100 RestrictClockIdPolicy) {
135 struct timespec ts; 101 struct timespec ts;
136 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts); 102 clock_gettime(base::TraceTicks::kClockSystemTrace, &ts);
137 } 103 }
138 104
139 #endif // defined(OS_CHROMEOS) 105 #endif // defined(OS_LINUX)
140 106
141 #if !defined(OS_ANDROID) 107 #if !defined(OS_ANDROID)
142 BPF_DEATH_TEST_C(ParameterRestrictions, 108 BPF_DEATH_TEST_C(ParameterRestrictions,
143 clock_gettime_crash_cpu_clock, 109 clock_gettime_crash_cpu_clock,
144 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), 110 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()),
145 RestrictClockIdPolicy) { 111 RestrictClockIdPolicy) {
146 // We can't use clock_getcpuclockid() because it's not implemented in newlib, 112 // We can't use clock_getcpuclockid() because it's not implemented in newlib,
147 // and it might not work inside the sandbox anyway. 113 // and it might not work inside the sandbox anyway.
148 const pid_t kInitPID = 1; 114 const pid_t kInitPID = 1;
149 const clockid_t kInitCPUClockID = 115 const clockid_t kInitCPUClockID =
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 getrusage_crash_not_self, 239 getrusage_crash_not_self,
274 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), 240 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()),
275 RestrictGetrusagePolicy) { 241 RestrictGetrusagePolicy) {
276 struct rusage usage; 242 struct rusage usage;
277 getrusage(RUSAGE_CHILDREN, &usage); 243 getrusage(RUSAGE_CHILDREN, &usage);
278 } 244 }
279 245
280 } // namespace 246 } // namespace
281 247
282 } // namespace sandbox 248 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698