Commit graph

10078 commits

Author SHA1 Message Date
Cyrill Gorcunov
f167d1f4e9 fown: Don't fail on dumping files opened with O_PATH
O_PATH opened files are special: they have empty
file operations in kernel space, so there not that
much we can do with them, even setting position is
not allowed. Same applies to a signal number for
owner settings.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Co-developed-by: Alexander Mikhalitsyn <alexander@mihalicyn.com>
Signed-off-by: Alexander Mikhalitsyn (Virtuozzo) <alexander@mihalicyn.com>
2020-03-27 19:36:20 +03:00
Andrei Vagin
58fd63042c zdtm/inhfd: force python to read new data from a file
python 2.7 doesn't call the read system call if it's read file to the
end once. The next seek allows to workaround this problem.

inhfd/memfd.py hangs due to this issue.

Reported-by: Mr Jenkins
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-03-27 19:36:20 +03:00
Andrei Vagin
fce196d88d memfd: don't corrupt a state of the dumped fd
Right now, criu uses a dumped fd to dump content of a memfd "file".

Here are two reasons why we should not do this:
* a state of a dumped fd doesn't have to be changed, but now criu calls
  lseek on it. This can be workarounded by using pread.
* a dumped descriptor can be write-only.

Reported-by: Mr Jenkins
Cc: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-03-27 19:36:20 +03:00
Andrei Vagin
ffe0896ed0 fs: use __open_proc instead of open("/proc/...", ... )
Processes can run in a mount namespace without /proc.

Reported-by: Mr Jenkins
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-03-27 19:36:20 +03:00
Adrian Reber
4129d3262a cgroup2: add minimal cgroup2 support
The runc test cases are (sometimes) mounting a cgroup inside of the
container. For these tests to succeed, let CRIU know that cgroup2 exists
and how to restore such a mount.

This does not fix any specific cgroup2 settings, it just enables CRIU to
mount cgroup2 in the restored container.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-03-27 19:36:20 +03:00
Adrian Reber
10416bcbcb seize: support cgroup v2 freezer
This adds support to checkpoint processes using the cgroup v2 freezer.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-03-27 19:36:20 +03:00
Adrian Reber
9f902e0c6b seize: factor out opening and writing the freezer state
More preparations for cgroupv2 freezer. Factor our the freezer state
opening and writing to have one location where to handle v1 and v2
differences.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-03-27 19:36:20 +03:00
Adrian Reber
563c5e5e76 seize: prepare for cgroupv2 freezer
The cgroupv2 freezer does not return the same strings as v1. Instead of
THAWED and FROZEN v2 returns 0 and 1 (strings). This prepares the seize
code to use 0 and 1 everywhere and THAWED and FROZEN only for v1
specific code paths.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-03-27 19:36:20 +03:00
Radostin Stoyanov
bb032cc3e2 criu(8): Convert tabs to spaces
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2020-03-27 19:36:20 +03:00
Radostin Stoyanov
48f3b6516b criu(8): Add documentation for --enable-fs
This option was introduced with:

e2c38245c6

v2: (comment from Pavel Tikhomirov) --enable-fs does not fit with
--external dev[]:, see try_resolve_ext_mount, external dev mounts
only determined for FSTYPE__UNSUPPORTED.

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2020-03-27 19:36:20 +03:00
Mike Rapoport
cdd08cdff8 uffd: use userns_call() to execute ioctl(UFFDIO_API)
In the recent kernels the userfaultfd support for FORK events is limited to
CAP_SYS_PTRACE. That causes the followong error when the ioctl(UFFDIO_API)
is executed from non-privilieged userns:

Error (criu/uffd.c:273): uffd: Failed to get uffd API: Operation not permitted

Wrapping the call to ioctl(UFFDIO_API) in userns_call() resolves the issue.

