OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sandbox/linux/seccomp-bpf/sandbox_bpf.h" | |
6 #include "sandbox/linux/seccomp-bpf/syscall_iterator.h" | |
7 #include "sandbox/linux/tests/unit_tests.h" | |
8 | |
9 using namespace playground2; | |
10 | |
11 namespace { | |
12 | |
13 SANDBOX_TEST(SyscallIterator, Monotonous) { | |
14 // We're assuming MIN_SYSCALL == 0 for all architectures. | |
15 // This is currently valid for Intel and ARM EABI. | |
16 SANDBOX_ASSERT(MIN_SYSCALL == 0u); | |
jln (very slow on Chromium)
2012/10/13 02:44:22
This assert is confusing, because I don't think an
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
17 | |
18 for (int i = 0; i < 2; ++i) { | |
19 bool invalid_only = !i; // Testing both |invalid_only| cases. | |
20 SyscallIterator iter(invalid_only); | |
21 uint32_t next = iter.Next(); | |
22 | |
23 if (!invalid_only) { | |
24 // MIN_SYSCALL should be the first valid syscall. | |
25 SANDBOX_ASSERT(next == MIN_SYSCALL); | |
jln (very slow on Chromium)
2012/10/13 02:44:22
I think 0 was correct there. The contract (syscall
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
26 } | |
27 for (uint32_t last = next; !iter.Done(); last = next) { | |
28 next = iter.Next(); | |
29 SANDBOX_ASSERT(last < next); | |
30 } | |
31 // The iterator should return 0xFFFFFFFFu as the last value. | |
32 SANDBOX_ASSERT(next == 0xFFFFFFFFu); | |
33 } | |
34 } | |
35 | |
36 SANDBOX_TEST(SyscallIterator, PublicSyscallRange) { | |
37 // We're assuming MIN_SYSCALL == 0 for all architectures. | |
38 // This is currently valid for Intel and ARM EABI. | |
39 SANDBOX_ASSERT(MIN_SYSCALL == 0u); | |
jln (very slow on Chromium)
2012/10/13 02:44:22
Assertions are nice in a place where they help to
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
40 | |
41 SyscallIterator iter(false); | |
42 uint32_t next = iter.Next(); | |
43 | |
44 // The iterator should cover the public syscall range | |
45 // without skipping syscalls. | |
46 SANDBOX_ASSERT(next == MIN_SYSCALL); | |
jln (very slow on Chromium)
2012/10/13 02:44:22
It's not obvious why you'd assert that. You can as
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
47 for (uint32_t last = next; next < MAX_PUBLIC_SYSCALL + 1; last = next) { | |
48 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | |
49 } | |
50 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | |
51 } | |
52 | |
53 #if defined(__arm__) | |
54 SANDBOX_TEST(SyscallIterator, ARMPrivateSyscallRange) { | |
55 SyscallIterator iter(false); | |
56 uint32_t next = iter.Next(); | |
57 while (next < MIN_PRIVATE_SYSCALL - 1) { | |
jln (very slow on Chromium)
2012/10/13 02:44:22
This is an implementation detail that we'll actual
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
58 next = iter.Next(); | |
59 } | |
60 // The iterator should cover the ARM private syscall range | |
61 // without skipping syscalls. | |
62 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL - 1); | |
63 for (uint32_t last = next; next < MAX_PRIVATE_SYSCALL + 1; last = next) { | |
64 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | |
65 } | |
66 SANDBOX_ASSERT(next == MAX_PRIVATE_SYSCALL + 1); | |
67 } | |
68 | |
69 SANDBOX_TEST(SyscallIterator, ARMHiddenSyscallRange) { | |
70 SyscallIterator iter(false); | |
71 uint32_t next = iter.Next(); | |
72 while (next < MIN_GHOST_SYSCALL - 1) { | |
jln (very slow on Chromium)
2012/10/13 02:44:22
The same remark as above applies.
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
73 next = iter.Next(); | |
74 } | |
75 // The iterator should cover the ARM hidden syscall range | |
76 // without skipping syscalls. | |
77 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); | |
78 for (uint32_t last = next; next < MAX_SYSCALL + 1; last = next) { | |
79 SANDBOX_ASSERT((next = iter.Next()) == last + 1); | |
80 } | |
81 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | |
82 } | |
83 #endif | |
84 | |
85 SANDBOX_TEST(SyscallIterator, Invalid) { | |
86 for (int i = 0; i < 2; ++i) { | |
87 bool invalid_only = !i; // Testing both |invalid_only| cases. | |
88 SyscallIterator iter(invalid_only); | |
89 uint32_t next = iter.Next(); | |
90 | |
91 while (next < MAX_SYSCALL + 1) { | |
92 next = iter.Next(); | |
93 } | |
94 | |
95 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | |
96 while (next < 0x7FFFFFFFu) { | |
97 next = iter.Next(); | |
98 } | |
99 | |
100 // The iterator should return the signed/unsigned corner cases. | |
101 SANDBOX_ASSERT(next == 0x7FFFFFFFu); | |
jln (very slow on Chromium)
2012/10/13 02:44:22
I don't really like that this is testing implement
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
102 next = iter.Next(); | |
103 SANDBOX_ASSERT(next == 0x80000000u); | |
104 SANDBOX_ASSERT(!iter.Done()); | |
105 next = iter.Next(); | |
106 SANDBOX_ASSERT(iter.Done()); | |
107 SANDBOX_ASSERT(next == 0xFFFFFFFFu); | |
108 } | |
109 } | |
110 | |
111 SANDBOX_TEST(SyscallIterator, InvalidOnly) { | |
112 bool invalid_only = true; | |
113 SyscallIterator iter(invalid_only); | |
114 uint32_t next = iter.Next(); | |
115 // First invalid syscall should be |MAX_PUBLIC_SYSCALL + 1|. | |
jln (very slow on Chromium)
2012/10/13 02:44:22
This is only true if 0 is a valid syscall, otherwi
Jorge Lucangeli Obes
2012/10/13 04:45:42
Done.
| |
116 SANDBOX_ASSERT(next == MAX_PUBLIC_SYSCALL + 1); | |
117 | |
118 #if defined(__arm__) | |
119 next = iter.Next(); | |
120 // The iterator should skip until the last invalid syscall in this range. | |
121 SANDBOX_ASSERT(next == MIN_PRIVATE_SYSCALL - 1); | |
122 while (next <= MAX_PRIVATE_SYSCALL) { | |
123 next = iter.Next(); | |
jln (very slow on Chromium)
2012/10/13 02:44:22
You're testing implementation details. In fact the
Jorge Lucangeli Obes
2012/10/13 04:45:42
The notion of an iterator and the wording in the i
| |
124 } | |
125 | |
126 next = iter.Next(); | |
127 // The iterator should skip until the last invalid syscall in this range. | |
128 SANDBOX_ASSERT(next == MIN_GHOST_SYSCALL - 1); | |
129 while (next <= MAX_SYSCALL) { | |
130 next = iter.Next(); | |
131 } | |
132 SANDBOX_ASSERT(next == MAX_SYSCALL + 1); | |
133 #endif | |
134 } | |
135 | |
136 } // namespace | |
137 | |
OLD | NEW |