aboutsummaryrefslogtreecommitdiffstats
path: root/src/faudit
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2016-07-02 07:41:19 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2016-07-02 07:41:19 -0400
commit7655973d13775fc8a939cae7ebbadf3b38209a02 (patch)
tree07792b22f23daa4cc51298fdca3db75e78f3a679 /src/faudit
parentaudit pid (diff)
downloadfirejail-7655973d13775fc8a939cae7ebbadf3b38209a02.tar.gz
firejail-7655973d13775fc8a939cae7ebbadf3b38209a02.tar.zst
firejail-7655973d13775fc8a939cae7ebbadf3b38209a02.zip
faudit: caps
Diffstat (limited to 'src/faudit')
-rw-r--r--src/faudit/caps.c77
-rw-r--r--src/faudit/faudit.h4
-rw-r--r--src/faudit/main.c7
-rw-r--r--src/faudit/pid.c6
4 files changed, 89 insertions, 5 deletions
diff --git a/src/faudit/caps.c b/src/faudit/caps.c
new file mode 100644
index 000000000..364cfcd03
--- /dev/null
+++ b/src/faudit/caps.c
@@ -0,0 +1,77 @@
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_caps(uint64_t *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, "CapBnd:\t", 8) == 0) {
32 char *ptr = buf + 8;
33 unsigned long long tmp;
34 sscanf(ptr, "%llx", &tmp);
35 *val = tmp;
36 fclose(fp);
37 return 0;
38 }
39 }
40
41 fclose(fp);
42 return 1;
43}
44
45// return 1 if the capability is in tbe map
46static int check_capability(uint64_t map, int cap) {
47 int i;
48 uint64_t mask = 1ULL;
49
50 for (i = 0; i < 64; i++, mask <<= 1) {
51 if ((i == cap) && (mask & map))
52 return 1;
53 }
54
55 return 0;
56}
57
58void caps(void) {
59 uint64_t caps_val;
60
61 if (extract_caps(&caps_val)) {
62 printf("SKIP: cannot extract capabilities on this platform\n");
63 return;
64 }
65
66 if (caps_val) {
67 printf("BAD: the capability map is %llx, it should be all zero\n", (unsigned long long) caps_val);
68
69 if (check_capability(caps_val, CAP_SYS_ADMIN))
70 printf("UGLY: CAP_SYS_ADMIN is enabled\n");
71 if (check_capability(caps_val, CAP_SYS_BOOT))
72 printf("UGLY: CAP_SYS_BOOT is enabled\n");
73 }
74 else
75 printf("GOOD: all capabilities are disabled\n");
76}
77
diff --git a/src/faudit/faudit.h b/src/faudit/faudit.h
index 9c001c285..74426ac0a 100644
--- a/src/faudit/faudit.h
+++ b/src/faudit/faudit.h
@@ -22,6 +22,7 @@
22#define FAUDIT_H 22#define FAUDIT_H
23#include <stdio.h> 23#include <stdio.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <stdint.h>
25#include <string.h> 26#include <string.h>
26#include <unistd.h> 27#include <unistd.h>
27#include <sys/types.h> 28#include <sys/types.h>
@@ -34,4 +35,7 @@
34// pid.c 35// pid.c
35void pid(void); 36void pid(void);
36 37
38// caps.c
39void caps(void);
40
37#endif \ No newline at end of file 41#endif \ No newline at end of file
diff --git a/src/faudit/main.c b/src/faudit/main.c
index d90eb1c0b..a3407caa1 100644
--- a/src/faudit/main.c
+++ b/src/faudit/main.c
@@ -20,12 +20,15 @@
20#include "faudit.h" 20#include "faudit.h"
21 21
22int main(int argc, char **argv) { 22int main(int argc, char **argv) {
23 printf("FAUDIT: Firejail audit started\n"); 23 printf("\n----- Firejail Audit: the Good, the Bad and the Ugly -----\n");
24 24
25 // check pid namespace 25 // check pid namespace
26 pid(); 26 pid();
27
28 // chack capabilities
29 caps();
27 30
28 printf("FAUDIT: Firejail audit ended\n"); 31 printf("----------------------------------------------------------\n");
29 return 0; 32 return 0;
30 33
31} 34}
diff --git a/src/faudit/pid.c b/src/faudit/pid.c
index 861324255..a6f02c051 100644
--- a/src/faudit/pid.c
+++ b/src/faudit/pid.c
@@ -69,7 +69,7 @@ void pid(void) {
69 if (strncmp(buf, kern_proc[j], strlen(kern_proc[j])) == 0) { 69 if (strncmp(buf, kern_proc[j], strlen(kern_proc[j])) == 0) {
70 fclose(fp); 70 fclose(fp);
71 free(fname); 71 free(fname);
72 printf("FAUDIT: Process PID %d, not running in a PID namespace\n", getpid()); 72 printf("BAD: Process PID %d, not running in a PID namespace\n", getpid());
73 return; 73 return;
74 } 74 }
75 j++; 75 j++;
@@ -80,10 +80,10 @@ void pid(void) {
80 } 80 }
81 81
82 82
83 printf("FAUDIT: Process PID %d, running in a PID namespace\n", getpid()); 83 printf("GOOD: Process PID %d, running in a PID namespace\n", getpid());
84 84
85 // try to guess the type of container/sandbox 85 // try to guess the type of container/sandbox
86 char *str = getenv("container"); 86 char *str = getenv("container");
87 if (str) 87 if (str)
88 printf("FAUDIT: Container/sandbox: %s\n", str); 88 printf("Container/sandbox: %s\n", str);
89} 89}