Commit graph

10246 commits

Author SHA1 Message Date
Mike Rapoport
2c5ea59efb travis: restore lazy-pages tests for uns flavor
Since commit cdd08cdff ("uffd: use userns_call() to execute
ioctl(UFFDIO_API)") UFFD_API ioctl() is wrapped with userns_call() and this
allows runing lazy-pages tests on recent kernels in uns.

Restore testing of lazy-pages in uns in travis.

Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-08-26 08:13:37 -07:00
Abhishek Vijeev
7a576bf7b7 criu: don't use the deprecated security_context_t (SELinux)
This change fixes the error:
error: 'security_context_t' is deprecated
[-Werror=deprecated-declarations]

Source files modified:

* lsm.c
* net.c

Please refer to:
9eb9c9327

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
d84886719a scripts: adding libbpf for Travis tests
Source files modified:

* travis/vagrant.sh - Adding libbpf-devel

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
f0f104f917 zdtm: adding tests for BPF maps
This commit adds ZDTM tests for c/r of processes with BPF maps as open
files

Source files added:

* zdtm/static/bpf_hash.c - Tests for c/r of the data and meta-data of
BPF map type BPF_MAP_TYPE_HASH

* zdtm/static/bpf_array.c - Tests for c/r of the data and meta-data
of BPF map type BPF_MAP_TYPE_ARRAY

Source files modified:

* zdtm/static/Makefile - Generating build artifacts for BPF tests

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
87ea9546ed criu: restoring BPF map data
This commit restores the data of BPF maps. A hash table (indexed by
the map's id) is used to store data objects for multiple BPF map
files that a process may have opened. Collisions are resolved with
chaining using a linked list.

Source files modified:

* bpfmap.c - Structure and function definitions needed to:
    (a) collect the protobuf image containing BPF map data
    (b) read the BPF map's data from the image and store it in the
    hash table
    (c) restore the map's data using bpf_map_update_batch()

* include/bpfmap.h
    - Defines the size of the hash table and maks to be used while
	indexing into it
	- Structure and function declarations that are used while restoring
	BPF map data

* cr-restore.c - Collects the protobuf image containing BPF map data
during the restoration phase

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
af561dbc7d criu: restoring BPF maps (without data)
This commit enables CRIU to restore a process' BPF map file
descriptors.

Source files modified:

* bpfmap.c - Structure and function definitions needed to:
    (a) collect a BPF map's information from its protobuf image
    (b) create and open a BPF map with the same parameters as when
    it was dumped
    (c) add the newly opened BPF map to the process' file descriptor
    list

* include/bpfmap.h - Structure declarations for restoring BPF maps

* files.c - Collects a BPF map's file entry during the restoration
phase

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
f1f1f6ab6a crit: add BPF map data decoding
This commit enables CRIT to decode the contents of a protobuf image
that stores information related to BPF map

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
c46225ea80 criu: dumping BPF map data
This commit enables CRIU to dump data(key-value) pairs stored in BPF
maps

Source files modified:

* bpfmap.c

    - Function dump_one_bpfmap_data() reads the map's keys and
    values into two buffers using bpf_map_lookup_batch() and then
    writes them out to a protobuf image along with the number of
    key-value pairs read

    - Function dump_one_bpfmap() now dumps the data as well before
    returning

* include/bpfmap.h - Includes headers and declares functions needed to
dump BPF map data

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
62941bdff4 criu: dumping meta-data about BPF map files
This commit enables CRIU to dump meta-data about BPF maps files by
prividing the structures and functions needed by other parts of the
code-base.

Source files added:

* bpfmap.c - defines new structures and functions:

    (a) struct fdtype_ops bpfmap_dump_ops:
            sets up the function handler to dump BPF maps

    (b) is_bpfmap_link():
            checks whether an anonymous inode is a BPF map file

    (c) dump_one_bpfmap():
            parses information for a BPF map file from procfs and
			dumps it

* include/bpfmap.h - structure and function declarations

Source files modified:

* Makefile.crtools - generates build artifacts for bpfmap.c

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
adf2da9bec criu: parse information about BPF maps from procfs
This commit enables CRIU to:
(a) identify an anonymous inode as being a BPF map
(b) parse information about BPF maps from procfs

Source files modified:

* files.c - Checks anonymous inodes to see whether they are BPF maps.
If so, sets struct fdtype_ops *ops to a structure that knows how to
dump BPF maps

* proc_parse.c - Function parse_fdinfo_pid_s() now checks whether the
current file being processed is a BPF map. If so, it calls a newly
defined function parse_bpfmap() which knows how to parse information
about BPF maps from procfs

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
4d5fc9fe5c Set Makefile config variables for libbpf
Source files modified:

* Makefile.config - Checks whether libbpf is installed on the system.
If so, we add -lbpf to LIBS_FEATURES, -DCONFIG_HAS_LIBBPF to
FEATURE_DEFINES and set CONFIG_HAS_LIBBPF. This allows us to check for
the presence of libbpf before compiling or executing BPF c/r code and
ZDTM tests.

* Makefile - Set CONFIG_HAS_LIBBPF to clean all files.

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
c325572b85 criu: define constants for c/r of BPF maps
This commit defines constants and includes necessary headers to c/r
BPF maps

Source files modified:

* magic.h - Defining BPFMAP_FILE_MAGIC and BPFMAP_DATA_MAGIC

* image-desc.h - Defining CR_FD_BPFMAP_FILE and CR_FD_BPFMAP_DATA

* image-desc.c - Create new entries for bpfmap-file and bpfmap-data
in CRIU's file descriptor set

* protobuf-desc.h - Defining PB_BPFMAP_FILE and PB_BPFMAP_DATA

* protobuf-desc.c - Including headers for BPF map protobuf images

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Abhishek Vijeev
737caa8bc8 images: protobuf definitions for BPF map meta-data and data
This commit adds protobuf definitions needed to checkpoint and
restore BPF map files along with the data they contain

Source files added:

* bpfmap-file.proto - Stores the meta-data about BPF maps

* bpfmap-data.proto - Stores the data (key-value pairs) contained
in BPF maps

Source files modified:

* fdinfo.proto - Added BPF map as a new kind of file descriptor.
'message file_entry' can now hold information about BPF map file
descriptors

* Makefile - Now generates build artifacts for bpfmap-file.proto
and bpfmap-data.proto

Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
2020-08-25 20:45:50 -07:00
Adrian Reber
c6ea0855f4 travis: add a focal based test run
It seems travis supports now Ubuntu 20.04. Let's run at least one test
also on 20.04 (focal).

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-08-25 20:35:24 -07:00
Adrian Reber
1acfb4c609 travis: switch travis to Python 3
Signed-off-by: Adrian Reber <areber@redhat.com>
2020-08-17 22:16:55 -07:00
Pavel Emelyanov
7562f3a8a7 contrib: Add python-future to Debian packages
This one contains builtins module from which zdtm.py imports.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-17 22:14:10 -07:00
Mike Rapoport
dc96b17479 github: disable cross-compule for mips on master branch
Master branch does not have mips support yet, so automated builds for
mips on the master branch fail.

Temporarily split mips cross-build into a separate files until mips
support will be mergded into the master branch.

Suggested-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-08-13 20:29:01 -07:00
Andrei Vagin
779c36d928 criu: the type of a socket inode has to be "unsigned int"
(00.015271) unix: 	Add a peer: ino 2203289876 peer_ino 2203289875 family    1 type    1 state  1 name /mnt/test/zdtm/static/sockets03.test
(00.015277) Warn  (criu/sk-unix.c:475): unix: Shutdown mismatch -2091677421:1 -> -2091677420:0

Reported-by: Mr Jenkins
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-08-11 11:23:49 -07:00
Adrian Reber
09ea96686c actions: create file for daily rebuild
This adds a definition to do a daily rebuild of all cross-compile tests
on the master and criu-dev branch.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-08-10 21:05:31 -07:00
Adrian Reber
170f59ce89 travis: loop over apt-get to recover from errors
One of the most common CI errors we see is that package install fails
due to some hashsum mismatch or some DNS errors.

This adds a loop around each apt-get install call to do a clean, update
and install and if one of the steps fails it repeats it up to 10 times.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-08-10 13:40:05 -07:00
Adrian Reber
65a930d923 Makefiles: do not re-generate magic.py every time
I always wondered why re-running make on a criu checkout always prints
out

  GEN      magic.py

even if no file has changed. It seems the Makefile was looking for the
file in the wrong location. Providing the full path to the file will now
only rebuild magic.py if something actually changed that requires a
rebuild.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-08-06 23:28:43 -07:00
Otto Bittner
5106b232e7 python: Handle byte strings when converting protobuf to dict
Fixes #1165
Traceback (most recent call last):
  File "../criu/crit/crit-python3", line 6, in <module>
    cli.main()
  File "/home/xcv/repos/criu/crit/pycriu/cli.py", line 410, in main
    opts["func"](opts)
  File "/home/xcv/repos/criu/crit/pycriu/cli.py", line 43, in decode
    json.dump(img, f, indent=indent)
  File "/usr/lib/python3.8/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/usr/lib/python3.8/json/encoder.py", line 431, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 325, in _iterencode_list
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 405, in _iterencode_dict
    yield from chunks
  File "/usr/lib/python3.8/json/encoder.py", line 438, in _iterencode
    o = _default(o)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable

Co-authored-by: Julian <jb@futureplay.de>
Signed-off-by: Otto Bittner <otto-bittner@gmx.de>
2020-08-06 00:07:41 -07:00
rppt
487cd0fff8
Merge pull request #1168 from rppt/misc/CONTRIBUTE.md
CONTRIBUTING.md: clarify placement of Fixes: tags
2020-08-06 09:37:17 +03:00
Mike Rapoport
1d7796192e CONTRIBUTING.md: clarify placement of Fixes: tags
The description of the Fixes: tags could be misleading and may be
understood as if "Fixes: " should be the commit summary.

Add a sentence with explicit description of Fixme: tags placement.

Reported-by: Otto Bittner <otto-bittner@gmx.de>
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
2020-08-05 17:41:23 +03:00
Adrian Reber
eeff0e171d lib/c: extend receive to handle incoming FDs
When using libcriu with the notify callback functionality CRIU transmits
an FD during 'orphan-pts-master' back to libcriu user. This is message
is sent via sendmsg() to transmit the FD and not via write() as all
other protobuf messages.

libcriu was using recv() and to be able to receive the FD this needs to
be changed to recvmsg() and if an FD is attached to it (currently only
for 'orphan-pts-master' this FD is stored in a variable which can be
retrieved with the function criu_get_orphan_pts_master_fd().

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-08-04 23:24:35 -07:00
Pavel Emelyanov
c513730fb6 log: Ask developers not to use print_on_level directly
The decision whether a log message is info/warning/error should
be made by the place in code where it's shown, not by any other
expression. This makes it pointless to use the print_on_level
directly, as in each particular place the needed pr_foo() helper
can be chosen.

However, we cannot (easily) make this function static, so keep
it in header, but ask people to think twise (or more times) before
calling it directly.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-03 22:46:23 -07:00
Pavel Emelyanov
17d46979e1 log: Hide vprint_on_level in log.c
This one is not used outside of log.c.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-03 22:46:23 -07:00
Pavel Emelyanov
e7f69d22fd util: Use pr_info in vma printing
Same as previous patch -- all users are coded as pr_info-s
and are naturally such.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-03 22:46:23 -07:00
Pavel Emelyanov
846452a108 ipc: Use pr_info() instead of print_on_level(PR_INFO...)
All the cases here are naturally and de-facto pr_info-s.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-03 22:46:23 -07:00
Pavel Emelyanov
9200c10de2 proc_parse: Do not feed loglevel into restore_loginuid
If a helper routine doesn't know whether its failure leads
to the error, then it should just emit a warning and return
-1. It's the caller who should print (or not) the error.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-03 22:46:23 -07:00
Pavel Emelyanov
8d228177da check: Use pr_foo macros
Instead of directly calling the print_on_level.
The pr_msg/pr_warn seems to be better choise for all those cases.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
2020-08-03 22:46:23 -07:00
Radostin Stoyanov
eccd06c10d vagrant: Update to Fedora 32
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2020-08-02 21:38:24 -07:00
Ajay Bharadwaj
3d273435ef criu/files-reg.c: build-id size bug fix
This addresses a bug where the RegFileEntry n_build_id field would be
populated with incorrect data, causing dump to crash at times.

Signed-off-by: Ajay Bharadwaj <ajayrbharadwaj@gmail.com>
2020-07-28 22:28:20 -07:00
Ajay Bharadwaj
1eeb21583a criu/files-reg.c: build-id from multiple headers fix
This addresses a bug when the ELF file contains multiple PT_NOTE program
headers but only the first header is checked for the build-id.

Signed-off-by: Ajay Bharadwaj <ajayrbharadwaj@gmail.com>
2020-07-28 22:28:20 -07:00
Dmitry Safonov
b0d9dab137 compel/infect: Don't adjust stack/args alignment
Instead, fail to infect task and let compel cure it.

Signed-off-by: Dmitry Safonov <dima@arista.com>
2020-07-28 22:22:30 -07:00
Nicolas Viennot
703f453e77 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-07-27 18:02:55 +01:00
Nicolas Viennot
aa02d0e86d 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-07-27 18:02:55 +01:00
Nicolas Viennot
ea263bc472 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-07-27 18:02:55 +01:00
Nicolas Viennot
d7353b9bb7 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-07-27 17:09:45 +01:00
Nicolas Viennot
67965cb836 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-07-27 16:32:34 +01:00
Nicolas Viennot
3d2eb4146d 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-07-27 16:31:37 +01:00
Nicolas Viennot
dd5b9c8bf9 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-07-27 16:30:25 +01:00
Nicolas Viennot
0bceb02e66 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-07-27 15:48:37 +01:00
Andrei Vagin
395353f706 zdtm: make cgroup_yard to be aware of cgroup2
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-07-23 11:36:51 -07:00
Andrei Vagin
ce67ab3dd9 tests: skip cgroup04 and cgroup_ifpriomap on pure cgroup2 systems
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-07-23 11:36:51 -07:00
Andrei Vagin
996fdbed85 zdtm.py: add the cgroup2 freezer support
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-07-23 11:36:51 -07:00
Andrei Vagin
f82b8a6d94 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-07-23 11:36:51 -07:00
Adrian Reber
1c8306db57 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-07-23 11:35:42 -07:00
Ajay Bharadwaj
90bc4590b6 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-07-21 20:41:17 -07:00
Ajay Bharadwaj
6d81a7001a 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-07-21 20:41:17 -07:00