Commit graph

88 commits

Author SHA1 Message Date
Adrian Reber
2ed16451b0 proc_parse: Copy into fixed size buffer (STRING_OVERFLOW)
CID 226480 (#1 of 1): Copy into fixed size buffer (STRING_OVERFLOW)
 You might overrun the 4096-character fixed-size string root_link.name by copying new->root without checking the length.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-10-20 00:18:24 -07:00
Abhishek Vijeev
b85709797c 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-10-20 00:18:24 -07:00
Pavel Emelyanov
99fc76d8b5 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-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
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
Andrei Vagin
c83a0aae2c proc: parse clock symbolic names in /proc/pid/timens_offsets
Clock IDs in this file has been replaced by clock symbolic names.

Now it looks like this:
    $ cat /proc/774/timens_offsets
    monotonic      864000         0
    boottime      1728000         0

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-04-25 00:43:23 -07:00
Andrei Vagin
4127ef4ab7 criu: Add support for time namespaces
The time namespace allows for per-namespace offsets to the system
monotonic and boot-time clocks.

C/R of time namespaces are very straightforward. On dump, criu enters a
target time namespace and dumps currents clocks values, then on restore,
criu creates a new namespace and restores clocks values.

Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-04-25 00:43:23 -07:00
Andrei Vagin
10b1d46f67 mem/vma: set VMA_FILE_{PRIVATE,SHARED} if a vma file is borrowed
Here is a fast path when two consequent vma-s share the same file.

But one of these vma-s can map a file with MAP_SHARED, but another one
can map it with MAP_PRIVATE and we need to take this into account.
2020-03-27 19:36:20 +03:00
Andrei Vagin
fb65ab2b1a mem: dump shared memory file descriptors
Any shared memroy mapping can be opened via /proc/self/maps_files/.
Such file descriptors look like memfd file descriptors, so
they can be dumped by the same way.

Signed-off-by: Andrei Vagin <avagin@gmail.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
Michał Cłapiński
dc4677123b Checkpoint only specified controllers
Before this change CRIU would checkpoint all controllers, even the ones
not specified in --cgroup-dump-controller. That becomes a problem if
there's a cgroup controller on the checkpointing machine that doesn't
exist on the restoring machine even if CRIU is instructed not to dump
that controller. After that change everything works as expected.

Signed-off-by: Michał Cłapiński <mclapinski@google.com>
2020-02-04 12:39:04 -08:00
Nicolas Viennot
71c2a9dc73 Guard against empty file lock status
The lock status string may be empty. This can happen when the owner of
the lock is invisible from our PID namespace. This unfortunate behavior
is fixed in kernels v4.19 and up (see commit 1cf8e5de40)

Signed-off-by: Nicolas Viennot <Nicolas.Viennot@twosigma.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-02-04 12:39:04 -08:00
Radostin Stoyanov
813bfbeb4f Convert pr_msg() error messages to pr_err()
Print error messages to stderr (instead of stdout).

Suggested-by: Andrei Vagin <avagin@gmail.com>
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
2020-02-04 12:38:23 -08:00
Cyrill Gorcunov
8f9ae895d0 mem/vma: Sanitize struct vm_area_list
- make names more descriptive
 - add comments
 - use union for nr_priv_pages and rst_priv_size since
   former priv_size has been used with different meaning:
   number of pages during checkpoint time and size in bytes
   on restore moment

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2019-09-07 15:59:54 +03:00
Cyrill Gorcunov
32e9f15525 mem/vma: Use vm_area_list_init where appropriate
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Reviewed-by: Mike Rapoport <rppt@linux.ibm.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2019-09-07 15:59:54 +03:00
Dmitry Safonov
de53191179 criu/vdso: Purge CONFIG_VDSO
Vigorously remove the config ifdef.
The config option *never* had any excuse to exist:
- for x86 we were grand
- for ppc64/arm64 patches to support mremap() on vdso were long ago
accepted, but regardless - it's not possible to disable CONFIG_VDSO for
those platforms in kernel
- for s390 - patches were mainstreamed not that long ago, but it's not
possible to disable the kernel config
- for arm32 it's possible to disable the kernel config, but kernel
returns to userspace historically through sigpage, not vdso.
That's the only platform that criu disallows to have CONFIG_VDSO=y in
kernel, but that's just meaningles. A kernel patch for sigpage mremap()
has gone into v4.13: commit 280e87e98c09 ("ARM: 8683/1: ARM32: Support
mremap() for sigpage/vDSO").

So, removing the config was long-lived item on my TODO list that bligted
arm32 users and made changes to vdso more complex by all "needed"
iffdeferry. Get rid of it with fire.

Fixes: #446

Signed-off-by: Dmitry Safonov <dima@arista.com>
2019-09-07 15:59:52 +03:00
Adrian Reber
0df6ddba69 proc_parse: fix coverity RESOURCE_LEAK
criu-3.12/criu/proc_parse.c:2280: leaked_storage: Variable "dir" going
out of scope leaks the storage it points to.

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2019-09-07 15:59:51 +03:00
Cyrill Gorcunov
fa989970ec epoll: Save fields of target files in eventpoll_tfd_entry
We will use them to fast lookup of targets files.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-10-30 19:27:53 +03:00
Pavel Tikhomirov
5451fc230d inventory: save uptime to know when dump had happened
We want to use a simple fact: If we have an alive process in a pstree we
want to dump, and a starttime of that process is less than pre-dump's
timestamp (taken while all processes were freezed), then these exact
process existed (100% sure) at the time of these pre-dump and the
process' memory was dumped in images.

So save inventory image on pre-dump and put there an uptime.

https://jira.sw.ru/browse/PSBM-67502

v9: improve comment, put uptime to ivnentory image as 1) where is no
stats in parent images directory if --work-dir option is set to
something different then images directory, 2) stats-dump is not an image
and it is a bad practice to put there data required for restoring.
v10:s/u_int64_t/uint64_t/

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:26:50 +03:00
Pavel Tikhomirov
b610f28ada parse: add a helper to obtain an uptime
will be used in the next patch

