OLD | NEW |
---|---|
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 "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | 5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" |
6 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | 6 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" |
7 #include "sandbox/linux/tests/unit_tests.h" | 7 #include "sandbox/linux/tests/unit_tests.h" |
8 | 8 |
9 namespace sandbox { | 9 namespace sandbox { |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 } | 22 } |
23 for (uint32_t last = next; !iter.Done(); last = next) { | 23 for (uint32_t last = next; !iter.Done(); last = next) { |
24 next = iter.Next(); | 24 next = iter.Next(); |
25 SANDBOX_ASSERT(last < next); | 25 SANDBOX_ASSERT(last < next); |
26 } | 26 } |
27 // The iterator should always return 0xFFFFFFFFu as the last value. | 27 // The iterator should always return 0xFFFFFFFFu as the last value. |
28 SANDBOX_ASSERT(next == 0xFFFFFFFFu); | 28 SANDBOX_ASSERT(next == 0xFFFFFFFFu); |
29 } | 29 } |
30 } | 30 } |
31 | 31 |
32 SANDBOX_TEST(SyscallIterator, PublicSyscallRange) { | 32 #if defined(__mips__) |
33 SANDBOX_TEST(SyscallIterator, PublicSyscallRangeMIPS) { | |
33 SyscallIterator iter(false); | 34 SyscallIterator iter(false); |
34 uint32_t next = iter.Next(); | 35 uint32_t next = iter.Next(); |
jln (very slow on Chromium)
2014/06/20 00:37:06
Assert that's its 0?
nedeljko
2014/06/20 14:09:51
Done.
| |
35 | 36 |
37 // Since on MIPS MIN_SYSCALL != 0 we need to move iterator to valid range. | |
38 next = iter.Next(); | |
39 SANDBOX_ASSERT(next == MIN_SYSCALL - 1); | |
40 | |
41 // The iterator should cover the public syscall range | |
42 // MIN_SYSCALL..MAX_PUBLIC_SYSCALL, without skipping syscalls. | |
43 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL + 1; last = next) { | |
44 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | |
45 } | |
46 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | |
47 } | |
48 #else | |
49 SANDBOX_TEST(SyscallIterator, PublicSyscallRangeIntelArm) { | |
50 SyscallIterator iter(false); | |
51 uint32_t next = iter.Next(); | |
52 | |
36 // The iterator should cover the public syscall range | 53 // The iterator should cover the public syscall range |
37 // MIN_SYSCALL..MAX_PUBLIC_SYSCALL, without skipping syscalls. | 54 // MIN_SYSCALL..MAX_PUBLIC_SYSCALL, without skipping syscalls. |
38 // We're assuming MIN_SYSCALL == 0 for all architectures, | 55 // We're assuming MIN_SYSCALL == 0 for all architectures, |
39 // this is currently valid for Intel and ARM EABI. | 56 // this is currently valid for Intel and ARM EABI. |
40 SANDBOX_ASSERT(MIN_SYSCALL == 0); | 57 SANDBOX_ASSERT(MIN_SYSCALL == 0); |
41 SANDBOX_ASSERT(next == MIN_SYSCALL); | 58 SANDBOX_ASSERT(next == MIN_SYSCALL); |
42 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL + 1; last = next) { | 59 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL + 1; last = next) { |
43 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | 60 SANDBOX_ASSERT((next = iter.Next()) == last + 1); |
44 } | 61 } |
45 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | 62 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); |
46 } | 63 } |
64 #endif // defined(__mips__) | |
47 | 65 |
48 #if defined(__arm__) | 66 #if defined(__arm__) |
49 SANDBOX_TEST(SyscallIterator, ARMPrivateSyscallRange) { | 67 SANDBOX_TEST(SyscallIterator, ARMPrivateSyscallRange) { |
50 SyscallIterator iter(false); | 68 SyscallIterator iter(false); |
51 uint32_t next = iter.Next(); | 69 uint32_t next = iter.Next(); |
52 while (next < MIN_PRIVATE_SYSCALL - 1) { | 70 while (next < MIN_PRIVATE_SYSCALL - 1) { |
53 next = iter.Next(); | 71 next = iter.Next(); |
54 } | 72 } |
55 // The iterator should cover the ARM private syscall range | 73 // The iterator should cover the ARM private syscall range |
56 // without skipping syscalls. | 74 // without skipping syscalls. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 SANDBOX_ASSERT(next == 0x7FFFFFFFu); | 114 SANDBOX_ASSERT(next == 0x7FFFFFFFu); |
97 next = iter.Next(); | 115 next = iter.Next(); |
98 SANDBOX_ASSERT(next == 0x80000000u); | 116 SANDBOX_ASSERT(next == 0x80000000u); |
99 SANDBOX_ASSERT(!iter.Done()); | 117 SANDBOX_ASSERT(!iter.Done()); |
100 next = iter.Next(); | 118 next = iter.Next(); |
101 SANDBOX_ASSERT(iter.Done()); | 119 SANDBOX_ASSERT(iter.Done()); |
102 SANDBOX_ASSERT(next == 0xFFFFFFFFu); | 120 SANDBOX_ASSERT(next == 0xFFFFFFFFu); |
103 } | 121 } |
104 } | 122 } |
105 | 123 |
106 SANDBOX_TEST(SyscallIterator, InvalidOnly) { | 124 #if defined(__mips__) |
125 SANDBOX_TEST(SyscallIterator, InvalidOnlyMIPS) { | |
107 bool invalid_only = true; | 126 bool invalid_only = true; |
108 SyscallIterator iter(invalid_only); | 127 SyscallIterator iter(invalid_only); |
109 uint32_t next = iter.Next(); | 128 uint32_t next = iter.Next(); |
129 SANDBOX_ASSERT(next == 0); | |
130 // For Mips O32 ABI we're assuming MIN_SYSCALL == 4000. | |
131 SANDBOX_ASSERT(MIN_SYSCALL == 4000); | |
132 | |
133 // Since on MIPS MIN_SYSCALL != 0, we need to move iterator to valid range | |
134 // The iterator should skip until the last invalid syscall in this range. | |
135 next = iter.Next(); | |
136 SANDBOX_ASSERT(next == MIN_SYSCALL - 1); | |
137 next = iter.Next(); | |
138 // First next invalid syscall should then be |MAX_PUBLIC_SYSCALL + 1|. | |
139 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | |
140 } | |
141 | |
142 #else | |
143 | |
144 SANDBOX_TEST(SyscallIterator, InvalidOnlyIntelArm) { | |
145 bool invalid_only = true; | |
146 SyscallIterator iter(invalid_only); | |
147 uint32_t next = iter.Next(); | |
110 // We're assuming MIN_SYSCALL == 0 for all architectures, | 148 // We're assuming MIN_SYSCALL == 0 for all architectures, |
111 // this is currently valid for Intel and ARM EABI. | 149 // this is currently valid for Intel and ARM EABI. |
112 // First invalid syscall should then be |MAX_PUBLIC_SYSCALL + 1|. | 150 // First invalid syscall should then be |MAX_PUBLIC_SYSCALL + 1|. |
113 SANDBOX_ASSERT(MIN_SYSCALL == 0); | 151 SANDBOX_ASSERT(MIN_SYSCALL == 0); |
114 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | 152 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); |
115 | 153 |
116 #if defined(__arm__) | 154 #if defined(__arm__) |
117 next = iter.Next(); | 155 next = iter.Next(); |
118 // The iterator should skip until the last invalid syscall in this range. | 156 // The iterator should skip until the last invalid syscall in this range. |
119 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL - 1); | 157 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL - 1); |
120 while (next <= MAX_PRIVATE_SYSCALL) { | 158 while (next <= MAX_PRIVATE_SYSCALL) { |
121 next = iter.Next(); | 159 next = iter.Next(); |
122 } | 160 } |
123 | 161 |
124 next = iter.Next(); | 162 next = iter.Next(); |
125 // The iterator should skip until the last invalid syscall in this range. | 163 // The iterator should skip until the last invalid syscall in this range. |
126 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); | 164 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); |
127 while (next <= MAX_SYSCALL) { | 165 while (next <= MAX_SYSCALL) { |
128 next = iter.Next(); | 166 next = iter.Next(); |
129 } | 167 } |
130 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | 168 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); |
131 #endif | 169 #endif // defined(__arm__) |
132 } | 170 } |
171 #endif // defined(__mips__) | |
133 | 172 |
134 } // namespace | 173 } // namespace |
135 | 174 |
136 } // namespace sandbox | 175 } // namespace sandbox |
OLD | NEW |