Commit graph

6552 commits

Author SHA1 Message Date
Cyrill Gorcunov
1700a9bf20 build: criu -- Don't forget to cleanup arch directory
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
0602bca40f cg: Add rollback in get_cg_set
In case of error inside collect_cgroups we need

- @ctls list has been spliced into @cs->ctls so we cant just free it,
   but rather use put_ctls on @cs->ctls

- delete @cs->l from global @cg_sets list before free it

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Reviewed-by: Andrew Vagin <avagin@openvz.org>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
be5062c1c2 cg: Add rollback for add_cgroup
If add_cgroup_properties failed we have @ncd sitting
in @match->children or @current_controller->heads
list, and then we free @ncd entry leaving those
lists carrying dead pointers.

Add proper rollback action.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
94bfda900e cg: Fix use-after-free in put_ctls
Since we're freeing list entries don't forget to
initialize list then, otherwise it gets out with
free entries and may hit use-after-free bug.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>
Acked-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Dmitry Safonov
c553fe04f4 parasite-syscall: print syscall number as %lu
We will still able to distinguish if it's garbage in ax register, but
this is definitely prettier:
(00.036900) 687 was trapped
(00.036903) 687 is going to execute the syscall 158
(00.036928) 687 was trapped
(00.036931) 687 is going to execute the syscall 173

Than that:
(00.024403) 687 was trapped
(00.024407) 687 is going to execute the syscall 9e
(00.024419) 687 was trapped
(00.024421) 687 is going to execute the syscall ad

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:44 +03:00
Cyrill Gorcunov
3e48109a4d criu: Drop prlimit compat layer
Previously when we've been on early stage we
tried to workaround lack of prlimit libc call
simply providing own implementation,  but it
cause problems on some libc configurations so
simply use rlimit64 and __NR_prlimit64 syscall
directly.

The kernel must support __NR_prlimit64 syscall
and provide rlimit64 structure as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:58:42 +03:00
Pavel Emelyanov
c881d0449c criu: Warn about --namespaces deprecation
The option was in use when we didn't have the /proc/pid/ns links
and thus ns ids. Later we used it at restore time to tell which
namespaces to restore the pstree into. Right now ids are always
generated and this option has no effect (and meaning).

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:56:50 +03:00
Pavel Emelyanov
75a9c3b697 rst: Deprecate no ids.img case
We've been writing this file since 0.4, hopefully nobody's
using such an oldie :)

v2: Don't BUG_ON, but return error, as this can be triggered
by corrupting images.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Cyrill Gorcunov
0cdd2a2964 pie: open_detach_mount -- Use pr_perror for regular build
This helper is used in both PIE and non-PIE code.
For the second we can use normal pr_perror.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Andrew Vagin
caec89267b util: return aligned pointers from shmalloc()
Atomic operations doesn't work for non-aligned pointers.

=[log]=> dump/zdtm/static/autofs/30/2/restore.log
------------------------ grep Error ------------------------
(00.185037)      5: Error (/root/git/criu/criu/include/lock.h:78): BUG at /root/git/criu/criu/include/lock.h:78
(00.207193) Error (cr-restore.c:1407): 100 killed by signal 9: Killed
(00.219187) Error (cr-restore.c:2237): Restoring FAILED.
------------------------ ERROR OVER ------------------------

4339  futex(0x7fa79c1561da, FUTEX_WAKE, 2147483647 <unfinished ...>
4339  <... futex resumed> )             = -1 EINVAL (Invalid argument)

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Andrew Vagin
52fe2af2f3 zdtm: non-root user can't dump aio01 (v2)
v2: copy aio00.desc

Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Kirill Tkhai
54c6ac7a2f aio: Take in account a ring never has a parent in pre-dump
Since AIO ring is never pre-dumped, it never has a parent
in pre-dump. Make generate_iovs() to know this.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Kirill Tkhai
c22c748f75 Add sys_io_submit definition
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:56 +03:00
Kirill Tkhai
3ed375809e zdtm: Add aio01 test
Description:

1)Create io context, submit several io operations and
get events of some of them.

2)Sleep on signal.

3)Check tail, head and nr events restored correct.

4)Emit one more io operation.

