aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2019-04-09 16:28:40 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2019-04-09 16:28:40 -0400
commit9a27ac2137f38b775eca8995a4ab800c2e956447 (patch)
treef2fe56c1e9182367020c4bca9a7a73130492e486 /src
parentseccomp testing (diff)
downloadfirejail-9a27ac2137f38b775eca8995a4ab800c2e956447.tar.gz
firejail-9a27ac2137f38b775eca8995a4ab800c2e956447.tar.zst
firejail-9a27ac2137f38b775eca8995a4ab800c2e956447.zip
seccomp fixes
Diffstat (limited to 'src')
-rw-r--r--src/firejail/firejail.h79
-rw-r--r--src/libpostexecseccomp/Makefile.in3
-rw-r--r--src/libpostexecseccomp/libpostexecseccomp.c12
3 files changed, 10 insertions, 84 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h
index 4cb10c875..b2c18d79f 100644
--- a/src/firejail/firejail.h
+++ b/src/firejail/firejail.h
@@ -21,90 +21,13 @@
21#define FIREJAIL_H 21#define FIREJAIL_H
22#include "../include/common.h" 22#include "../include/common.h"
23#include "../include/euid_common.h" 23#include "../include/euid_common.h"
24#include "../include/rundefs.h"
24#include <stdarg.h> 25#include <stdarg.h>
25#include <sys/stat.h> 26#include <sys/stat.h>
26 27
27// debug restricted shell 28// debug restricted shell
28//#define DEBUG_RESTRICTED_SHELL 29//#define DEBUG_RESTRICTED_SHELL
29 30
30// filesystem
31#define RUN_FIREJAIL_BASEDIR "/run"
32#define RUN_FIREJAIL_DIR "/run/firejail"
33#define RUN_FIREJAIL_APPIMAGE_DIR "/run/firejail/appimage"
34#define RUN_FIREJAIL_NAME_DIR "/run/firejail/name" // also used in src/lib/pid.c - todo: move it in a common place
35#define RUN_FIREJAIL_LIB_DIR "/run/firejail/lib"
36#define RUN_FIREJAIL_X11_DIR "/run/firejail/x11"
37#define RUN_FIREJAIL_NETWORK_DIR "/run/firejail/network"
38#define RUN_FIREJAIL_BANDWIDTH_DIR "/run/firejail/bandwidth"
39#define RUN_FIREJAIL_PROFILE_DIR "/run/firejail/profile"
40#define RUN_NETWORK_LOCK_FILE "/run/firejail/firejail-network.lock"
41#define RUN_DIRECTORY_LOCK_FILE "/run/firejail/firejail-run.lock"
42#define RUN_RO_DIR "/run/firejail/firejail.ro.dir"
43#define RUN_RO_FILE "/run/firejail/firejail.ro.file"
44#define RUN_MNT_DIR "/run/firejail/mnt" // a tmpfs is mounted on this directory before any of the files below are created
45#define RUN_CGROUP_CFG "/run/firejail/mnt/cgroup"
46#define RUN_CPU_CFG "/run/firejail/mnt/cpu"
47#define RUN_GROUPS_CFG "/run/firejail/mnt/groups"
48#define RUN_PROTOCOL_CFG "/run/firejail/mnt/protocol"
49#define RUN_NONEWPRIVS_CFG "/run/firejail/mnt/nonewprivs"
50#define RUN_HOME_DIR "/run/firejail/mnt/home"
51#define RUN_ETC_DIR "/run/firejail/mnt/etc"
52#define RUN_OPT_DIR "/run/firejail/mnt/opt"
53#define RUN_SRV_DIR "/run/firejail/mnt/srv"
54#define RUN_BIN_DIR "/run/firejail/mnt/bin"
55#define RUN_PULSE_DIR "/run/firejail/mnt/pulse"
56#define RUN_LIB_DIR "/run/firejail/mnt/lib"
57#define RUN_LIB_FILE "/run/firejail/mnt/libfiles"
58#define RUN_DNS_ETC "/run/firejail/mnt/dns-etc"
59
60#define RUN_SECCOMP_DIR "/run/firejail/mnt/seccomp"
61#define RUN_SECCOMP_LIST "/run/firejail/mnt/seccomp/seccomp.list" // list of seccomp files installed
62#define RUN_SECCOMP_PROTOCOL "/run/firejail/mnt/seccomp/seccomp.protocol" // protocol filter
63#define RUN_SECCOMP_CFG "/run/firejail/mnt/seccomp/seccomp" // configured filter
64#define RUN_SECCOMP_32 "/run/firejail/mnt/seccomp/seccomp.32" // 32bit arch filter installed on 64bit architectures
65#define RUN_SECCOMP_MDWX "/run/firejail/mnt/seccomp/seccomp.mdwx" // filter for memory-deny-write-execute
66#define RUN_SECCOMP_BLOCK_SECONDARY "/run/firejail/mnt/seccomp/seccomp.block_secondary" // secondary arch blocking filter
67#define RUN_SECCOMP_POSTEXEC "/run/firejail/mnt/seccomp/seccomp.postexec" // filter for post-exec library
68#define PATH_SECCOMP_DEFAULT (LIBDIR "/firejail/seccomp") // default filter built during make
69#define PATH_SECCOMP_DEFAULT_DEBUG (LIBDIR "/firejail/seccomp.debug") // default filter built during make
70#define PATH_SECCOMP_32 (LIBDIR "/firejail/seccomp.32") // 32bit arch filter built during make
71#define PATH_SECCOMP_MDWX (LIBDIR "/firejail/seccomp.mdwx") // filter for memory-deny-write-execute built during make
72#define PATH_SECCOMP_BLOCK_SECONDARY (LIBDIR "/firejail/seccomp.block_secondary") // secondary arch blocking filter built during make
73
74
75#define RUN_DEV_DIR "/run/firejail/mnt/dev"
76#define RUN_DEVLOG_FILE "/run/firejail/mnt/devlog"
77
78#define RUN_WHITELIST_X11_DIR "/run/firejail/mnt/orig-x11"
79#define RUN_WHITELIST_HOME_DIR "/run/firejail/mnt/orig-home" // default home directory masking
80#define RUN_WHITELIST_RUN_DIR "/run/firejail/mnt/orig-run" // default run directory masking
81#define RUN_WHITELIST_HOME_USER_DIR "/run/firejail/mnt/orig-home-user" // home directory whitelisting
82#define RUN_WHITELIST_RUN_USER_DIR "/run/firejail/mnt/orig-run-user" // run directory whitelisting
83#define RUN_WHITELIST_TMP_DIR "/run/firejail/mnt/orig-tmp"
84#define RUN_WHITELIST_MEDIA_DIR "/run/firejail/mnt/orig-media"
85#define RUN_WHITELIST_MNT_DIR "/run/firejail/mnt/orig-mnt"
86#define RUN_WHITELIST_VAR_DIR "/run/firejail/mnt/orig-var"
87#define RUN_WHITELIST_DEV_DIR "/run/firejail/mnt/orig-dev"
88#define RUN_WHITELIST_OPT_DIR "/run/firejail/mnt/orig-opt"
89#define RUN_WHITELIST_SRV_DIR "/run/firejail/mnt/orig-srv"
90#define RUN_WHITELIST_ETC_DIR "/run/firejail/mnt/orig-etc"
91#define RUN_WHITELIST_SHARE_DIR "/run/firejail/mnt/orig-share"
92#define RUN_WHITELIST_MODULE_DIR "/run/firejail/mnt/orig-module"
93
94#define RUN_XAUTHORITY_FILE "/run/firejail/mnt/.Xauthority"
95#define RUN_XAUTHORITY_SEC_FILE "/run/firejail/mnt/sec.Xauthority"
96#define RUN_ASOUNDRC_FILE "/run/firejail/mnt/.asoundrc"
97#define RUN_HOSTNAME_FILE "/run/firejail/mnt/hostname"
98#define RUN_HOSTS_FILE "/run/firejail/mnt/hosts"
99#define RUN_MACHINEID "/run/firejail/mnt/machine-id"
100#define RUN_LDPRELOAD_FILE "/run/firejail/mnt/ld.so.preload"
101#define RUN_UTMP_FILE "/run/firejail/mnt/utmp"
102#define RUN_PASSWD_FILE "/run/firejail/mnt/passwd"
103#define RUN_GROUP_FILE "/run/firejail/mnt/group"
104#define RUN_FSLOGGER_FILE "/run/firejail/mnt/fslogger"
105#define RUN_UMASK_FILE "/run/firejail/mnt/umask"
106#define RUN_OVERLAY_ROOT "/run/firejail/mnt/oroot"
107#define RUN_READY_FOR_JOIN "/run/firejail/mnt/ready-for-join"
108 31
109 32
110// profiles 33// profiles
diff --git a/src/libpostexecseccomp/Makefile.in b/src/libpostexecseccomp/Makefile.in
index 92803342c..8d6dde4e0 100644
--- a/src/libpostexecseccomp/Makefile.in
+++ b/src/libpostexecseccomp/Makefile.in
@@ -13,13 +13,12 @@ LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now
13 13
14all: libpostexecseccomp.so 14all: libpostexecseccomp.so
15 15
16%.o : %.c $(H_FILE_LIST) 16%.o : %.c $(H_FILE_LIST) ../include/seccomp.h ../include/rundefs.h
17 $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ 17 $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
18 18
19libpostexecseccomp.so: $(OBJS) 19libpostexecseccomp.so: $(OBJS)
20 $(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl 20 $(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl
21 21
22
23clean:; rm -f $(OBJS) libpostexecseccomp.so 22clean:; rm -f $(OBJS) libpostexecseccomp.so
24 23
25distclean: clean 24distclean: clean
diff --git a/src/libpostexecseccomp/libpostexecseccomp.c b/src/libpostexecseccomp/libpostexecseccomp.c
index e51445de4..3983510ec 100644
--- a/src/libpostexecseccomp/libpostexecseccomp.c
+++ b/src/libpostexecseccomp/libpostexecseccomp.c
@@ -17,19 +17,22 @@
17 * with this program; if not, write to the Free Software Foundation, Inc., 17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/ 19*/
20#include "libpostexecseccomp.h"
21#include "../include/seccomp.h" 20#include "../include/seccomp.h"
21#include "../include/rundefs.h"
22#include <fcntl.h> 22#include <fcntl.h>
23#include <linux/filter.h> 23#include <linux/filter.h>
24#include <sys/mman.h> 24#include <sys/mman.h>
25#include <sys/prctl.h> 25#include <sys/prctl.h>
26#include <unistd.h> 26#include <unistd.h>
27#include <stdio.h>
27 28
28__attribute__((constructor)) 29__attribute__((constructor))
29static void load_seccomp(void) { 30static void load_seccomp(void) {
30 int fd = open(RUN_SECCOMP_POSTEXEC, O_RDONLY); 31 int fd = open(RUN_SECCOMP_POSTEXEC, O_RDONLY);
31 if (fd == -1) 32 if (fd == -1) {
33 fprintf(stderr, "Error: cannot open seccomp postexec filter file %s\n", RUN_SECCOMP_POSTEXEC);
32 return; 34 return;
35 }
33 36
34 off_t size = lseek(fd, 0, SEEK_END); 37 off_t size = lseek(fd, 0, SEEK_END);
35 if (size <= 0) { 38 if (size <= 0) {
@@ -40,11 +43,12 @@ static void load_seccomp(void) {
40 struct sock_filter *filter = MAP_FAILED; 43 struct sock_filter *filter = MAP_FAILED;
41 if (size != 0) 44 if (size != 0)
42 filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); 45 filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
43
44 close(fd); 46 close(fd);
45 47
46 if (filter == MAP_FAILED) 48 if (filter == MAP_FAILED) {
49 fprintf(stderr, "Error: cannot map seccomp postexec filter data\n");
47 return; 50 return;
51 }
48 52
49 // install filter 53 // install filter
50 struct sock_fprog prog = { 54 struct sock_fprog prog = {