aboutsummaryrefslogtreecommitdiffstats
path: root/src/faudit/seccomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/faudit/seccomp.c')
-rw-r--r--src/faudit/seccomp.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/faudit/seccomp.c b/src/faudit/seccomp.c
new file mode 100644
index 000000000..a50ec1e0c
--- /dev/null
+++ b/src/faudit/seccomp.c
@@ -0,0 +1,64 @@
1/*
2 * Copyright (C) 2014-2016 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 "faudit.h"
21#include <linux/capability.h>
22
23#define MAXBUF 4098
24static int extract_seccomp(int *val) {
25 FILE *fp = fopen("/proc/self/status", "r");
26 if (!fp)
27 return 1;
28
29 char buf[MAXBUF];
30 while (fgets(buf, MAXBUF, fp)) {
31 if (strncmp(buf, "Seccomp:\t", 8) == 0) {
32 char *ptr = buf + 8;
33 int tmp;
34 sscanf(ptr, "%d", &tmp);
35 *val = tmp;
36 fclose(fp);
37 return 0;
38 }
39 }
40
41 fclose(fp);
42 return 1;
43}
44
45void seccomp_test(void) {
46 int seccomp_status;
47 int rv = extract_seccomp(&seccomp_status);
48
49 if (rv) {
50 printf("SKIP: cannot extract seccomp configuration on this platform\n");
51 return;
52 }
53
54 if (seccomp_status == 0)
55 printf("BAD: seccomp disabled\n");
56 else if (seccomp_status == 1)
57 printf("GOOD: seccomp strict mode - only read, write, _exit, and sigreturn are allowd\n");
58 else if (seccomp_status == 2) {
59 printf("GOOD: seccomp BPF enababled\n");
60 }
61 else
62 fprintf(stderr, "Error: unrecognized seccomp mode\n");
63
64} \ No newline at end of file