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

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

Issue 11096012: Add a platform-specific syscall number iterator. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 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 unified diff | Download patch
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/seccomp-bpf/syscall_iterator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <ostream> 5 #include <ostream>
6 6
7 #include "sandbox/linux/seccomp-bpf/bpf_tests.h" 7 #include "sandbox/linux/seccomp-bpf/bpf_tests.h"
8 #include "sandbox/linux/seccomp-bpf/verifier.h" 8 #include "sandbox/linux/seccomp-bpf/verifier.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 28 matching lines...) Expand all
39 } 39 }
40 40
41 // A simple blacklist test 41 // A simple blacklist test
42 42
43 ErrorCode BlacklistNanosleepPolicy(int sysno) { 43 ErrorCode BlacklistNanosleepPolicy(int sysno) {
44 if (sysno < static_cast<int>(MIN_SYSCALL) || 44 if (sysno < static_cast<int>(MIN_SYSCALL) ||
45 sysno > static_cast<int>(MAX_SYSCALL)) { 45 sysno > static_cast<int>(MAX_SYSCALL)) {
46 // FIXME: we should really not have to do that in a trivial policy 46 // FIXME: we should really not have to do that in a trivial policy
47 return ErrorCode(ENOSYS); 47 return ErrorCode(ENOSYS);
48 } 48 }
49 #if defined(__arm__)
50 if (!Sandbox::isArmPrivateSyscall(sysno)) {
51 return ErrorCode(ENOSYS);
52 }
53 #endif
49 switch (sysno) { 54 switch (sysno) {
50 case __NR_nanosleep: 55 case __NR_nanosleep:
51 return ErrorCode(EACCES); 56 return ErrorCode(EACCES);
52 default: 57 default:
53 return ErrorCode(ErrorCode::ERR_ALLOWED); 58 return ErrorCode(ErrorCode::ERR_ALLOWED);
54 } 59 }
55 } 60 }
56 61
57 BPF_TEST(SandboxBpf, ApplyBasicBlacklistPolicy, BlacklistNanosleepPolicy) { 62 BPF_TEST(SandboxBpf, ApplyBasicBlacklistPolicy, BlacklistNanosleepPolicy) {
58 // nanosleep() should be denied 63 // nanosleep() should be denied
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 *(static_cast<int*>(aux)) = kExpectedReturnValue; 103 *(static_cast<int*>(aux)) = kExpectedReturnValue;
99 return -ENOMEM; 104 return -ENOMEM;
100 } 105 }
101 106
102 ErrorCode BlacklistNanosleepPolicySigsys(int sysno) { 107 ErrorCode BlacklistNanosleepPolicySigsys(int sysno) {
103 if (sysno < static_cast<int>(MIN_SYSCALL) || 108 if (sysno < static_cast<int>(MIN_SYSCALL) ||
104 sysno > static_cast<int>(MAX_SYSCALL)) { 109 sysno > static_cast<int>(MAX_SYSCALL)) {
105 // FIXME: we should really not have to do that in a trivial policy 110 // FIXME: we should really not have to do that in a trivial policy
106 return ErrorCode(ENOSYS); 111 return ErrorCode(ENOSYS);
107 } 112 }
113 #if defined(__arm__)
114 if (!Sandbox::isArmPrivateSyscall(sysno)) {
115 return ErrorCode(ENOSYS);
116 }
117 #endif
108 switch (sysno) { 118 switch (sysno) {
109 case __NR_nanosleep: 119 case __NR_nanosleep:
110 return Sandbox::Trap(EnomemHandler, 120 return Sandbox::Trap(EnomemHandler,
111 static_cast<void *>(&BlacklistNanosleepPolicySigsysAuxData)); 121 static_cast<void *>(&BlacklistNanosleepPolicySigsysAuxData));
112 default: 122 default:
113 return ErrorCode(ErrorCode::ERR_ALLOWED); 123 return ErrorCode(ErrorCode::ERR_ALLOWED);
114 } 124 }
115 } 125 }
116 126
117 BPF_TEST(SandboxBpf, BasicBlacklistWithSigsys, 127 BPF_TEST(SandboxBpf, BasicBlacklistWithSigsys,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 // exit_group() is special 204 // exit_group() is special
195 continue; 205 continue;
196 } 206 }
197 errno = 0; 207 errno = 0;
198 BPF_ASSERT(syscall(syscall_number) == -1); 208 BPF_ASSERT(syscall(syscall_number) == -1);
199 BPF_ASSERT(errno == SysnoToRandomErrno(syscall_number)); 209 BPF_ASSERT(errno == SysnoToRandomErrno(syscall_number));
200 } 210 }
201 } 211 }
202 212
203 } // namespace 213 } // namespace
OLDNEW
« no previous file with comments | « sandbox/linux/seccomp-bpf/sandbox_bpf.cc ('k') | sandbox/linux/seccomp-bpf/syscall_iterator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698