Commit graph

10205 commits

Author SHA1 Message Date
Nicolas Viennot
70ecbbcc86 compel: allocate the GOT table to avoid memory corruption
Previously, the GOT table was using the same memory location as the
args region, leading to difficult to debug memory corruption bugs.

We allocate the GOT table between the parasite blob and the args region.
The reason this is a good placement is:
1) Putting it after the args region is possible but a bit combersome as
the args region has a variable size
2) The cr-restore.c code maps the parasite code without the args region,
as it does not do RPC.

Another option is to rely on the linker to generate a GOT section, but I
failed to do so despite my best attempts.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
fee517b3da compel: remove x86/prologue.S
This file has been ignored since commit 19fadee9 from 2016.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
8d8dd5a799 compel: x86 parasite_service entry point simplification
We don't need to push 0 on the stack. This seems to be a remnant of the
initial commit of 2011 that had a `pushq $0`.

The 16 bytes %rsp alignment was added with commit 2a0cea29 in 2012.
This is no longer necessary as we already guarantee that %rsp is 16
bytes aligned. A BUG_ON() is added to enforce this guarantee.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
b8c1d9d939 compel: rewrite parasite cmd and args manipulation from assembly to C
Previously, __export_parasite_cmd was located in parasite-head.S, and
__export_parasite_args located exactly at the end of the parasite blob.
This is not ideal for various reasons:
1) These two variables work together. It would be preferrable to have
them in the same location
2) This prevent us from allocating another section betweeen the parasite
blob and the args area. We'll need this to allocate a GOT table

This commit changes the allocation of these symbols from assembly/linker
script to a C file.

Moreover, the assembly entry points that invoke parasite_service()
prepares arguments with hand crafted assembly. This is unecessary.
This commit rewrite this logic with regular C code.

Note: if it wasn't for the x86 compat mode, we could remove all
parasite-head.S files and directly jump to parasite_service() via
ptrace.  An int3 architecture specific equivalent could be called at the
end of parasite_service() with an inline asm statement.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
391da74647 compel: stop rounding up the parasite blob size and args region to PAGE_SIZE
It is unnecessary and potentially confusing for understanding the memory
layout requirement of the parasite blob.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
d99fc1e553 compel: remove "addr_" from offset variable names
It removes the potential confusion when it comes to virtual address vs
offsets. Further, doing so makes naming more consistent with the rest of
the parasite_blob_desc struct.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
a531f9a8bc compel: pass the parasite_blob_desc to compel_relocs_apply()
compel_relocs_apply() was taking arguments mostly from the struct
parasite_blob_desc. Instead of passing all the arguments, we pass a
pointer to the struct itself.

This makes the code safer, as cr-restore.c calls compel_relocs_apply().
It previously needed to poke into what can be considered private
variables of the restorer-pie.h file.

To allow the parasite_blob_desc struct to be populated without a
parasite_ctl struct, we expand the compel API to export a
parasite_setup_c_header_desc() in the generated pie.h.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
8ac0fa6aaf compel: add error message for COMMON symbols
COMMON symbols are emitted for global variable that are not initialized
in shared libraries.
They typically end up in the .bss section when linking an executable.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Andrei Vagin
f92948ccaf zdtm: make cgroup_yard to be aware of cgroup2
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-10-20 00:18:24 -07:00
Andrei Vagin
f96cd8c749 tests: skip cgroup04 and cgroup_ifpriomap on pure cgroup2 systems
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-10-20 00:18:24 -07:00
Andrei Vagin
5f160811aa zdtm.py: add the cgroup2 freezer support
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-10-20 00:18:24 -07:00
Andrei Vagin
98e9165f0c cgroup: Add the initial support for cgroup2
This change is very straightforward. We don't skip the cgroup2
controller and dump it as any other controllers.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
a93df9eb9b pidns: fixup
I pushed the wrong branch to the pidns PR

https://github.com/checkpoint-restore/criu/pull/1056

which resulted in the wrong patches getting merged.

This is the actual result from the review.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Ajay Bharadwaj
bb555b3720 criu/config.c: added cli option for build-id
file_validation_method field added to cr_options structure in
"criu/include/cr_options.h" along with the constants:
FILE_VALIDATION_FILE_SIZE
FILE_VALIDATION_BUILD_ID
FILE_VALIDATION_DEFAULT (Equal to FILE_VALIDATION_BUILD_ID)

Usage and description information is yet to be added

