summaryrefslogtreecommitdiffstats
path: root/src/libpostexecseccomp
diff options
context:
space:
mode:
authorLibravatar Topi Miettinen <toiwoton@gmail.com>2017-08-13 14:07:31 +0300
committerLibravatar Topi Miettinen <toiwoton@gmail.com>2017-08-13 17:31:07 +0300
commit63e9d849f662d1a494c6396d4a439cd4c91dfa7e (patch)
tree703cc8c9c0eb5b9e528f025961df7f322f797737 /src/libpostexecseccomp
parentmerges (diff)
downloadfirejail-63e9d849f662d1a494c6396d4a439cd4c91dfa7e.tar.gz
firejail-63e9d849f662d1a494c6396d4a439cd4c91dfa7e.tar.zst
firejail-63e9d849f662d1a494c6396d4a439cd4c91dfa7e.zip
Allow any syscall to be blacklisted (#1447)
Allow any syscall to be blacklisted with aid of LD_PRELOAD library, libpostexecseccomp.so. Closes: #1447
Diffstat (limited to 'src/libpostexecseccomp')
-rw-r--r--src/libpostexecseccomp/Makefile.in26
-rw-r--r--src/libpostexecseccomp/libpostexecseccomp.c59
-rw-r--r--src/libpostexecseccomp/libpostexecseccomp.h25
3 files changed, 110 insertions, 0 deletions
diff --git a/src/libpostexecseccomp/Makefile.in b/src/libpostexecseccomp/Makefile.in
new file mode 100644
index 000000000..92803342c
--- /dev/null
+++ b/src/libpostexecseccomp/Makefile.in
@@ -0,0 +1,26 @@
1CC=@CC@
2PREFIX=@prefix@
3VERSION=@PACKAGE_VERSION@
4NAME=@PACKAGE_NAME@
5HAVE_FATAL_WARNINGS=@HAVE_FATAL_WARNINGS@
6
7H_FILE_LIST = $(sort $(wildcard *.[h]))
8C_FILE_LIST = $(sort $(wildcard *.c))
9OBJS = $(C_FILE_LIST:.c=.o)
10BINOBJS = $(foreach file, $(OBJS), $file)
11CFLAGS += -ggdb $(HAVE_FATAL_WARNINGS) -O2 -DVERSION='"$(VERSION)"' -fstack-protector-all -D_FORTIFY_SOURCE=2 -fPIC -Wformat -Wformat-security
12LDFLAGS += -pie -Wl,-z,relro -Wl,-z,now
13
14all: libpostexecseccomp.so
15
16%.o : %.c $(H_FILE_LIST)
17 $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
18
19libpostexecseccomp.so: $(OBJS)
20 $(CC) $(LDFLAGS) -shared -fPIC -z relro -o $@ $(OBJS) -ldl
21
22
23clean:; rm -f $(OBJS) libpostexecseccomp.so
24
25distclean: clean
26 rm -fr Makefile
diff --git a/src/libpostexecseccomp/libpostexecseccomp.c b/src/libpostexecseccomp/libpostexecseccomp.c
new file mode 100644
index 000000000..801f968a6
--- /dev/null
+++ b/src/libpostexecseccomp/libpostexecseccomp.c
@@ -0,0 +1,59 @@
1/*
2 * Copyright (C) 2017 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 "libpostexecseccomp.h"
21#include <fcntl.h>
22#include <linux/audit.h>
23#include <linux/bpf.h>
24#include <linux/filter.h>
25#include <linux/seccomp.h>
26#include <sys/mman.h>
27#include <sys/prctl.h>
28#include <sys/ptrace.h>
29#include <sys/stat.h>
30#include <sys/types.h>
31#include <unistd.h>
32
33__attribute__((constructor))
34static void load_seccomp(void) {
35 int fd = open(RUN_SECCOMP_POSTEXEC, O_RDONLY);
36 if (fd == -1)
37 return;
38
39 int size = lseek(fd, 0, SEEK_END);
40 unsigned short entries = (unsigned short) size / (unsigned short) sizeof(struct sock_filter);
41 struct sock_filter *filter = MAP_FAILED;
42 if (size != 0)
43 filter = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
44
45 close(fd);
46
47 if (size == 0 || filter == MAP_FAILED)
48 return;
49
50 // install filter
51 struct sock_fprog prog = {
52 .len = entries,
53 .filter = filter,
54 };
55
56 prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0);
57 prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog);
58 munmap(filter, size);
59}
diff --git a/src/libpostexecseccomp/libpostexecseccomp.h b/src/libpostexecseccomp/libpostexecseccomp.h
new file mode 100644
index 000000000..c4aca540a
--- /dev/null
+++ b/src/libpostexecseccomp/libpostexecseccomp.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2017 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#ifndef LIBPOSTEXECSECCOMP_H
21#define LIBPOSTEXECSECCOMP_H
22
23#define RUN_SECCOMP_POSTEXEC "/run/firejail/mnt/seccomp.postexec"
24
25#endif