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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 BPF_DEATH_TEST_C(ParameterRestrictions, | 234 BPF_DEATH_TEST_C(ParameterRestrictions, |
235 prlimit64_crash_not_self, | 235 prlimit64_crash_not_self, |
236 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), | 236 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
237 RestrictPrlimit64Policy) { | 237 RestrictPrlimit64Policy) { |
238 const pid_t kInitPID = 1; | 238 const pid_t kInitPID = 1; |
239 BPF_ASSERT_NE(kInitPID, getpid()); | 239 BPF_ASSERT_NE(kInitPID, getpid()); |
240 sys_prlimit64(kInitPID, RLIMIT_AS, NULL, NULL); | 240 sys_prlimit64(kInitPID, RLIMIT_AS, NULL, NULL); |
241 } | 241 } |
242 | 242 |
| 243 class RestrictGetrusagePolicy : public bpf_dsl::Policy { |
| 244 public: |
| 245 RestrictGetrusagePolicy() {} |
| 246 ~RestrictGetrusagePolicy() override {} |
| 247 |
| 248 ResultExpr EvaluateSyscall(int sysno) const override { |
| 249 switch (sysno) { |
| 250 case __NR_getrusage: |
| 251 return RestrictGetrusage(); |
| 252 default: |
| 253 return Allow(); |
| 254 } |
| 255 } |
| 256 }; |
| 257 |
| 258 BPF_TEST_C(ParameterRestrictions, getrusage_allowed, RestrictGetrusagePolicy) { |
| 259 struct rusage usage; |
| 260 BPF_ASSERT_EQ(0, getrusage(RUSAGE_SELF, &usage)); |
| 261 } |
| 262 |
| 263 BPF_DEATH_TEST_C(ParameterRestrictions, |
| 264 getrusage_crash_not_self, |
| 265 DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), |
| 266 RestrictGetrusagePolicy) { |
| 267 struct rusage usage; |
| 268 getrusage(RUSAGE_CHILDREN, &usage); |
| 269 } |
| 270 |
243 } // namespace | 271 } // namespace |
244 | 272 |
245 } // namespace sandbox | 273 } // namespace sandbox |
OLD | NEW |