Usage:
--file-validation="filesize" (To use only the file size check)
--file-validation="buildid" (To try and use only the build-id check)

Signed-off-by: Ajay Bharadwaj <ajayrbharadwaj@gmail.com>
2020-10-20 00:18:24 -07:00
Ajay Bharadwaj
9191f8728d criu/files-reg.c: add build-id validation functionality
efi.h: Required for accessing the build-id of .efi files

This adds functions to find, store and compare with the stored build-id.
get_build_id() calls 32-bit or 64-bit helper functions depending on
the bitness of the ELF file after first ensuring that it is actually
an ELF file by checking for the magic number.

The number of iterations while searching the elf file for the
build-id before giving up (500 while searching the note section)
are limited.

Signed-off-by: Ajay Bharadwaj <ajayrbharadwaj@gmail.com>
2020-10-20 00:18:24 -07:00
Ajay Bharadwaj
7b18c13c19 images/regfile.proto: adds additional fields to RegFileEntry
This adds build-id, checksum, checksum-config and checksum-parameter fields
to RegFileEntry to store metadata used for file verification.

build_id: Holds the build-id if it could be obtained

checksum: Holds the checksum if it could be obtained

checksum_config: Holds the configuration of bytes for which checksum has
been calculated (The entire file, first N bytes or every Nth byte)

checksum_parameter: Specifies the value of 'N', if required, for the
configuration of bytes

Signed-off-by: Ajay Bharadwaj <ajayrbharadwaj@gmail.com>
2020-10-20 00:18:24 -07:00
Angie Ni
8354b526c4 restore: skip unnecessary setgroups calls
When groups already have desired values, we skip calling setgroups.
Furthermore, this check allows us to restore when in an
unprivileged user namespace that cannot use setgroups.

Signed-off-by: Angie Ni <avtni@google.com>
2020-10-20 00:18:24 -07:00
Nicolas Viennot
0d8d7f2329 tests: criu-image-streamer change dev branch to master branch
Now that the new CRIU to criu-image-streamer protocol is in, we can use
the master branch of criu-image-streamer.

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
2020-10-20 00:18:24 -07:00
Andrei Vagin
62d70bd482 test/zdtm/autofs: use sigaction instead of the deprecated siginterrupt
Reported-by: Mr Travis
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-10-20 00:18:24 -07:00
Angie Ni
539183fadd Add error logging to config + crtools init
CRIU sometimes returns 1 from main() with no explanation.
Changes made add more logging in the case of
initialization errors in config and crtools.

Signed-off-by: Angie Ni <avtni@google.com>
2020-10-20 00:18:24 -07:00
Angie Ni
9a4b933f24 Add error logging to kerndat init
CRIU sometimes returns 1 from main() with no explanation.
These changes add additional logging for initialization errors in kerndat.

Signed-off-by: Angie Ni <avtni@google.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
3490d997be test: test external namespace support
Adapt netns_ext tests to also work with pid namespaces and move it from
test/others/netns_ext/ to test/others/ns_ext/.

Also enable ns_ext tests in Travis runs.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
f3ebdeebe2 pidns: add external pidns to man-page
Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
9dd1ab00e7 pidns: support external PID namespaces
This allows CRIU to restore a process into an existing PID namespace.
During checkpointing the PID namespace can be marked as external using:

   --external pid[<inode>]:<label>

This can be the host PID namespace or any other PID namespace.

During restore a process can be restored into an existing PID namespace
using:

  --inherit-fd fd[<FD>]:<label>

The <label> has to be the same for checkpoint and restore. CRIU uses
the <label> to know which resource the user means.

A process can start in the host PID namespace and can be moved to
another namespace or the other way around. Any PID namespace can be
used.

This is necessary to checkpoint containers in a POD which share certain
namespaces and this code to support external PID namespaces is the first
step towards checkpointing and restoring containers which belong to a
POD.

This is not using the --join-ns functionality as it is not possible to
move existing process to a PID namespace using setns(). Only child
process will be created in the PID namespace and that is why setns()
needs to be called before clone().

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
f1e6b10369 pidns: write and read pidns information
This loads and stores the key for an external PID namespace if specified
by the user using: --external pid[<inode>]:<label>

Preparation for restoring into existing PID namespaces.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
4e7ec3c88b pidns: add pidns image file definition
TODO: create correct magic

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Pavel Tikhomirov
99c8487837 zdtm: add zombie_leader test
Create a session leader and it's child - session member, make leader
zombie. To restore this criu will need to create a helper task a child
of our zombie so that member can inherit session. Before fixes in this
patchset we segfault on empty ids and fail to restore cgroups because of
empty cg_set

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2020-10-20 00:18:24 -07:00
Pavel Tikhomirov
f0438f47f2 cgroup: make prepare_task_cgroup lookup current cgset in ancestors
In case if our parent is a dead task (zombie) or a helper which in it's
turn has zombie parent, and parent thus has zero cg_set we should look
for current cgset deeper.

Fixes: #1066

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2020-10-20 00:18:24 -07:00
Cyrill Gorcunov
d38046b003 mount: restore_task_mnt_ns - Lookup for mount namespace conditionally
In case if our parent is a dead task (zombie) we should lookup
for parent ids which will be inherited on restore. Otherwise
parent->ids may be nil and SIGSEGV produced.

Signed-off-by: Cyrill Gorcunov <gorcunov@virtuozzo.com>

Rework and port from vzcriu:
87b320964 ("vz7: mount: restore_task_mnt_ns - Lookup for mount namespace
conditionally")

Fixes: #1066

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
41b535d312 test: skip vdso test on non-vdso systems
Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Angie Ni
ce22e0f37d uffd: uffd_open prints info, caller prints error
When uffd_open is called from kerndat_uffd, userfaultfd failure is not
considered an error, so the goal is to suppress the error message --
instead, we print this message as info.

If the function fails, it is the responsibility of the caller
to print the error message.

Signed-off-by: Angie Ni <avtni@google.com>
2020-10-20 00:18:24 -07:00
Mike Rapoport
6815aa958d CONTRIBUTING.md: add pull request guidelines
Following the discussion at [1] describe best practices for pull request
creation.

[1] https://github.com/checkpoint-restore/criu/pull/1096

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-10-20 00:18:24 -07:00
Mike Rapoport
35f8c056ac CONTRIBUTING.md: add sections about patch description and splitting
Shamelessly stolen from the Linux kernel [1], shortened a bit and
relaxed to match CRIU.

[1] https://www.kernel.org/doc/html/latest/process/submitting-patches.html

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-10-20 00:18:24 -07:00
Mike Rapoport
2e5805878b CONTRIBUTING.md: minor formatting fixes
* Mark lowcase criu as code in the environment section
* Add missing brace around the reference to https://criu.org/Secrity
* Fixup an admolition block that GitHub cannot render
* Spelling fixups
* s/github/GitHub/g

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-10-20 00:18:24 -07:00
Mike Rapoport
d0fcb01d47 CONTRIBUTING.md: import "How to submit patches" from criu.org
Import "How to submit patches" article from CRIU wiki and update its
format to match GitHub markdown.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-10-20 00:18:24 -07:00
Mike Rapoport
808684c99e Add CONTRIBUTING.md
Move the existing contribution guidelines to a dedicated file for future
extensions.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-10-20 00:18:24 -07:00
Cyrill Gorcunov
6ee4b72382 arch/x86: Fix calculation of xstate_size
The layout of xsave frame in a standart format is predefined by the hardware.
Lets make sure we're increasing in frame offsets and use latest offset where
appropriate.

https://github.com/checkpoint-restore/criu/issues/1042

Reported-by: Ashutosh Mehra <mehra.ashutosh@ibm.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-20 00:18:24 -07:00
Kir Kolyshkin
1d9438aefb criu swrk: fix usage, allow common options
TL;DR: this makes possible -v with criu swrk, and removes showing usage
which is useless in swrk mode.

1. Since criu swrk command is not described in usage, there is no sense
   in showing it. Instead, show a one-line hint about how to use it.

2. In case some global options (like -v) are used, argv[1] might not
   point to "swrk". Use optind to point to a correct non-option
   argument.

3. While at it, also error out in case we have extra arguments.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
cbf099400a Travis: use Vagrant to run VMs
This adds the minimal configuration to run Fedora 31 based VMs on
Travis.

This can be used to test cgroupv2 based tests, tests with vdso=off and
probably much more which requires booting a newer kernel.

As an example this builds CRIU on Fedora 31 and reconfigures it to boot
without VDSO support and runs one single test.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
d72428b7c4 Also report clone3() errors correctly
Without clone3() CRIU was able to detect a process with a wrong PID only
in the already created child process. With clone3() this error can
happen before the process is created.

In the case of EEXIST this error will now be correctly forwarded to an
RPC client.

This was detected by running test/others/libcriu on a clone3() system.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
047ecd3a15 test/others/libcriu: test version library calls
This adds the previously added libcriu version functions to the libcriu
tests.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
55f71b8667 lib/c: add criu_get_version()
Although the CRIU version is exported in macros in version.h it only
contains the CRIU version of libcriu during build time.

As it is possible that CRIU is upgraded since the last time something
was built against libcriu, this adds functions to query the actual CRIU
binary about its version.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
ZeyadYasser
e57e74a18d criu: optimize find_unix_sk_by_ino()
Fixes: #339
Replaced the linear search with a hashtable lookup.

Signed-off-by: Zeyad Yasser <zeyady98@gmail.com>
2020-10-20 00:18:24 -07:00
Kir Kolyshkin
62c03530c9 swrk: send notification instead of using status fd
When we use swrk, we have a mechanism to send notifications over RPC.
It is cleaner and more straightforward than sending \0 to status fd.

For now, both mechanisms are supported, although status fd request
option is now deprecated, so a warning is logged in case it's used.

Guess we can remove it in a few years.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-20 00:18:24 -07:00
Kir Kolyshkin
faf6dbf33e close_service_fd: rename to status_ready
The name close_service_fd() is misleading, as it not just closes the
status_fd, but also writes to it. On a high level, though, it signals
the other side that we are ready, so rename to status_ready.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
e34f5dd3a3 clang: Branch condition evaluates to a garbage value
criu-3.14/criu/namespaces.c:692:7: warning: Branch condition evaluates to a garbage value

criu-3.14/criu/namespaces.c:690:3: note: 'supported' declared without an initial value
              protobuf_c_boolean supported;
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu-3.14/criu/namespaces.c:691:8: note: Calling 'get_ns_id'
              id = get_ns_id(pid, &time_for_children_ns_desc, &supported);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu-3.14/criu/namespaces.c:479:9: note: Calling '__get_ns_id'
      return __get_ns_id(pid, nd, supported, NULL);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu-3.14/criu/namespaces.c:454:6: note: Assuming 'proc_dir' is < 0
      if (proc_dir < 0)
          ^~~~~~~~~~~~
criu-3.14/criu/namespaces.c:454:2: note: Taking true branch
      if (proc_dir < 0)
      ^
criu-3.14/criu/namespaces.c:455:3: note: Returning without writing to '*supported'
              return 0;
              ^
criu-3.14/criu/namespaces.c:479:9: note: Returning from '__get_ns_id'
      return __get_ns_id(pid, nd, supported, NULL);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu-3.14/criu/namespaces.c:479:2: note: Returning without writing to '*supported'
      return __get_ns_id(pid, nd, supported, NULL);
      ^
criu-3.14/criu/namespaces.c:691:8: note: Returning from 'get_ns_id'
              id = get_ns_id(pid, &time_for_children_ns_desc, &supported);
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
criu-3.14/criu/namespaces.c:692:7: note: Branch condition evaluates to a garbage value
              if (!supported || !id) {
                  ^~~~~~~~~~
690|   		protobuf_c_boolean supported;
691|   		id = get_ns_id(pid, &time_for_children_ns_desc, &supported);
692|-> 		if (!supported || !id) {
693|   			pr_err("Can't make timens id\n");
694|

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
b4c51ea492 coverity: fix FORWARD_NULL in criu/proc_parse.c: 1481
8. criu-3.14/criu/proc_parse.c:1511: var_deref_model: Passing null pointer "f" to "fclose", which dereferences it.
  1509|   	exit_code = 0;
  1510|   out:
  1511|-> 	fclose(f);
  1512|   	return exit_code;
  1513|   }

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Adrian Reber
64347398c1 coverity: fix RESOURCE_LEAK criu/timens.c: 67
7. criu-3.14/criu/timens.c:67: leaked_storage: Variable "img" going out of scope leaks the storage it points to.
    65|   	if (id == 0 && empty_image(img)) {
    66|   		pr_warn("Clocks values have not been dumped\n");
    67|-> 		return 0;
    68|   	}

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Radostin Stoyanov
f334102520 libcriu: Add space between 'if' and parenthesis
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2020-10-20 00:18:24 -07:00
Radostin Stoyanov
4ac9a3c904 libcriu: Use spaces around '='
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2020-10-20 00:18:24 -07:00