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

lsm: add a test for apparmor

Signed-off-by: 's avatarTycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent cf7a7338
......@@ -198,6 +198,7 @@ generate_test_list()
ns/static/clean_mntns
static/remap_dead_pid
static/poll
static/apparmor
"
TEST_CR_KERNEL="
......@@ -330,6 +331,7 @@ mntns_rw_ro_rw
netns-dev
sockets00
cow01
apparmor
"
CRIU_CPT=$CRIU
......
/lib/libzdtmtst.a
/live/static/apparmor
/live/static/arm-neon00
/live/static/bind-mount
/live/static/busyloop00
......
......@@ -122,6 +122,7 @@ TST_NOFILE = \
remap_dead_pid \
aio00 \
fd \
apparmor \
# jobctl00 \
TST_FILE = \
......
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <linux/limits.h>
#include <signal.h>
#include "zdtmtst.h"
const char *test_doc = "Check that an apparmor profile is restored";
const char *test_author = "Tycho Andersen <tycho.andersen@canonical.com>";
#define PROFILE "criu_test"
int setprofile()
{
char profile[1024];
int fd, len;
len = snprintf(profile, sizeof(profile), "changeprofile " PROFILE);
if (len < 0 || len >= sizeof(profile)) {
fail("bad sprintf\n");
return -1;
}
fd = open("/proc/self/attr/current", O_WRONLY);
if (fd < 0) {
fail("couldn't open fd\n");
return -1;
}
/* apparmor wants this in exactly one write, so we use write() here
* vs. fprintf Just To Be Sure */
len = write(fd, profile, len);
close(fd);
if (len < 0) {
fail("couldn't write profile\n");
return -1;
}
return 0;
}
int checkprofile()
{
FILE *f;
char path[PATH_MAX], profile[1024];
int len;
sprintf(path, "/proc/self/attr/current");
f = fopen(path, "r");
if (!f) {
fail("couldn't open lsm current\n");
return -1;
}
len = fscanf(f, "%[^ \n]s", profile);
fclose(f);
if (len != 1) {
fail("wrong number of items scanned %d\n", len);
return -1;
}
if (strcmp(profile, PROFILE) != 0) {
fail("bad profile .%s. expected .%s.\n", profile, PROFILE);
return -1;
}
return 0;
}
int main(int argc, char **argv)
{
test_init(argc, argv);
if (access("/sys/kernel/security/apparmor", F_OK) != 0) {
skip("apparmor not enabled\n");
return 1;
}
if (system("apparmor_parser -r apparmor.profile") < 0) {
fail("apparmor profile parse failed");
return -1;
}
setprofile();
test_daemon();
test_waitsig();
if (checkprofile(0) == 0)
pass();
return 0;
}
#!/bin/bash
test -d /sys/kernel/security/apparmor
# vim:syntax=apparmor
profile criu_test {
/** rwmlkix,
capability,
unix,
signal,
}
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