CID 302712 (#1 of 1): Resource leak (RESOURCE_LEAK)
Variable build_id going out of scope leaks the storage it points to.
Signed-off-by: Adrian Reber <areber@redhat.com>
CID 302714 (#1 of 1): Resource leak (RESOURCE_LEAK)
Variable dirnew going out of scope leaks the storage it points to.
Signed-off-by: Adrian Reber <areber@redhat.com>
CID 302715 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
fd is passed to a parameter that cannot be negative.
Signed-off-by: Adrian Reber <areber@redhat.com>
CID 302717 (#2 of 2): Resource leak (RESOURCE_LEAK)
Variable dirnew going out of scope leaks the storage it points to.
Signed-off-by: Adrian Reber <areber@redhat.com>
CID 302718 (#1 of 1): Double close (USE_AFTER_FREE)
Calling close(int) closes handle sockfd which has already been closed.
Signed-off-by: Adrian Reber <areber@redhat.com>
CID 302719 (#1 of 1): Argument cannot be negative (NEGATIVE_RETURNS)
img_raw_fd(img) is passed to a parameter that cannot be negative.
Signed-off-by: Adrian Reber <areber@redhat.com>
This commit achieves the following:
a) Refactors ZDTM tests bpf_array.c and bpf_hash.c to make use of the
BPF ZDTM library functions. In addition, these tests now verify whether
information obtained from both procfs and BPF_OBJ_GET_INFO_BY_FD are
the same before and after c/r.
b) Updates ZDTM tests bpf_array.c and bpf_hash.c to include a BPF map's
name and also to freeze maps
Source files modified:
* zdtm/static/bpf_array.c
* zdtm/static/bpf_hash.c
Source files added:
* zdtm/static/bpf_array.desc
* zdtm/static/bpf_hash.desc
Note: ${test_name}.desc files have the 'suid' flag set because
BPF_MAP_FREEZE requires the global (root-userns) CAP_SYS_ADMIN or
CAP_BPF. Hence, only test flavors 'h' and 'ns' are executed ('uns'
is skipped) because BPF_MAP_FREEZE can't be used from non-root user
namespaces.
Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
This commit achieves the following:
a) C/R of a BPF map's name as well as ifindex (index of the network
interface to which the map is attached). This information is not
available from procfs and therefore has to be obtained using the
bpf() system call with BPF_OBJ_GET_INFO_BY_FD.
b) Adds support for frozen maps - during the restore operation, CRIU
now freezes a BPF map that was frozen during checkpoint.
Source files modified:
* bpfmap.c
Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
This commit adds a BPF map's name and ifindex to its protobuf image.
ifindex is the index of the network interface to which the BPF map is
attached and can be specified via a parameter while creating the BPF
map (BPF_MAP_CREATE). This commit also provides a default value of
false to the field 'frozen'.
Source files modified:
* images/bpfmap-file.proto
Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
This commit adds BPF helper functions needed by tests in a new library.
It defines new functions that allow verifying BPF map meta-data from
the procfs as well as using the bpf() system call with
BPF_OBJ_GET_INFO_BY_FD. It is necessary to verify from procfs and using
BPF_OBJ_GET_INFO_BY_FD because the information available from both
these places is disjoint (for example, checking whether a map is frozen
cannot be performed with BPF_OBJ_GET_INFO_BY_FD).
Source files modified:
* test/zdtm/lib/Makefile - Generating build artifacts
Source files added:
* test/zdtm/lib/bpfmap_zdtm.c - Provides definitions for 3 new
functions:
(a) parse_bpfmap_fdinfo() - Parses information about the BPF map
from procfs
(b) cmp_bpf_map_info() - Compares the attributes of a BPF map file
obtained from BPF_OBJ_GET_INFO_BY_FD. This function is typically
used to verify that the attributes of a BPF map remain the same
before checkpoint and after restore
(c) cmp_bpfmap_fdinfo() - Compares the attributes of a BPF map file
obtained from procfs. This function is typically used to verify
that the attributes of a BPF map remain the same before checkpoint
and after restore
* test/zdtm/lib/bpfmap_zdtm.h - Structure and function declarations.
Declares struct bpfmap_fdinfo_obj, which stores information about BPF
maps parsed from procfs
Signed-off-by: Abhishek Vijeev <abhishek.vijeev@gmail.com>
We can have tmp != sfd if fcntl(F_DUPFD) sees that sfd is already used,
but tmp is left open on this error path, lets close it.
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
If the tcp-close has been set for dump, it has to set for restore too.
But we don't need to require matching of tcp-close for criu lazy-pages.
Reported-by: Mr Travis
There is no direct way to get this state but we can get polling events
for a socket and guess its shutdown state.
Reported-by: Mr Jenkins
Signed-off-by: Andrei Vagin <avagin@gmail.com>
The github action based cross compile tests are only running when
pushing to master or criu-dev. This changes this to have it run on all
branches. Useful to have all CI tests running on personal CRIU checkouts
on branches with other names.
If I prepare a branch to create a new pull request, the cross compile
tests have not been running if my branch has another name than criu-dev
or master. With this change these tests will run on all branches.
Signed-off-by: Adrian Reber <areber@redhat.com>
The previously introduced apt_install loop function to make package
install more robust against network errors is now moved to its own
script used in multiple places.
Signed-off-by: Adrian Reber <areber@redhat.com>
Shellcheck (https://github.com/koalaman/shellcheck) can identify common
errors in shell scripts. This initial integration of shellcheck only
checks the scripts in the 'scripts/' folder. This commit fixes (or
disables) all reports of shellcheck to ensure this part starts error
free. I am not convinced this is really necessary as most changes do not
seem to be necessary for their circumstances. On the other hand it
probably does not hurt to use a checker to avoid unnecessary errors.
Signed-off-by: Adrian Reber <areber@redhat.com>
In this case, states of established tcp connections will not be dumped
and they will not be blocked. This will be useful in case of snapshots,
when we don't need to restore tcp connections.
Signed-off-by: Andrei Vagin <avagin@gmail.com>
The SO_LINGER option allows to control how a TCP connection is closed.
The default behavior is to return immediately when close() is called,
and any unsent data is not guaranteed to be delivered. When SO_LINGER
is enabled, the close() call would block until all final data is
delivered to the remote end, for a specified time interval. When the
time interval is set to zero, the connection is aborted and any pending
data is immediately discarded upon close().
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
This patch enables checkpoint/restore of the SO_OOBINLINE socket option.
When the SO_OOBINLINE option is used, out-of-band data is placed in the
normal input queue as it is received. This permits it to be read using
read or recv without specifying the MSG_OOB flag.
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Make two mounts, binds of the same file system, the first has root "/"
and the second has a cut root "/auxiliary". This insures that on restore
criu will mount the first mount first and latter bind the second from
it. After set the first mount unbindable to check if restoring these
flag does not interfere with restoring mounts.
Before the fix in these series we had the error:
(00.031286) 1: mnt: Mounting tmpfs @/tmp/.criu.mntns.wGroPU/12-0000000000/zdtm/static/unbindable.test/bind_of_unbindable (0)
(00.031298) 1: mnt: Bind /tmp/.criu.mntns.wGroPU/12-0000000000/zdtm/static/unbindable.test/unbindable/auxiliary to /tmp/.criu.mntns.wGroPU/12-0000000000/zdtm/static/unbindable.test/bind_of_unbindable
(00.031329) 1: Error (criu/mount.c:2298): mnt: Can't mount at /tmp/.criu.mntns.wGroPU/12-0000000000/zdtm/static/unbindable.test/bind_of_unbindable: Invalid argument
https://bugs.openvz.org/browse/OVZ-7116
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Replace in restore_shared_options "->mountpoint" in messages with more
descriptive "->mnt_id". Mountpoints concide a lot, and mnt_id is unique.
These also makes a message shorter. (We already print a mapping from
mnt_id to mountpoint in mnt_tree_show, so we can easily find mountpoint
if we want).
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Setting mounts unbindable just after mounting them and before other
mounts of the same superblock are mounted can break the restore of
mounts, because other mounts will try to bind from it and obviously will
fail. See the test "unbindable" for more info.
Currently we can't delay if the mount is overmounted, if we will
need these in future we would likely set it through open fd on the
mountpoint.
https://bugs.openvz.org/browse/OVZ-7116
v2: simplify coderead, print message on setting unbindable error, add
some more comments about unbindable.
v3: add a list to optimise a walk over delayed unbindable mounts, don't
call set_unbindable on error path.
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Netlink sockets normally kernel-assign a peer id based on the
requesting pid at bind time. CRIU saves this peer ID and tries
to restore it. At restore time, it's possible for the id to
already be in use (e.g., assigned to another process, perhaps
in another pid namespace).
This patch tries to use the original id, but if that fails then
allows the kernel to auto-allocate a new peer id. We make a
warning message, because it is possible (although rather unlikely)
the application cares what its peer id is.
Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
The field id 18 is used in Virtuozzo criu in multiple releases, so that
we can't change the id easily. So we can at least kindly ask not to use
this field in mainstream criu to decrease the pain of Virtuozzo criu
rebases.
Reference to related patch in Virtuozzo criu:
https://src.openvz.org/projects/OVZ/repos/criu/commits/58e61a20c22c#images/sk-unix.proto
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This adds three epoll targets on tfd 702 and then adds two epoll targets
on tfd 701. This test is for off calculation in dump_one_eventpoll, the
reverse order makes qsort to actually work.
v2: update test_doc with longer explanation, remove unused DUPFDNO
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Kcmp expect off to be a number of inclusion of target tfd. So we should
set off=0 to a first inclusion and off++ for all next inclusions.
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
In dump_one_eventpoll we call find_tfd_bsearch with arguments
"e->tfd[i]->tfd, toff[i].off". By this we want to check if
"toff[i].off"-th inclusion of target "e->tfd[i]->tfd" in an eventpoll
coresponds to our fd "e->tfd[i]->tfd" in terms of kcmp.
But because of toff was sorted to calculate off, indexes in e->tfd and
toff does not address the same eventpoll target at this point.
Let's sort toff back to original state to make indexes consistent.
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
The docker hub container registry is not updated as fast as Fedora's
registry at registry.fedoraproject.org. Fedora's registry gets a new
image whenever there is a new version of rawhide, docker hub's rawhide
image can take a couple of weeks because the process is not automated.
Especially when Fedora branches of a new release we see lot's of errors
in CRIU's Fedora rawhide based Travis runs. Switch to Fedora's registry
to always have the newest rawhide images for our tests.
Signed-off-by: Adrian Reber <areber@redhat.com>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>