2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00
Commit Graph

4636 Commits

Author SHA1 Message Date
Cyrill Gorcunov
0bb002ce69 vdso: dump -- Don't dump contents of vvar zone
vvar zone is mapped by a kernel and must not ever
been dumped into image, the data present there is
valid on running kernel only.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:48:41 +04:00
Cyrill Gorcunov
72ead490e4 vdso: image -- Add VMA_AREA_VVAR flag
Will need it to handle vvar zones in a special way.

Because VMA_UNSUPP never goes into the image file
lets reuse bit 12 for VVAR.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:48:40 +04:00
Filipe Brandenburger
e0b3018b71 git: add /dev to test/.gitignore
The /dev directory is also created by zdtm when running ns/ enabled tests.
Add it to the list, together with entries such as /bin and /lib.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:44:42 +04:00
Filipe Brandenburger
340a246444 zdtm: add missing entries to test/zdtm/.gitignore
This adds new tests "cgroup00" and "clean_mntns" to the .gitignore file.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:44:40 +04:00
Filipe Brandenburger
6cf2906b0a zdtm: add new dumpable02 test to check that dumpable flag set to 0 or 2 works
This confirms that the fix to handle dumpable flag set to 2 still works after
restore.

To force dumpable flag set to 0 or 2 (whatever the fs.suid_dumpable is set to),
chmod the test binary to 0111 (executable, but not readable) and execv() it
while running as non-root.  The kernel will unset the dumpable flag to prevent
a core dump or ptrace to giving the user access to the pages of the binary
(which are supposedly not readable by that user.)

Tested:
- # test/zdtm.sh static/dumpable02
  Test: zdtm/live/static/dumpable02, Result: PASS
- # test/zdtm.sh ns/static/dumpable02
  Test: zdtm/live/static/dumpable02, Result: PASS
- Used -DDEBUG to confirm the value of the dumpable flag was 0 or 2 to match
  the fs.suid_dumpable sysctl in the tests (both in and out of namespaces.)
- Confirmed that the test fails if the commit that fixes handling of dumpable
  flag with value 2 is reverted and the fs.suid_dumpable sysctl is set to 2.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:44:39 +04:00
Filipe Brandenburger
f662df452d restore: preserve dumpable flag when it is set to 2
Commit d5bb7e9748 started to preserve the dumpable flag across migration by
using prctl to get the value on dump and set it back on restore.

On some situations, the dumpable flag can be set to 2.  This happens when it is
not reset (with prctl) after using setuid() or after using execv() on a binary
that has executable but not read permissions, when the fs.suid_dumpable sysctl
is also set to 2.  However, it is not possible to set it to 2 using prctl,
which would make criu restore fail.

Fix this by checking for the value before passing it to prctl.  In case the
value of the dumpable flag was 2 at the source, check whether it is already 2
at the destination, which is likely to happen if the fs.suid_dumpable sysctl is
also set to 2 where restore is running.  In that case, preserve the value,
otherwise reset it to 0 which is the most secure fallback.

Fixes: d5bb7e9748

Tested:
- Using dumpable02 zdtm test after setting fs.suid_dumpable to 2.
  # sysctl -w fs.suid_dumpable=2
  # test/zdtm.sh ns/static/dumpable02
  4: DEBUG: before dump: dumpable=2
  4: DEBUG: after restore: dumpable=2
  4: PASS
  Test: zdtm/live/static/dumpable02, Result: PASS

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:44:38 +04:00
Filipe Brandenburger
9f30b9e7e3 Revert "pie: A quick workaround for PR_SET_DUMPABLE == 2 restore error."
This reverts commit 8870aa1e4f.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:44:35 +04:00
Filipe Brandenburger
1176081e1f zdtm: add new dumpable01 test to check that dumpable flag is preserved
This confirms that the fix in commit d5bb7e9748 to preserve the dumpable flag
after migration is working as expected.