Fixes: #964
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-03-27 19:36:20 +03:00
Pavel Tikhomirov
38793699e7 test/jenkins: remove empty line at the end of file
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2020-03-27 19:36:20 +03:00
Andrei Vagin
3eab205bae python: sort imports
202 Additional newline in a group of imports.
I100 Import statements are in the wrong order.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-03-27 19:36:20 +03:00
Dmitry Safonov
bc49927bbc criu: Make use strlcpy() to copy into allocated strings
strncpy() with n == strlen(src) won't put NULL-terminator in dst.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-03-27 19:36:20 +03:00
Dmitry Safonov
ec11644954 criu: Use strlcpy() instead of strncpy()
gcc8 in Fedora Rawhide has a new useful warning:

> criu/img-remote.c: In function 'push_snapshot_id':
> criu/img-remote.c:1099:2: error: 'strncpy' specified bound 4096 equals destination size [-Werror=stringop-truncation]
>  1099 |  strncpy(rn.snapshot_id, snapshot_id, PATH_MAX);
>       |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From man 3 strncpy:
> Warning:  If there is no null byte among the first n bytes of src,
> the string placed in dest will not be null-terminated.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
2dd105b8df memfd: add tests
Testing for all the memfd features, namely support for CR of:
* the same fd shared by multiple processes
* the same file shared by multiple processes
* the memfd content
* file flags and fd flags
* mmaps, MAP_SHARED and MAP_PRIVATE
* seals, excluding F_SEAL_FUTURE_WRITE because this feature only exists
  in recent kernels (5.1 and up)
* inherited fd

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
b133c375ad inhfd_test: add support for non-pair files
File pairs naturally block on read() until the write() happen (or the
writer is closed). This is not the case for regular files, so we
take extra precaution for these.

Also cleaned-up an extra my_file.close()

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
56d8e2455f memfd: add seals support
See "man fcntl" for more information about seals.

memfd are the only files that can be sealed, currently. For this
reason, we dump the seal values in the MEMFD_INODE image.

Restoring seals must be done carefully as the seal F_SEAL_FUTURE_WRITE
prevents future write access. This means that any memory mapping with
write access must be restored before restoring the seals.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
29a1a88bce memfd: add memory mapping support
* During checkpoint, we add a vma flags: VMA_AREA_MEMFD to denote memfd
  regions.
* Even though memfd is backed by the shmem device, we use the file
  semantics of memfd (via /proc/map_files/<vma>) which we already have
  support for.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
b25684e24a memfd: add --inherit-fd support
Upon file restore, inherited_fd() is called to check for a user-defined
inerit-fd override. Note that the MEMFD_INODE image is read at each
invocation (memfd name is not cached).

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
875ac4d03f files: increase path buffer size in inherited_fd()
Prepare memfd to use inherited_fd(), needing long path names support.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Nicolas Viennot
c1e72aa936 memfd: add file support
See "man memfd_create" for more information of what memfd is.

This adds support for memfd open files, that are not not memory mapped.

* We add a new kind of file: MEMFD.
* We add two image types MEMFD_FILE, and MEMFD_INODE.
  MEMFD_FILE contains usual file information (e.g., position).
  MEMFD_INODE contains the memfd name, and a shmid identifier
  referring to the content.
* We reuse the shmem facilities for dumping memfd content as it
  would be easier to support incremental checkpoints in the future.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-03-27 19:36:20 +03:00
