zdtm: add mnt_root_ext test

This test has one external mount [criumntns] /zdtm_root_ext.tmp ->
[testmntns] /mnt_root_ext.test, and it specifically gives '--external
mnt[MNT]:.zdtm_root_ext.tmp' option on restore without '/' to make
dirname on it return static '.' path (see glibc dirname() code) and
reproduce a segfault in resolve_mountpoint().

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
Pavel Tikhomirov 2022-06-20 12:54:29 +03:00 committed by Andrei Vagin
parent 8a18faea09
commit f29d51560e
4 changed files with 90 additions and 0 deletions

View file

@ -402,6 +402,7 @@ TST_DIR = \
mnt_ext_master \
mnt_ext_dev \
mnt_ext_root \
mnt_root_ext \
mnt_ext_collision \
mntns_pivot_root \
mntns_pivot_root_ro \

View file

@ -0,0 +1,79 @@
#include <sched.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <linux/limits.h>
#include "zdtmtst.h"
const char *test_doc = "Check external mount from host's rootfs";
const char *test_author = "Pavel Tikhomirov <ptikhomirov@virtuozzo.com>";
char *dirname = "mnt_root_ext.test";
TEST_OPTION(dirname, string, "directory name", 1);
int main(int argc, char **argv)
{
char *root, testdir[PATH_MAX], nstestdir[PATH_MAX];
char *zdtm_newns = getenv("ZDTM_NEWNS");
char tmp[] = "/.zdtm_root_ext.tmp";
root = getenv("ZDTM_ROOT");
if (root == NULL) {
pr_perror("root");
return 1;
}
if (!zdtm_newns) {
pr_perror("ZDTM_NEWNS is not set");
return 1;
} else if (strcmp(zdtm_newns, "1")) {
goto test;
}
/* Prepare directories in test root */
sprintf(testdir, "%s/%s", root, dirname);
mkdir(testdir, 0755);
/* Prepare directories in criu root */
mkdir(tmp, 0755);
/* Make criu's mntns root mount shared */
if (mount(NULL, "/", NULL, MS_SHARED, NULL)) {
pr_perror("make shared");
return 1;
}
/*
* Create temporary mntns, next mounts will not show up in criu mntns
*/
if (unshare(CLONE_NEWNS)) {
pr_perror("unshare");
return 1;
}
/*
* Populate to the tests root host's rootfs subdir
*/
if (mount(tmp, testdir, NULL, MS_BIND, NULL)) {
pr_perror("bind");
return 1;
}
test:
test_init(argc, argv);
/*
* Make "external" mount to be slave
*/
sprintf(nstestdir, "/%s", dirname);
if (mount(NULL, nstestdir, NULL, MS_SLAVE, NULL)) {
pr_perror("make slave");
return 1;
}
test_daemon();
test_waitsig();
pass();
return 0;
}

View file

@ -0,0 +1,5 @@
{ 'dopts': '--external mnt[/mnt_root_ext.test]:MNT',
'feature': 'mnt_id move_mount_set_group',
'flavor': 'ns uns',
'flags': 'suid',
'ropts': '--external mnt[MNT]:.zdtm_root_ext.tmp --no-mntns-compat-mode'}

View file

@ -0,0 +1,5 @@
#!/bin/bash
[ "$1" == "--clean" ] || exit 0
rmdir /.zdtm_root_ext.tmp