In this test case, the dumpable flag is expected to always be set to 1, as
test_init will use prctl to reset it to 1 after using setuid and setgid.

Tested:
- # test/zdtm.sh static/dumpable01
  Test: zdtm/live/static/dumpable01, Result: PASS
- # test/zdtm.sh ns/static/dumpable01
  Test: zdtm/live/static/dumpable01, Result: PASS
- Confirmed that the test fails after reverting commit d5bb7e9748.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-24 22:44:34 +04:00
Cyrill Gorcunov
7f3de2889e restore: Make sure the last_pid is writen with zero offset
Otherwise I see on 3.16-rc1 and higher

| [  100.851730] futex wrote to ns_last_pid when file position was not 0!
| This will not be supported in the future. To silence this
| warning, set kernel.sysctl_writes_strict = -1

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-23 16:49:40 +04:00
Pavel Emelyanov
687c389478 iov: Add page_server_iov to iov and back helpers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-20 16:35:54 +04:00
Pavel Emelyanov
3b995f1aef iov: Add iovec2pagemap() helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-20 16:35:52 +04:00
Pavel Emelyanov
cd34724092 iov: Add iov_init() helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-20 16:35:51 +04:00
Pavel Emelyanov
bb7ac03a5b iov: Add iov_grow_page() helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-20 16:35:14 +04:00
Andrey Vagin
997f08eaa6 vdso: don't forget to adjust vma_area_list->nr
A proxy vdso is removed from the vma_area_list list,
so vma_area_list->nr must be decremented.

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-20 16:28:03 +04:00
Pavel Emelyanov
7edf0994c9 criu: Version 1.3-rc2
Next acheivement -- external bind mounts and tasks-to-cgroups
bindings. Plus many bugfixes in memory restore and mounpoints
dump, many thanks to Google guys for reports and patches!

We have quite a few things left to make workable LXC and Docker
support, hopefully the next tag will be the 1.3 one :)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
v1.3-rc2
2014-06-18 13:34:36 +04:00
Saied Kazemi
8870aa1e4f pie: A quick workaround for PR_SET_DUMPABLE == 2 restore error.
[ xemul: It's a temporary workaround not to lock the -rc2 release.
  Once we have some better solution, this will be rolled back. ]

Signed-off-by: Saied Kazemi <saied@google.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 21:44:50 +04:00
Andrey Vagin
2ad1ba72fa zdtm: check bind-mounted files in static/mountpoints
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:40:23 +04:00
Andrey Vagin
494c044384 mount: dump one file system only once (v2)
A file system can be bind-mounted a few times and some of these mounts
can be non-root. We need to find one of root mounts and dump it.

v2: don't forget to check pm->dumped and pm->parent
    don't dump a root file system, it's always external for now.

Reported-by: Saied Kazemi <saied@google.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:40:00 +04:00
Andrey Vagin
697211908a tmpfs: use device number instead of mnt_id in image names
One file system can be mounted a few times, so mnt_id isn't unique for it.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:39:52 +04:00
Pavel Emelyanov
061d6cfadf mnt: Handle external bind mounts according to --ext-mount option (v3)
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:36:52 +04:00
Pavel Emelyanov
c7e0042946 crtools: Introduce the --ext-mount-map option (v3)
On dump one uses one or more --ext-mount-map option with A:B arguments.
A denotes a mountpoint (as seen from the target mount namespace) criu
dumps and B is the string that will be written into the image file
instead of the mountpoint's root.

On restore one uses the same --ext-mount-map option(s) with similar
A:B arguments, but this time criu treats A as string from the image's
root field (foobar in the example above) and B as the path in criu's
mount namespace the should be bind mounted into the mountpoint.

