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

Unified Diff: components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc

Issue 286363003: Non-SFI NaCl: Disallow fancy clock IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow CPU clocks for the current process/thread to match SFI NaCl Created 6 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_sandbox.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
diff --git a/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc b/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
index febbcd927057d65610c5624915b6fb740e79af44..fff8ed22093e5b284d725ebf3fb75ccfa80703a2 100644
--- a/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
+++ b/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
@@ -22,6 +22,7 @@
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include <time.h>
#include <unistd.h>
#include "base/bind.h"
@@ -391,6 +392,42 @@ BPF_TEST_C(NaClNonSfiSandboxTest,
BPF_ASSERT_EQ(ENOMEM, errno);
}
+BPF_TEST_C(NaClNonSfiSandboxTest,
+ clock_gettime_allowed,
+ nacl::nonsfi::NaClNonSfiBPFSandboxPolicy) {
+ struct timespec ts;
+ BPF_ASSERT_EQ(0, clock_gettime(CLOCK_MONOTONIC, &ts));
hamaji 2014/05/19 05:54:11 Maybe better to check if |ts| is filled.
mdempsky 2014/05/19 06:59:22 Done.
+ BPF_ASSERT_EQ(0, clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts));
+ BPF_ASSERT_EQ(0, clock_gettime(CLOCK_REALTIME, &ts));
+ BPF_ASSERT_EQ(0, clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts));
+}
+
+class ClockGetTimeCrashCPUClockDelegate : public sandbox::BPFTesterDelegate {
hamaji 2014/05/19 05:54:11 Could you add a brief comment to explain why we ne
mdempsky 2014/05/19 06:59:22 Done.
+ public:
+ ClockGetTimeCrashCPUClockDelegate() {
+ const pid_t kInitPID = 1;
+ CHECK_EQ(0, clock_getcpuclockid(kInitPID, &init_clock_id_));
+ }
+
+ virtual scoped_ptr<sandbox::SandboxBPFPolicy> GetSandboxBPFPolicy() OVERRIDE {
+ return scoped_ptr<sandbox::SandboxBPFPolicy>(
+ new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy);
+ }
+
+ virtual void RunTestFunction() OVERRIDE {
+ struct timespec ts;
+ clock_gettime(init_clock_id_, &ts);
+ }
+
+ private:
+ clockid_t init_clock_id_;
+};
+
+BPF_DEATH_TEST_D(NaClNonSfiSandboxTest,
+ clock_gettime_crash_cpu_clock,
+ DEATH_MESSAGE(sandbox::GetErrorMessageContentForTests()),
+ ClockGetTimeCrashCPUClockDelegate);
hamaji 2014/05/19 05:54:11 I think you can also test CLOCK_MONOTONIC_RAW
mdempsky 2014/05/19 06:59:22 Done.
+
// The following test cases check if syscalls return EPERM regardless
// of arguments.
#define RESTRICT_SYSCALL_EPERM_TEST(name) \
« no previous file with comments | « components/nacl/loader/nonsfi/nonsfi_sandbox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698