aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.in6
-rwxr-xr-xconfigure3
-rw-r--r--configure.ac2
-rw-r--r--etc/disable-programs.inc1
-rw-r--r--etc/minetest.profile3
-rw-r--r--etc/playonlinux.profile28
-rw-r--r--etc/sylpheed.profile29
-rw-r--r--src/fsec-optimize/Makefile.in45
-rw-r--r--src/fsec-optimize/fsec_optimize.h30
-rw-r--r--src/fsec-optimize/main.c94
-rw-r--r--src/fsec-optimize/optimizer.c136
11 files changed, 373 insertions, 4 deletions
diff --git a/Makefile.in b/Makefile.in
index 81907022b..27187f53a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,6 +1,6 @@
1all: apps man filters 1all: apps man filters
2MYLIBS = src/lib 2MYLIBS = src/lib
3APPS = src/firejail src/firemon src/fsec-print src/firecfg src/fnetfilter src/libtrace src/libtracelog src/ftee src/faudit src/fnet src/fseccomp src/fbuilder src/fcopy src/fldd src/libpostexecseccomp 3APPS = src/firejail src/firemon src/fsec-print src/fsec-optimize src/firecfg src/fnetfilter src/libtrace src/libtracelog src/ftee src/faudit src/fnet src/fseccomp src/fbuilder src/fcopy src/fldd src/libpostexecseccomp
4MANPAGES = firejail.1 firemon.1 firecfg.1 firejail-profile.5 firejail-login.5 4MANPAGES = firejail.1 firemon.1 firecfg.1 firejail-profile.5 firejail-login.5
5SECCOMP_FILTERS = seccomp seccomp.debug seccomp.32 seccomp.64 seccomp.block_secondary seccomp.mdwx 5SECCOMP_FILTERS = seccomp seccomp.debug seccomp.32 seccomp.64 seccomp.block_secondary seccomp.mdwx
6 6
@@ -42,9 +42,13 @@ man: $(MANPAGES)
42filters: src/fseccomp 42filters: src/fseccomp
43ifeq ($(HAVE_SECCOMP),-DHAVE_SECCOMP) 43ifeq ($(HAVE_SECCOMP),-DHAVE_SECCOMP)
44 src/fseccomp/fseccomp default seccomp 44 src/fseccomp/fseccomp default seccomp
45 src/fsec-optimize/fsec-optimize seccomp
45 src/fseccomp/fseccomp default seccomp.debug allow-debuggers 46 src/fseccomp/fseccomp default seccomp.debug allow-debuggers
47 src/fsec-optimize/fsec-optimize seccomp.debug
46 src/fseccomp/fseccomp secondary 32 seccomp.32 48 src/fseccomp/fseccomp secondary 32 seccomp.32
49 src/fsec-optimize/fsec-optimize seccomp.32
47 src/fseccomp/fseccomp secondary 64 seccomp.64 50 src/fseccomp/fseccomp secondary 64 seccomp.64
51 src/fsec-optimize/fsec-optimize seccomp.64
48 src/fseccomp/fseccomp secondary block seccomp.block_secondary 52 src/fseccomp/fseccomp secondary block seccomp.block_secondary
49 src/fseccomp/fseccomp memory-deny-write-execute seccomp.mdwx 53 src/fseccomp/fseccomp memory-deny-write-execute seccomp.mdwx
50endif 54endif
diff --git a/configure b/configure
index f556f44b5..761cebc1e 100755
--- a/configure
+++ b/configure
@@ -3823,7 +3823,7 @@ if test "$prefix" = /usr; then
3823 sysconfdir="/etc" 3823 sysconfdir="/etc"
3824fi 3824fi
3825 3825
3826ac_config_files="$ac_config_files Makefile src/lib/Makefile src/fcopy/Makefile src/fnet/Makefile src/firejail/Makefile src/fnetfilter/Makefile src/firemon/Makefile src/libtrace/Makefile src/libtracelog/Makefile src/firecfg/Makefile src/fbuilder/Makefile src/fsec-print/Makefile src/ftee/Makefile src/faudit/Makefile src/fseccomp/Makefile src/fldd/Makefile src/libpostexecseccomp/Makefile" 3826ac_config_files="$ac_config_files Makefile src/lib/Makefile src/fcopy/Makefile src/fnet/Makefile src/firejail/Makefile src/fnetfilter/Makefile src/firemon/Makefile src/libtrace/Makefile src/libtracelog/Makefile src/firecfg/Makefile src/fbuilder/Makefile src/fsec-print/Makefile src/ftee/Makefile src/faudit/Makefile src/fseccomp/Makefile src/fldd/Makefile src/libpostexecseccomp/Makefile src/fsec-optimize/Makefile"
3827 3827
3828cat >confcache <<\_ACEOF 3828cat >confcache <<\_ACEOF
3829# This file is a shell script that caches the results of configure 3829# This file is a shell script that caches the results of configure
@@ -4549,6 +4549,7 @@ do
4549 "src/fseccomp/Makefile") CONFIG_FILES="$CONFIG_FILES src/fseccomp/Makefile" ;; 4549 "src/fseccomp/Makefile") CONFIG_FILES="$CONFIG_FILES src/fseccomp/Makefile" ;;
4550 "src/fldd/Makefile") CONFIG_FILES="$CONFIG_FILES src/fldd/Makefile" ;; 4550 "src/fldd/Makefile") CONFIG_FILES="$CONFIG_FILES src/fldd/Makefile" ;;
4551 "src/libpostexecseccomp/Makefile") CONFIG_FILES="$CONFIG_FILES src/libpostexecseccomp/Makefile" ;; 4551 "src/libpostexecseccomp/Makefile") CONFIG_FILES="$CONFIG_FILES src/libpostexecseccomp/Makefile" ;;
4552 "src/fsec-optimize/Makefile") CONFIG_FILES="$CONFIG_FILES src/fsec-optimize/Makefile" ;;
4552 4553
4553 *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; 4554 *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
4554 esac 4555 esac
diff --git a/configure.ac b/configure.ac
index 4633ea35c..952dec3b8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -177,7 +177,7 @@ fi
177 177
178AC_OUTPUT(Makefile src/lib/Makefile src/fcopy/Makefile src/fnet/Makefile src/firejail/Makefile src/fnetfilter/Makefile \ 178AC_OUTPUT(Makefile src/lib/Makefile src/fcopy/Makefile src/fnet/Makefile src/firejail/Makefile src/fnetfilter/Makefile \
179src/firemon/Makefile src/libtrace/Makefile src/libtracelog/Makefile src/firecfg/Makefile src/fbuilder/Makefile src/fsec-print/Makefile \ 179src/firemon/Makefile src/libtrace/Makefile src/libtracelog/Makefile src/firecfg/Makefile src/fbuilder/Makefile src/fsec-print/Makefile \
180src/ftee/Makefile src/faudit/Makefile src/fseccomp/Makefile src/fldd/Makefile src/libpostexecseccomp/Makefile) 180src/ftee/Makefile src/faudit/Makefile src/fseccomp/Makefile src/fldd/Makefile src/libpostexecseccomp/Makefile src/fsec-optimize/Makefile)
181 181
182echo 182echo
183echo "Configuration options:" 183echo "Configuration options:"
diff --git a/etc/disable-programs.inc b/etc/disable-programs.inc
index feb01e142..74e7e45a7 100644
--- a/etc/disable-programs.inc
+++ b/etc/disable-programs.inc
@@ -214,6 +214,7 @@ blacklist ${HOME}/.config/zathura
214blacklist ${HOME}/.config/zoomus.conf 214blacklist ${HOME}/.config/zoomus.conf
215blacklist ${HOME}/.conkeror.mozdev.org 215blacklist ${HOME}/.conkeror.mozdev.org
216blacklist ${HOME}/.curlrc 216blacklist ${HOME}/.curlrc
217blacklist ${HOME}/.dashcore
217blacklist ${HOME}/.dia 218blacklist ${HOME}/.dia
218blacklist ${HOME}/.dillo 219blacklist ${HOME}/.dillo
219blacklist ${HOME}/.dooble 220blacklist ${HOME}/.dooble
diff --git a/etc/minetest.profile b/etc/minetest.profile
index 147328616..aa4c2218d 100644
--- a/etc/minetest.profile
+++ b/etc/minetest.profile
@@ -32,7 +32,8 @@ shell none
32disable-mnt 32disable-mnt
33private-bin minetest 33private-bin minetest
34private-dev 34private-dev
35private-etc asound.conf,ca-certificates,drirc,fonts,group,host.conf,hostname,hosts,ld.so.cache,ld.so.preload,localtime,nsswitch.conf,passwd,pulse,resolv.conf,ssl 35# private-etc needs to be updated, see #1702
36#private-etc asound.conf,ca-certificates,drirc,fonts,group,host.conf,hostname,hosts,ld.so.cache,ld.so.preload,localtime,nsswitch.conf,passwd,pulse,resolv.conf,ssl
36private-tmp 37private-tmp
37 38
38noexec ${HOME} 39noexec ${HOME}
diff --git a/etc/playonlinux.profile b/etc/playonlinux.profile
new file mode 100644
index 000000000..676b6a5c6
--- /dev/null
+++ b/etc/playonlinux.profile
@@ -0,0 +1,28 @@
1# Firejail profile for playonlinux
2# This file is overwritten after every install/update
3# Persistent local customizations
4include /etc/firejail/playonlinux.local
5# Persistent global definitions
6include /etc/firejail/globals.local
7
8noblacklist ${HOME}/.Steam
9noblacklist ${HOME}/.local/share/Steam
10noblacklist ${HOME}/.local/share/steam
11noblacklist ${HOME}/.steam
12noblacklist ${HOME}/.PlayOnLinux
13
14# nc is needed to run playonlinux
15noblacklist ${PATH}/nc
16
17include /etc/firejail/disable-common.inc
18include /etc/firejail/disable-devel.inc
19include /etc/firejail/disable-programs.inc
20
21caps.drop all
22netfilter
23nodvd
24nogroups
25nonewprivs
26noroot
27notv
28seccomp
diff --git a/etc/sylpheed.profile b/etc/sylpheed.profile
new file mode 100644
index 000000000..c4d93a0e3
--- /dev/null
+++ b/etc/sylpheed.profile
@@ -0,0 +1,29 @@
1# Firejail profile for sylpheed
2# This file is overwritten after every install/update
3# Persistent local customizations
4include /etc/firejail/sylpheed.local
5# Persistent global definitions
6include /etc/firejail/globals.local
7
8noblacklist ${HOME}/.sylpheed-2.0
9
10include /etc/firejail/disable-common.inc
11include /etc/firejail/disable-devel.inc
12include /etc/firejail/disable-passwdmgr.inc
13include /etc/firejail/disable-programs.inc
14
15caps.drop all
16netfilter
17nodvd
18nogroups
19nonewprivs
20noroot
21nosound
22notv
23novideo
24protocol unix,inet,inet6
25seccomp
26shell none
27
28private-dev
29private-tmp
diff --git a/src/fsec-optimize/Makefile.in b/src/fsec-optimize/Makefile.in
new file mode 100644
index 000000000..6ddbfc075
--- /dev/null
+++ b/src/fsec-optimize/Makefile.in
@@ -0,0 +1,45 @@
1all: fsec-optimize
2
3CC=@CC@
4prefix=@prefix@
5exec_prefix=@exec_prefix@
6libdir=@libdir@
7sysconfdir=@sysconfdir@
8
9VERSION=@PACKAGE_VERSION@
10NAME=@PACKAGE_NAME@
11HAVE_SECCOMP_H=@HAVE_SECCOMP_H@
12HAVE_SECCOMP=@HAVE_SECCOMP@
13HAVE_CHROOT=@HAVE_CHROOT@
14HAVE_BIND=@HAVE_BIND@
15HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@
16HAVE_NETWORK=@HAVE_NETWORK@
17HAVE_USERNS=@HAVE_USERNS@
18HAVE_X11=@HAVE_X11@
19HAVE_FILE_TRANSFER=@HAVE_FILE_TRANSFER@
20HAVE_WHITELIST=@HAVE_WHITELIST@
21HAVE_GLOBALCFG=@HAVE_GLOBALCFG@
22HAVE_APPARMOR=@HAVE_APPARMOR@
23HAVE_OVERLAYFS=@HAVE_OVERLAYFS@
24HAVE_PRIVATE_HOME=@HAVE_PRIVATE_HOME@
25EXTRA_LDFLAGS +=@EXTRA_LDFLAGS@
26HAVE_GCOV=@HAVE_GCOV@
27EXTRA_LDFLAGS +=@EXTRA_LDFLAGS@
28
29H_FILE_LIST = $(sort $(wildcard *.[h]))
30C_FILE_LIST = $(sort $(wildcard *.c))
31OBJS = $(C_FILE_LIST:.c=.o)
32BINOBJS = $(foreach file, $(OBJS), $file)
33CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' $(HAVE_GCOV) -DPREFIX='"$(prefix)"' -DSYSCONFDIR='"$(sysconfdir)/firejail"' -DLIBDIR='"$(libdir)"' $(HAVE_X11) $(HAVE_PRIVATE_HOME) $(HAVE_APPARMOR) $(HAVE_OVERLAYFS) $(HAVE_SECCOMP) $(HAVE_GLOBALCFG) $(HAVE_SECCOMP_H) $(HAVE_CHROOT) $(HAVE_NETWORK) $(HAVE_USERNS) $(HAVE_BIND) $(HAVE_FILE_TRANSFER) $(HAVE_WHITELIST) -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIE -pie -Wformat -Wformat-security
34LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now -lpthread
35
36%.o : %.c $(H_FILE_LIST) ../include/common.h ../include/seccomp.h ../include/syscall.h
37 $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
38
39fsec-optimize: $(OBJS) ../lib/libnetlink.o
40 $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) $(EXTRA_LDFLAGS)
41
42clean:; rm -f *.o fsec-optimize *.gcov *.gcda *.gcno
43
44distclean: clean
45 rm -fr Makefile
diff --git a/src/fsec-optimize/fsec_optimize.h b/src/fsec-optimize/fsec_optimize.h
new file mode 100644
index 000000000..ff4d53ab2
--- /dev/null
+++ b/src/fsec-optimize/fsec_optimize.h
@@ -0,0 +1,30 @@
1/*
2 * Copyright (C) 2014-2017 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#ifndef FSEC_OPTIMIZE_H
21#define FSEC_OPTIMIZE_H
22#include "../include/common.h"
23#include "../include/seccomp.h"
24#include <sys/mman.h>
25
26// optimize.c
27struct sock_filter *duplicate(struct sock_filter *filter, int entries);
28int optimize(struct sock_filter * filter, int entries);
29
30#endif \ No newline at end of file
diff --git a/src/fsec-optimize/main.c b/src/fsec-optimize/main.c
new file mode 100644
index 000000000..2c11b91ef
--- /dev/null
+++ b/src/fsec-optimize/main.c
@@ -0,0 +1,94 @@
1/*
2 * Copyright (C) 2014-2017 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#include "fsec_optimize.h"
21
22static void usage(void) {
23 printf("Usage:\n");
24 printf("\tfsec-optimize file - optimize seccomp filter\n");
25}
26
27int main(int argc, char **argv) {
28#if 0
29{
30//system("cat /proc/self/status");
31int i;
32for (i = 0; i < argc; i++)
33 printf("*%s* ", argv[i]);
34printf("\n");
35}
36#endif
37 if (argc != 2) {
38 usage();
39 return 1;
40 }
41
42 if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) {
43 usage();
44 return 0;
45 }
46
47 char *fname = argv[1];
48
49 // open input file
50 int fd = open(fname, O_RDONLY);
51 if (fd == -1)
52 goto errexit;
53
54 // calculate the number of entries
55 int size = lseek(fd, 0, SEEK_END);
56 if (size == -1) // todo: check maximum size of seccomp filter (4KB?)
57 goto errexit;
58 unsigned short entries = (unsigned short) size / (unsigned short) sizeof(struct sock_filter);
59
60 // read filter
61 struct sock_filter *filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
62 if (filter == MAP_FAILED)
63 goto errexit;
64 close(fd);
65
66 // duplicate the filter memory and unmap the file
67 struct sock_filter *outfilter = duplicate(filter, entries);
68 if (munmap(filter, size) == -1)
69 perror("Error un-mmapping the file");
70
71 // optimize filter
72 entries = optimize(outfilter, entries);
73
74 // write the new file and free memory
75 fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0755);
76 if (fd == -1) {
77 fprintf(stderr, "Error: cannot open output file\n");
78 return 1;
79 }
80 size = write(fd, outfilter, entries * sizeof(struct sock_filter));
81 if (size != entries * sizeof(struct sock_filter)) {
82 fprintf(stderr, "Error: cannot write output file\n");
83 return 1;
84 }
85 close(fd);
86 free(outfilter);
87
88 return 0;
89errexit:
90 close(fd);
91 fprintf(stderr, "Error: cannot read %s\n", fname);
92 exit(1);
93
94}
diff --git a/src/fsec-optimize/optimizer.c b/src/fsec-optimize/optimizer.c
new file mode 100644
index 000000000..8e61935d3
--- /dev/null
+++ b/src/fsec-optimize/optimizer.c
@@ -0,0 +1,136 @@
1/*
2 * Copyright (C) 2014-2017 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#include "fsec_optimize.h"
21
22// From /usr/include/linux/filter.h
23//struct sock_filter { /* Filter block */
24// __u16 code; /* Actual filter code */
25// __u8 jt; /* Jump true */
26// __u8 jf; /* Jump false */
27// __u32 k; /* Generic multiuse field */
28//};
29
30
31#define LIMIT_BLACKLISTS 4 // we optimize blacklists only if we have more than
32
33static inline int is_blacklist(struct sock_filter *bpf) {
34 if (bpf->code == BPF_JMP + BPF_JEQ + BPF_K &&
35 (bpf + 1)->code == BPF_RET + BPF_K &&
36 (bpf + 1)->k == SECCOMP_RET_KILL )
37 return 1;
38 return 0;
39}
40
41static int count_blacklists(struct sock_filter *filter, int entries) {
42 int cnt = 0;
43 int i;
44
45 for (i = 0; i < (entries - 1); i++, filter++) { // is_blacklist works on two consecutive lines; using entries - 1
46 if (is_blacklist(filter))
47 cnt++;
48 }
49
50 return cnt;
51}
52
53typedef struct {
54 int to_remove;
55 int to_fix_jumps;
56} Action;
57
58static int optimize_blacklists(struct sock_filter *filter, int entries) {
59 assert(entries);
60 assert(filter);
61 int i;
62 int j;
63
64 // step1: extract information
65 Action action[entries];
66 memset(&action[0], 0, sizeof(Action) * entries);
67 int remove_cnt = 0;
68 for (i = 0; i < (entries - 1); i++) { // is_blacklist works on two consecutive lines; using entries - 1
69 if (is_blacklist(filter + i)) {
70 action[i]. to_fix_jumps = 1;
71 i++;
72 action[i].to_remove = 1;
73 remove_cnt++;
74 }
75 }
76
77 // step2: remove lines
78 struct sock_filter *filter_step2 = duplicate(filter, entries);
79 Action action_step2[entries];
80 memset(&action_step2[0], 0, sizeof(Action) * entries);
81 for (i = 0, j = 0; i < entries; i++) {
82 if (!action[i].to_remove) {
83 memcpy(&filter_step2[j], &filter[i], sizeof(struct sock_filter));
84 memcpy(&action_step2[j], &action[i], sizeof(Action));
85 j++;
86 }
87 else {
88 // do nothing, we are removing this line
89 }
90 }
91
92 // step 3: add the new ret KILL, and recalculate entries
93 filter_step2[j].code = BPF_RET + BPF_K;
94 filter_step2[j].k == SECCOMP_RET_KILL;
95 entries = j + 1;
96
97 // step 4: recalculate jumps
98 for (i = 0; i < entries; i++) {
99 if (action_step2[i].to_fix_jumps) {
100 filter_step2[i].jt = entries - i - 2;
101 filter_step2[i].jf = 0;
102 }
103 }
104
105 // update
106 memcpy(filter, filter_step2, entries * sizeof(struct sock_filter));
107 free(filter_step2);
108 return entries;
109}
110
111int optimize(struct sock_filter *filter, int entries) {
112 assert(filter);
113 assert(entries);
114
115 //**********************************
116 // optimize blacklist statements
117 //**********************************
118 // count "ret KILL"
119 int cnt = count_blacklists(filter, entries);
120 if (cnt > LIMIT_BLACKLISTS)
121 entries = optimize_blacklists(filter, entries);
122 return entries;
123}
124
125struct sock_filter *duplicate(struct sock_filter *filter, int entries) {
126 int len = sizeof(struct sock_filter) * entries;
127 struct sock_filter *rv = malloc(len);
128 if (!rv) {
129 errExit("malloc");
130 exit(1);
131 }
132
133 memcpy(rv, filter, len);
134 return rv;
135}
136