5)Check tail has moved one number forward (i.e. synchronize
in-kernel and userspace tails if they were different).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Kirill Tkhai
b6386369d7 aio: Add aio sanity checks
Check nr in aio header during dump and correctness of
tail, head and nr during restore.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Kirill Tkhai
3a7968d495 aio: Restore aio ring content
1)Dump/restore mmaped aio ring like any other private vma entry,
  with the only exception we do not predump it.
2)Create io context, set head and tail using write to /dev/null.
3)Copy aio ring restored in (1) to created in (2).
4)Remap (2) to address of (1).

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Kirill Tkhai
868f24e6a2 mem: Propagate struct pape_pipe ** type argument pp_ret to prep_dump_pages_args()
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Kirill Tkhai
1c9f5adf3e aio: Move aio restore related code from __export_restore_task to separate function
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Kirill Tkhai
a2f8aefd86 aio: Make struct aio_ring visible for everybody
Move the declaration from .c to header file.
Also rename parasite_check_aios() since we
have one more function with the same name.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Adrian Reber
a3ecca2e30 Move TCP server/client setup code util.c
The page server already knows how to create a TCP server and client. The
code has been hidden behind static-s in page-xfer.c. This commit moves
the common TCP server/client code to util.c to be able to also use it
in the upcoming remote lazy-server/lazy-client userfaultfd enhanced criu.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-07 13:54:55 +03:00
Andrew Vagin
5cfd96c46f restore: add missing break-s
Signed-off-by: Andrew Vagin <avagin@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:16 +03:00
Dmitry Safonov
b3283a6996 pie/util-vdso: split parse_elf_symbols from vdso_fill_symtable
Impact: no functional changes, cleanup.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
69b163ebdb pie/util-vdso: split parse_elf_dynamic from vdso_fill_symtable
Impact: no functional changes, cleanup.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
9eb043b44a pie/util-vdso: split parse_elf_phdr from vdso_fill_symtable
Impact: no functional changes, cleanup

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
4c69339cd2 string.h/pie: use builtin strncmp instead of strcmp
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
86cc00fb5f pie/util-vdso: check elf structure end oob
Add checks that structure end is inside memory area [mem, mem + size]
before dereferencing structures.
Otherwise, for example, vdso_fill_symtable will try to dereference
ehdr members even with vma size 0.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
7ec96efe3c pie/vdso: convert (char *mem) to (uintptr_t mem)
Impact: drop additional casts all around. Cleanup.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
3bf85ce939 pie/util-vdso: separate has_elf_identity
Impact: refactor

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
f7f1c24073 pie/util-vdso: down with UB in __ptr_oob
As I am here to fix some things, I would like to remove UB-based
pointer compare (6.5.8.5). We have -fno-strict-aliasing in pie
CFLAGS, but it even looks nicer and more readable with uintptr_t.

Impact: refactoring

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
46d197eb94 pie: make util-vdso a little less 64-specific
Add Elf32 types and wrap them with Elf64 into some more generic types.
This is for parsing vDSO from image file.

Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Pavel Emelyanov
a356a2fd87 tcp: Get TCP_INFO once per socket
Right now we get SOL_TCP.TCP_INFO option twice, but one time
is enough.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Pavel Emelyanov
e34fcc70ba tcp: Move refresh routine into dump one
This is prerequisite for the next patch and, actually, for the libsoccr :)

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Dmitry Safonov
35f209ff76 fault: add dump pages fault for parasite_dump_pages_seized
Parasite should cleanup after fauilure and remove read-protection
from VMAs. Check it with maps00 test & fault injection.

Tested on travis with some addition:
python test/zdtm.py run -t zdtm/static/maps00 --fault 3 --keep-going --report report -f h || false
https://travis-ci.org/0x7f454c46/criu/jobs/119252291

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:15 +03:00
Pavel Emelyanov
058808007b pstree: Move the ids reading into separate function
It's just a cleanup to get rid of in-function {<code>} block.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
070d420be6 test: Check nomemfd parasite injection
By default criu tries to create parasite mem with memfd syscall,
which is present in many systems. Let's check also the legacy way.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
5c17b30236 zdtm: Nicer flavs removal
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
362784f032 pipe/fifo: Collect data via cinfo engine
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
f674cbd60f unix: Collect packets via cinfo engine
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
508cb93374 collect: Add img argument to cinfo
The plan is to allow ->collect callbacks to read more
stuff from image files.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
347d670f29 tty: Setup tty slavery via post_cb engine
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
92eb5ff594 pipe: Run master resolve via post_cb engine
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
3b288ca392 unix: Run peer resolving via post_cb engine
With autofs patches we've merged a small engine that allows
to queue random routine for post-prepare execution. Re-use
this for unix sockets' interconneting routine.