Andrei Vagin
5dbc24b206 util: introduce the mount_detached_fs helper
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-03-27 19:36:14 +03:00
Pavel Emelyanov
8bd634c1af
Merge pull request #940 from avagin/v3.14-part1
Preparing the v3.14 release.
2020-03-06 16:43:19 +03:00
Andrei Vagin
e19f4cf3b1 MAINTAINERS: Add Dima and Adrian to maintainers
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-03-03 11:48:47 -08:00
Mike Rapoport
42db2c1563 MAINTAINERS: add Mike
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-02-29 10:00:04 -08:00
Pavel Emelyanov
872b795a56
Maintainers: Suggest the maintainers codex (#932)
The guide is based on the one from the RunC project, but
has some criu-related specifics.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-02-21 18:48:41 +03:00
Andrei Vagin
ff756cbb28 python: sort imports
202 Additional newline in a group of imports.
I100 Import statements are in the wrong order.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-16 09:15:31 -08:00
Andrei Vagin
d68a68b8f4 test/zdtm/inhfd: update dump options one each iteration
This allows to run inhfd tests with many iterations of C/R.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-16 09:15:15 -08:00
Adrian Reber
f5181b2767 Travis: fix podman test case
Podman changed the output of 'podman ps'. For the test only running
containers are interesting. Adding the filter '-f status=running' only
returns running containers as previously.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-16 09:15:15 -08:00
Radostin Stoyanov
3a4c33c502 zdtm: mntns_rw_ro_rw update error msg
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2020-02-16 09:15:15 -08:00
Dmitry Safonov
9cb4067e13 vdso: Don't page-align vvar
It's always page-aligned (as any VMA).

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-02-16 09:15:15 -08:00
Dmitry Safonov
a96a7ed87f vdso: Repair !CONFIG_VDSO
Apparently, C/R is broken when CONFIG_VDSO is not set.
Probably, I've broken it while adding arm vdso support.
Or maybe some commits after.

Repair it by adding checks into vdso_init_dump(), vdso_init_restore().
Also, don't try handling vDSO in restorer if it wasn't present in
parent. And prevent summing VDSO_BAD_SIZE to {vdso,vvar}_rt_size.

Reported-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-02-16 09:15:15 -08:00
Dmitry Safonov
0022c28468 vdso: Add vdso_is_present() helper
Use it in kerndat to check if the kernel provides vDSO.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-02-16 09:15:15 -08:00
Dmitry Safonov
99346a2824 zdtm: Make test_{doc,author} weak variables
Allows to override them in every test, optionally.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-02-16 09:15:15 -08:00
Dmitry Safonov
72ff290708 criu: Make use strlcpy() to copy into allocated strings
strncpy() with n == strlen(src) won't put NULL-terminator in dst.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-02-16 09:15:14 -08:00
Nicolas Viennot
0f438ceeed typo: fix missing space in error message
Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-02-16 09:14:37 -08:00
Andrei Vagin
9bc9366c94 vdso: use correct offsets to remap vdso and vvar mappings
In the current version, the offsets of remapping vvar and vdso regions
are mixed up.

If vdso is before vvar, vvar has to be mapped with the vdso_size offset.
if vvar is before vdso, vdso has to be mapped with the vvar_size offset.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-16 09:14:37 -08:00
Andrei Vagin
f1714ccce7 test/vdso: check the code path when here is no API to map vDSO
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-16 09:14:37 -08:00
Sergei Trofimovich
56258da176 criu: fix build failure against gcc-10
On gcc-10 (and gcc-9 -fno-common) build fails as:

```
ld: criu/arch/x86/crtools.o:criu/include/cr_options.h:159:
  multiple definition of `rpc_cfg_file'; criu/arch/x86/cpu.o:criu/include/cr_options.h:159: first defined here
make[2]: *** [scripts/nmk/scripts/build.mk:164: criu/arch/x86/crtools.built-in.o] Error 1
```

gcc-10 will change the default from -fcommon to fno-common:
https://gcc.gnu.org/PR85678.

The error also happens if CFLAGS=-fno-common passed explicitly.

Reported-by: Toralf Förster
Bug: https://bugs.gentoo.org/707942
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2020-02-04 12:39:44 -08:00
Kir Kolyshkin
23374b7798 criu(8): fix for asciidoctor
Commit 0493724c8e added support for using asciidoctor
(instead of asciidoc + xmlto) to generate man pages.

For some reason, asciidoctor does not deal well with some
complex formatting that we use for options such as --external,
leading to literal ’ and ' appearing in the man page instead
of italic formatting. For example:

> --inherit-fd fd[’N']:’resource'

(here both N and resource should be in italic).

Asciidoctor documentation (asciidoctor --help syntax) tells:

> == Text Formatting
>
> .Constrained (applied at word boundaries)
> *strong importance* (aka bold)
> _stress emphasis_ (aka italic)
> `monospaced` (aka typewriter text)
> "`double`" and '`single`' typographic quotes
> +passthrough text+ (substitutions disabled)
> `+literal text+` (monospaced with substitutions disabled)
>
> .Unconstrained (applied anywhere)
> **C**reate+**R**ead+**U**pdate+**D**elete
> fan__freakin__tastic
> ``mono``culture

so I had to carefully replace *bold* with **bold** and
'italic' with __italic__ to make it all work.

Tested with both terminal and postscript output, with both
asciidoctor and asciidoc+xmlto.

TODO: figure out how to fix examples (literal multi-line text),
since asciidoctor does not display it in monospaced font (this
is only true for postscript/pdf output so low priority).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-02-04 12:39:44 -08:00
Kir Kolyshkin
a15426a111 criu(8): some minor rewording
1. Add a/the articles where I see them missing

2. s/Forbid/disable/

3. s/crit/crit(1)/ as we're referring to a man page

4. Simplify some descriptions

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-02-04 12:39:44 -08:00
Kir Kolyshkin
8477875dc2 doc/Makefile: don't hide xmlto stderr
In case asciidoc is installed and xmlto is not, make returns an error
but there's no diagnostics shown, since "xmlto: command not found"
goes to /dev/null.

Remove the redirect.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-02-04 12:39:44 -08:00
Alexander Mikhalitsyn
c98af78c58 compel: add -ffreestanding to force gcc not to use builtin memcpy, memset
This patch fixes the problem with SSE (xmm) registers corruption on amd64
architecture. The problem was that gcc generates parasite blob that uses
xmm registers, but we don't preserve this registers in CRIU when injecting
parasite. Also, gcc, even with -nostdlib option uses builtin memcpy,
memset functions that optimized for amd64 and involves SSE registers.

It seems, that optimal solution is to use -ffreestanding gcc option
to compile parasite. This option implies -fno-builtin and also it designed
for OS kernels compilation/another code that suited to work on non-hosted
environments and could prevent future sumilar bugs.

To check that you amd64 CRIU build affected by this problem you could simply
objdump -dS criu/pie/parasite.o | grep xmm
Output should be empty.

Reported-by: Diyu Zhou <zhoudiyupku at gmail.com>
Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn@virtuozzo.com>
Signed-off-by: Alexander Mikhalitsyn <alexander@mihalicyn.com>
2020-02-04 12:39:44 -08:00
Adrian Reber
f6de8d4ea9 travis: fix warning and errors from validation
This fixes the validation errors from Travis:

 Build config validation
 root: deprecated key sudo (The key `sudo` has no effect anymore.)
 root: missing os, using the default linux
 root: key matrix is an alias for jobs, using jobs

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-04 12:39:44 -08:00
Adrian Reber
0e291d26c9 arm: use clone3() if it exists
This is the last architecture specific change to make CRIU use clone3()
with set_tid if available. Just as on all other architectures this adds
a clone3() based assembler wrapper to be used in the restorer code.

Tested on Fedora 31 with the same 5.5.0-rc6 kernel as on the other
architectures.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-04 12:39:44 -08:00
Adrian Reber
f991f23506 aarch64: use clone3() if possible
This adds the parasite clone3() with set_tid wrapper for aarch64.

Tested on Fedora 31 with 5.5.0-rc6.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-04 12:39:44 -08:00
Adrian Reber
3dabd38a82 clone3: handle clone3() with CLONE_PARENT
clone3() explicitly blocks setting an exit_signal if CLONE_PARENT is
specified. With clone() it also did not work, but there was no error
message. The exit signal from the thread group leader is taken.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-04 12:39:44 -08:00
Adrian Reber
f6469493dd ppc64le: use clone3() if possible
This adds the parasite clone3() with set_tid wrapper for ppc64le.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-04 12:39:44 -08:00
Adrian Reber
55c8ec62a5 arm: remove stack pointer from clobber list
Just like on all other supported architectures gcc complains about the
stack pointer register being part of the clobber list. This removes the
stack pointer from the clobber list.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-02-04 12:39:44 -08:00