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 |
11 namespace { | 11 namespace { |
12 | 12 |
13 SANDBOX_TEST(SyscallIterator, Monotonous) { | 13 SANDBOX_TEST(SyscallIterator, Monotonous) { |
14 for (int i = 0; i < 2; ++i) { | 14 for (int i = 0; i < 2; ++i) { |
15 bool invalid_only = !i; // Testing both |invalid_only| cases. | 15 bool invalid_only = !i; // Testing both |invalid_only| cases. |
16 SyscallIterator iter(invalid_only); | 16 SyscallIterator iter(invalid_only); |
17 uint32_t next = iter.Next(); | 17 uint32_t next = iter.Next(); |
18 | 18 |
19 if (!invalid_only) { | 19 if (!invalid_only) { |
20 #if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32) | |
21 // The iterator should start at 4000 for MIPS O32 ABI | |
22 SANDBOX_ASSERT(next == 4000); | |
jln (very slow on Chromium)
2014/05/02 20:42:04
This adds no value, we need to re-work these tests
nedeljko
2014/05/07 15:40:05
Done.
| |
23 #else | |
20 // The iterator should start at 0. | 24 // The iterator should start at 0. |
21 SANDBOX_ASSERT(next == 0); | 25 SANDBOX_ASSERT(next == 0); |
jln (very slow on Chromium)
2014/05/02 20:42:04
This should still hold on MIPS.
nedeljko
2014/05/07 15:40:05
Done.
| |
26 #endif | |
22 } | 27 } |
23 for (uint32_t last = next; !iter.Done(); last = next) { | 28 for (uint32_t last = next; !iter.Done(); last = next) { |
24 next = iter.Next(); | 29 next = iter.Next(); |
25 SANDBOX_ASSERT(last < next); | 30 SANDBOX_ASSERT(last < next); |
26 } | 31 } |
27 // The iterator should always return 0xFFFFFFFFu as the last value. | 32 // The iterator should always return 0xFFFFFFFFu as the last value. |
28 SANDBOX_ASSERT(next == 0xFFFFFFFFu); | 33 SANDBOX_ASSERT(next == 0xFFFFFFFFu); |
29 } | 34 } |
30 } | 35 } |
31 | 36 |
32 SANDBOX_TEST(SyscallIterator, PublicSyscallRange) { | 37 SANDBOX_TEST(SyscallIterator, PublicSyscallRange) { |
33 SyscallIterator iter(false); | 38 SyscallIterator iter(false); |
34 uint32_t next = iter.Next(); | 39 uint32_t next = iter.Next(); |
35 | 40 |
36 // The iterator should cover the public syscall range | 41 // The iterator should cover the public syscall range |
37 // MIN_SYSCALL..MAX_PUBLIC_SYSCALL, without skipping syscalls. | 42 // MIN_SYSCALL..MAX_PUBLIC_SYSCALL, without skipping syscalls. |
38 // We're assuming MIN_SYSCALL == 0 for all architectures, | 43 // We're assuming MIN_SYSCALL == 0 for all architectures |
39 // this is currently valid for Intel and ARM EABI. | 44 // (this is currently valid for Intel and ARM EABI), except for |
45 // Mips O32 ABI for which MIN_SYSCALL == 4000 . | |
46 #if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32) | |
47 SANDBOX_ASSERT(MIN_SYSCALL == 4000); | |
48 #else | |
40 SANDBOX_ASSERT(MIN_SYSCALL == 0); | 49 SANDBOX_ASSERT(MIN_SYSCALL == 0); |
50 #endif | |
41 SANDBOX_ASSERT(next == MIN_SYSCALL); | 51 SANDBOX_ASSERT(next == MIN_SYSCALL); |
42 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL + 1; last = next) { | 52 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL + 1; last = next) { |
43 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | 53 SANDBOX_ASSERT((next = iter.Next()) == last + 1); |
44 } | 54 } |
45 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | 55 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); |
46 } | 56 } |
47 | 57 |
48 #if defined(__arm__) | 58 #if defined(__arm__) |
49 SANDBOX_TEST(SyscallIterator, ARMPrivateSyscallRange) { | 59 SANDBOX_TEST(SyscallIterator, ARMPrivateSyscallRange) { |
50 SyscallIterator iter(false); | 60 SyscallIterator iter(false); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 next = iter.Next(); | 110 next = iter.Next(); |
101 SANDBOX_ASSERT(iter.Done()); | 111 SANDBOX_ASSERT(iter.Done()); |
102 SANDBOX_ASSERT(next == 0xFFFFFFFFu); | 112 SANDBOX_ASSERT(next == 0xFFFFFFFFu); |
103 } | 113 } |
104 } | 114 } |
105 | 115 |
106 SANDBOX_TEST(SyscallIterator, InvalidOnly) { | 116 SANDBOX_TEST(SyscallIterator, InvalidOnly) { |
107 bool invalid_only = true; | 117 bool invalid_only = true; |
108 SyscallIterator iter(invalid_only); | 118 SyscallIterator iter(invalid_only); |
109 uint32_t next = iter.Next(); | 119 uint32_t next = iter.Next(); |
110 // We're assuming MIN_SYSCALL == 0 for all architectures, | 120 // We're assuming MIN_SYSCALL == 0 for all architectures |
111 // this is currently valid for Intel and ARM EABI. | 121 // (this is currently valid for Intel and ARM EABI), except |
122 // for Mips O32 ABI for which MIN_SYSCALL == 4000. | |
112 // First invalid syscall should then be |MAX_PUBLIC_SYSCALL + 1|. | 123 // First invalid syscall should then be |MAX_PUBLIC_SYSCALL + 1|. |
124 #if defined(__mips__) && (_MIPS_SIM == _MIPS_SIM_ABI32) | |
125 SANDBOX_ASSERT(MIN_SYSCALL == 4000); | |
126 #else | |
113 SANDBOX_ASSERT(MIN_SYSCALL == 0); | 127 SANDBOX_ASSERT(MIN_SYSCALL == 0); |
128 #endif | |
114 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | 129 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); |
115 | 130 |
116 #if defined(__arm__) | 131 #if defined(__arm__) |
117 next = iter.Next(); | 132 next = iter.Next(); |
118 // The iterator should skip until the last invalid syscall in this range. | 133 // The iterator should skip until the last invalid syscall in this range. |
119 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL - 1); | 134 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL - 1); |
120 while (next <= MAX_PRIVATE_SYSCALL) { | 135 while (next <= MAX_PRIVATE_SYSCALL) { |
121 next = iter.Next(); | 136 next = iter.Next(); |
122 } | 137 } |
123 | 138 |
124 next = iter.Next(); | 139 next = iter.Next(); |
125 // The iterator should skip until the last invalid syscall in this range. | 140 // The iterator should skip until the last invalid syscall in this range. |
126 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); | 141 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); |
127 while (next <= MAX_SYSCALL) { | 142 while (next <= MAX_SYSCALL) { |
128 next = iter.Next(); | 143 next = iter.Next(); |
129 } | 144 } |
130 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | 145 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); |
131 #endif | 146 #endif |
132 } | 147 } |
133 | 148 |
134 } // namespace | 149 } // namespace |
135 | 150 |
136 } // namespace sandbox | 151 } // namespace sandbox |
OLD | NEW |