Commit 138d2631 authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

zdtm: add a new test to check tmpfs in a non-root mntns (v2)

v2: add a file mapping from a test tmpfs mount
Signed-off-by: 's avatarAndrew Vagin <avagin@virtuozzo.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 947dcc73
......@@ -190,6 +190,7 @@ generate_test_list()
ns/static/session01
ns/static/tempfs
ns/static/tempfs_ro
ns/static/tempfs_subns
ns/static/mnt_ro_bind
ns/static/mount_paths
ns/static/bind-mount
......@@ -334,6 +335,7 @@ rtc
maps007
tempfs
tempfs_ro
tempfs_subns
mnt_ro_bind
bind-mount
mountpoints
......
......@@ -186,6 +186,7 @@ TST_DIR = \
overmount_sock \
tempfs \
tempfs_ro \
tempfs_subns \
mnt_ro_bind \
mount_paths \
bind-mount \
......
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sched.h>
#include <sys/mount.h>
#include <signal.h>
#include <sys/prctl.h>
#include "zdtmtst.h"
const char *test_doc = "Check tmpfs in a non-root mntns";
const char *test_author = "Andrew Vagin <avagin@virtuozzo.com";
char *dirname;
TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv)
{
int fds[2];
pid_t pid;
int fd, status;
test_init(argc, argv);
if (pipe(fds)) {
pr_perror("pipe");
return 1;
}
if (mount(NULL, "/", NULL, MS_PRIVATE | MS_REC, NULL)) {
pr_perror("mount");
}
pid = fork();
if (pid < 0) {
pr_perror("fork");
return 1;
}
if (pid == 0) {
void *addr;
pid = fork();
if (pid == 0) {
if (unshare(CLONE_NEWNS)) {
pr_perror("unshare");
return 1;
}
prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
while (1)
sleep(1);
return 1;
}
if (unshare(CLONE_NEWNS)) {
pr_perror("unshare");
return 1;
}
mkdir(dirname, 0755);
if (mount("zdtm", dirname, "tmpfs", 0, NULL)) {
pr_perror("mount");
return 1;
}
chdir(dirname);
fd = open("test", O_CREAT | O_RDWR | O_APPEND, 0666);
if (fd < 0) {
pr_perror("open");
return 1;
}
ftruncate(fd, PAGE_SIZE);
addr = mmap(NULL, PAGE_SIZE, PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_FILE, fd, 0);
if (addr == MAP_FAILED) {
pr_perror("mmap");
return 1;
}
if (write(fds[1], &fd, sizeof(fd)) != sizeof(fd)) {
pr_perror("write");
return 1;
}
test_waitsig();
if (close(fd)) {
pr_perror("close");
return 1;
}
fd = open("test", O_RDONLY | O_APPEND);
if (fd < 0) {
pr_perror("open");
return 1;
}
close(fd);
return 0;
}
close(fds[1]);
if (read(fds[0], &fd, sizeof(fd)) != sizeof(fd)) {
pr_perror("read");
return 1;
}
test_daemon();
test_waitsig();
kill(pid, SIGTERM);
status = -1;
if (waitpid(pid, &status, 0) != pid) {
pr_perror("waitpid");
return 1;
}
if (status) {
pr_err("Returned non-zero code: 0x%x\n", status);
return 1;
}
pass();
return 0;
}
{'flavor': 'ns uns', 'flags': 'suid'}
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