https://jira.sw.ru/browse/PSBM-67502

note: man for /proc/uptime says that uptime is in seconds and for now
the format is "seconds.centiseconds", where ecentiseconds is 2 digits

note: now uptime is in csec but I prefer saving it in usec, that allows
us to be reuse these image field when/if we have more accurate value.

v8: add length specifier to parse only centiseconds
v9: put uptime to u_int64_t directly, define CSEC_PER_SEC
v10: switch to uint64_t from u_int64_t, comment about usec in image

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:26:50 +03:00
Andrei Vagin
e57fd31f8b criu: musl scanf and printf don't support the L modifer for intergers
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-09 18:26:48 +03:00
Dmitry Safonov
bbe7721075 criu/proc: Define BUF_SIZE without PAGE_SIZE dependency
PAGE_SIZE will be a variable value on platforms where it can be
different due to large pages.
And looks like (c) there is no reason for BUF_SIZE == PAGE_SIZE,
so let's keep it as it was, rather than complicating it with dynamic
allocation for the buffer.

Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-07-04 03:17:17 +03:00
Radostin Stoyanov
348b169518 Remove redundant semicolons
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2018-05-12 11:45:32 +03:00
Pavel Begunkov
6c86fcb5a7 locks: Remove duplicated locks
CRIU creates dictinct lock record for each file descriptor on the same
OFD. The patch removes this duplicates. To do so, it adds new field into
struct file_lock, which stores pid of fd, on which lock was found.
'owner pid' is not actually helpful, because the original fd, on which
lock have been set, can be already closed.

Also it purges crutches doing the same stuff but only for file leases.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
90fc8622e2 locks: Add c/r of breaking leases (kernel>=v4.1)
restore of breaking leases is executed in 2 steps:
1. restore the lease in a state it was before break
2. break it by opening associated file.

The patch fixes type of broken leases to 'target lease type',
because procfs always returns 'READ' in this case.

Also, it adds 'updated' field in lock structure. It's used to remove all
duplicated records for single lease from the image, which wasn't
corrected by 'correct_lease_type'.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Pavel Begunkov
49cd3eb2ad locks: Add c/r of non broken leases (kernel>=v4.1)
Leases in breaking state are not supported. In that case criu will
report an error during the dumping. Also lock info in
/proc/<pid>/fdinfo should be presented (since kernel 4.1).