v3:
* Added documentation
* Added RPC bits
* Changed option name into --ext-mount-map
* Use colon as key and value separator

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:36:30 +04:00
Pavel Emelyanov
c3ea0ba06f mnt: Tossing bits around in validate_mounts
Just for simpler further patching.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-17 10:36:02 +04:00
Tycho Andersen
43c96be798 Allow dumping of pstore, securityfs, fusectl, debugfs
These are mounted by default in ubuntu containers, so criu should know about
them and remount them on restore.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-11 15:09:15 +04:00
Pavel Emelyanov
72a9372aff fs: Opening FE-s after fchdir doesn't work
It uses absolute file names, so any open-s should happen _before_
we change tasks' root.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-10 17:47:32 +04:00
Pavel Emelyanov
7aa7e95f7e fs: Don't hide error from prepare_fs
If fchroot() succeeds the further failures don't get
noticed by caller.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-10 17:47:31 +04:00
Pavel Emelyanov
bd7bddb889 zdtm: Add test for mount namespace w/o mountpoints
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-09 15:29:52 +04:00
Pavel Emelyanov
701f883765 restore: Do fchroot() via proc helpers
There's no such thing as fchroot() in Linux, but we need to do
chroot() into existing file descriptor. Before this patch we did
this by chroot()-ing into /proc/self/fd/$fd. W/o proc mounted it's
no longer possible, so do this like

fchdir(proc_service_fd);
chroot("./self/fd/$root_fd");
fchdir($cwd_fd);

