Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,7 @@ set(BASIC_TESTS
x86/seccomp_stop_remote_syscall
seccomp_tsync
seccomp_veto_exec
seccomp_veto_exit
self_shebang
self_sigint
sem
Expand Down
19 changes: 13 additions & 6 deletions src/replay_syscall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,10 @@ static void process_init_buffers(ReplayTask* t, ReplayTraceStep* step) {

static int non_negative_syscall(int sys) { return sys < 0 ? INT32_MAX : sys; }

static bool failed_during_preparation(ReplayTask* t) {
return t->current_trace_frame().event().Syscall().failed_during_preparation;
}

template <typename Arch>
static void rep_after_enter_syscall_arch(ReplayTask* t) {
switch (non_negative_syscall(t->regs().original_syscallno())) {
Expand Down Expand Up @@ -1051,14 +1055,17 @@ static void rep_after_enter_syscall_arch(ReplayTask* t) {
}

case Arch::exit:
/* Destroy buffers now to match when we destroyed them during recording.
It's possible for another mapping to be created overlapping our
buffers before this task truly exits, and we don't want to trash
that mapping by destroying our buffers then. */
t->destroy_buffers();
if (!failed_during_preparation(t)) {
/* Destroy buffers now to match when we destroyed them during recording.
It's possible for another mapping to be created overlapping our
buffers before this task truly exits, and we don't want to trash
that mapping by destroying our buffers then. */
t->destroy_buffers();
}
break;
case Arch::exit_group:
if (t->thread_group()->task_set().size() == 1) {
if (t->thread_group()->task_set().size() == 1 &&
!failed_during_preparation(t)) {
/* See above. */
t->destroy_buffers();
}
Expand Down
57 changes: 57 additions & 0 deletions src/test/seccomp_veto_exit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "util.h"

/* A single-threaded child's seccomp filter makes exit_group(VETOED_STATUS)
and exit(VETOED_STATUS) fail with E2BIG. The child makes both and goes on
to exit normally, so rr must keep its buffers until then, in recording
and in replay. */

#define VETOED_STATUS 66
#define CHILD_STATUS 77

static void install_filter(void) {
struct sock_filter filter[] = {
BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_exit_group, 1, 0),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, SYS_exit, 0, 3),
BPF_STMT(BPF_LD | BPF_W | BPF_ABS,
offsetof(struct seccomp_data, args[0])),
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, VETOED_STATUS, 0, 1),
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | E2BIG),
BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW)
};
struct sock_fprog prog = {
.len = (unsigned short)(sizeof(filter) / sizeof(filter[0])),
.filter = filter,
};
int ret;

test_assert(0 == prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0));
ret = syscall(RR_seccomp, SECCOMP_SET_MODE_FILTER, 0, &prog);
if (ret == -1 && errno == ENOSYS) {
ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog);
}
test_assert(ret == 0);
}

int main(void) {
pid_t child;
int status;

if (0 == (child = fork())) {
install_filter();
test_assert(-1 == syscall(SYS_exit_group, VETOED_STATUS));
test_assert(errno == E2BIG);
test_assert(-1 == syscall(SYS_exit, VETOED_STATUS));
test_assert(errno == E2BIG);
return CHILD_STATUS;
}
test_assert(child > 0);

test_assert(child == waitpid(child, &status, 0));
test_assert(WIFEXITED(status) && WEXITSTATUS(status) == CHILD_STATUS);

atomic_puts("EXIT-SUCCESS");
return 0;
}
Loading