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

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

Issue 286363003: Non-SFI NaCl: Disallow fancy clock IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test name 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
Index: components/nacl/loader/nonsfi/nonsfi_sandbox.cc
diff --git a/components/nacl/loader/nonsfi/nonsfi_sandbox.cc b/components/nacl/loader/nonsfi/nonsfi_sandbox.cc
index 0e4550c5dee9eec964720529f34cfb67ce2dbc3c..8d42150fe9a26004368bfcaa1dde6d759019c029 100644
--- a/components/nacl/loader/nonsfi/nonsfi_sandbox.cc
+++ b/components/nacl/loader/nonsfi/nonsfi_sandbox.cc
@@ -73,6 +73,25 @@ ErrorCode RestrictFcntlCommands(SandboxBPF* sb) {
sb->Trap(sandbox::CrashSIGSYS_Handler, NULL))));
}
+ErrorCode RestrictClockID(SandboxBPF* sb) {
+ // We allow accessing only CLOCK_MONOTONIC, CLOCK_PROCESS_CPUTIME_ID,
+ // CLOCK_REALTIME, and CLOCK_THREAD_CPUTIME_ID.
Mark Seaborn 2014/05/20 21:21:30 Maybe also say: "Don't allow reading the clocks of
mdempsky 2014/05/20 23:02:51 Done.
+ COMPILE_ASSERT(4 == sizeof(clockid_t), clockid_is_not_32bit);
+ return sb->Cond(0, ErrorCode::TP_32BIT,
+ ErrorCode::OP_EQUAL, CLOCK_MONOTONIC,
+ ErrorCode(ErrorCode::ERR_ALLOWED),
+ sb->Cond(0, ErrorCode::TP_32BIT,
+ ErrorCode::OP_EQUAL, CLOCK_PROCESS_CPUTIME_ID,
+ ErrorCode(ErrorCode::ERR_ALLOWED),
+ sb->Cond(0, ErrorCode::TP_32BIT,
+ ErrorCode::OP_EQUAL, CLOCK_REALTIME,
+ ErrorCode(ErrorCode::ERR_ALLOWED),
+ sb->Cond(0, ErrorCode::TP_32BIT,
+ ErrorCode::OP_EQUAL, CLOCK_THREAD_CPUTIME_ID,
+ ErrorCode(ErrorCode::ERR_ALLOWED),
+ sb->Trap(sandbox::CrashSIGSYS_Handler, NULL)))));
+}
+
ErrorCode RestrictClone(SandboxBPF* sb) {
// We allow clone only for new thread creation.
return sb->Cond(0, ErrorCode::TP_32BIT, ErrorCode::OP_EQUAL,
@@ -212,9 +231,6 @@ ErrorCode NaClNonSfiBPFSandboxPolicy::EvaluateSyscall(SandboxBPF* sb,
#elif defined(__x86_64__)
case __NR_lseek:
#endif
- // NaCl runtime exposes clock_gettime and clock_getres to untrusted code.
- case __NR_clock_getres:
- case __NR_clock_gettime:
case __NR_close:
case __NR_dup:
case __NR_dup2:
@@ -252,6 +268,10 @@ ErrorCode NaClNonSfiBPFSandboxPolicy::EvaluateSyscall(SandboxBPF* sb,
#endif
return ErrorCode(ErrorCode::ERR_ALLOWED);
+ case __NR_clock_getres:
+ case __NR_clock_gettime:
+ return RestrictClockID(sb);
+
case __NR_clone:
return RestrictClone(sb);

Powered by Google App Engine
This is Rietveld 408576698