2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 13:58:34 +00:00
Commit Graph

708 Commits

Author SHA1 Message Date
Pavel Emelyanov
6bf63b3f01 security: Push full creds info into may_xxx checks
It's not enough to check only uids on dump and restore -- we need to
check e-ids and s-ids now (and caps in the future).

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-28 15:48:44 +04:00
Ruslan Kuprieiev
547d9bf959 v2 security: set suid flag on crtools and check real uid on dump/restore
v2: remove redundant functions and variables.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-10-02 17:11:17 +04:00
Andrey Vagin
07930a8df4 ns: replace pid on id in per-namespace files
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-10-01 12:17:04 +04:00
Andrey Vagin
79d47a939d crtoools: add support of stopped tasks (v2)
Currently we catch processes on the exit point from sigreturn.
If a task must be restored in the stopped state, we can send SIGSTOP
before detaching from it.

v2: add more descriptive comment about skipping SIGSTOP in ptrace.c
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-10-01 11:21:34 +04:00
Pavel Emelyanov
f1edcb32f5 rst: Introduce fine-grained pgid-restore synchronization
We can restore task's pgid which is not equal to its pid,
only when the respective group leader is alive. To make
restore reliable we wait for all group leaders to restore
using separate restore stage.

It's better to optimize this -- each task has a pointer on
its group leader and waits for one to become such.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-27 04:38:00 +04:00
Pavel Emelyanov
c378f790b8 fs: Restore root
First of all, this should be done strictly after we've stopped accessing
files by their paths, even absolute. This place is right before going
into restorer.

And the second thing is that we want to re-use the open_fd_by_id engine,
since it handles various tricky cases of open-file-by-path. And since
there's no such thing as fchroot(int fd), we emulate it using the
/proc/self/fd/ links.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-25 13:59:20 +04:00
Pavel Emelyanov
75b1d4a1e3 rst: Open sys.ns_last_pid before diving into restorer
We restore chroot before doing this, so if we might need to
open one, we may have no access to the /proc/... paths.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-25 13:59:17 +04:00
Andrey Vagin
e1e1034786 restorer: rework unmaping old VMA-s (v3)
All process VMA-s are in "premmaped area". All restorer stuff are in
bootstap "area", so we have two areas.

So we don't need to unmap extra VMA-s one by one. We can call munmap
three times for the region before the first area, for the hole between
areas and for the region after the second area.

The old scheme didn't work, because the list of VMA-s can be changed
after collecting. It can be due to memory allocations by libc or due to
increased stack.

v2: improve readability at the expense of beautiness
v3: print return code of munmap in error messages
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-23 15:23:11 +04:00
Andrey Vagin
89d8b20186 restorer: unmap itself (v2)
This patch adds a function for removing the restorer blob. This function
never returns and the process must be trapped on the exit from the
munmap syscall.

v2: * release parasite_ctl sturcture and use the new interface of
      parasite_prep_ctl

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-23 15:23:09 +04:00
Andrey Vagin
66f21e6b71 restore: catch task on the exit from sigreturn (v4)
A task is stopped here for unmaping restorer blob and restoring a state.

The method is the same as for parasite. CRIU attaches to processes via
ptrace and start to trace all syscalls.

v2: don't use a software breakpoint
v3: stop all thread on the exit from sigreturn
v4: attach to each thread
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-23 15:23:08 +04:00
Andrey Vagin
f43ac0643e restore: save a task state on pstree_item
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-23 15:23:07 +04:00
Andrey Vagin
5a37481914 restore: get real pid for each task (v2)
For the root task the clone syscall returns the pid in criu's pidns,
but for other processes the clone syscall returns PID in the restored
namespace.

The /proc/self link contains the PID value of the current process, so if
we want to determing the PID in a criu's pidns, we should use criu's
/proc.

v2: readlink() does not append a null byte to buf, so we must do that
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-23 15:22:58 +04:00
Ruslan Kuprieiev
4eb2872b27 v2 crtools: write pidfile, when service/page server is run as daemon and "--pidfile" is set
When service/page server becomes daemon, we may need to know it's pid.

Signed-off-by: Ruslan Kuprieiev<kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-09-16 15:45:01 +04:00
Andrey Vagin
7d8ed36c33 cr-restore.c: fixed compilation errors on ARM
Use decode_pointer() to convert a virtual address into a native pointer.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 15:10:58 +04:00
Andrey Vagin
fd58e62b1c mm: map grow-down VMA-s with guard pages
In /proc/pid/maps grow-down VMA-s are shown without guard pages, but
sometime these "guard" pages can contain usefull data. For example if
a real guard page has been remmaped by another VMA. Let's call such
pages as fake guard pages.

So when a grow-down VMA is mmaped on restore, it should be mapped with
one more guard page to restore content of the fake guard page.

https://bugzilla.openvz.org/show_bug.cgi?id=2715
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-30 14:25:14 +04:00
Andrey Vagin
39e6d7f553 restore: decode exit status in sigchld_handler
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-28 17:16:55 +04:00
Pavel Emelyanov
84737e2796 build: Generate most of the pb-desc automatically
These contain linkage between number, data type and routines
for pb messages we write/read to/from image files. Most of them
have simple number-type-routines mapping, so introduce a generating
script for that.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-23 21:47:31 +04:00
Pavel Emelyanov
1ac6d76cbd tun: Restore tun files and tun links
This thing is pretty straightforward -- on netns creation
populate it with tun-s, after this collect tun files, open
and attach them with regular fd-s engine.

One tricky thing -- when populating namespace with tun links
make them all persistent and drop this flag (if required)
later, when the first alive opened appears.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-23 19:10:15 +04:00
Pavel Emelyanov
60e6d38868 collect: Shorten common images collecting code
Now we have a set of cinfo-s, it's possible to collect all
this stuff in a plan for-loop.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-21 03:52:18 +04:00
Andrey Vagin
ef3ca3a104 restore: do not kill processes if not-all of them have been created
If processes are restored without pidns, criu knows pidtheir -s from images,
but part of those task may have not yet forked, and thus the pids can not
exist or (!) be used by other processes.

To address that we abort stages RESTORE_NS and FORKING without killing tasks,
but with task_entries->start futex by writing STATE_FAIL into it and making
the tasks to check that. Since during RESTORE_NS and FORKING stages tasks can
only block on the mentioned futes, we can safely do it.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-20 15:17:30 +04:00
Andrey Vagin
f824d8c3e9 restore: remove restore_one_fake, which duplicates the code
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-16 18:55:26 +04:00
Pavel Emelyanov
01f113ecd3 rst: Remove threads restore serialization
This thing was introduced by 01f8f8f4 to help not mixing
per-thread error messages in log files. Now messages are
not mixed by other means, so this thing is useless.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-12 09:17:02 +04:00
Pavel Emelyanov
0a6da43db9 rst: Check core near the place read it from image
Doing it several steps further is less clean.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-12 09:04:56 +04:00
Pavel Emelyanov
e0b8f91493 rst: Make clean error path for root task restore
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-12 06:33:21 +04:00
Pavel Emelyanov
44a85ee08d rst: Switch-and-wait creds restore stage with existing helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-12 06:23:11 +04:00
Pavel Emelyanov
e5534e8e3a rstore: Invert switch_restore_stage logic
Currentl it waits for previous stage to complete and starts the
next one. Now it starts the next one and waits for it to complete.
The latter way fits better into both -- the code and the head.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-12 06:17:04 +04:00
Pavel Emelyanov
9b45833b81 stats: Account total time to restore
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 21:25:42 +04:00
Pavel Emelyanov
2df39a4b47 stats: Account for time to fork tasks on restore
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 21:22:40 +04:00
Pavel Emelyanov
ebd826c97b rst: Reuse vma_list.priv_size for premapped area size calculation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:46:00 +04:00
Pavel Emelyanov
4c8e1c9927 rst: Close vmas image earlier
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:42:55 +04:00
Pavel Emelyanov
e93566c791 rst: Write comment about why we need two calls to restore_pgid
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:23:18 +04:00
Pavel Emelyanov
4c83c432d6 rst: Minor formatting fix
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:16:24 +04:00
Pavel Emelyanov
ede980c077 restore: Move kids (and session) restore into a helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:15:43 +04:00
Pavel Emelyanov
26aa61a344 rst: Rename read_vmas into prepare_vmas
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:10:44 +04:00
Pavel Emelyanov
e2a0258de3 util: Use open_detahc_mount helper for proc service fd creation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 20:00:28 +04:00
Andrey Vagin
1f9da83048 mm: do check on shared pages only if a vma is inherited (v2)
v2: restore page contents directly into memory
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-14 11:18:48 +04:00
Pavel Emelyanov
e99576f655 rst: Collect stats about checked-vs-cowed pages
On restore we compare pages' contents with memcmp to check which
of them can remain shared. Report this info in restore stats.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 13:36:24 +04:00
Pavel Emelyanov
6ac4870181 stats: Prepare for collecting restore stats
Restore stats are difficult -- we have to collect them from several
tasks and thus existing plain variables would not work. We'll need
shared memory with stats, so prepre for allocating one.

