Commit eaa79ea2 authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

ia32/vdso: pretify helper for mmaping 32bit vDSO

Forward CRIU's log fd into helper, so it can actually print errors.
This will help to debug troubles with helper, like #273.
Log fd can be safely written to, as it's opened in CRIU with
O_APPEND or it's line-buffered (stdout) or not buffered (stderr)
stream. Anyway, it's double safe, as there is simple synchronization
between helper and CRIU, so only one of them will log at a time.
Also expanded the comment about a helper.
Acked-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 63ccf14e
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "kerndat.h" #include "kerndat.h"
#include "vdso.h" #include "vdso.h"
#include "util.h" #include "util.h"
#include "log.h" #include "criu-log.h"
#include "mem.h" #include "mem.h"
#include "vma.h" #include "vma.h"
#include <compel/compel.h> #include <compel/compel.h>
...@@ -330,39 +330,62 @@ static int vdso_fill_self_symtable(struct vdso_symtable *s) ...@@ -330,39 +330,62 @@ static int vdso_fill_self_symtable(struct vdso_symtable *s)
} }
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
static void exit_on(int ret, int err_fd, char *reason)
{
if (ret) {
syscall(__NR_write, err_fd, reason, strlen(reason));
syscall(__NR_exit, ret);
}
}
/* /*
* The helper runs under fork() - it remaps vdso/vvar blobs to compatible. * Because of restrictions of ARCH_MAP_VDSO_* API, new vDSO blob
* After that it copies them into shared with parent mmaped vma so that * can be mapped only if there is no vDSO blob present for a process.
* parent could parse compat vdso's symbols and blob sizes into vdso_compat_rt. * This is a helper process, it unmaps 64-bit vDSO and maps 32-bit vDSO.
* All system calls should be as light as possible after unmapping vdso. * Then it copies vDSO blob to shared with CRIU mapping.
* If we call something clever through Glibc here - the child will blow up. *
* The purpose is to fill compat vdso's symtable (vdso_compat_rt).
* It's an optimization to fill symtable only once at CRIU restore
* for all restored tasks.
*
* @native - 64-bit vDSO blob (for easy unmap)
* @pipe_fd - to get size of compat blob from /proc/.../maps
* @err_fd - to print error messages
* @vdso_buf, buf_size - shared with CRIU buffer
*
* WARN: This helper shouldn't call pr_err() or any syscall with
* Glibc's wrapper function - it may very likely blow up.
*/ */
static void compat_vdso_helper(struct vdso_symtable *native, int pipe_fd, static void compat_vdso_helper(struct vdso_symtable *native, int pipe_fd,
void *vdso_buf, size_t buf_size) int err_fd, void *vdso_buf, size_t buf_size)
{ {
size_t vma_size; size_t vma_size;
void *vdso_addr; void *vdso_addr;
long vdso_size; long vdso_size;
long ret;
vma_size = native->vma_end - native->vma_start; vma_size = native->vma_end - native->vma_start;
if (syscall(__NR_munmap, native->vma_start, vma_size)) ret = syscall(__NR_munmap, native->vma_start, vma_size);
syscall(__NR_exit, 2); exit_on(ret, err_fd, "Error: Failed to unmap native vdso\n");
vma_size = native->vvar_end - native->vvar_start; vma_size = native->vvar_end - native->vvar_start;
if (syscall(__NR_munmap, native->vvar_start, vma_size)) ret = syscall(__NR_munmap, native->vvar_start, vma_size);
syscall(__NR_exit, 3); exit_on(ret, err_fd, "Error: Failed to unmap native vvar\n");
vdso_size = syscall(__NR_arch_prctl, ret = syscall(__NR_arch_prctl, ARCH_MAP_VDSO_32, native->vma_start);
ARCH_MAP_VDSO_32, native->vma_start); if (ret < 0)
if (vdso_size < 0) exit_on(ret, err_fd, "Error: ARCH_MAP_VDSO failed\n");
syscall(__NR_exit, 4);
vdso_size = ret;
if (vdso_size > buf_size) if (vdso_size > buf_size)
syscall(__NR_exit, 5); exit_on(-1, err_fd, "Error: Compatible vdso's size is bigger than reserved buf\n");
syscall(__NR_kill, syscall(__NR_getpid), SIGSTOP); /* Stop so CRIU could parse smaps to find 32-bit vdso's size */
ret = syscall(__NR_kill, syscall(__NR_getpid), SIGSTOP);
exit_on(ret, err_fd, "Error: Can't stop myself with SIGSTOP (having a good time)\n");
if (syscall(__NR_read, pipe_fd, &vdso_addr, sizeof(void *)) != sizeof(void *)) ret = syscall(__NR_read, pipe_fd, &vdso_addr, sizeof(void *));
syscall(__NR_exit, 6); if (ret != sizeof(void *))
exit_on(-1, err_fd, "Error: Can't read size of mmaped vdso from pipe\n");
memcpy(vdso_buf, vdso_addr, vdso_size); memcpy(vdso_buf, vdso_addr, vdso_size);
...@@ -388,7 +411,8 @@ static int vdso_mmap_compat(struct vdso_symtable *native, ...@@ -388,7 +411,8 @@ static int vdso_mmap_compat(struct vdso_symtable *native,
syscall(__NR_exit, 1); syscall(__NR_exit, 1);
} }
compat_vdso_helper(native, fds[0], vdso_buf, buf_size); compat_vdso_helper(native, fds[0], log_get_fd(),
vdso_buf, buf_size);
BUG(); BUG();
} }
...@@ -427,13 +451,17 @@ static int vdso_mmap_compat(struct vdso_symtable *native, ...@@ -427,13 +451,17 @@ static int vdso_mmap_compat(struct vdso_symtable *native,
} }
waitpid(pid, &status, WUNTRACED); waitpid(pid, &status, WUNTRACED);
if (!WIFEXITED(status) || WEXITSTATUS(status)) if (WIFEXITED(status)) {
pr_err("Compat vdso helper failed\n"); ret = WEXITSTATUS(status);
else if (ret)
ret = 0; pr_err("Helper for mmaping compat vdso failed with %d\n", ret);
goto out_close;
}
pr_err("Compat vDSO helper didn't exit, status: %d\n", status);
out_kill: out_kill:
kill(pid, SIGKILL); kill(pid, SIGKILL);
out_close:
if (close(fds[1])) if (close(fds[1]))
pr_perror("Failed to close pipe"); pr_perror("Failed to close pipe");
return ret; return ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment