1 |
commit: a0285db815b3604899453c215cce93df74066fdc |
2 |
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 17 00:22:29 2016 +0000 |
4 |
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 17 00:22:29 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/sandbox.git/commit/?id=a0285db8 |
7 |
|
8 |
tests: add test for overriding mmap |
9 |
|
10 |
URL: http://bugs.gentoo.org/290249 |
11 |
Reported-by: Diego E. Pettenò <flameeyes <AT> gentoo.org> |
12 |
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org> |
13 |
|
14 |
tests/Makefile.am | 3 +++ |
15 |
tests/execvp-0.c | 15 +++++++++++++++ |
16 |
tests/malloc-0 | 7 +++++++ |
17 |
tests/malloc-1.sh | 4 ++++ |
18 |
tests/malloc.at | 1 + |
19 |
tests/malloc_mmap_tst.c | 26 ++++++++++++++++++++++++++ |
20 |
6 files changed, 56 insertions(+) |
21 |
|
22 |
diff --git a/tests/Makefile.am b/tests/Makefile.am |
23 |
index 3627344..943ce3b 100644 |
24 |
--- a/tests/Makefile.am |
25 |
+++ b/tests/Makefile.am |
26 |
@@ -18,6 +18,7 @@ check_PROGRAMS = \ |
27 |
chown-0 \ |
28 |
creat-0 \ |
29 |
creat64-0 \ |
30 |
+ execvp-0 \ |
31 |
faccessat-0 \ |
32 |
fchmodat-0 \ |
33 |
fchownat-0 \ |
34 |
@@ -72,6 +73,7 @@ check_PROGRAMS = \ |
35 |
\ |
36 |
getcwd-gnulib_tst \ |
37 |
libsigsegv_tst \ |
38 |
+ malloc_mmap_tst \ |
39 |
pipe-fork_tst \ |
40 |
pipe-fork_static_tst \ |
41 |
sb_printf_tst \ |
42 |
@@ -81,6 +83,7 @@ check_PROGRAMS = \ |
43 |
|
44 |
dist_check_SCRIPTS = \ |
45 |
$(wildcard $(srcdir)/*-[0-9]*.sh) \ |
46 |
+ malloc-0 \ |
47 |
script-0 \ |
48 |
trace-0 |
49 |
|
50 |
|
51 |
diff --git a/tests/execvp-0.c b/tests/execvp-0.c |
52 |
new file mode 100644 |
53 |
index 0000000..6cfce13 |
54 |
--- /dev/null |
55 |
+++ b/tests/execvp-0.c |
56 |
@@ -0,0 +1,15 @@ |
57 |
+/* |
58 |
+ * A simple wrapper for execvp. Useful when most host programs don't match |
59 |
+ * the ABI of the active libsandbox.so (e.g. 64bit vs 32bit). |
60 |
+ */ |
61 |
+ |
62 |
+#include "tests.h" |
63 |
+ |
64 |
+int main(int argc, char *argv[]) |
65 |
+{ |
66 |
+ if (argc < 2) { |
67 |
+ printf("usage: execvp <path> [argv0 [argvN] ...]\n"); |
68 |
+ return 0; |
69 |
+ } |
70 |
+ return execvp(argv[1], argv + 2); |
71 |
+} |
72 |
|
73 |
diff --git a/tests/malloc-0 b/tests/malloc-0 |
74 |
new file mode 100755 |
75 |
index 0000000..9a4190b |
76 |
--- /dev/null |
77 |
+++ b/tests/malloc-0 |
78 |
@@ -0,0 +1,7 @@ |
79 |
+#!/bin/sh |
80 |
+# make sure `timeout` is available. |
81 |
+if timeout --help >/dev/null ; then |
82 |
+ exit 0 |
83 |
+else |
84 |
+ exit 77 |
85 |
+fi |
86 |
|
87 |
diff --git a/tests/malloc-1.sh b/tests/malloc-1.sh |
88 |
new file mode 100755 |
89 |
index 0000000..2b5623d |
90 |
--- /dev/null |
91 |
+++ b/tests/malloc-1.sh |
92 |
@@ -0,0 +1,4 @@ |
93 |
+#!/bin/sh |
94 |
+# Since the malloc binary is in the target ABI, make sure the exec is |
95 |
+# launched from the same ABI so the same libsandbox.so is used. |
96 |
+timeout -s KILL 10 execvp-0 malloc_mmap_tst malloc_mmap_tst |
97 |
|
98 |
diff --git a/tests/malloc.at b/tests/malloc.at |
99 |
new file mode 100644 |
100 |
index 0000000..081d7d2 |
101 |
--- /dev/null |
102 |
+++ b/tests/malloc.at |
103 |
@@ -0,0 +1 @@ |
104 |
+SB_CHECK(1) |
105 |
|
106 |
diff --git a/tests/malloc_mmap_tst.c b/tests/malloc_mmap_tst.c |
107 |
new file mode 100644 |
108 |
index 0000000..a1a15e1 |
109 |
--- /dev/null |
110 |
+++ b/tests/malloc_mmap_tst.c |
111 |
@@ -0,0 +1,26 @@ |
112 |
+/* Make sure programs that override mmap don't mess us up. #290249 */ |
113 |
+ |
114 |
+#include "headers.h" |
115 |
+ |
116 |
+/* A few basic stubs that do nothing. */ |
117 |
+void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) |
118 |
+{ |
119 |
+ errno = ENOMEM; |
120 |
+ return MAP_FAILED; |
121 |
+} |
122 |
+int munmap(void *addr, size_t length) |
123 |
+{ |
124 |
+ errno = ENOMEM; |
125 |
+ return -1; |
126 |
+} |
127 |
+ |
128 |
+int main(int argc, char *argv[]) |
129 |
+{ |
130 |
+ /* Don't loop forever. */ |
131 |
+ alarm(10); |
132 |
+ |
133 |
+ /* Make sure we do an operation to trigger the sandbox. */ |
134 |
+ open("/dev/null", 0); |
135 |
+ |
136 |
+ return 0; |
137 |
+} |