diff options
author | Fred Barclay <Fred-Barclay@users.noreply.github.com> | 2017-05-22 01:48:27 -0500 |
---|---|---|
committer | Fred Barclay <Fred-Barclay@users.noreply.github.com> | 2017-05-22 01:48:27 -0500 |
commit | cfbcbf2c95455373aa2570827c52b7b87d80cfef (patch) | |
tree | a29ac95c58a14c7f69c9b900b10fd1d63ba4ec19 /src/firejail/fs_dev.c | |
parent | Fix 1291 - remove nonexistent *.inc from qupzilla profile (diff) | |
download | firejail-cfbcbf2c95455373aa2570827c52b7b87d80cfef.tar.gz firejail-cfbcbf2c95455373aa2570827c52b7b87d80cfef.tar.zst firejail-cfbcbf2c95455373aa2570827c52b7b87d80cfef.zip |
--novideo option
Still a work in progress. Code needs cleanup and improvement, but
it does block /dev/video* in all of my tests so far.
Diffstat (limited to 'src/firejail/fs_dev.c')
-rw-r--r-- | src/firejail/fs_dev.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/firejail/fs_dev.c b/src/firejail/fs_dev.c index 9b73ac9fc..159c8e654 100644 --- a/src/firejail/fs_dev.c +++ b/src/firejail/fs_dev.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <fcntl.h> | 26 | #include <fcntl.h> |
27 | #include <pwd.h> | 27 | #include <pwd.h> |
28 | #ifndef _BSD_SOURCE | 28 | #ifndef _BSD_SOURCE |
29 | #define _BSD_SOURCE | 29 | #define _BSD_SOURCE |
30 | #endif | 30 | #endif |
31 | #include <sys/sysmacros.h> | 31 | #include <sys/sysmacros.h> |
32 | #include <sys/types.h> | 32 | #include <sys/types.h> |
@@ -35,6 +35,7 @@ typedef struct { | |||
35 | const char *dev_fname; | 35 | const char *dev_fname; |
36 | const char *run_fname; | 36 | const char *run_fname; |
37 | int sound; | 37 | int sound; |
38 | int video; | ||
38 | int hw3d; | 39 | int hw3d; |
39 | } DevEntry; | 40 | } DevEntry; |
40 | 41 | ||
@@ -93,16 +94,16 @@ static void deventry_mount(void) { | |||
93 | fclose(fp); | 94 | fclose(fp); |
94 | } | 95 | } |
95 | } | 96 | } |
96 | 97 | ||
97 | if (mount(dev[i].run_fname, dev[i].dev_fname, NULL, MS_BIND|MS_REC, NULL) < 0) | 98 | if (mount(dev[i].run_fname, dev[i].dev_fname, NULL, MS_BIND|MS_REC, NULL) < 0) |
98 | errExit("mounting dev file"); | 99 | errExit("mounting dev file"); |
99 | fs_logger2("whitelist", dev[i].dev_fname); | 100 | fs_logger2("whitelist", dev[i].dev_fname); |
100 | } | 101 | } |
101 | 102 | ||
102 | i++; | 103 | i++; |
103 | } | 104 | } |
104 | } | 105 | } |
105 | 106 | ||
106 | static void create_char_dev(const char *path, mode_t mode, int major, int minor) { | 107 | static void create_char_dev(const char *path, mode_t mode, int major, int minor) { |
107 | dev_t dev = makedev(major, minor); | 108 | dev_t dev = makedev(major, minor); |
108 | if (mknod(path, S_IFCHR | mode, dev) == -1) | 109 | if (mknod(path, S_IFCHR | mode, dev) == -1) |
@@ -112,7 +113,7 @@ static void create_char_dev(const char *path, mode_t mode, int major, int minor) | |||
112 | ASSERT_PERMS(path, 0, 0, mode); | 113 | ASSERT_PERMS(path, 0, 0, mode); |
113 | 114 | ||
114 | return; | 115 | return; |
115 | 116 | ||
116 | errexit: | 117 | errexit: |
117 | fprintf(stderr, "Error: cannot create %s device\n", path); | 118 | fprintf(stderr, "Error: cannot create %s device\n", path); |
118 | exit(1); | 119 | exit(1); |
@@ -161,7 +162,7 @@ void fs_private_dev(void){ | |||
161 | if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) | 162 | if (mount("tmpfs", "/dev", "tmpfs", MS_NOSUID | MS_STRICTATIME | MS_REC, "mode=755,gid=0") < 0) |
162 | errExit("mounting /dev"); | 163 | errExit("mounting /dev"); |
163 | fs_logger("tmpfs /dev"); | 164 | fs_logger("tmpfs /dev"); |
164 | 165 | ||
165 | deventry_mount(); | 166 | deventry_mount(); |
166 | 167 | ||
167 | // bring back /dev/log | 168 | // bring back /dev/log |
@@ -174,11 +175,11 @@ void fs_private_dev(void){ | |||
174 | errExit("mounting /dev/log"); | 175 | errExit("mounting /dev/log"); |
175 | fs_logger("clone /dev/log"); | 176 | fs_logger("clone /dev/log"); |
176 | } | 177 | } |
177 | } | 178 | } |
178 | if (mount(RUN_RO_DIR, RUN_DEV_DIR, "none", MS_BIND, "mode=400,gid=0") < 0) | 179 | if (mount(RUN_RO_DIR, RUN_DEV_DIR, "none", MS_BIND, "mode=400,gid=0") < 0) |
179 | errExit("disable /dev/snd"); | 180 | errExit("disable /dev/snd"); |
180 | 181 | ||
181 | 182 | ||
182 | // create /dev/shm | 183 | // create /dev/shm |
183 | if (arg_debug) | 184 | if (arg_debug) |
184 | printf("Create /dev/shm directory\n"); | 185 | printf("Create /dev/shm directory\n"); |
@@ -267,24 +268,24 @@ void fs_dev_shm(void) { | |||
267 | fwarning("/dev/shm not mounted\n"); | 268 | fwarning("/dev/shm not mounted\n"); |
268 | dbg_test_dir("/dev/shm"); | 269 | dbg_test_dir("/dev/shm"); |
269 | } | 270 | } |
270 | 271 | ||
271 | } | 272 | } |
272 | } | 273 | } |
273 | #endif | 274 | #endif |
274 | 275 | ||
275 | static void disable_file_or_dir(const char *fname) { | 276 | static void disable_file_or_dir(const char *fname) { |
276 | if (arg_debug) | 277 | if (arg_debug) |
277 | printf("disable %s\n", fname); | 278 | printf("disable %s\n", fname); |
278 | struct stat s; | 279 | struct stat s; |
279 | if (stat(fname, &s) != -1) { | 280 | if (stat(fname, &s) != -1) { |
280 | if (is_dir(fname)) { | 281 | if (is_dir(fname)) { |
281 | if (mount(RUN_RO_DIR, fname, "none", MS_BIND, "mode=400,gid=0") < 0) | 282 | if (mount(RUN_RO_DIR, fname, "none", MS_BIND, "mode=400,gid=0") < 0) |
282 | errExit("disable directory"); | 283 | errExit("disable directory"); |
283 | } | 284 | } |
284 | else { | 285 | else { |
285 | if (mount(RUN_RO_FILE, fname, "none", MS_BIND, "mode=400,gid=0") < 0) | 286 | if (mount(RUN_RO_FILE, fname, "none", MS_BIND, "mode=400,gid=0") < 0) |
286 | errExit("disable file"); | 287 | errExit("disable file"); |
287 | } | 288 | } |
288 | } | 289 | } |
289 | fs_logger2("blacklist", fname); | 290 | fs_logger2("blacklist", fname); |
290 | 291 | ||
@@ -299,6 +300,15 @@ void fs_dev_disable_sound(void) { | |||
299 | } | 300 | } |
300 | } | 301 | } |
301 | 302 | ||
303 | void fs_dev_disable_video(void) { | ||
304 | int i = 0; | ||
305 | while (dev[i].dev_fname != NULL) { | ||
306 | if (dev[i].video) | ||
307 | disable_file_or_dir(dev[i].dev_fname); | ||
308 | i++; | ||
309 | } | ||
310 | } | ||
311 | |||
302 | void fs_dev_disable_3d(void) { | 312 | void fs_dev_disable_3d(void) { |
303 | int i = 0; | 313 | int i = 0; |
304 | while (dev[i].dev_fname != NULL) { | 314 | while (dev[i].dev_fname != NULL) { |