Also this is a tiny optimization -- when we don't have unix
sockets to interconnect we don't make extra list walk.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
46408840a4 rst: Mark post_prepare_cbs static
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Tycho Andersen
03e13d475d restore: zombies should collect their children
Consider when there is a double fork of helpers or zombies, e.g. when a
zombie has a session id which doesn't match its pid. If the child dies and
exits before the grandchild, the grandchild reparents to init, and when the
task dies init doesn't have it in the helper list, so init dies as well,
viz. the log below.

(00.118789) Add a helper 293 for restoring SID 293
(00.118792) Attach 294 to the temporary task 293
...
(01.394403)    294: Restoring zombie with 0 code
...
pie: Task 294  exited, status= 0
(01.434279) Error (cr-restore.c:1308): 12097 killed by signal 19
(01.434420) Error (cr-restore.c:1308): 12097 killed by signal 19
(01.450258) Switching to new ns to clean ghosts
(01.450324) Error (cr-restore.c:2138): Restoring FAILED.

Let's have the helpers reap their children before they exit to avoid this.

v2: block SIGCHLD when waiting on helpers so that it doesn't race with the
    SICGHLD handler
v3: * only helpers should collect their children, zombies can't have kids
    * don't double decrement nr_tasks in zombie case

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:10:14 +03:00
Pavel Emelyanov
a6c6ec89ad Remove bogus add_ns_shared_cb extern declaration
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:01:55 +03:00
Mike Rapoport
366c9131ff autofs: fix build on Fedora 22
The following error happens when building CRIU on Fedora 22:

  CC       autofs.o
autofs.c: In function ‘autofs_mount’:
autofs.c:892:9: error: implicit declaration of function ‘add_post_prepare_cb’ [-Werror=implicit-function-declaration]
   ret = add_post_prepare_cb(autofs_add_mount_info, mi);
         ^
cc1: all warnings being treated as errors

Adding forward declaration of add_post_prepare_cb resolves the issue.

Signed-off-by: Mike Rapoport <rapoport@il.ibm.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:01:53 +03:00
Stanislav Kinsburskiy
d6b97ad536 cr-restore: move add_ns_shared_cb declaration to include/namespaces.h
Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:01:41 +03:00
Stanislav Kinsburskiy
7d7373a429 cr-restore: new list of ns shared objects introduced
Autofs restore needs to create some shared data structures to be able to pass
data to actual autofs master.
But on mount restore stage shared data is not configured yet.
This list of objects and their actors is processed after all mounts and shared
data are restored to let autofs to create the objects.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-04 17:01:10 +03:00
Tycho Andersen
84a89b46ad restore: correctly restore cgroup mounts inside a container
Before the nsroot= mount option, we were just getting lucky because the
cgroup superblocks "matched" when inspecting them from userspace, so we
were actually getting a bind mount from the host when migrating from within
cgroup namespaces.

Instead, let's actually do a new (i.e. not a bind mount) for cgroup
namespaces. For this, we need two things:

1. to prepare the cgroup namespace (and thus the cgroups) before the mount
   ns, so when the mount() occurrs it is relative to the right cgroup path.

2. not reject cgroup filesystems with no root. A cgroup ns mount looks
   like:

	 223 222 0:22 /lxc/unpriv /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime - cgroup cgroup rw,xattr,release_agent=/lib/systemd/systemd-cgroups-agent,name=systemd,nsroot=/lxc/unpriv

   i.e. it has /lxc/unpriv as its root, and thus doesn't look rooted to CRIU.
   We use the fstype->parse hook to rewrite this root to /, since it
   is handled by the cgroup ns infrastructure.

v2: add new fstype->munge hook, allowing fstypes to munge their parsed
    mountinfo entries if they want to. this allows us to get rid of the
    ugly hacks with FSTYPE__CGROUP everywhere in teh patch.
v3: s/fstype->munge/fstype->parse for FSTYPE__CGROUP

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-01 18:06:31 +03:00
Dmitry Safonov
870089d1ee Makefile: drop 'rebuild' from help message
The target has been broken for some time without complaints from users.
https://lists.openvz.org/pipermail/criu/2016-March/026525.html

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-04-01 18:06:31 +03:00