2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-31 06:15:24 +00:00
Commit Graph

4900 Commits

Author SHA1 Message Date
Pavel Emelyanov
199619791d mnt: Factor out find-mount-by-s_dev code
And move the 2nd piece lower to avoid fwd declaration and
keep similar calls close to each other.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-19 13:17:30 +04:00
Cyrill Gorcunov
b6c3270b2f scripts: Exit early if no scripts passed
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-14 15:51:28 +04:00
Andrey Vagin
61b8c9dac3 zdtm: execute mntns_shared_bind* only if mnt_id is in fdinfo
Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-13 15:53:18 +04:00
Andrey Vagin
f07e25c62b zdtm: add a test to check non-root shared bind-mounts
Here is an example from a fedora container:
65 64 252:0 /vz/private/1 / rw,relatime shared:29 - ext4 /dev/mapper/centos_pcs-root rw,data=ordered
77 65 252:0 /vz/private/1/var/tmp/systemd-httpd.service-XLnJPNc/tmp /var/tmp rw,relatime shared:41 - ext4 /dev/mapper/centos_pcs-root rw,data=ordered

We can see non-root shared mount, which is mounted to the root
mount from the same shared group. The test emulates this situation.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:55:17 +04:00
Andrey Vagin
104d3b84d5 mount: rework can_mount_now() to support bind-mounts of shared mounts
Fedora bind-mounts a part of the root mount to itself. Currently we
don't allow to mount children of a shared mount, if other mount from
this shared group are not mounted.

This patch adds an exclusion for cases, when a child has the same
group. We allow to mount a child, if wider mounts are mounted.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:54:39 +04:00
Andrey Vagin
beeabc3b2b mount: add the mnt_roots mount in the mount tree on restore
Currently we connect roots of sub-namespaces to the root of the root
mount namespace. And we get problems, if the root of the root mntns is
shared, because all children of a shared mount must be propagated to
other mounts in this group.

Actually we mount tmpfs in mnt_roots and here is nothing wrong to add it
in a tree.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:54:37 +04:00
Pavel Emelyanov
4e7064cd7e mount: Remove the len variable
And use the expression for it, it's quite short. This
makes the amount of variables in the code fit into brains.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:33 +04:00
Pavel Emelyanov
0fbee68f26 mount: Add helper for searching for shared peer
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:32 +04:00
Pavel Emelyanov
cedd10254c mount: Sanitize the path recalculation between submounts
Do paths conversions and checks step-by-step and add many comments
what we do in each step and why.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:31 +04:00
Pavel Emelyanov
991c02874a mount: Use pre-calculated ct->mountpoint + t_mpnt_l value
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:30 +04:00
Pavel Emelyanov
ffe5f9b422 mount: Use issubpath() when checking for submount visibility
When we check whether a submount of a mount is visible in another
mount (shared peer of the latter), we can and should use the new
issubpath helper.

Should because the used strncmp may scan beyond ct_mpnt_rpath if
its length is smaller (no checks for this in the code).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:29 +04:00
Pavel Emelyanov
e9512502d1 mount: Move some variables out of search loop
These are constant for given m, so calculate them outside
of the loop. Also rename them to reflect what they are.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:28 +04:00
Pavel Emelyanov
028d6355e6 mount: Rename paths' lengths to reflect whose lengths they are
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:27 +04:00
Pavel Emelyanov
6b0059049d mount: Add helper for path length calculations
The path lenght is zero for the "/" one and strlen(path)
for all the others. This is done so to make it possible
to use this length to get tail-paths: if path_1 starts
with path_2 and both are absolute, then

   path_1 + path_length(path_2)

would give the tail of the tail of path_1 relative to
path_2 even if the path_2 is just "/".

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:26 +04:00
Pavel Emelyanov
64c95bf586 mount: Add helper to search for widest shared peer
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-12 12:54:25 +04:00
Andrey Vagin
1cf5168cab mntns: rework validation to support non-root shared bind-mounts (v2)
A problem which is solved in this path is that some children can be
unaccessiable (unvisiable) for non-root bind-mounts

root	mount point
-------------------
/	/a (shared:1)
/	/a/x
/	/a/x/y
/	/a/z
/x	/b (shared:1)
/	/b/y

/b is a non-root bind-mount of /a
/y is visiable to both mounts
/z is vidiable only for /a

Before this patch we checked that the set of children is the same for
all mount in a shared group. Now we check that a visiable set of mounts
is the same for all mounts in a shared group.

Now we take the next mount in the shared group, which is wider or equal
to current and compare children between them.

Before this patch validate_shared(m) validates the m->parent mount.
Now it validates the "m" mount. So you can find following lines in the
patch:
-               if (m->parent->shared_id && validate_shared(m))
+               if (m->shared_id && validate_shared(m))

We doesn't support shared mounts with different set of children.
Here is an example of such case can be created:
mount tmpfs a /a
mount --make-shared /a
mkdir /a/b
mount tmpfs b /a/b
mount --bind /a /c

In this case /c doesn't have the /b child. To support such cases,
we need to sort all shared mounts accoding with a set of children.

v2: If root is equal to "/", its len should be zero. We expect that the
last symbol in a path is not "/".

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-12 12:54:21 +04:00
Andrew Vagin
022094db40 zdtm: typo fix
expr ns/user/static/env00 ns/user
expr: syntax error

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:21:08 +04:00
Cyrill Gorcunov
98d9264563 bfd: Use LOG_PREFIX
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:19:36 +04:00
Cyrill Gorcunov
88031bf89e proc_parse: Convert parse_pid_status to BFD engine
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:18:27 +04:00
Pavel Emelyanov
8f937e0461 zdtm: Don't test userns tests if no required APIs found
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:17:57 +04:00
Pavel Emelyanov
a7bfa05a21 collect: Rename children/threads collecting routines
Make their name look similar.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:16:43 +04:00
Pavel Emelyanov
ac1c74fc5b collect: Don't check for zombie before collecting
We have sanity check for zombie-with kids below, no
need in additional.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:16:29 +04:00
Pavel Emelyanov
8078e38774 collect: Factor out recurring collection of threads and children
We scan threads and children list several times while freezing
the tree, this is done to avoid race with new threads/kids
appearing.

Factor out the iterations code.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:16:22 +04:00
Pavel Emelyanov
83df36e731 collect: Move parse_threads into collect_threads
To make the threads collect code be structured similar to
children collect. This will also help in further patching.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:16:13 +04:00
Pavel Emelyanov
13a628df95 collect: Clean children collect code variables usage
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:16:05 +04:00
Pavel Emelyanov
009c173be5 collect: Clean children and threads recurring collect checks
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:15:57 +04:00
Pavel Emelyanov
a2691591b2 kerndat: Sanitize the get_fs_stat internals
Keeping the whole stat buf it too much information.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:15:27 +04:00
Pavel Emelyanov
00770a91c1 kerndat: Handle errors from devtmpfs virtualized checks
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:15:17 +04:00
Pavel Emelyanov
69bffe26d3 kerndat: Make fs-virtualized check report yes/no
Right now it returns the whole struct stat which is excessive.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:15:09 +04:00
Pavel Emelyanov
19a76494a9 kerndat: Collect all global variables on one struct
Not to spoil the global namespace and unify the kerndat
data names.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:14:53 +04:00
Andrey Vagin
5f7933e3a0 zdtm/fork: create 10 process concurrently
Currently this test creates one process and wait it. So most part of the
time this test has only one process without children.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:14:04 +04:00
Andrey Vagin
b37ce2f118 zdtm: add transition/fork2 in the test list
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:13:55 +04:00
Andrey Vagin
77bdb1828c zdtm: compare file descriptors only for static tests
For other tests set of file descriptors can be changed

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:13:49 +04:00
Pavel Emelyanov
f639680bf1 userns: Don't fork task not to dump userns
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-11 20:13:18 +04:00
Pavel Emelyanov
1283921d53 ns: Don't do manual lookup_ns_by_id
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:12:49 +04:00
Pavel Emelyanov
ba983f9819 ns: Factor out nsid listing code
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:12:34 +04:00
Pavel Emelyanov
f33908a897 ns: Rename "created" futex and comment what it is
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:11:58 +04:00
Pavel Emelyanov
ee2e8e5bb9 parasite: Cleanup args size fetching
Right now we push all the auxiliary arguments to parasite_infect_seized
while 2 of them are only required to calculate the size of args area.

