Commit c03df1ba authored by Tycho Andersen's avatar Tycho Andersen Committed by Pavel Emelyanov

add a test for SECCOMP_MODE_STRICT

Note that we don't add the test into the list of tests to run, because it will
fail without the associated kernel patch.

v2: spin lock until seccomp strict is set on the child
Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 0d8aec0c
...@@ -333,6 +333,7 @@ netns-dev ...@@ -333,6 +333,7 @@ netns-dev
sockets00 sockets00
cow01 cow01
apparmor apparmor
seccomp_strict
" "
CRIU_CPT=$CRIU CRIU_CPT=$CRIU
......
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
/live/static/rtc /live/static/rtc
/live/static/sched_policy00 /live/static/sched_policy00
/live/static/sched_prio00 /live/static/sched_prio00
/live/static/seccomp_strict
/live/static/selfexe00 /live/static/selfexe00
/live/static/sem /live/static/sem
/live/static/session00 /live/static/session00
......
...@@ -123,6 +123,7 @@ TST_NOFILE = \ ...@@ -123,6 +123,7 @@ TST_NOFILE = \
aio00 \ aio00 \
fd \ fd \
apparmor \ apparmor \
seccomp_strict \
# jobctl00 \ # jobctl00 \
TST_FILE = \ TST_FILE = \
......
#include <unistd.h>
#include <stdbool.h>
#include <signal.h>
#include <sys/prctl.h>
#include <linux/seccomp.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Check that SECCOMP_MODE_STRICT is restored";
const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>";
int get_seccomp_mode(pid_t pid, bool after_checkpoint)
{
FILE *f;
char buf[PATH_MAX];
sprintf(buf, "/proc/%d/status", pid);
f = fopen(buf, "r+");
if (!f) {
err("fopen failed");
return -1;
}
while (NULL != fgets(buf, sizeof(buf), f)) {
int mode;
char state;
if (after_checkpoint && sscanf(buf, "State: %c %*s", &state) == 1 && state != 'R') {
fail("resumed but state is not R (%c), seccomp killed the process during resume\n", state);
break;
}
if (sscanf(buf, "Seccomp:\t%d", &mode) != 1)
continue;
fclose(f);
return mode;
}
fclose(f);
return -1;
}
int main(int argc, char ** argv)
{
pid_t pid;
int ret = 1, mode;
test_init(argc, argv);
pid = fork();
if (pid < 0) {
err("fork");
return -1;
}
if (pid == 0) {
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_STRICT) < 0) {
err("prctl failed");
return -1;
}
while(1)
/* can't sleep() here, seccomp kills us */;
}
while(get_seccomp_mode(pid, false) != SECCOMP_MODE_STRICT)
sleep(1);
test_daemon();
test_waitsig();
mode = get_seccomp_mode(pid, true);
if (mode != SECCOMP_MODE_STRICT) {
fail("seccomp mode mismatch %d\n", mode);
} else {
pass();
ret = 0;
}
kill(pid, SIGKILL);
return ret;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment