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

Unified Diff: sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc

Issue 550473002: Linux sandbox: whitelist allowed Futex operations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move Android futex definitions to the existing separate file. Created 6 years, 3 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: sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc b/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
index 2f7578586ed8640ffc79be80cb428b646aafa816..799c529390791e3df6dacd8b5e7e6d9e1056cbcb 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.cc
@@ -25,13 +25,16 @@
#include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
#include "sandbox/linux/seccomp-bpf/linux_seccomp.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
-#include "sandbox/linux/services/android_futex.h"
#if defined(OS_ANDROID)
+
+#include "sandbox/linux/services/android_futex.h"
+
#if !defined(F_DUPFD_CLOEXEC)
#define F_DUPFD_CLOEXEC (F_LINUX_SPECIFIC_BASE + 6)
#endif
-#endif
+
+#endif // defined(OS_ANDROID)
#if defined(__arm__) && !defined(MAP_STACK)
#define MAP_STACK 0x20000 // Daisy build environment has old headers.
@@ -207,19 +210,20 @@ ResultExpr RestrictKillTarget(pid_t target_pid, int sysno) {
}
ResultExpr RestrictFutex() {
- // In futex.c, the kernel does "int cmd = op & FUTEX_CMD_MASK;". We need to
- // make sure that the combination below will cover every way to get
- // FUTEX_CMP_REQUEUE_PI.
- const int kBannedFutexBits =
- ~(FUTEX_CMD_MASK | FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME);
- COMPILE_ASSERT(0 == kBannedFutexBits,
- need_to_explicitly_blacklist_more_bits);
+ const int kAllowedFutexFlags = FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME;
+ const int kOperationMask = ~kAllowedFutexFlags;
+ const int kAllowedFutexOperations[] = {
+ FUTEX_WAIT, FUTEX_WAKE, FUTEX_FD, FUTEX_REQUEUE,
Mark Seaborn 2014/09/06 00:29:28 You shouldn't need FUTEX_FD. The man page says "B
+ FUTEX_CMP_REQUEUE, FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET};
const Arg<int> op(1);
- return If(op == FUTEX_CMP_REQUEUE_PI || op == FUTEX_CMP_REQUEUE_PI_PRIVATE ||
- op == (FUTEX_CMP_REQUEUE_PI | FUTEX_CLOCK_REALTIME) ||
- op == (FUTEX_CMP_REQUEUE_PI_PRIVATE | FUTEX_CLOCK_REALTIME),
- CrashSIGSYSFutex()).Else(Allow());
+
+ BoolExpr IsAllowedOp = (op & kOperationMask) == kAllowedFutexOperations[0];
+ for (size_t i = 1; i < arraysize(kAllowedFutexOperations); ++i) {
+ IsAllowedOp =
+ IsAllowedOp || ((op & kOperationMask) == kAllowedFutexOperations[i]);
Mark Seaborn 2014/09/06 00:29:28 Does this end up calculating "op & kOperationMask"
jln (very slow on Chromium) 2014/09/06 00:36:48 Yep. mdempsky is implementing better support in th
mdempsky 2014/09/06 00:38:10 Currently, yes. I'm hoping we can make the compil
+ }
+ return If(IsAllowedOp, Allow()).Else(CrashSIGSYSFutex());
}
} // namespace sandbox.
« no previous file with comments | « sandbox/linux/seccomp-bpf-helpers/baseline_policy_unittest.cc ('k') | sandbox/linux/services/android_futex.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698