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

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

Issue 1295513003: Non-SFI mode: Sandbox support for NaCl async-signals. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Used the correct constant for SIGUSR1 Created 5 years, 4 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_unittest.cc
diff --git a/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc b/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
index 4338fb6fe295555f5f63aa4014aa9b78124f87bc..a95a6d016c5dd5e0f207058ad59992c326862429 100644
--- a/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
+++ b/components/nacl/loader/nonsfi/nonsfi_sandbox_unittest.cc
@@ -641,6 +641,70 @@ BPF_DEATH_TEST_C(NaClNonSfiSandboxTest,
sandbox::Syscall::InvalidCall();
}
+// The following tests check for several restrictions in tgkill(). A delegate is
+// needed to be able to call getpid() from inside the process that will be
+// sandboxed, but before the sandbox is installed.
+template<void(*callback)(int pid, int tid)>
+class TgkillDelegate : public sandbox::BPFTesterDelegate {
+ public:
+ TgkillDelegate() {}
+ ~TgkillDelegate() override {}
+
+ scoped_ptr<sandbox::bpf_dsl::Policy> GetSandboxBPFPolicy() override {
+ // These two values must be obtained when running in the sandboxed process.
+ // They cannot be set in the constructor and are also not available from
+ // within |RunTestFunction|.
+ pid_ = getpid();
+ tid_ = syscall(__NR_gettid);
+
+ return scoped_ptr<sandbox::bpf_dsl::Policy>(
+ new nacl::nonsfi::NaClNonSfiBPFSandboxPolicy());
+ }
+
+ void RunTestFunction() override {
+ callback(pid_, tid_);
+ }
+
+ int pid_;
+ int tid_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TgkillDelegate);
+};
+
+#define BPF_TGKILL_TEST(name) \
+ void BPF_TEST_D_##name(int pid, int tid); \
+ BPF_TEST_D(NaClNonSfiSandboxTest, \
+ name, \
+ TgkillDelegate<BPF_TEST_D_##name>); \
+ void BPF_TEST_D_##name(int pid, int tid) \
+
+#define BPF_TGKILL_DEATH_TEST(name) \
+ void BPF_TEST_D_##name(int pid, int tid); \
+ BPF_DEATH_TEST_D( \
+ NaClNonSfiSandboxTest, \
+ name, \
+ DEATH_SEGV_MESSAGE(sandbox::GetErrorMessageContentForTests()), \
+ TgkillDelegate<BPF_TEST_D_##name>); \
+ void BPF_TEST_D_##name(int pid, int tid) \
+
+BPF_TGKILL_DEATH_TEST(tgkill_with_invalid_signum) {
jln (very slow on Chromium) 2015/08/17 21:21:11 The complexity of BPF test is already considerable
Luis Héctor Chávez 2015/08/17 22:13:07 Done.
+ syscall(__NR_tgkill, pid, tid, SIGKILL);
+}
+
+BPF_TGKILL_DEATH_TEST(tgkill_with_invalid_tgid) {
+ syscall(__NR_tgkill, 1, tid, LINUX_SIGUSR1);
+}
+
+BPF_TGKILL_DEATH_TEST(tgkill_with_negative_tid) {
+ syscall(__NR_tgkill, pid, -1, LINUX_SIGUSR1);
+}
+
+BPF_TGKILL_TEST(tgkill_with_invalid_tid) {
+ BPF_ASSERT_EQ(-1, syscall(__NR_tgkill, pid, 1, LINUX_SIGUSR1));
+ BPF_ASSERT_EQ(ESRCH, errno);
+}
+
// The following test cases check if syscalls return EPERM regardless
// of arguments.
#define RESTRICT_SYSCALL_EPERM_TEST(name) \

Powered by Google App Engine
This is Rietveld 408576698