Skip to content

Commit f13afab

Browse files
committed
Use Linux 5.4's seccomp-bpf userspace notifications
This change finally gets rid of all the weird SIGSYS detectors in favor of seccomp-bpf userspace notifications. Now all the forbidden syscalls are being tracked, regardless of which process triggered it, since before only the first process in the tree would get the correct SIGSYS notification to the pid1 process. This also now works with a debugger and `strace(1)`, since `ptrace(2)` is now officially supported!
1 parent 8948ad9 commit f13afab

14 files changed

Lines changed: 408 additions & 855 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*.stamp
55
java-compile
66
omegajail
7-
sigsys-tracer
87
stdio-mux
98
.mypy_cache/
109

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[submodule "minijail"]
22
path = minijail
33
url = https://android.googlesource.com/platform/external/minijail
4-
branch = master
4+
branch = refs/changes/98/1538098/17
55
[submodule "cxxopts"]
66
path = cxxopts
77
url = https://github.com/jarro2783/cxxopts.git

Makefile

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
BINARIES := omegajail sigsys-tracer stdio-mux java-compile
1+
BINARIES := omegajail stdio-mux java-compile
22
POLICIES := policies/gcc.bpf policies/cpp.bpf policies/ghc.bpf policies/hs.bpf \
33
policies/javac.bpf policies/java.bpf policies/fpc.bpf policies/pas.bpf \
44
policies/pyc.bpf policies/py.bpf policies/ruby.bpf policies/lua.bpf \
@@ -19,11 +19,11 @@ ARCH ?= $(shell uname -m)
1919
CXX ?= g++
2020
CFLAGS += -Wall -Werror -O2
2121
CXXFLAGS += -std=c++2a
22-
LDFLAGS += -lcap -fPIE -fstack-protector
22+
LDFLAGS += -lcap -pthread -fPIE -fstack-protector
2323

2424
TEST_CFLAGS += $(CFLAGS)
2525
TEST_CXXFLAGS += $(CXXFLAGS) -isystem googletest/googletest/include
26-
TEST_LDFLAGS += $(LDFLAGS) -pthread
26+
TEST_LDFLAGS += $(LDFLAGS)
2727

2828
.PHONY: all
2929
all: ${BINARIES} ${POLICIES}
@@ -51,19 +51,18 @@ args.o: args.cpp args.h logging.h version.h
5151
omegajail: main.cpp ${MINIJAIL_CORE_OBJECT_FILES} args.o util.o logging.o version.o
5252
$(CXX) $(CFLAGS) $(CXXFLAGS) -fno-exceptions $^ $(LDFLAGS) -o $@
5353

54-
sigsys-tracer: sigsys_tracer.cpp ${MINIJAIL_CORE_OBJECT_FILES} util.o logging.o
55-
$(CXX) $(CFLAGS) $(CXXFLAGS) -fno-exceptions $^ $(LDFLAGS) -o $@
56-
5754
stdio-mux: stdio_mux.cpp util.o logging.o
5855
$(CXX) $(CFLAGS) $(CXXFLAGS) -fno-exceptions $^ $(LDFLAGS) -o $@
5956

6057
java-compile: java_compile.cpp util.o logging.o
6158
$(CXX) $(CFLAGS) $(CXXFLAGS) -Os -fno-exceptions $^ $(LDFLAGS) -static -o $@
6259

63-
policies/%.bpf: policies/%.policy | minijail/constants.json
60+
policies/%.bpf: policies/%.policy policies/omegajail.policy | minijail/constants.json
6461
./minijail/tools/compile_seccomp_policy.py \
65-
--use-kill-process --arch-json=minijail/constants.json \
66-
$^ $@
62+
--use-kill-process \
63+
--default-action=user-notify \
64+
--arch-json=minijail/constants.json \
65+
$< $@
6766

6867
.PHONY: install
6968
install: ${BINARIES} tools/omegajail-setup ${POLICIES}

args.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ ParseArgs(int argc, char* argv[], const std::string_view cwd) throw() {
104104
cxxopts::value<int64_t>()->default_value("-1"), "bytes")
105105
("cgroup-memory-limit", "sets the memory limit with cgroups",
106106
cxxopts::value<ssize_t>(), "bytes")
107-
("sigsys-detector", "one of 'sigsys_tracer' (default), 'ptrace', 'none'.",
108-
cxxopts::value<std::string>())
109107
("disable-sandboxing",
110108
"completely disable containerization. This is very insecure and should "
111109
"only be used when omegajail is already being run in a container",
@@ -210,20 +208,6 @@ bool Args::Parse(int argc, char* argv[], struct minijail* j) throw() {
210208
stderr_redirect = MakeAbsolute(options["stderr"].as<std::string>(), cwd);
211209
if (options.count("meta"))
212210
meta = options["meta"].as<std::string>();
213-
if (options.count("sigsys-detector")) {
214-
std::string detector = options["sigsys-detector"].as<std::string>();
215-
if (detector == "sigsys_tracer") {
216-
sigsys_detector = SigsysDetector::SIGSYS_TRACER;
217-
} else if (detector == "ptrace") {
218-
sigsys_detector = SigsysDetector::PTRACE;
219-
} else if (detector == "none") {
220-
sigsys_detector = SigsysDetector::NONE;
221-
} else {
222-
std::cerr << "invalid value for --sigsys-detector: \"" << detector
223-
<< "\"";
224-
return false;
225-
}
226-
}
227211

228212
if (options.count("time-limit")) {
229213
uint64_t raw_limit_msec = options["time-limit"].as<uint64_t>();
@@ -630,7 +614,8 @@ std::string Args::UseSeccompProgram(const std::string_view seccomp_program_path,
630614

631615
if (!disable_sandboxing) {
632616
minijail_use_seccomp_filter(j);
633-
minijail_set_seccomp_filter_tsync(j);
617+
minijail_use_seccomp_filter_tsync(j);
618+
minijail_set_seccomp_filter_install_user_notification(j);
634619
minijail_set_seccomp_filters(j, &seccomp_program);
635620
}
636621
return std::string(seccomp_program_path.substr(

args.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111

1212
struct minijail;
1313

14-
enum class SigsysDetector {
15-
SIGSYS_TRACER,
16-
PTRACE,
17-
NONE,
18-
};
19-
2014
struct ResourceLimit {
2115
__rlimit_resource resource;
2216
struct rlimit rlim;
@@ -37,7 +31,6 @@ struct Args {
3731
ssize_t memory_limit_in_bytes = -1;
3832
size_t vm_memory_size_in_bytes = 0;
3933
uint64_t wall_time_limit_msec = kMaxWallTimeLimitMsec;
40-
SigsysDetector sigsys_detector = SigsysDetector::PTRACE;
4134
bool disable_sandboxing = false;
4235
std::vector<ResourceLimit> rlimits{
4336
ResourceLimit{RLIMIT_STACK, {RLIM_INFINITY, RLIM_INFINITY}}};

0 commit comments

Comments
 (0)