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

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

Issue 590213003: Linux sandbox: Allow restricting sched_* on other processes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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_unittests.cc
diff --git a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc b/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc
index 7ea1cc2ff9ae286bcb97d5da8268353a45ce3b87..3a6b7dc5095fc95158a2712d545caf6bfc6e5897 100644
--- a/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc
+++ b/sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions_unittests.cc
@@ -4,9 +4,12 @@
#include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
+#include <sched.h>
#include <time.h>
+#include "base/bind.h"
#include "base/sys_info.h"
+#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
@@ -136,6 +139,63 @@ BPF_DEATH_TEST_C(ParameterRestrictions,
}
#endif // !defined(OS_ANDROID)
+class RestrictSchedPolicy : public SandboxBPFDSLPolicy {
+ public:
+ RestrictSchedPolicy() {}
+ virtual ~RestrictSchedPolicy() {}
+
+ virtual ResultExpr EvaluateSyscall(int sysno) const OVERRIDE {
+ switch (sysno) {
+ case __NR_sched_getaffinity:
+ return RestrictSchedTarget(getpid(), sysno);
+ default:
+ return Allow();
+ }
+ }
+};
+
+void CheckSchedGetAffinity(pid_t pid, cpu_set_t* mask) {
+ BPF_ASSERT_EQ(0, sched_getaffinity(pid, sizeof(*mask), mask));
+}
+
+void SchedGetAffinityThread() {
+ const pid_t pid = getpid();
+ const pid_t tid = syscall(__NR_gettid);
+ BPF_ASSERT_NE(pid, tid);
+
+ cpu_set_t current_pid_mask;
+ CheckSchedGetAffinity(pid, &current_pid_mask);
+
+ cpu_set_t zero_mask;
+ CheckSchedGetAffinity(0, &zero_mask);
+
+ cpu_set_t tid_mask;
+ CheckSchedGetAffinity(tid, &tid_mask);
+
+ BPF_ASSERT(CPU_EQUAL(&zero_mask, &tid_mask));
jln (very slow on Chromium) 2014/09/22 21:56:44 Could you add some testing of errno if you make so
rickyz (no longer on Chrome) 2014/09/23 06:03:20 Done.
+}
+
+BPF_TEST_C(ParameterRestrictions,
+ sched_getaffinity_allowed,
+ RestrictClockIdPolicy) {
+ // Run the actual test in a new thread so that the current pid and tid are
+ // different.
+ base::Thread getaffinity_thread("getaffinity_thread");
+ BPF_ASSERT(getaffinity_thread.Start());
+ getaffinity_thread.message_loop()->PostTask(
+ FROM_HERE, base::Bind(&SchedGetAffinityThread));
+ getaffinity_thread.Stop();
jln (very slow on Chromium) 2014/09/22 21:56:44 You need synchronization here to make sure that yo
rickyz (no longer on Chrome) 2014/09/23 06:03:20 Done.
+}
+
+BPF_DEATH_TEST_C(ParameterRestrictions,
+ sched_getaffinity_crash_non_zero,
+ DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()),
+ RestrictSchedPolicy) {
+ const pid_t kInitPID = 1;
+ cpu_set_t mask;
+ sched_getaffinity(kInitPID, sizeof(mask), &mask);
+}
+
} // namespace
} // namespace sandbox

Powered by Google App Engine
This is Rietveld 408576698