diff options
author | netblue30 <netblue30@yahoo.com> | 2016-07-02 09:48:57 -0400 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2016-07-02 09:48:57 -0400 |
commit | 7ac22ed3588ce9e8bb5ec7ebd3d7062dcf65a64c (patch) | |
tree | ce7c86ad245b580acd5230addb73e2be875930ef /src/faudit/seccomp.c | |
parent | faudit: caps (diff) | |
download | firejail-7ac22ed3588ce9e8bb5ec7ebd3d7062dcf65a64c.tar.gz firejail-7ac22ed3588ce9e8bb5ec7ebd3d7062dcf65a64c.tar.zst firejail-7ac22ed3588ce9e8bb5ec7ebd3d7062dcf65a64c.zip |
audit: seccomp
Diffstat (limited to 'src/faudit/seccomp.c')
-rw-r--r-- | src/faudit/seccomp.c | 64 |
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 | ||
24 | static 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 | |||
45 | void 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 | ||