diff options
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | RELNOTES | 1 | ||||
-rw-r--r-- | src/firejail/firejail.h | 4 | ||||
-rw-r--r-- | src/firejail/main.c | 6 | ||||
-rw-r--r-- | src/firejail/profile.c | 7 | ||||
-rw-r--r-- | src/firejail/sandbox.c | 13 | ||||
-rw-r--r-- | src/firejail/usage.c | 1 | ||||
-rw-r--r-- | src/man/firejail-profile.txt | 4 | ||||
-rw-r--r-- | src/man/firejail.txt | 10 | ||||
-rwxr-xr-x | test/nice.exp | 80 | ||||
-rw-r--r-- | test/nice.profile | 1 | ||||
-rwxr-xr-x | test/test.sh | 3 |
12 files changed, 139 insertions, 3 deletions
@@ -68,4 +68,14 @@ The current netfilter configuration (--netfilter option) looks like this: | |||
68 | The filter is loaded by default for Firefox if a network namespace is configured: | 68 | The filter is loaded by default for Firefox if a network namespace is configured: |
69 | ````` | 69 | ````` |
70 | $ firejail --net=eth0 firefox | 70 | $ firejail --net=eth0 firefox |
71 | ````` \ No newline at end of file | 71 | ````` |
72 | |||
73 | ## Set sandbox nice value | ||
74 | ````` | ||
75 | --nice=value | ||
76 | Set nice value for all processes running inside the sandbox. | ||
77 | |||
78 | Example: | ||
79 | $ firejail --nice=-5 firefox | ||
80 | ````` | ||
81 | |||
@@ -2,6 +2,7 @@ firejail (0.9.39) baseline; urgency=low | |||
2 | * work in progress! | 2 | * work in progress! |
3 | * default seccomp filter update | 3 | * default seccomp filter update |
4 | * disable STUN/WebRTC in default netfilter configuration | 4 | * disable STUN/WebRTC in default netfilter configuration |
5 | * added --nice optoin | ||
5 | * bugfixes | 6 | * bugfixes |
6 | -- netblue30 <netblue30@yahoo.com> Tue, 8 Feb 2016 10:00:00 -0500 | 7 | -- netblue30 <netblue30@yahoo.com> Tue, 8 Feb 2016 10:00:00 -0500 |
7 | 8 | ||
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 90c3589d9..feb6854fc 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -157,8 +157,9 @@ typedef struct config_t { | |||
157 | unsigned rlimit_fsize; | 157 | unsigned rlimit_fsize; |
158 | unsigned rlimit_sigpending; | 158 | unsigned rlimit_sigpending; |
159 | 159 | ||
160 | // cpu affinity and control groups | 160 | // cpu affinity, nice and control groups |
161 | uint32_t cpus; | 161 | uint32_t cpus; |
162 | int nice; | ||
162 | char *cgroup; | 163 | char *cgroup; |
163 | 164 | ||
164 | 165 | ||
@@ -231,6 +232,7 @@ extern int arg_nosound; // disable sound | |||
231 | extern int arg_quiet; // no output for scripting | 232 | extern int arg_quiet; // no output for scripting |
232 | extern int arg_join_network; // join only the network namespace | 233 | extern int arg_join_network; // join only the network namespace |
233 | extern int arg_join_filesystem; // join only the mount namespace | 234 | extern int arg_join_filesystem; // join only the mount namespace |
235 | extern int arg_nice; // nice value configured | ||
234 | 236 | ||
235 | extern int parent_to_child_fds[2]; | 237 | extern int parent_to_child_fds[2]; |
236 | extern int child_to_parent_fds[2]; | 238 | extern int child_to_parent_fds[2]; |
diff --git a/src/firejail/main.c b/src/firejail/main.c index 5b88481d1..2f64d2268 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -92,7 +92,7 @@ int arg_nosound = 0; // disable sound | |||
92 | int arg_quiet = 0; // no output for scripting | 92 | int arg_quiet = 0; // no output for scripting |
93 | int arg_join_network = 0; // join only the network namespace | 93 | int arg_join_network = 0; // join only the network namespace |
94 | int arg_join_filesystem = 0; // join only the mount namespace | 94 | int arg_join_filesystem = 0; // join only the mount namespace |
95 | 95 | int arg_nice = 0; // nice value configured | |
96 | 96 | ||
97 | int parent_to_child_fds[2]; | 97 | int parent_to_child_fds[2]; |
98 | int child_to_parent_fds[2]; | 98 | int child_to_parent_fds[2]; |
@@ -678,6 +678,10 @@ int main(int argc, char **argv) { | |||
678 | arg_ipc = 1; | 678 | arg_ipc = 1; |
679 | else if (strncmp(argv[i], "--cpu=", 6) == 0) | 679 | else if (strncmp(argv[i], "--cpu=", 6) == 0) |
680 | read_cpu_list(argv[i] + 6); | 680 | read_cpu_list(argv[i] + 6); |
681 | else if (strncmp(argv[i], "--nice=", 7) == 0) { | ||
682 | cfg.nice = atoi(argv[i] + 7); | ||
683 | arg_nice = 1; | ||
684 | } | ||
681 | else if (strncmp(argv[i], "--cgroup=", 9) == 0) { | 685 | else if (strncmp(argv[i], "--cgroup=", 9) == 0) { |
682 | if (arg_cgroup) { | 686 | if (arg_cgroup) { |
683 | fprintf(stderr, "Error: only a cgroup can be defined\n"); | 687 | fprintf(stderr, "Error: only a cgroup can be defined\n"); |
diff --git a/src/firejail/profile.c b/src/firejail/profile.c index bbec17447..e0de69e5e 100644 --- a/src/firejail/profile.c +++ b/src/firejail/profile.c | |||
@@ -290,6 +290,13 @@ int profile_check_line(char *ptr, int lineno, const char *fname) { | |||
290 | return 0; | 290 | return 0; |
291 | } | 291 | } |
292 | 292 | ||
293 | // nice value | ||
294 | if (strncmp(ptr, "nice ", 4) == 0) { | ||
295 | cfg.nice = atoi(ptr + 5); | ||
296 | arg_nice = 1; | ||
297 | return 0; | ||
298 | } | ||
299 | |||
293 | // cgroup | 300 | // cgroup |
294 | if (strncmp(ptr, "cgroup ", 7) == 0) { | 301 | if (strncmp(ptr, "cgroup ", 7) == 0) { |
295 | set_cgroup(ptr + 7); | 302 | set_cgroup(ptr + 7); |
diff --git a/src/firejail/sandbox.c b/src/firejail/sandbox.c index 85f65b610..1ba655301 100644 --- a/src/firejail/sandbox.c +++ b/src/firejail/sandbox.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <sys/resource.h> | 27 | #include <sys/resource.h> |
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <dirent.h> | 29 | #include <dirent.h> |
30 | #include <errno.h> | ||
30 | 31 | ||
31 | #include <sched.h> | 32 | #include <sched.h> |
32 | #ifndef CLONE_NEWUSER | 33 | #ifndef CLONE_NEWUSER |
@@ -582,6 +583,18 @@ int sandbox(void* sandbox_arg) { | |||
582 | // set user-supplied environment variables | 583 | // set user-supplied environment variables |
583 | env_apply(); | 584 | env_apply(); |
584 | 585 | ||
586 | // set nice | ||
587 | if (arg_nice) { | ||
588 | errno = 0; | ||
589 | int rv = nice(cfg.nice); | ||
590 | (void) rv; | ||
591 | printf("nice rv %d\n", rv); | ||
592 | if (errno) { | ||
593 | fprintf(stderr, "Warning: cannot set nice value\n"); | ||
594 | errno = 0; | ||
595 | } | ||
596 | } | ||
597 | |||
585 | //**************************** | 598 | //**************************** |
586 | // set security filters | 599 | // set security filters |
587 | //**************************** | 600 | //**************************** |
diff --git a/src/firejail/usage.c b/src/firejail/usage.c index fa48c55cf..33724c80f 100644 --- a/src/firejail/usage.c +++ b/src/firejail/usage.c | |||
@@ -178,6 +178,7 @@ void usage(void) { | |||
178 | printf("\t--netstats - monitor network statistics for sandboxes creating a new\n"); | 178 | printf("\t--netstats - monitor network statistics for sandboxes creating a new\n"); |
179 | printf("\t\tnetwork namespace.\n\n"); | 179 | printf("\t\tnetwork namespace.\n\n"); |
180 | #endif | 180 | #endif |
181 | printf("\t--nice=value - set nice value\n\n"); | ||
181 | printf("\t--noblacklist=dirname_or_filename - disable blacklist for directory\n"); | 182 | printf("\t--noblacklist=dirname_or_filename - disable blacklist for directory\n"); |
182 | printf("\t\tor file.\n\n"); | 183 | printf("\t\tor file.\n\n"); |
183 | printf("\t--nogroups - disable supplementary groups. Without this option,\n"); | 184 | printf("\t--nogroups - disable supplementary groups. Without this option,\n"); |
diff --git a/src/man/firejail-profile.txt b/src/man/firejail-profile.txt index 20fd731e1..3ebb11549 100644 --- a/src/man/firejail-profile.txt +++ b/src/man/firejail-profile.txt | |||
@@ -228,6 +228,10 @@ Set the CPU cores available for this sandbox using \fBcpu\fR command. Examples: | |||
228 | cpu 1,2,3 | 228 | cpu 1,2,3 |
229 | Use only CPU cores 0, 1 and 2. | 229 | Use only CPU cores 0, 1 and 2. |
230 | 230 | ||
231 | .TP | ||
232 | nice -5 | ||
233 | Set a nice value of -5 to all processes running inside the sandbox. | ||
234 | |||
231 | .SH Control Groups | 235 | .SH Control Groups |
232 | Place the sandbox in an existing control group specified by the full path of the task file using \fBcgroup\fR. Example: | 236 | Place the sandbox in an existing control group specified by the full path of the task file using \fBcgroup\fR. Example: |
233 | 237 | ||
diff --git a/src/man/firejail.txt b/src/man/firejail.txt index 784f1583e..bdd1bb1f6 100644 --- a/src/man/firejail.txt +++ b/src/man/firejail.txt | |||
@@ -761,6 +761,16 @@ PID User RX(KB/s) TX(KB/s) Command | |||
761 | .br | 761 | .br |
762 | 7383 netblue 9.045 0.112 firejail \-\-net=eth0 transmission | 762 | 7383 netblue 9.045 0.112 firejail \-\-net=eth0 transmission |
763 | 763 | ||
764 | .TP | ||
765 | \fB\-\-nice=value | ||
766 | Set nice value for all processes running inside the sandbox. | ||
767 | .br | ||
768 | |||
769 | .br | ||
770 | Example: | ||
771 | .br | ||
772 | $ firejail --nice=-5 firefox | ||
773 | |||
764 | 774 | ||
765 | .TP | 775 | .TP |
766 | \fB\-\-noblacklist=dirname_or_filename | 776 | \fB\-\-noblacklist=dirname_or_filename |
diff --git a/test/nice.exp b/test/nice.exp new file mode 100755 index 000000000..f4afb547d --- /dev/null +++ b/test/nice.exp | |||
@@ -0,0 +1,80 @@ | |||
1 | #!/usr/bin/expect -f | ||
2 | |||
3 | set timeout 10 | ||
4 | spawn $env(SHELL) | ||
5 | match_max 100000 | ||
6 | |||
7 | send -- "firejail --nice=15\r" | ||
8 | expect { | ||
9 | timeout {puts "TESTING ERROR 0\n";exit} | ||
10 | "Child process initialized" | ||
11 | } | ||
12 | sleep 1 | ||
13 | |||
14 | send -- "top -b -n 1\r" | ||
15 | expect { | ||
16 | timeout {puts "TESTING ERROR 1\n";exit} | ||
17 | "netblue" | ||
18 | } | ||
19 | expect { | ||
20 | timeout {puts "TESTING ERROR 2\n";exit} | ||
21 | "15" | ||
22 | } | ||
23 | expect { | ||
24 | timeout {puts "TESTING ERROR 3\n";exit} | ||
25 | "bash" | ||
26 | } | ||
27 | expect { | ||
28 | timeout {puts "TESTING ERROR 4\n";exit} | ||
29 | "netblu" | ||
30 | } | ||
31 | expect { | ||
32 | timeout {puts "TESTING ERROR 5\n";exit} | ||
33 | "15" | ||
34 | } | ||
35 | expect { | ||
36 | timeout {puts "TESTING ERROR 6\n";exit} | ||
37 | "top" | ||
38 | } | ||
39 | |||
40 | sleep 1 | ||
41 | send -- "exit\r" | ||
42 | sleep 1 | ||
43 | |||
44 | send -- "firejail --profile=nice.profile\r" | ||
45 | expect { | ||
46 | timeout {puts "TESTING ERROR 10\n";exit} | ||
47 | "Child process initialized" | ||
48 | } | ||
49 | sleep 1 | ||
50 | |||
51 | send -- "top -b -n 1\r" | ||
52 | expect { | ||
53 | timeout {puts "TESTING ERROR 11\n";exit} | ||
54 | "netblue" | ||
55 | } | ||
56 | expect { | ||
57 | timeout {puts "TESTING ERROR 12\n";exit} | ||
58 | "15" | ||
59 | } | ||
60 | expect { | ||
61 | timeout {puts "TESTING ERROR 13\n";exit} | ||
62 | "bash" | ||
63 | } | ||
64 | expect { | ||
65 | timeout {puts "TESTING ERROR 14\n";exit} | ||
66 | "netblu" | ||
67 | } | ||
68 | expect { | ||
69 | timeout {puts "TESTING ERROR 15\n";exit} | ||
70 | "15" | ||
71 | } | ||
72 | expect { | ||
73 | timeout {puts "TESTING ERROR 16\n";exit} | ||
74 | "top" | ||
75 | } | ||
76 | |||
77 | |||
78 | |||
79 | puts "\nall done\n" | ||
80 | |||
diff --git a/test/nice.profile b/test/nice.profile new file mode 100644 index 000000000..d02c8f58b --- /dev/null +++ b/test/nice.profile | |||
@@ -0,0 +1 @@ | |||
nice 15 | |||
diff --git a/test/test.sh b/test/test.sh index ca7152b55..923a9b390 100755 --- a/test/test.sh +++ b/test/test.sh | |||
@@ -6,6 +6,9 @@ | |||
6 | 6 | ||
7 | ./fscheck.sh | 7 | ./fscheck.sh |
8 | 8 | ||
9 | echo "TESTING: nice" | ||
10 | ./nice.exp | ||
11 | |||
9 | echo "TESTING: protocol" | 12 | echo "TESTING: protocol" |
10 | ./protocol.exp | 13 | ./protocol.exp |
11 | 14 | ||