summaryrefslogtreecommitdiffstats
path: root/test/filters
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-04-30 07:27:31 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2016-04-30 07:27:31 -0400
commita1272742cfbdbfe999a701f804b58ceb4605713d (patch)
tree16d6013c8d99d9e4370d1672b4018f958081f416 /test/filters
parentMerge pull request #490 from reinerh/master (diff)
downloadfirejail-a1272742cfbdbfe999a701f804b58ceb4605713d.tar.gz
firejail-a1272742cfbdbfe999a701f804b58ceb4605713d.tar.zst
firejail-a1272742cfbdbfe999a701f804b58ceb4605713d.zip
added make test-filters
Diffstat (limited to 'test/filters')
-rwxr-xr-xtest/filters/caps.exp72
-rwxr-xr-xtest/filters/noroot.exp156
-rwxr-xr-xtest/filters/protocol.exp180
-rw-r--r--test/filters/protocol1.profile1
-rw-r--r--test/filters/protocol2.profile1
-rwxr-xr-xtest/filters/seccomp-bad-empty.exp38
-rw-r--r--test/filters/seccomp-bad-empty.profile1
-rw-r--r--test/filters/seccomp-bad-empty2.profile1
-rw-r--r--test/filters/seccomp.profile1
-rwxr-xr-xtest/filters/syscall_testbin0 -> 9552 bytes
-rw-r--r--test/filters/syscall_test.c82
-rwxr-xr-xtest/filters/syscall_test32bin0 -> 6868 bytes
12 files changed, 533 insertions, 0 deletions
diff --git a/test/filters/caps.exp b/test/filters/caps.exp
new file mode 100755
index 000000000..034d6a733
--- /dev/null
+++ b/test/filters/caps.exp
@@ -0,0 +1,72 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2016 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --caps.keep=chown,fowner --noprofile\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 "Child process initialized"
14}
15sleep 2
16
17send -- "cat /proc/self/status\r"
18expect {
19 timeout {puts "TESTING ERROR 2\n";exit}
20 "CapBnd: 0000000000000009"
21}
22expect {
23 timeout {puts "TESTING ERROR 3\n";exit}
24 "Seccomp:"
25}
26send -- "exit\r"
27sleep 1
28
29send -- "firejail --caps.drop=all --noprofile\r"
30expect {
31 timeout {puts "TESTING ERROR 4\n";exit}
32 "Child process initialized"
33}
34sleep 2
35
36send -- "cat /proc/self/status\r"
37expect {
38 timeout {puts "TESTING ERROR 5\n";exit}
39 "CapBnd: 0000000000000000"
40}
41expect {
42 timeout {puts "TESTING ERROR 6\n";exit}
43 "Seccomp:"
44}
45send -- "exit\r"
46sleep 1
47
48send -- "firejail --caps.drop=chown,dac_override,dac_read_search,fowner --noprofile\r"
49expect {
50 timeout {puts "TESTING ERROR 7\n";exit}
51 "Child process initialized"
52}
53sleep 2
54
55send -- "cat /proc/self/status\r"
56expect {
57 timeout {puts "TESTING ERROR 8\n";exit}
58 "CapBnd:"
59}
60expect {
61 timeout {puts "TESTING ERROR 9\n";exit}
62 "fffffff0"
63}
64expect {
65 timeout {puts "TESTING ERROR 10\n";exit}
66 "Seccomp:"
67}
68send -- "exit\r"
69sleep 1
70
71
72puts "\nall done\n"
diff --git a/test/filters/noroot.exp b/test/filters/noroot.exp
new file mode 100755
index 000000000..a1f6ce88d
--- /dev/null
+++ b/test/filters/noroot.exp
@@ -0,0 +1,156 @@
1#!/usr/bin/expect -f
2# This file is part of Firejail project
3# Copyright (C) 2014-2016 Firejail Authors
4# License GPL v2
5
6set timeout 10
7spawn $env(SHELL)
8match_max 100000
9
10send -- "firejail --noprofile --noroot --caps.drop=all --seccomp\r"
11expect {
12 timeout {puts "TESTING ERROR 1\n";exit}
13 "Child process initialized"
14}
15sleep 1
16
17send -- "cat /proc/self/status\r"
18expect {
19 timeout {puts "TESTING ERROR 1\n";exit}
20 "CapBnd: 0000000000000000"
21}
22expect {
23 timeout {puts "TESTING ERROR 2\n";exit}
24 "Seccomp:"
25}
26expect {
27 timeout {puts "TESTING ERROR 3\n";exit}
28 "2"
29}
30expect {
31 timeout {puts "TESTING ERROR 4\n";exit}
32 "Cpus_allowed:"
33}
34puts "\n"
35
36send -- "ping 0\r"
37expect {
38 timeout {puts "TESTING ERROR 5\n";exit}
39 "Operation not permitted"
40}
41send -- "whoami\r"
42expect {
43 timeout {puts "TESTING ERROR 6\n";exit}
44 $env(USER)
45}
46send -- "sudo -s\r"
47expect {
48 timeout {puts "TESTING ERROR 8\n";exit}
49 "effective uid is not 0, is sudo installed setuid root?" { puts "OK\n";}
50 "sudo must be owned by uid 0 and have the setuid bit set" { puts "OK\n";}
51}
52send -- "cat /proc/self/uid_map | wc -l\r"
53expect {
54 timeout {puts "TESTING ERROR 7\n";exit}
55 "1"
56}
57send -- "cat /proc/self/gid_map | wc -l\r"
58expect {
59 timeout {puts "TESTING ERROR 8\n";exit}
60 "3"
61}
62
63puts "\n"
64send -- "exit\r"
65sleep 2
66
67
68
69send -- "firejail --name=test --noroot --noprofile\r"
70expect {
71 timeout {puts "TESTING ERROR 9\n";exit}
72 "Child process initialized"
73}
74sleep 1
75
76send -- "cat /proc/self/status\r"
77expect {
78 timeout {puts "TESTING ERROR 10\n";exit}
79 "CapBnd:"
80}
81expect {
82 timeout {puts "TESTING ERROR 11\n";exit}
83 "ffffffff"
84}
85expect {
86 timeout {puts "TESTING ERROR 12\n";exit}
87 "Seccomp:"
88}
89expect {
90 timeout {puts "TESTING ERROR 13\n";exit}
91 "0"
92}
93expect {
94 timeout {puts "TESTING ERROR 14\n";exit}
95 "Cpus_allowed:"
96}
97puts "\n"
98
99send -- "whoami\r"
100expect {
101 timeout {puts "TESTING ERROR 15\n";exit}
102 $env(USER)
103}
104send -- "sudo -s\r"
105expect {
106 timeout {puts "TESTING ERROR 16\n";exit}
107 "effective uid is not 0, is sudo installed setuid root?" { puts "OK\n";}
108 "sudo must be owned by uid 0 and have the setuid bit set" { puts "OK\n";}
109}
110send -- "ping 0\r"
111expect {
112 timeout {puts "TESTING ERROR 17\n";exit}
113 "Operation not permitted"
114}
115send -- "cat /proc/self/uid_map | wc -l\r"
116expect {
117 timeout {puts "TESTING ERROR 18\n";exit}
118 "1"
119}
120send -- "cat /proc/self/gid_map | wc -l\r"
121expect {
122 timeout {puts "TESTING ERROR 19\n";exit}
123 "3"
124}
125
126
127
128spawn $env(SHELL)
129send -- "firejail --debug --join=test\r"
130expect {
131 timeout {puts "TESTING ERROR 20\n";exit}
132 "User namespace detected"
133}
134expect {
135 timeout {puts "TESTING ERROR 21\n";exit}
136 "Joining user namespace"
137}
138sleep 1
139
140send -- "sudo -s\r"
141expect {
142 timeout {puts "TESTING ERROR 22\n";exit}
143 "effective uid is not 0, is sudo installed setuid root?" { puts "OK\n";}
144 "sudo must be owned by uid 0 and have the setuid bit set" { puts "OK\n";}
145}
146send -- "cat /proc/self/uid_map | wc -l\r"
147expect {
148 timeout {puts "TESTING ERROR 23\n";exit}
149 "1"
150}
151send -- "cat /proc/self/gid_map | wc -l\r"
152expect {
153 timeout {puts "TESTING ERROR 24\n";exit}
154 "3"
155}
156puts "\nall done\n"
diff --git a/test/filters/protocol.exp b/test/filters/protocol.exp
new file mode 100755
index 000000000..cf552da56
--- /dev/null
+++ b/test/filters/protocol.exp
@@ -0,0 +1,180 @@
1#!/usr/bin/expect -f
2
3set timeout 10
4spawn $env(SHELL)
5match_max 100000
6
7send -- "firejail --noprofile --protocol=unix ./syscall_test socket\r"
8expect {
9 timeout {puts "TESTING ERROR 1\n";exit}
10 "Child process initialized"
11}
12expect {
13 timeout {puts "TESTING ERROR 1.1\n";exit}
14 "socket AF_INET"
15}
16expect {
17 timeout {puts "TESTING ERROR 1.2\n";exit}
18 "Operation not supported"
19}
20expect {
21 timeout {puts "TESTING ERROR 1.3\n";exit}
22 "socket AF_INET6"
23}
24expect {
25 timeout {puts "TESTING ERROR 1.4\n";exit}
26 "Operation not supported"
27}
28expect {
29 timeout {puts "TESTING ERROR 1.5\n";exit}
30 "socket AF_NETLINK"
31}
32expect {
33 timeout {puts "TESTING ERROR 1.6\n";exit}
34 "Operation not supported"
35}
36expect {
37 timeout {puts "TESTING ERROR 1.7\n";exit}
38 "socket AF_UNIX"
39}
40expect {
41 timeout {puts "TESTING ERROR 1.8\n";exit}
42 "socket AF_PACKETX"
43}
44expect {
45 timeout {puts "TESTING ERROR 1.9\n";exit}
46 "Operation not supported"
47}
48sleep 1
49
50send -- "firejail --noprofile --protocol=inet6,packet ./syscall_test socket\r"
51expect {
52 timeout {puts "TESTING ERROR 2\n";exit}
53 "Child process initialized"
54}
55expect {
56 timeout {puts "TESTING ERROR 2.1\n";exit}
57 "socket AF_INET"
58}
59expect {
60 timeout {puts "TESTING ERROR 2.2\n";exit}
61 "Operation not supported"
62}
63expect {
64 timeout {puts "TESTING ERROR 2.3\n";exit}
65 "socket AF_INET6"
66}
67expect {
68 timeout {puts "TESTING ERROR 2.4\n";exit}
69 "socket AF_NETLINK"
70}
71expect {
72 timeout {puts "TESTING ERROR 2.5\n";exit}
73 "Operation not supported"
74}
75expect {
76 timeout {puts "TESTING ERROR 2.6\n";exit}
77 "socket AF_UNIX"
78}
79expect {
80 timeout {puts "TESTING ERROR 2.7\n";exit}
81 "Operation not supported"
82}
83expect {
84 timeout {puts "TESTING ERROR 2.8\n";exit}
85 "socket AF_PACKETX"
86}
87expect {
88 timeout {puts "TESTING ERROR 2.9\n";exit}
89 "after socket"
90}
91sleep 1
92
93# profile testing
94send -- "firejail --profile=protocol1.profile ./syscall_test socket\r"
95expect {
96 timeout {puts "TESTING ERROR 3\n";exit}
97 "Child process initialized"
98}
99expect {
100 timeout {puts "TESTING ERROR 3.1\n";exit}
101 "socket AF_INET"
102}
103expect {
104 timeout {puts "TESTING ERROR 3.2\n";exit}
105 "Operation not supported"
106}
107expect {
108 timeout {puts "TESTING ERROR 3.3\n";exit}
109 "socket AF_INET6"
110}
111expect {
112 timeout {puts "TESTING ERROR 3.4\n";exit}
113 "Operation not supported"
114}
115expect {
116 timeout {puts "TESTING ERROR 3.5\n";exit}
117 "socket AF_NETLINK"
118}
119expect {
120 timeout {puts "TESTING ERROR 3.6\n";exit}
121 "Operation not supported"
122}
123expect {
124 timeout {puts "TESTING ERROR 3.7\n";exit}
125 "socket AF_UNIX"
126}
127expect {
128 timeout {puts "TESTING ERROR 3.8\n";exit}
129 "socket AF_PACKETX"
130}
131expect {
132 timeout {puts "TESTING ERROR 3.9\n";exit}
133 "Operation not supported"
134}
135sleep 1
136
137send -- "firejail --profile=protocol2.profile ./syscall_test socket\r"
138expect {
139 timeout {puts "TESTING ERROR 4\n";exit}
140 "Child process initialized"
141}
142expect {
143 timeout {puts "TESTING ERROR 4.1\n";exit}
144 "socket AF_INET"
145}
146expect {
147 timeout {puts "TESTING ERROR 4.2\n";exit}
148 "Operation not supported"
149}
150expect {
151 timeout {puts "TESTING ERROR 4.3\n";exit}
152 "socket AF_INET6"
153}
154expect {
155 timeout {puts "TESTING ERROR 4.4\n";exit}
156 "socket AF_NETLINK"
157}
158expect {
159 timeout {puts "TESTING ERROR 4.5\n";exit}
160 "Operation not supported"
161}
162expect {
163 timeout {puts "TESTING ERROR 4.6\n";exit}
164 "socket AF_UNIX"
165}
166expect {
167 timeout {puts "TESTING ERROR 4.7\n";exit}
168 "Operation not supported"
169}
170expect {
171 timeout {puts "TESTING ERROR 4.8\n";exit}
172 "socket AF_PACKETX"
173}
174expect {
175 timeout {puts "TESTING ERROR 4.9\n";exit}
176 "after socket"
177}
178sleep 1
179
180puts "\nall done\n"
diff --git a/test/filters/protocol1.profile b/test/filters/protocol1.profile
new file mode 100644
index 000000000..3e1ea2a29
--- /dev/null
+++ b/test/filters/protocol1.profile
@@ -0,0 +1 @@
protocol unix
diff --git a/test/filters/protocol2.profile b/test/filters/protocol2.profile
new file mode 100644
index 000000000..b7eb4ab91
--- /dev/null
+++ b/test/filters/protocol2.profile
@@ -0,0 +1 @@
protocol inet6,packet
diff --git a/test/filters/seccomp-bad-empty.exp b/test/filters/seccomp-bad-empty.exp
new file mode 100755
index 000000000..631d67743
--- /dev/null
+++ b/test/filters/seccomp-bad-empty.exp
@@ -0,0 +1,38 @@
1#!/usr/bin/expect -f
2
3set timeout 10
4spawn $env(SHELL)
5match_max 100000
6
7send -- "firejail --seccomp=\r"
8expect {
9 timeout {puts "TESTING ERROR 0\n";exit}
10 "Error: empty syscall lists are not allowed"
11}
12
13send -- "firejail --seccomp.drop=\r"
14expect {
15 timeout {puts "TESTING ERROR 2\n";exit}
16 "Error: empty syscall lists are not allowed"
17}
18
19send -- "firejail --seccomp.keep=\r"
20expect {
21 timeout {puts "TESTING ERROR 4\n";exit}
22 "Error: empty syscall lists are not allowed"
23}
24
25send -- "firejail --profile=seccomp-bad-empty.profile\r"
26expect {
27 timeout {puts "TESTING ERROR 6\n";exit}
28 "Error: line 1 in seccomp-bad-empty.profile is invalid"
29}
30
31send -- "firejail --profile=seccomp-bad-empty2.profile\r"
32expect {
33 timeout {puts "TESTING ERROR 7\n";exit}
34 "Error: line 1 in seccomp-bad-empty2.profile is invalid"
35}
36sleep 1
37puts "\nall done\n"
38
diff --git a/test/filters/seccomp-bad-empty.profile b/test/filters/seccomp-bad-empty.profile
new file mode 100644
index 000000000..2d4fcde7c
--- /dev/null
+++ b/test/filters/seccomp-bad-empty.profile
@@ -0,0 +1 @@
seccomp.drop
diff --git a/test/filters/seccomp-bad-empty2.profile b/test/filters/seccomp-bad-empty2.profile
new file mode 100644
index 000000000..c4e6c9f74
--- /dev/null
+++ b/test/filters/seccomp-bad-empty2.profile
@@ -0,0 +1 @@
seccomp.keep
diff --git a/test/filters/seccomp.profile b/test/filters/seccomp.profile
new file mode 100644
index 000000000..cb0b15aee
--- /dev/null
+++ b/test/filters/seccomp.profile
@@ -0,0 +1 @@
seccomp chmod,fchmod,fchmodat
diff --git a/test/filters/syscall_test b/test/filters/syscall_test
new file mode 100755
index 000000000..bf29c5b99
--- /dev/null
+++ b/test/filters/syscall_test
Binary files differ
diff --git a/test/filters/syscall_test.c b/test/filters/syscall_test.c
new file mode 100644
index 000000000..422af619d
--- /dev/null
+++ b/test/filters/syscall_test.c
@@ -0,0 +1,82 @@
1// This file is part of Firejail project
2// Copyright (C) 2014-2016 Firejail Authors
3// License GPL v2
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <unistd.h>
8#include <sys/types.h>
9#include <sys/socket.h>
10#include <linux/netlink.h>
11#include <net/ethernet.h>
12#include <sys/mount.h>
13
14int main(int argc, char **argv) {
15 if (argc != 2) {
16 printf("Usage: test [sleep|socket|mkdir|mount]\n");
17 return 1;
18 }
19
20 if (strcmp(argv[1], "sleep") == 0) {
21 printf("before sleep\n");
22 sleep(1);
23 printf("after sleep\n");
24 }
25 else if (strcmp(argv[1], "socket") == 0) {
26 int sock;
27
28 printf("testing socket AF_INET\n");
29 if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
30 perror("socket");
31 }
32 else
33 close(sock);
34
35 printf("testing socket AF_INET6\n");
36 if ((sock = socket(AF_INET6, SOCK_STREAM, 0)) < 0) {
37 perror("socket");
38 }
39 else
40 close(sock);
41
42 printf("testing socket AF_NETLINK\n");
43 if ((sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) < 0) {
44 perror("socket");
45 }
46 else
47 close(sock);
48
49 printf("testing socket AF_UNIX\n");
50 if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
51 perror("socket");
52 }
53 else
54 close(sock);
55
56 // root needed to be able to handle this
57 printf("testing socket AF_PACKETX\n");
58 if ((sock = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_ARP))) < 0) {
59 perror("socket");
60 }
61 else
62 close(sock);
63 printf("after socket\n");
64 }
65 else if (strcmp(argv[1], "mkdir") == 0) {
66 printf("before mkdir\n");
67 mkdir("tmp", 0777);
68 printf("after mkdir\n");
69 }
70 else if (strcmp(argv[1], "mount") == 0) {
71 printf("before mount\n");
72 if (mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) {
73 perror("mount");
74 }
75 printf("after mount\n");
76 }
77 else {
78 fprintf(stderr, "Error: invalid argument\n");
79 return 1;
80 }
81 return 0;
82}
diff --git a/test/filters/syscall_test32 b/test/filters/syscall_test32
new file mode 100755
index 000000000..8d72f58c4
--- /dev/null
+++ b/test/filters/syscall_test32
Binary files differ