Other than this -- put call to write_stats() where appropriate for
restore.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-11 13:00:45 +04:00
Andrew Vagin
53aae95796 restore: unset dumpable flag for zombies (v2)
We have already tried to prevent generating core files for zombies:

commit 6da52216ce
Author: Andrey Vagin <avagin@openvz.org>
Date:   Fri Jul 12 18:14:23 2013 +0400

    restore: set the zero limit for RLIMIT_CORE

But it doesn't work if a core file is sent into a pipe.
This functionality is used by the abrt daemon for example.

This patch uses more direct way, it unsets the dumpable flag with help
of PR_SET_DUMPABLE.

v2: remove the previous hack

Signed-off-by: Andrew Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-08-07 13:51:35 +04:00
Pavel Emelyanov
7405f88c8f rst: Add some comments to VMAs inheritance procedure
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-25 18:29:03 +04:00
Pavel Emelyanov
fa66d9267f rst: Rename parent vmas list variable to reflect what it is
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-25 18:25:51 +04:00
Andrey Vagin
81e11b44de restore: unlock network before disabling repair mode on sockets (v2)
Window probe is sent during disabling repair mode on a socket, so
network must be unlocked in this moment.

https://bugzilla.openvz.org/show_bug.cgi?id=2670

v2: don't fail after unlocking network
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-15 18:47:41 +04:00
Andrey Vagin
64c37b72ff restore: add __restore_switch_stage, which just switches stages
It never returns errors.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-15 18:47:32 +04:00
Andrey Vagin
6da52216ce restore: set the zero limit for RLIMIT_CORE
This should be done to prevent generating core files, if a process was
killed by SIGSEGV, SIGBUS, etc

https://bugzilla.openvz.org/show_bug.cgi?id=2655

Looks-good-to: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-12 18:14:23 +04:00
Cyrill Gorcunov
a18f28d61e restore: Set up zombie name on restore
Otherwise we lost 1:1 mapping between names being
dumped and what user sees after restore.

| 1455 pts/0    T      0:00          \_ ./crtools restore -t 1448
| 1448 ?        Ss     0:00          |   \_ ./zombie00 --pidfile=zombie00.pid --outfile=zombie00.out
| 1449 ?        Z      0:00          |       \_ [zombie00] <defunct>
| 1450 ?        Z      0:00          |       \_ [zombie00] <defunct>
| 1451 ?        Z      0:00          |       \_ [zombie00] <defunct>
| 1452 ?        Z      0:00          |       \_ [zombie00] <defunct>

https://bugzilla.openvz.org/show_bug.cgi?id=2635

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-12 18:12:12 +04:00
Pavel Emelyanov
34f4e2d05c rst: Compile fix for rst mem API usage in rlims
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-09 13:48:59 +04:00
Cyrill Gorcunov
73a8b996c5 restorer: Use rst memory allocator for rlimits restore
Number of rlimits may vary depending on system version
criu is compiled against. So we use rst-allocator to
carry all limits read from file.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-09 00:21:31 +04:00
Pavel Emelyanov
bd58fce18f core: Sanitize check_core return evaluation
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-08 19:10:11 +04:00
Pavel Emelyanov
1133ed73bd rst: Create rst-mem pages _after_ local smaps parse
This memory is unmapped by handr, so no need in polluting
self-smaps with it.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-05 16:39:43 +04:00
Pavel Emelyanov
402707107f rst: Simplify before/after remap API
Actually after remap the rst-mem is still visible in the crtools,
although at another address.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2013-07-05 16:27:03 +04:00