aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/seccomp.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2017-08-20 11:11:50 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2017-08-20 11:11:50 -0400
commit02302cb0ceed6689d0b3cca3609df258b8c86e28 (patch)
treec8d137215c80378d6aa8d35d6500414f3ef6e1ce /src/firejail/seccomp.c
parentMerge branch 'master' of https://github.com/netblue30/firejail (diff)
downloadfirejail-02302cb0ceed6689d0b3cca3609df258b8c86e28.tar.gz
firejail-02302cb0ceed6689d0b3cca3609df258b8c86e28.tar.zst
firejail-02302cb0ceed6689d0b3cca3609df258b8c86e28.zip
enhancement: print all seccomp filters under --debug
Diffstat (limited to 'src/firejail/seccomp.c')
-rw-r--r--src/firejail/seccomp.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/firejail/seccomp.c b/src/firejail/seccomp.c
index aaf53b2a1..f0b25c8cc 100644
--- a/src/firejail/seccomp.c
+++ b/src/firejail/seccomp.c
@@ -26,6 +26,7 @@
26typedef struct filter_list { 26typedef struct filter_list {
27 struct filter_list *next; 27 struct filter_list *next;
28 struct sock_fprog prog; 28 struct sock_fprog prog;
29 const char *fname;
29} FilterList; 30} FilterList;
30 31
31static FilterList *filter_list_head = NULL; 32static FilterList *filter_list_head = NULL;
@@ -67,6 +68,10 @@ int seccomp_install_filters(void) {
67 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); 68 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
68 69
69 for (; fl; fl = fl->next) { 70 for (; fl; fl = fl->next) {
71 assert(fl->fname);
72 if (arg_debug)
73 printf("Installing %s seccomp filter\n", fl->fname);
74
70 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &fl->prog)) { 75 if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &fl->prog)) {
71 if (!err_printed) 76 if (!err_printed)
72 fwarning("seccomp disabled, it requires a Linux kernel version 3.5 or newer.\n"); 77 fwarning("seccomp disabled, it requires a Linux kernel version 3.5 or newer.\n");
@@ -92,7 +97,7 @@ int seccomp_load(const char *fname) {
92 goto errexit; 97 goto errexit;
93 unsigned short entries = (unsigned short) size / (unsigned short) sizeof(struct sock_filter); 98 unsigned short entries = (unsigned short) size / (unsigned short) sizeof(struct sock_filter);
94 if (arg_debug) 99 if (arg_debug)
95 printf("configuring %d seccomp entries from %s\n", entries, fname); 100 printf("configuring %d seccomp entries in %s\n", entries, fname);
96 101
97 // read filter 102 // read filter
98 struct sock_filter *filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); 103 struct sock_filter *filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
@@ -110,7 +115,16 @@ int seccomp_load(const char *fname) {
110 fl->next = filter_list_head; 115 fl->next = filter_list_head;
111 fl->prog.len = entries; 116 fl->prog.len = entries;
112 fl->prog.filter = filter; 117 fl->prog.filter = filter;
118 fl->fname = strdup(fname);
119 if (fl->fname == NULL)
120 errExit("strdup");
113 filter_list_head = fl; 121 filter_list_head = fl;
122
123 if (arg_debug && access(PATH_FSECCOMP, X_OK) == 0) {
124 sbox_run(SBOX_USER | SBOX_CAPS_NONE | SBOX_SECCOMP, 3,
125 PATH_FSECCOMP, "print", fname);
126 }
127
114 return 0; 128 return 0;
115errexit: 129errexit:
116 fprintf(stderr, "Error: cannot read %s\n", fname); 130 fprintf(stderr, "Error: cannot read %s\n", fname);
@@ -221,12 +235,12 @@ int seccomp_filter_drop(int enforce_seccomp) {
221 } 235 }
222 236
223 if (arg_debug && access(PATH_FSECCOMP, X_OK) == 0) { 237 if (arg_debug && access(PATH_FSECCOMP, X_OK) == 0) {
224 sbox_run(SBOX_USER | SBOX_CAPS_NONE | SBOX_SECCOMP, 3,
225 PATH_FSECCOMP, "print", RUN_SECCOMP_CFG);
226 struct stat st; 238 struct stat st;
227 if (stat(RUN_SECCOMP_POSTEXEC, &st) != -1 && st.st_size != 0) 239 if (stat(RUN_SECCOMP_POSTEXEC, &st) != -1 && st.st_size != 0) {
228 sbox_run(SBOX_USER | SBOX_CAPS_NONE | SBOX_SECCOMP, 3, 240 printf("configuring postexec seccomp filter in %s\n", RUN_SECCOMP_POSTEXEC);
229 PATH_FSECCOMP, "print", RUN_SECCOMP_POSTEXEC); 241 sbox_run(SBOX_USER | SBOX_CAPS_NONE | SBOX_SECCOMP, 3,
242 PATH_FSECCOMP, "print", RUN_SECCOMP_POSTEXEC);
243 }
230 } 244 }
231 245
232 return 0; 246 return 0;