Let's better keep track of required args size and get rid of excessive
arguments to parasite_infect_seized().

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-11 20:11:34 +04:00
Pavel Emelyanov
ca3b8ca051 dump: Comment how we dump zombies in pid namespaces
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-10 17:42:22 +04:00
Andrey Vagin
7c896efff5 page-xfer: receive information about presence of a parent from a page server (v2)
We need to know this to insert holes. Currently xfer->parent isn't
initialized for remote sessions. In most cases it has a non-zero value,
so generate_iovs() is called with has_parent = true.

bash test/zdtm.sh -p -P -i 3 ns/transition/fork
(00.000106) Error (sysctl.c:194): Can't open sysctl net/ipv4/tcp_wmem: No such file or directory
(00.017048)    420: Error (image.c:231): Unable to open pagemap-420.img: No such file or directory
(00.017065)    420: Error (image.c:231): Unable to open pages-420.img: No such file or directory
(00.017090)    420: Error (page-read.c:73): No parent for snapshot pagemap
(00.017290)     86: Error (cr-restore.c:1185): 420 exited, status=1
(00.017317) Error (cr-restore.c:1831): Restoring FAILED.

v2: add a new command to open a page server. It's required to save
backward compatibility. If someone tries to use an old version of
page server, he will get an error.

Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-10 09:36:04 +04:00
Andrey Vagin
5f13a31e9d check: return non-zero code if PR_SET_MM_MAP is unsupported
We do the same for other features.

Here is an exception in case of the --ms option.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-10 09:35:19 +04:00
Pavel Emelyanov
1cad9b1049 util: Fix the ispathsub corner case
ispathsub("/foo", "/") reports false. This is a corner case,
as 2nd argument is not expected to end with /. Fix this and
add comment about ispathsub() arguments assumptions.

Reported-by: Andrey Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-09 23:26:56 +04:00
Andrey Vagin
6bc8b637e5 test: increase permissions for the "test" directory (v2)
Restoring mount namespaces requires to create temporary directories
in a test root.

When tests execute in a new userns, they have non-zero gid and uid,
so we need to grant permissions for them.

v2: add +rx as well

Reported-by: Mr Jenkins
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 23:50:47 +04:00
Pavel Emelyanov
32f58742ca mnt: Introduce and use issubpath helper
When we validate the mount tree not to have overmounts we need to
check one path to be the sub-path of another. Here's a helper for
this.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-11-07 17:39:23 +04:00
Pavel Emelyanov
b3f644572e ns: Fix compilation on Fedora-19
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:23:17 +04:00
Andrey Vagin
b414318c4b userns: check that all namespaces were created from a target userns
We enter into the target userns and try to enter in other namespaces.
The "enter" operation requires CAP_SYS_ADMIN in a user namespace,
where a taget namespace was created.

Now if one or more namespaces were created in another userns,
criu stops dumping and return an error. I want to find someone, who uses
this configuration. In this case restore will be more complicated.
Current version covers containers needs.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:22:20 +04:00
Andrey Vagin
f290444655 zdtm: add tests which can be executed in a new user namespace (v2)
Sockets tests are excluded, because SO_RCVBUFFORCE and SO_SNDBUFFORCE
are protected by CAP_NET_ADMIN

tty*, pty* are excluded, because TIOCSLCKTRMIOS protected by
CAP_SYS_ADMIN

*ghost, *notify, *unlink* are excluded, because linkat(AT_EMPTY_PATH)
are protected by CAP_DAC_READ_SEARCH

v2: use a blacklist
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:20:48 +04:00
Andrey Vagin
b109e9ef11 zdtm: add ability to execute tests in another user namespace
v2: don't forget to initialize groups
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:20:21 +04:00
Andrey Vagin
0014a12d96 zdtm: prepare a file tree for userns
Here are two issues:
1. All mounts in a new user namespace are locked, so
we need to create a new root mount. We need to bind-mount root to
itself.
2. /proc and /sys must be mounted before umounting /proc and /sys
which were inhereted. It's a security policy.

"""
Author: Eric W. Biederman <ebiederm@xmission.com>
Date:   Sun Mar 24 14:28:27 2013 -0700

    userns: Restrict when proc and sysfs can be mounted

    Only allow unprivileged mounts of proc and sysfs if they are already
    mounted when the user namespace is created.
"""

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:19:45 +04:00
Andrey Vagin
ed5a1ba122 zdtm: create devices before forking a test process
Devices can not be created in a new user namespace.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-11-07 17:19:36 +04:00