Thanks to Andrey Vagin for this trick ;)

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-09 15:29:50 +04:00
Pavel Emelyanov
3659d60ab7 restore: Open /proc/sys/kernel/ns_last_pid via helpers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-09 15:29:49 +04:00
Pavel Emelyanov
0066d5e813 restore: Open /proc/self/maps via helpers
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-09 15:29:47 +04:00
Pavel Emelyanov
8644ce9628 util: Prepare proc opening helpers to open any files
We have a set of routines that open /proc/$pid files via proc service
descriptor. Teach them to accept non-pids as pids to open /proc/self/*
and /proc/* files via the same engine.

Signed-f-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-09 15:29:46 +04:00
Pavel Emelyanov
d9e7a5f155 zdtm: Add ability just to start the test
When running test with ns/ prefix zdth.sh does complex preparations.
Make it possible to make them and let started process ready for
manual investigation.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-09 15:29:44 +04:00
Cyrill Gorcunov
c09b7c2f37 vdso: x86 -- Use dynamic symbols for parsing
New vDSO are in stripped format so use dynamic
symbols instead of sectioned ones.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-06 15:26:31 +04:00
Cyrill Gorcunov
3ca8b12ee7 vdso: x86 -- Drop DECLARE_VDSO macro
We're not sharing the code anymore so drop it.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-06 15:26:14 +04:00
Pavel Emelyanov
8a07349388 files: Fix open_path() to provide mntns root fd to callbacks
This fixes the support for fifo-s in mount namespaces and
makes it easier to control the correct open_path() usage in
the future.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-06 12:20:02 +04:00
Pavel Emelyanov
b9c6cf3dd3 mnt: Strip commas from options string
Not all filesystems like it. Other than this options in the
image just look cleaner.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-06 12:19:15 +04:00
Pavel Emelyanov
0457c94c69 zdtm: Make it possible for test to get ZDTM_NEWNS variable
I will need to make cgroup test behave slightly differently
when it's in and out of ns/ run. To do so it's handy to use
the ZDTM_NEWNS variable set by zdtm.sh

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-06-06 12:18:50 +04:00
Pavel Emelyanov
30e95be264 mnt: Fix validation of dumpable mountpoints
This patch consists of 3 unsplittable (from my POV) fixes.

1. Remove messy check from dump_one_mountpoint() -- we have
   validate_mounts to check whether we can dump the tree
   or not.

2. Other than being in the wron place the mentioned check
   is wrong. Comparing of the length of the mp->source-s
   makes no sense -- it should be mp->root, but even this
   would be wrong...

3. ... instead, we should check for bind mount root path
   being accessible from the target mount root path, i.e.
   the bind->root should start with src->root.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-04 19:34:54 +04:00
Pavel Emelyanov
3635f2c4b9 mnt: Relax checks for top-mount in validate_mounts
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@parallels.com>
2014-06-04 19:34:53 +04:00
Pavel Emelyanov
c75b7ab61c mnt: Devpts options get corrupted on dump (v2)
The memcpy() in devpts_dump() just overwrites part of them.
Fix this and move the whole code into sub-routine for future.

v2: Fix off-by-one error spotted by Filipe.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Filipe Brandenburger <filbranden@google.com>
2014-06-02 13:07:11 +04:00
Cyrill Gorcunov
06f559fcc7 vdso: make -- Arch targets depends on config
We use config.h in vDSO handling code so arch
targets should depend on it.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-28 00:51:07 +04:00
Pavel Emelyanov
441b9b9ee5 zdtm: Stupid test for task-in-cgroup
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-28 00:24:54 +04:00
Pavel Emelyanov
203c291467 cg: Restore tasks into proper cgroups
On restore find out in which sets tasks live in and move
them there.

Optimization note -- move tasks into cgroups _before_ fork
kids to make them inherit cgroups if required. This saves
a lot of time.

Accessibility note -- when moving tasks into cgroups don't
search for existing host mounts (they may be not available)
and don't mount temporary ones (may be impossible due to
user namespaces). Instead introduce service fd with a yard
of mounts.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:48:06 +04:00
Pavel Emelyanov
1ba9d2cae9 cg: Dump cgroups tasks live in
Each task points to a single ID of cgroup-set it lives in. This
is done so to save some space in the image, as tasks likely
live in the same set of cgroups.

Other than this we keep track of what cgroup set we dump the
subtree from. If it happens, that root task lives in the same
cgroup set as criu does, we don't allow for any other sub-cgroups
and make restore (next patch) much simpler and faster.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:48:06 +04:00
Pavel Emelyanov
8b8eb53a0a cg: Skeleton for cgroup code
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:48:06 +04:00
Pavel Emelyanov
06f7243380 image: Add bits and pieces for cgroups image
The exact structure of the image will be revealed in the
next patch(es). What is important here, is that cgroup
image is somewhat new.

It will likely contain arrays of objects of different types,
so I introduce the "header" object, that will link these
arrays using pb repeated fields. This will help us to avoid
many image files for different cgroup objects and will make
the amount of write()-s required be 1.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:48:06 +04:00
Pavel Emelyanov
b48e4cbfb8 proc: Introduce helper for parsing /proc/$pid/cgroup file
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:48:06 +04:00
Pavel Emelyanov
e5eb73ea48 util: Introduce strstartswith helper
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:48:06 +04:00
Cyrill Gorcunov
c473461d24 vdso: Make it arch specific
Currently we build vDSO handling code for all archs provided
in the source code having some "common" parts inside pie/vdso.c,
pie/vdso-stub.c, vdso-stub.c and vdso.c. This were more or
less well but in new linux kernels (starting from 3.16 presumably)
the vDSO has been significantly reworked so every architecture
must have own vDSO handling engine (just like the kernel does).

So in this patch we move vDSO code to arch specific and because
aarch64 actually doesn't implement proxification yet due to
kernel restrictions -- we drops it out. When there will be
kernel support we bring it back in proper arch/aarch64
implementation.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:41:31 +04:00
Cyrill Gorcunov
676708e3b3 vdso: Put CONFIG_VDSO where needed
Guard vDSO code with CONFIG_VDSO, no need to even build it
on archs which do not support vDSO handling.

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:40:07 +04:00
Cyrill Gorcunov
89faae1e9b vdso: dump -- Drop duplicated include
Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Alexander Kartashov <alekskartashov@parallels.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2014-05-27 23:40:00 +04:00