summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-02-11 09:03:35 -0500
committerLibravatar netblue30 <netblue30@yahoo.com>2016-02-11 09:03:35 -0500
commit8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1 (patch)
tree24b29e51104c6bda6700f1771becf7f41cdcaba0
parentfix problem with relative path in storage_find function (diff)
downloadfirejail-8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1.tar.gz
firejail-8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1.tar.zst
firejail-8fdc4029ad9bd2489aa0266bbbcaefac4fb239d1.zip
set sandbox nice value
-rw-r--r--README.md12
-rw-r--r--RELNOTES1
-rw-r--r--src/firejail/firejail.h4
-rw-r--r--src/firejail/main.c6
-rw-r--r--src/firejail/profile.c7
-rw-r--r--src/firejail/sandbox.c13
-rw-r--r--src/firejail/usage.c1
-rw-r--r--src/man/firejail-profile.txt4
-rw-r--r--src/man/firejail.txt10
-rwxr-xr-xtest/nice.exp80
-rw-r--r--test/nice.profile1
-rwxr-xr-xtest/test.sh3
12 files changed, 139 insertions, 3 deletions
diff --git a/README.md b/README.md
index 625df6554..5f3ffbd8a 100644
--- a/README.md
+++ b/README.md
@@ -68,4 +68,14 @@ The current netfilter configuration (--netfilter option) looks like this:
68The filter is loaded by default for Firefox if a network namespace is configured: 68The 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
diff --git a/RELNOTES b/RELNOTES
index 9e9a40bdc..9b025d423 100644
--- a/RELNOTES
+++ b/RELNOTES
@@ -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
231extern int arg_quiet; // no output for scripting 232extern int arg_quiet; // no output for scripting
232extern int arg_join_network; // join only the network namespace 233extern int arg_join_network; // join only the network namespace
233extern int arg_join_filesystem; // join only the mount namespace 234extern int arg_join_filesystem; // join only the mount namespace
235extern int arg_nice; // nice value configured
234 236
235extern int parent_to_child_fds[2]; 237extern int parent_to_child_fds[2];
236extern int child_to_parent_fds[2]; 238extern 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
92int arg_quiet = 0; // no output for scripting 92int arg_quiet = 0; // no output for scripting
93int arg_join_network = 0; // join only the network namespace 93int arg_join_network = 0; // join only the network namespace
94int arg_join_filesystem = 0; // join only the mount namespace 94int arg_join_filesystem = 0; // join only the mount namespace
95 95int arg_nice = 0; // nice value configured
96 96
97int parent_to_child_fds[2]; 97int parent_to_child_fds[2];
98int child_to_parent_fds[2]; 98int 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;
591printf("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:
228cpu 1,2,3 228cpu 1,2,3
229Use only CPU cores 0, 1 and 2. 229Use only CPU cores 0, 1 and 2.
230 230
231.TP
232nice -5
233Set a nice value of -5 to all processes running inside the sandbox.
234
231.SH Control Groups 235.SH Control Groups
232Place the sandbox in an existing control group specified by the full path of the task file using \fBcgroup\fR. Example: 236Place 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
7627383 netblue 9.045 0.112 firejail \-\-net=eth0 transmission 7627383 netblue 9.045 0.112 firejail \-\-net=eth0 transmission
763 763
764.TP
765\fB\-\-nice=value
766Set nice value for all processes running inside the sandbox.
767.br
768
769.br
770Example:
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
3set timeout 10
4spawn $env(SHELL)
5match_max 100000
6
7send -- "firejail --nice=15\r"
8expect {
9 timeout {puts "TESTING ERROR 0\n";exit}
10 "Child process initialized"
11}
12sleep 1
13
14send -- "top -b -n 1\r"
15expect {
16 timeout {puts "TESTING ERROR 1\n";exit}
17 "netblue"
18}
19expect {
20 timeout {puts "TESTING ERROR 2\n";exit}
21 "15"
22}
23expect {
24 timeout {puts "TESTING ERROR 3\n";exit}
25 "bash"
26}
27expect {
28 timeout {puts "TESTING ERROR 4\n";exit}
29 "netblu"
30}
31expect {
32 timeout {puts "TESTING ERROR 5\n";exit}
33 "15"
34}
35expect {
36 timeout {puts "TESTING ERROR 6\n";exit}
37 "top"
38}
39
40sleep 1
41send -- "exit\r"
42sleep 1
43
44send -- "firejail --profile=nice.profile\r"
45expect {
46 timeout {puts "TESTING ERROR 10\n";exit}
47 "Child process initialized"
48}
49sleep 1
50
51send -- "top -b -n 1\r"
52expect {
53 timeout {puts "TESTING ERROR 11\n";exit}
54 "netblue"
55}
56expect {
57 timeout {puts "TESTING ERROR 12\n";exit}
58 "15"
59}
60expect {
61 timeout {puts "TESTING ERROR 13\n";exit}
62 "bash"
63}
64expect {
65 timeout {puts "TESTING ERROR 14\n";exit}
66 "netblu"
67}
68expect {
69 timeout {puts "TESTING ERROR 15\n";exit}
70 "15"
71}
72expect {
73 timeout {puts "TESTING ERROR 16\n";exit}
74 "top"
75}
76
77
78
79puts "\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
9echo "TESTING: nice"
10./nice.exp
11
9echo "TESTING: protocol" 12echo "TESTING: protocol"
10./protocol.exp 13./protocol.exp
11 14