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

Side by Side Diff: sandbox/linux/seccomp-bpf/syscall_unittest.cc

Issue 101773003: Linux sandbox: cleanup sandbox-bpf naming. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address namespace sandbox nits. Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <asm/unistd.h> 5 #include <asm/unistd.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <sys/mman.h> 7 #include <sys/mman.h>
8 #include <sys/syscall.h> 8 #include <sys/syscall.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/posix/eintr_wrapper.h" 14 #include "base/posix/eintr_wrapper.h"
15 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" 15 #include "sandbox/linux/seccomp-bpf/bpf_tests.h"
16 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" 16 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
17 #include "sandbox/linux/seccomp-bpf/syscall.h" 17 #include "sandbox/linux/seccomp-bpf/syscall.h"
18 #include "sandbox/linux/tests/unit_tests.h" 18 #include "sandbox/linux/tests/unit_tests.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using namespace playground2; 21 namespace sandbox {
22 22
23 namespace { 23 namespace {
24 24
25 // Different platforms use different symbols for the six-argument version 25 // Different platforms use different symbols for the six-argument version
26 // of the mmap() system call. Test for the correct symbol at compile time. 26 // of the mmap() system call. Test for the correct symbol at compile time.
27 #ifdef __NR_mmap2 27 #ifdef __NR_mmap2
28 const int kMMapNr = __NR_mmap2; 28 const int kMMapNr = __NR_mmap2;
29 #else 29 #else
30 const int kMMapNr = __NR_mmap; 30 const int kMMapNr = __NR_mmap;
31 #endif 31 #endif
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 // SIGSYS trap handler that will be called on __NR_uname. 71 // SIGSYS trap handler that will be called on __NR_uname.
72 intptr_t CopySyscallArgsToAux(const struct arch_seccomp_data& args, void* aux) { 72 intptr_t CopySyscallArgsToAux(const struct arch_seccomp_data& args, void* aux) {
73 // |aux| is a pointer to our BPF_AUX. 73 // |aux| is a pointer to our BPF_AUX.
74 std::vector<uint64_t>* const seen_syscall_args = 74 std::vector<uint64_t>* const seen_syscall_args =
75 static_cast<std::vector<uint64_t>*>(aux); 75 static_cast<std::vector<uint64_t>*>(aux);
76 BPF_ASSERT(arraysize(args.args) == 6); 76 BPF_ASSERT(arraysize(args.args) == 6);
77 seen_syscall_args->assign(args.args, args.args + arraysize(args.args)); 77 seen_syscall_args->assign(args.args, args.args + arraysize(args.args));
78 return -ENOMEM; 78 return -ENOMEM;
79 } 79 }
80 80
81 ErrorCode CopyAllArgsOnUnamePolicy(Sandbox* sandbox, int sysno, void* aux) { 81 ErrorCode CopyAllArgsOnUnamePolicy(SandboxBPF* sandbox, int sysno, void* aux) {
82 if (!Sandbox::IsValidSyscallNumber(sysno)) { 82 if (!SandboxBPF::IsValidSyscallNumber(sysno)) {
83 return ErrorCode(ENOSYS); 83 return ErrorCode(ENOSYS);
84 } 84 }
85 if (sysno == __NR_uname) { 85 if (sysno == __NR_uname) {
86 return sandbox->Trap(CopySyscallArgsToAux, aux); 86 return sandbox->Trap(CopySyscallArgsToAux, aux);
87 } else { 87 } else {
88 return ErrorCode(ErrorCode::ERR_ALLOWED); 88 return ErrorCode(ErrorCode::ERR_ALLOWED);
89 } 89 }
90 } 90 }
91 91
92 // We are testing SandboxSyscall() by making use of a BPF filter that allows us 92 // We are testing SandboxSyscall() by making use of a BPF filter that allows us
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 EXPECT_EQ(8192, SandboxSyscall(__NR_read, fd, buf, 8192L)); 190 EXPECT_EQ(8192, SandboxSyscall(__NR_read, fd, buf, 8192L));
191 EXPECT_EQ(0, memcmp(addr2, buf, 8192)); 191 EXPECT_EQ(0, memcmp(addr2, buf, 8192));
192 192
193 // Clean up 193 // Clean up
194 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr2, 8192L)); 194 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr2, 8192L));
195 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr3, 4096L)); 195 EXPECT_EQ(0, SandboxSyscall(__NR_munmap, addr3, 4096L));
196 EXPECT_EQ(0, IGNORE_EINTR(SandboxSyscall(__NR_close, fd))); 196 EXPECT_EQ(0, IGNORE_EINTR(SandboxSyscall(__NR_close, fd)));
197 } 197 }
198 198
199 } // namespace 199 } // namespace
200
201 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/syscall_iterator_unittest.cc ('k') | sandbox/linux/seccomp-bpf/trap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698