Before taking out new lease it modifies process fsuid to match file uid
(see fcntl F_SETLEASE).

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-12-12 09:16:04 +03:00
Cyrill Gorcunov
c94fb7d069 fault-injection: Add FI_HUGE_ANON_SHMEM_ID type
To test if we can survive with shmid more than 4 bytes
long in image formats.

Without the fix for shmid

 | [root@uranus criu] test/zdtm.py run -t zdtm/static/maps01 --fault 132 -f h -k always
 | === Run 1/1 ================ zdtm/static/maps01
 |
 | ========================= Run zdtm/static/maps01 in h ==========================
 | Start test
 | Test is SUID
 | ./maps01 --pidfile=maps01.pid --outfile=maps01.out
 | Run criu dump
 | Forcing 132 fault
 | Run criu restore
 | Forcing 132 fault
 | =[log]=> dump/zdtm/static/maps01/36/1/restore.log
 | ------------------------ grep Error ------------------------
 | (00.016464)     37: Opening 0x007f39c04b5000-0x007f3a004b5000 0000000000000000 (101) vma
 | (00.016465)     37: Search for 0x007f39c04b5000 shmem 0x10118e915 0x7f97f7ae4ae8/36
 | (00.016470)     37: Waiting for the 10118e915 shmem to appear
 | (00.016479)     36: No pagemap-shmem-18409749.img image
 | (00.016481)     36: Error (criu/shmem.c:559): Can't restore shmem content
 | (00.016501)     36: Error (criu/mem.c:1208): `- Can't open vma
 | (00.016552) Error (criu/cr-restore.c:2449): Restoring FAILED.
 | ------------------------ ERROR OVER ------------------------

And with the fix

 | [root@uranus criu] test/zdtm.py run -t zdtm/static/maps01 --fault 132 -f h -k always
 | === Run 1/1 ================ zdtm/static/maps01
 |
 | ========================= Run zdtm/static/maps01 in h ==========================
 | Start test
 | Test is SUID
 | ./maps01 --pidfile=maps01.pid --outfile=maps01.out
 | Run criu dump
 | Forcing 132 fault
 | Run criu restore
 | Forcing 132 fault
 | Send the 15 signal to  36
 | Wait for zdtm/static/maps01(36) to die for 0.100000
 | ========================= Test zdtm/static/maps01 PASS =========================

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-11-23 20:23:13 +03:00
Mike Rapoport
9f61de8776 proc_parse: make smaps parsing helpers globally available
The is_vma_range_fmt and parse_vmflags will be required for detection of
availability of PR_SET_THP_DISABLE prctl

Acked-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-09-16 12:30:22 +03:00
Michael Holzheu
6603b419c7 s390:criu: Add TASK_SIZE check for dump and restore
For kernels that don't have commit ee71d16d22 ("s390/mm: make TASK_SIZE
independent from the number of page table levels") criu sets TASK_SIZE
to 4 TB on s390 (see compel_task_size()).

When dumping tasks >= 4 TB on such systems, we would silently loose
memory >= 4TB.

So add a check and refuse to dump the task in that case.

When restoring tasks >= 4 TB on such systems, the remap() call for
moving the vmas at the end of the restor process would fail
and a very unclear error message is printed.

So add a check and write a more speaking error message in that case.

Reviewed-by: Alice Frosi <alice@linux.vnet.ibm.com>
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-08-09 18:51:41 +03:00
Pavel Emelyanov
e3311ea37b cgroup: Skip unified hier controllers (v2)
The unified hierarchy controller doesn't have any name, so criu hangs
while parsing this sort of strings.

Let's skip those for now, until we implement cgroup2 support.

https://github.com/xemul/criu/issues/252

v2: Code comments

Reported-and-tested-by: Adrian Reber <adrian@lisas.de>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 20:01:28 +03:00
Pavel Emelyanov
e42c769555 proc: Remove unneeded callback arg from parse_fdinfo
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:46 +03:00
Pavel Emelyanov
c14cede697 timerfd: Rework parse_fdinfo not to use callback
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:45 +03:00
Pavel Emelyanov
e5b4ef20fc fanotify: Rework parse_fdinfo not to use callback
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:45 +03:00
Pavel Emelyanov
3150b56ddc inotify: Rework parse_fdinfo not to use callback
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:45 +03:00
Pavel Emelyanov
cd8db2edc5 eventpoll: Rework parse_fdinfo not to use callback
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:45 +03:00
Pavel Emelyanov
54fb48d715 signalfd: Rework parse_fdinfo no to use callback
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:45 +03:00
Pavel Emelyanov
c94d0cacb4 eventfd: Rework parse_fdinfo not to use callback
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-07-18 09:34:45 +03:00
Cyrill Gorcunov
be37925cff mem: Don't assume guard page is returned in procfs with new kernels
If the guard page is not reported in show_map_vma we should
not ajust vma address neither we should call unmap_guard_pages
in restorer.

https://github.com/xemul/criu/issues/322

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-06-27 21:34:50 +03:00
Kirill Tkhai
08ca20e29e compel: Add more arguments to compel_wait_task()
Some get_status() methods may allocate data, because
not all of the fields in /proc/[pid]/status file
have the fixed size. For example, NSpid, which
size may vary.

Introduce new method free_status() in counterweight
for such type get_status() methods. it will be called
in case of we go to try_again and need to free allocated
data.

Also, introduce data parameter for a use in the future.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-05-10 04:26:56 +03:00
Pavel Emelyanov
5859206432 restore: Parse self maps via bfd
When injecting the restorer blob criu parses /proc/self/maps
file to find out the hole for the blob itself. It happens
every time and the maps file for criu is now HUGE (~12k),
so it's much more efficient to use bfd for it rather than
glibc's fopen.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-05-10 04:13:42 +03:00
Pavel Emelyanov
903be4131d seize: Make seize_wait_task() parse task status via callback
When seizeing task we need to parse /proc/pid/status for its
state, parent, signals and seccomp status.

In criu case we also parse other stuff in one go, so make
this parsing be a callback which criu will provide.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 00:05:56 +03:00
Pavel Emelyanov
6e49bce780 seize: Split proc_status_creds into pieces
There's a subset of this structure is required by seize_catch_task(),
which in turn will go to compel library. So prepare for that.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-15 00:05:56 +03:00
Pavel Emelyanov
c58d33944e vma: Factor out stat()ing vma
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-02 00:19:03 +03:00
Pavel Emelyanov
4beb34e90a vma: Mark fname arg as const
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-02 00:19:03 +03:00
Pavel Emelyanov
8054c345d2 vma: Remove vma_area_list arg from handle_vma
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-02 00:19:03 +03:00
Pavel Emelyanov
ff967070e3 vma: Move non-root map_files handling into subroutine
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
2017-03-02 00:19:03 +03:00
Kirill Tkhai
e4335cf061 pstree: Make pstree_item::pid pointer and move virt and node to array
So, after the patch struct pid will look as:

struct pid {
        struct pstree_item *item;
        pid_t real;
        int state;
        struct {
                pid_t virt;
                struct rb_node node;
        } ns[1];
};

travis-ci: success for Make pstree_item::pid allocated dynamically
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-03 18:04:22 +03:00
Begunkov Pavel
34c9119acd locks: Add ofd locks c/r
OFD locks logic reuses existing locks c/r functionality.

https://github.com/xemul/criu/issues/42
travis-ci: success for series starting with [1/2] locks: Add ofd locks c/r
Signed-off-by: Begunkov Pavel <asml.silence@gmail.com>
Signed-off-by: Eugene Batalov <eabatalov89@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2017-02-01 17:37:11 +03:00
Yixun Lan
f6c7c0735e include sys/sysmacros.h for minor/major/makedev funcs
Since glibc is moving away from implicitly including sys/sysmacros.h
all the time via sys/types.h, include the header directly in more
places.  This seems to cover most makedev/major/minor usage.

Signed-off-by: Yixun Lan <dlan@gentoo.org>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Reviewed-by: Dmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-12-09 22:42:27 +03:00
Kir Kolyshkin
fc4e022b9a criu/*: annual pr_perror() usage sanitization
When using pr_perror(), we should not end the message with \n,
as it is added automatically.

Unfortunately, I still can't figure a way to check this at compile
time, so here's the annual patch.

travis-ci: success for Assorted nitpicks
Signed-off-by: Kir Kolyshkin <kir@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
2016-11-12 11:06:21 +03:00