2011-09-23 12:00:45 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
2012-10-11 16:52:52 +04:00
|
|
|
#include <grp.h>
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/vfs.h>
|
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <sys/wait.h>
|
2011-12-01 18:21:17 +04:00
|
|
|
#include <sys/file.h>
|
2012-02-14 20:20:10 +03:00
|
|
|
#include <sys/shm.h>
|
2012-06-19 15:53:00 +04:00
|
|
|
#include <sys/mount.h>
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
#include <sched.h>
|
|
|
|
|
|
|
|
#include <sys/sendfile.h>
|
|
|
|
|
|
|
|
#include "compiler.h"
|
2013-01-09 17:02:47 +04:00
|
|
|
#include "asm/types.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
#include "image.h"
|
|
|
|
#include "util.h"
|
2011-12-19 18:52:50 +04:00
|
|
|
#include "log.h"
|
2011-10-26 17:35:50 +04:00
|
|
|
#include "syscall.h"
|
2011-10-24 22:23:06 +04:00
|
|
|
#include "restorer.h"
|
2011-12-26 22:12:03 +04:00
|
|
|
#include "sockets.h"
|
2012-08-09 16:17:41 +04:00
|
|
|
#include "sk-packet.h"
|
2011-12-26 20:33:09 +04:00
|
|
|
#include "lock.h"
|
2012-01-10 18:03:00 +04:00
|
|
|
#include "files.h"
|
2012-06-22 16:24:00 +04:00
|
|
|
#include "files-reg.h"
|
2012-05-03 17:36:00 +04:00
|
|
|
#include "pipes.h"
|
2012-06-26 02:36:13 +04:00
|
|
|
#include "fifo.h"
|
2012-04-28 17:38:46 +04:00
|
|
|
#include "sk-inet.h"
|
2012-05-04 13:38:00 +04:00
|
|
|
#include "eventfd.h"
|
2012-05-04 13:38:00 +04:00
|
|
|
#include "eventpoll.h"
|
2012-08-02 12:26:35 +04:00
|
|
|
#include "signalfd.h"
|
2012-01-13 20:52:35 +04:00
|
|
|
#include "proc_parse.h"
|
2012-01-14 21:22:06 +03:00
|
|
|
#include "restorer-blob.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
#include "crtools.h"
|
2012-01-26 15:27:00 +04:00
|
|
|
#include "namespaces.h"
|
2012-05-03 18:01:05 +04:00
|
|
|
#include "shmem.h"
|
2012-05-04 13:38:00 +04:00
|
|
|
#include "mount.h"
|
2013-01-14 20:47:51 +04:00
|
|
|
#include "fsnotify.h"
|
2012-06-26 14:51:00 +04:00
|
|
|
#include "pstree.h"
|
2012-08-10 19:14:36 +04:00
|
|
|
#include "net.h"
|
2012-09-12 20:00:54 +04:00
|
|
|
#include "tty.h"
|
2012-12-21 17:35:36 +04:00
|
|
|
#include "cpu.h"
|
2013-01-17 16:09:34 +08:00
|
|
|
#include "file-lock.h"
|
2012-01-16 23:52:15 +03:00
|
|
|
|
2012-07-18 16:25:06 +04:00
|
|
|
#include "protobuf.h"
|
|
|
|
#include "protobuf/sa.pb-c.h"
|
2012-07-18 16:27:01 +04:00
|
|
|
#include "protobuf/itimer.pb-c.h"
|
2012-07-19 12:43:36 +04:00
|
|
|
#include "protobuf/vma.pb-c.h"
|
2013-01-10 20:08:38 +04:00
|
|
|
#include "protobuf/rlimit.pb-c.h"
|
2013-03-12 21:00:05 +04:00
|
|
|
#include "protobuf/pagemap.pb-c.h"
|
2012-07-18 16:25:06 +04:00
|
|
|
|
2013-01-09 17:39:23 +04:00
|
|
|
#include "asm/restore.h"
|
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
static struct pstree_item *current;
|
2011-11-13 12:57:16 +04:00
|
|
|
|
2012-01-26 15:26:00 +04:00
|
|
|
static int restore_task_with_children(void *);
|
2012-11-20 20:39:08 +04:00
|
|
|
static int sigreturn_restore(pid_t pid, CoreEntry *core);
|
2012-09-14 14:51:40 +04:00
|
|
|
static int prepare_restorer_blob(void);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2013-03-01 20:12:33 +04:00
|
|
|
static VM_AREA_LIST(rst_vmas); /* XXX .longest is NOT tracked for this guy */
|
2012-11-20 20:39:08 +04:00
|
|
|
|
2012-01-17 15:28:13 +03:00
|
|
|
static int shmem_remap(void *old_addr, void *new_addr, unsigned long size)
|
2011-12-26 21:27:03 +04:00
|
|
|
{
|
2012-03-17 11:47:00 +04:00
|
|
|
void *ret;
|
2011-12-26 21:27:03 +04:00
|
|
|
|
2012-03-17 11:47:00 +04:00
|
|
|
ret = mremap(old_addr, size, size,
|
|
|
|
MREMAP_FIXED | MREMAP_MAYMOVE, new_addr);
|
|
|
|
if (new_addr != ret) {
|
|
|
|
pr_perror("mremap failed");
|
2011-12-26 21:27:03 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-03-17 11:47:00 +04:00
|
|
|
return 0;
|
2011-12-26 21:27:03 +04:00
|
|
|
}
|
|
|
|
|
2013-01-22 22:45:31 +04:00
|
|
|
static int crtools_prepare_shared(struct cr_options *opts)
|
2012-09-17 20:06:06 +04:00
|
|
|
{
|
|
|
|
if (prepare_shared_fdinfo())
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Connections are unlocked from crtools */
|
|
|
|
if (collect_inet_sockets())
|
|
|
|
return -1;
|
|
|
|
|
2013-01-22 22:45:31 +04:00
|
|
|
if (tty_prep_fds(opts))
|
2012-10-18 15:51:56 +04:00
|
|
|
return -1;
|
|
|
|
|
2012-09-17 20:06:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int root_prepare_shared(void)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-01-26 20:30:31 +04:00
|
|
|
int ret = 0;
|
2012-04-05 15:34:31 +04:00
|
|
|
struct pstree_item *pi;
|
2012-01-26 20:30:31 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
pr_info("Preparing info about shared resources\n");
|
|
|
|
|
2012-05-03 18:01:05 +04:00
|
|
|
if (prepare_shmem_restore())
|
2011-12-13 15:03:33 +04:00
|
|
|
return -1;
|
2011-12-26 21:15:30 +04:00
|
|
|
|
2012-09-14 17:58:46 +04:00
|
|
|
if (prepare_shared_tty())
|
|
|
|
return -1;
|
|
|
|
|
2012-09-17 20:12:58 +04:00
|
|
|
if (prepare_shared_reg_files())
|
|
|
|
return -1;
|
|
|
|
|
2012-04-03 00:50:50 +04:00
|
|
|
if (collect_reg_files())
|
|
|
|
return -1;
|
|
|
|
|
2012-04-05 20:02:00 +04:00
|
|
|
if (collect_pipes())
|
|
|
|
return -1;
|
|
|
|
|
2012-06-26 02:36:13 +04:00
|
|
|
if (collect_fifo())
|
|
|
|
return -1;
|
|
|
|
|
2012-04-06 19:27:08 +04:00
|
|
|
if (collect_unix_sockets())
|
|
|
|
return -1;
|
2012-04-03 00:58:41 +04:00
|
|
|
|
2012-08-09 16:17:41 +04:00
|
|
|
if (collect_packet_sockets())
|
|
|
|
return -1;
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
if (collect_eventfd())
|
|
|
|
return -1;
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
if (collect_eventpoll())
|
|
|
|
return -1;
|
|
|
|
|
2012-08-02 12:26:35 +04:00
|
|
|
if (collect_signalfd())
|
|
|
|
return -1;
|
|
|
|
|
2012-05-04 13:38:00 +04:00
|
|
|
if (collect_inotify())
|
|
|
|
return -1;
|
|
|
|
|
2012-09-12 20:00:54 +04:00
|
|
|
if (collect_tty())
|
|
|
|
return -1;
|
|
|
|
|
2012-05-31 14:50:00 +04:00
|
|
|
for_each_pstree_item(pi) {
|
2012-08-02 15:54:54 +04:00
|
|
|
if (pi->state == TASK_HELPER)
|
|
|
|
continue;
|
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
ret = prepare_shmem_pid(pi->pid.virt);
|
2012-01-26 20:30:31 +04:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2013-01-11 18:16:25 +04:00
|
|
|
ret = prepare_fd_pid(pi);
|
2012-01-26 20:30:31 +04:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-09-12 20:11:33 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
2012-04-05 20:02:00 +04:00
|
|
|
mark_pipe_master();
|
2012-09-14 17:50:46 +04:00
|
|
|
|
2012-10-15 20:02:29 +04:00
|
|
|
ret = tty_setup_slavery();
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
2012-09-12 20:00:54 +04:00
|
|
|
|
2012-04-06 19:27:08 +04:00
|
|
|
ret = resolve_unix_peers();
|
2012-09-12 20:11:33 +04:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2012-04-05 20:02:00 +04:00
|
|
|
|
2012-09-14 14:51:40 +04:00
|
|
|
ret = prepare_restorer_blob();
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2012-09-12 20:11:33 +04:00
|
|
|
show_saved_shmems();
|
|
|
|
show_saved_files();
|
2012-09-12 20:00:54 +04:00
|
|
|
err:
|
2012-01-26 20:30:31 +04:00
|
|
|
return ret;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-11-20 20:48:23 +04:00
|
|
|
/* Map a private vma, if it is not mapped by a parrent yet */
|
2012-11-20 20:48:28 +04:00
|
|
|
static int map_private_vma(pid_t pid, struct vma_area *vma, void *tgt_addr,
|
2012-11-20 20:48:23 +04:00
|
|
|
struct vma_area **pvma, struct list_head *pvma_list)
|
|
|
|
{
|
2012-11-20 20:48:28 +04:00
|
|
|
int ret;
|
2012-11-20 20:48:23 +04:00
|
|
|
void *addr, *paddr = NULL;
|
2012-11-20 20:48:33 +04:00
|
|
|
unsigned long nr_pages;
|
2012-11-20 20:48:23 +04:00
|
|
|
struct vma_area *p = *pvma;
|
|
|
|
|
2012-11-20 20:48:28 +04:00
|
|
|
if (vma_entry_is(&vma->vma, VMA_FILE_PRIVATE)) {
|
|
|
|
ret = get_filemap_fd(pid, &vma->vma);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("Can't fixup fd\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
vma->vma.fd = ret;
|
|
|
|
/* shmid will be used for a temporary address */
|
|
|
|
vma->vma.shmid = 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 20:48:33 +04:00
|
|
|
nr_pages = vma_entry_len(&vma->vma) / PAGE_SIZE;
|
|
|
|
vma->page_bitmap = xzalloc(BITS_TO_LONGS(nr_pages) * sizeof(long));
|
|
|
|
if (vma->page_bitmap == NULL)
|
|
|
|
return -1;
|
|
|
|
|
2012-11-20 20:48:23 +04:00
|
|
|
list_for_each_entry_continue(p, pvma_list, list) {
|
|
|
|
if (p->vma.start > vma->vma.start)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (p->vma.end == vma->vma.end &&
|
|
|
|
p->vma.start == vma->vma.start) {
|
2013-01-16 19:20:08 +04:00
|
|
|
pr_info("COW 0x%016"PRIx64"-0x%016"PRIx64" 0x%016"PRIx64" vma\n",
|
2012-11-20 20:48:23 +04:00
|
|
|
vma->vma.start, vma->vma.end, vma->vma.pgoff);
|
2013-01-18 11:08:38 +04:00
|
|
|
paddr = decode_pointer(vma_premmaped_start(&p->vma));
|
2012-11-20 20:48:23 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*pvma = p;
|
|
|
|
|
|
|
|
if (paddr == NULL) {
|
2013-01-16 19:20:08 +04:00
|
|
|
pr_info("Map 0x%016"PRIx64"-0x%016"PRIx64" 0x%016"PRIx64" vma\n",
|
2012-11-20 20:48:23 +04:00
|
|
|
vma->vma.start, vma->vma.end, vma->vma.pgoff);
|
|
|
|
|
|
|
|
addr = mmap(tgt_addr, vma_entry_len(&vma->vma),
|
|
|
|
vma->vma.prot | PROT_WRITE,
|
|
|
|
vma->vma.flags | MAP_FIXED,
|
|
|
|
vma->vma.fd, vma->vma.pgoff);
|
|
|
|
|
|
|
|
if (addr == MAP_FAILED) {
|
|
|
|
pr_perror("Unable to map ANON_VMA");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
2012-11-20 20:48:33 +04:00
|
|
|
vma->ppage_bitmap = p->page_bitmap;
|
|
|
|
|
2012-11-20 20:48:23 +04:00
|
|
|
addr = mremap(paddr, vma_area_len(vma), vma_area_len(vma),
|
|
|
|
MREMAP_FIXED | MREMAP_MAYMOVE, tgt_addr);
|
|
|
|
if (addr != tgt_addr) {
|
|
|
|
pr_perror("Unable to remap a private vma");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
vma_premmaped_start(&(vma->vma)) = (unsigned long) addr;
|
|
|
|
|
2012-11-20 20:48:28 +04:00
|
|
|
if (vma_entry_is(&vma->vma, VMA_FILE_PRIVATE))
|
|
|
|
close(vma->vma.fd);
|
|
|
|
|
2012-11-20 20:48:23 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 20:48:30 +04:00
|
|
|
static int restore_priv_vma_content(pid_t pid)
|
|
|
|
{
|
|
|
|
struct vma_area *vma;
|
2013-03-12 21:00:05 +04:00
|
|
|
int fd, fd_pg, ret = 0;
|
2012-11-20 20:48:30 +04:00
|
|
|
|
2012-11-20 20:48:34 +04:00
|
|
|
unsigned int nr_restored = 0;
|
|
|
|
unsigned int nr_shared = 0;
|
|
|
|
unsigned int nr_droped = 0;
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
vma = list_first_entry(&rst_vmas.h, struct vma_area, list);
|
2012-11-20 20:48:30 +04:00
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
fd = open_image_ro(CR_FD_PAGEMAP, (long)pid);
|
2012-11-20 20:48:30 +04:00
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
fd_pg = open_pages_image(O_RSTR, fd);
|
|
|
|
if (fd_pg < 0) {
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-20 20:48:30 +04:00
|
|
|
/*
|
|
|
|
* Read page contents.
|
|
|
|
*/
|
|
|
|
while (1) {
|
2013-03-12 21:00:05 +04:00
|
|
|
PagemapEntry *pe;
|
|
|
|
unsigned long off, i;
|
|
|
|
unsigned long va;
|
2012-11-20 20:48:30 +04:00
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
ret = pb_read_one_eof(fd, &pe, PB_PAGEMAP);
|
|
|
|
if (ret <= 0)
|
2012-11-20 20:48:30 +04:00
|
|
|
break;
|
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
va = (unsigned long)decode_pointer(pe->vaddr);
|
2012-11-20 20:48:30 +04:00
|
|
|
|
|
|
|
BUG_ON(va < vma->vma.start);
|
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
for (i = 0; i < pe->nr_pages; i++) {
|
|
|
|
unsigned char buf[PAGE_SIZE];
|
|
|
|
void *p;
|
2012-11-20 20:48:33 +04:00
|
|
|
|
2013-03-15 18:24:27 +04:00
|
|
|
while (va >= vma->vma.end) {
|
|
|
|
BUG_ON(vma->list.next == &rst_vmas.h);
|
|
|
|
vma = list_entry(vma->list.next, struct vma_area, list);
|
|
|
|
}
|
|
|
|
|
|
|
|
off = (va - vma->vma.start) / PAGE_SIZE;
|
|
|
|
va += PAGE_SIZE;
|
|
|
|
|
|
|
|
set_bit(off, vma->page_bitmap);
|
2013-03-12 21:00:05 +04:00
|
|
|
if (vma->ppage_bitmap)
|
2013-03-15 18:24:27 +04:00
|
|
|
clear_bit(off, vma->ppage_bitmap);
|
2012-11-20 20:48:33 +04:00
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
ret = read(fd_pg, buf, PAGE_SIZE);
|
|
|
|
if (ret != PAGE_SIZE) {
|
|
|
|
pr_err("Can'r read mapping page %d\n", ret);
|
|
|
|
return -1;
|
|
|
|
}
|
2012-11-20 20:48:30 +04:00
|
|
|
|
2013-03-15 18:24:27 +04:00
|
|
|
p = (void *)((off) * PAGE_SIZE +
|
2012-11-20 20:48:30 +04:00
|
|
|
vma_premmaped_start(&vma->vma));
|
2013-03-15 18:24:27 +04:00
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
if (memcmp(p, buf, PAGE_SIZE) == 0) {
|
|
|
|
nr_shared++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(p, buf, PAGE_SIZE);
|
|
|
|
nr_restored++;
|
2012-11-20 20:48:34 +04:00
|
|
|
}
|
2012-11-20 20:48:30 +04:00
|
|
|
|
2013-03-12 21:00:05 +04:00
|
|
|
pagemap_entry__free_unpacked(pe, NULL);
|
2012-11-20 20:48:30 +04:00
|
|
|
}
|
2013-03-12 21:00:05 +04:00
|
|
|
close(fd_pg);
|
2012-11-20 20:48:30 +04:00
|
|
|
close(fd);
|
2013-03-12 21:00:05 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2012-11-20 20:48:30 +04:00
|
|
|
|
2012-11-20 20:48:33 +04:00
|
|
|
/* Remove pages, which were not shared with a child */
|
2013-03-01 20:11:51 +04:00
|
|
|
list_for_each_entry(vma, &rst_vmas.h, list) {
|
2012-11-20 20:48:33 +04:00
|
|
|
unsigned long size, i = 0;
|
2013-01-18 11:08:38 +04:00
|
|
|
void *addr = decode_pointer(vma_premmaped_start(&vma->vma));
|
2012-11-20 20:48:33 +04:00
|
|
|
|
|
|
|
if (vma->ppage_bitmap == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
size = vma_entry_len(&vma->vma) / PAGE_SIZE;
|
|
|
|
while (1) {
|
|
|
|
/* Find all pages, which are not shared with this child */
|
|
|
|
i = find_next_bit(vma->ppage_bitmap, size, i);
|
|
|
|
|
|
|
|
if ( i >= size)
|
|
|
|
break;
|
|
|
|
|
|
|
|
ret = madvise(addr + PAGE_SIZE * i,
|
|
|
|
PAGE_SIZE, MADV_DONTNEED);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_perror("madvise failed\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
i++;
|
2012-11-20 20:48:34 +04:00
|
|
|
nr_droped++;
|
2012-11-20 20:48:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-20 20:48:34 +04:00
|
|
|
pr_info("nr_restored_pages: %d\n", nr_restored);
|
|
|
|
pr_info("nr_shared_pages: %d\n", nr_shared);
|
|
|
|
pr_info("nr_droped_pages: %d\n", nr_droped);
|
|
|
|
|
2012-11-20 20:48:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 20:39:08 +04:00
|
|
|
static int read_vmas(int pid)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-11-20 20:39:06 +04:00
|
|
|
int fd, ret = 0;
|
|
|
|
LIST_HEAD(old);
|
2012-11-20 20:48:23 +04:00
|
|
|
struct vma_area *pvma, *vma;
|
|
|
|
unsigned long priv_size = 0;
|
|
|
|
void *addr;
|
|
|
|
|
|
|
|
void *old_premmapped_addr = NULL;
|
|
|
|
unsigned long old_premmapped_len, pstart = 0;
|
2012-03-27 16:34:00 +04:00
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
rst_vmas.nr = 0;
|
|
|
|
list_replace_init(&rst_vmas.h, &old);
|
2012-11-20 20:39:05 +04:00
|
|
|
|
|
|
|
/* Skip errors, because a zombie doesn't have an image of vmas */
|
2012-03-27 16:34:00 +04:00
|
|
|
fd = open_image_ro(CR_FD_VMAS, pid);
|
2012-11-20 20:39:05 +04:00
|
|
|
if (fd < 0) {
|
2012-11-20 20:39:06 +04:00
|
|
|
if (errno != ENOENT)
|
|
|
|
ret = fd;
|
|
|
|
goto out;
|
2012-11-20 20:39:05 +04:00
|
|
|
}
|
2012-03-27 16:34:00 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
while (1) {
|
2012-03-27 16:34:00 +04:00
|
|
|
struct vma_area *vma;
|
2012-07-19 12:43:36 +04:00
|
|
|
VmaEntry *e;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-03-27 16:34:00 +04:00
|
|
|
ret = -1;
|
|
|
|
vma = alloc_vma_area();
|
|
|
|
if (!vma)
|
|
|
|
break;
|
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one_eof(fd, &e, PB_VMAS);
|
2012-03-21 19:36:00 +04:00
|
|
|
if (ret <= 0)
|
2012-03-27 16:34:00 +04:00
|
|
|
break;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
rst_vmas.nr++;
|
|
|
|
list_add_tail(&vma->list, &rst_vmas.h);
|
2012-11-20 20:39:03 +04:00
|
|
|
|
2012-08-10 10:17:50 +04:00
|
|
|
if (e->fd != -1) {
|
|
|
|
ret = -1;
|
2012-08-11 21:34:35 +04:00
|
|
|
pr_err("Error in vma->fd setting (%Ld)\n",
|
2012-08-10 10:17:50 +04:00
|
|
|
(unsigned long long)e->fd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-19 12:43:36 +04:00
|
|
|
vma->vma = *e;
|
|
|
|
vma_entry__free_unpacked(e, NULL);
|
2012-11-20 20:48:23 +04:00
|
|
|
|
|
|
|
if (!vma_priv(&vma->vma))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
priv_size += vma_area_len(vma);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve a place for mapping private vma-s one by one */
|
|
|
|
addr = mmap(NULL, priv_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
|
|
|
|
if (addr == MAP_FAILED) {
|
2013-03-14 19:41:31 +04:00
|
|
|
pr_perror("Unable to reserve memory (%lu bytes)", priv_size);
|
2012-11-20 20:48:23 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-12-06 13:19:01 +03:00
|
|
|
old_premmapped_addr = current->rst->premmapped_addr;
|
|
|
|
old_premmapped_len = current->rst->premmapped_len;
|
|
|
|
current->rst->premmapped_addr = addr;
|
|
|
|
current->rst->premmapped_len = priv_size;
|
2012-11-20 20:48:23 +04:00
|
|
|
|
|
|
|
pvma = list_entry(&old, struct vma_area, list);
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
list_for_each_entry(vma, &rst_vmas.h, list) {
|
2012-11-20 20:48:23 +04:00
|
|
|
if (pstart > vma->vma.start) {
|
|
|
|
ret = -1;
|
|
|
|
pr_err("VMA-s are not sorted in the image file\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pstart = vma->vma.start;
|
|
|
|
|
|
|
|
if (!vma_priv(&vma->vma))
|
|
|
|
continue;
|
|
|
|
|
2012-11-20 20:48:28 +04:00
|
|
|
ret = map_private_vma(pid, vma, addr, &pvma, &old);
|
2012-11-20 20:48:23 +04:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
addr += vma_area_len(vma);
|
2012-11-20 20:39:02 +04:00
|
|
|
}
|
2012-07-19 12:43:36 +04:00
|
|
|
|
2012-11-20 20:48:30 +04:00
|
|
|
if (ret == 0)
|
|
|
|
ret = restore_priv_vma_content(pid);
|
2012-11-20 20:39:02 +04:00
|
|
|
close(fd);
|
2012-11-20 20:39:06 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
while (!list_empty(&old)) {
|
|
|
|
vma = list_first_entry(&old, struct vma_area, list);
|
|
|
|
list_del(&vma->list);
|
|
|
|
xfree(vma);
|
|
|
|
}
|
|
|
|
|
2012-11-20 20:48:23 +04:00
|
|
|
if (old_premmapped_addr &&
|
|
|
|
munmap(old_premmapped_addr, old_premmapped_len)) {
|
|
|
|
pr_perror("Unable to unmap %p(%lx)",
|
|
|
|
old_premmapped_addr, old_premmapped_len);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-20 20:39:02 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-10 16:08:07 +03:00
|
|
|
static int open_vmas(int pid)
|
2012-11-20 20:39:02 +04:00
|
|
|
{
|
|
|
|
struct vma_area *vma;
|
|
|
|
int ret = 0;
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
list_for_each_entry(vma, &rst_vmas.h, list) {
|
2012-03-27 16:34:00 +04:00
|
|
|
if (!(vma_entry_is(&vma->vma, VMA_AREA_REGULAR)))
|
2011-09-23 12:00:45 +04:00
|
|
|
continue;
|
|
|
|
|
2013-01-16 19:20:08 +04:00
|
|
|
pr_info("Opening 0x%016"PRIx64"-0x%016"PRIx64" 0x%016"PRIx64" (%x) vma\n",
|
2012-11-02 15:59:20 +03:00
|
|
|
vma->vma.start, vma->vma.end,
|
|
|
|
vma->vma.pgoff, vma->vma.status);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-03-27 16:34:00 +04:00
|
|
|
if (vma_entry_is(&vma->vma, VMA_AREA_SYSVIPC))
|
|
|
|
ret = vma->vma.shmid;
|
|
|
|
else if (vma_entry_is(&vma->vma, VMA_ANON_SHARED))
|
|
|
|
ret = get_shmem_fd(pid, &vma->vma);
|
2012-11-20 20:48:28 +04:00
|
|
|
else if (vma_entry_is(&vma->vma, VMA_FILE_SHARED))
|
2012-03-27 16:34:00 +04:00
|
|
|
ret = get_filemap_fd(pid, &vma->vma);
|
2012-11-02 16:00:18 +03:00
|
|
|
else if (vma_entry_is(&vma->vma, VMA_AREA_SOCKET))
|
|
|
|
ret = get_socket_fd(pid, &vma->vma);
|
2012-03-21 19:38:00 +04:00
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("Can't fixup fd\n");
|
2012-03-27 16:34:00 +04:00
|
|
|
break;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
2012-03-21 19:38:00 +04:00
|
|
|
|
2012-11-02 15:59:20 +03:00
|
|
|
pr_info("\t`- setting %d as mapping fd\n", ret);
|
2012-03-27 16:34:00 +04:00
|
|
|
vma->vma.fd = ret;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
2012-03-27 16:34:00 +04:00
|
|
|
|
2012-11-20 20:39:02 +04:00
|
|
|
return ret < 0 ? -1 : 0;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-01-19 01:33:19 +03:00
|
|
|
static rt_sigaction_t sigchld_act;
|
2011-11-29 15:12:25 +03:00
|
|
|
static int prepare_sigactions(int pid)
|
|
|
|
{
|
2011-12-03 17:24:05 +04:00
|
|
|
rt_sigaction_t act, oact;
|
2012-02-01 15:24:39 +04:00
|
|
|
int fd_sigact;
|
2012-07-18 16:25:06 +04:00
|
|
|
SaEntry *e;
|
2012-05-18 15:39:00 +04:00
|
|
|
int sig;
|
2012-02-01 15:24:39 +04:00
|
|
|
int ret = -1;
|
2011-11-29 15:12:25 +03:00
|
|
|
|
2011-12-29 19:56:34 +04:00
|
|
|
fd_sigact = open_image_ro(CR_FD_SIGACT, pid);
|
|
|
|
if (fd_sigact < 0)
|
2011-12-13 15:03:33 +04:00
|
|
|
return -1;
|
2011-12-01 17:15:00 +04:00
|
|
|
|
2012-12-04 19:26:54 +04:00
|
|
|
for (sig = 1; sig <= SIGMAX; sig++) {
|
2011-11-29 15:12:25 +03:00
|
|
|
if (sig == SIGKILL || sig == SIGSTOP)
|
|
|
|
continue;
|
|
|
|
|
2012-12-04 19:26:54 +04:00
|
|
|
ret = pb_read_one_eof(fd_sigact, &e, PB_SIGACT);
|
|
|
|
if (ret == 0) {
|
|
|
|
if (sig != SIGMAX_OLD + 1) { /* backward compatibility */
|
|
|
|
pr_err("Unexpected EOF %d\n", sig);
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pr_warn("This format of sigacts-%d.img is depricated\n", pid);
|
|
|
|
break;
|
|
|
|
}
|
2012-01-26 20:30:31 +04:00
|
|
|
if (ret < 0)
|
|
|
|
break;
|
2011-11-29 15:12:25 +03:00
|
|
|
|
2013-01-18 11:08:38 +04:00
|
|
|
ASSIGN_TYPED(act.rt_sa_handler, decode_pointer(e->sigaction));
|
2012-07-18 16:25:06 +04:00
|
|
|
ASSIGN_TYPED(act.rt_sa_flags, e->flags);
|
2013-01-18 11:08:38 +04:00
|
|
|
ASSIGN_TYPED(act.rt_sa_restorer, decode_pointer(e->restorer));
|
2012-07-18 16:25:06 +04:00
|
|
|
ASSIGN_TYPED(act.rt_sa_mask.sig[0], e->mask);
|
|
|
|
|
|
|
|
sa_entry__free_unpacked(e, NULL);
|
2011-12-02 23:17:30 +04:00
|
|
|
|
2012-01-19 01:33:19 +03:00
|
|
|
if (sig == SIGCHLD) {
|
|
|
|
sigchld_act = act;
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-02 23:17:30 +04:00
|
|
|
/*
|
|
|
|
* A pure syscall is used, because glibc
|
|
|
|
* sigaction overwrites se_restorer.
|
|
|
|
*/
|
2012-04-18 01:55:00 +04:00
|
|
|
ret = sys_sigaction(sig, &act, &oact, sizeof(rt_sigset_t));
|
2011-11-29 15:12:25 +03:00
|
|
|
if (ret == -1) {
|
|
|
|
pr_err("%d: Can't restore sigaction: %m\n", pid);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
2012-02-29 13:39:21 +03:00
|
|
|
close_safe(&fd_sigact);
|
2011-11-29 15:12:25 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
static int pstree_wait_helpers()
|
|
|
|
{
|
|
|
|
struct pstree_item *pi;
|
|
|
|
|
2012-10-08 18:59:26 +04:00
|
|
|
list_for_each_entry(pi, ¤t->children, sibling) {
|
2012-06-22 00:38:00 +04:00
|
|
|
int status, ret;
|
|
|
|
|
|
|
|
if (pi->state != TASK_HELPER)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Check, that a helper completed. */
|
|
|
|
ret = waitpid(pi->pid.virt, &status, 0);
|
|
|
|
if (ret == -1) {
|
|
|
|
if (errno == ECHILD)
|
|
|
|
continue; /* It has been waited in sigchld_handler */
|
|
|
|
pr_err("waitpid(%d) failed\n", pi->pid.virt);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!WIFEXITED(status) || WEXITSTATUS(status)) {
|
2012-11-23 16:43:33 +04:00
|
|
|
pr_err("%d exited with non-zero code (%d,%d)\n", pi->pid.virt,
|
2012-06-22 00:38:00 +04:00
|
|
|
WEXITSTATUS(status), WTERMSIG(status));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:51:00 +04:00
|
|
|
|
2012-07-19 13:23:01 +04:00
|
|
|
static int restore_one_alive_task(int pid, CoreEntry *core)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-05-02 14:42:00 +04:00
|
|
|
pr_info("Restoring resources\n");
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
if (pstree_wait_helpers())
|
|
|
|
return -1;
|
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
if (prepare_fds(current))
|
2011-12-13 15:03:33 +04:00
|
|
|
return -1;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-04-09 13:41:05 +04:00
|
|
|
if (prepare_fs(pid))
|
|
|
|
return -1;
|
|
|
|
|
2013-01-17 16:09:34 +08:00
|
|
|
if (prepare_file_locks(pid))
|
|
|
|
return -1;
|
|
|
|
|
2011-11-29 15:12:25 +03:00
|
|
|
if (prepare_sigactions(pid))
|
2011-12-13 15:03:33 +04:00
|
|
|
return -1;
|
2011-11-29 15:12:25 +03:00
|
|
|
|
2012-09-02 01:02:30 +04:00
|
|
|
log_closedir();
|
|
|
|
|
2012-12-10 16:08:07 +03:00
|
|
|
if (open_vmas(pid))
|
2012-12-10 16:04:46 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return sigreturn_restore(pid, core);
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-01-22 20:28:30 +04:00
|
|
|
static void zombie_prepare_signals(void)
|
|
|
|
{
|
|
|
|
sigset_t blockmask;
|
|
|
|
int sig;
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
sigfillset(&blockmask);
|
|
|
|
sigprocmask(SIG_UNBLOCK, &blockmask, NULL);
|
|
|
|
|
|
|
|
memset(&act, 0, sizeof(act));
|
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
|
2012-12-04 19:26:54 +04:00
|
|
|
for (sig = 1; sig <= SIGMAX; sig++)
|
2012-01-22 20:28:30 +04:00
|
|
|
sigaction(sig, &act, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SIG_FATAL_MASK ( \
|
|
|
|
(1 << SIGHUP) |\
|
|
|
|
(1 << SIGINT) |\
|
|
|
|
(1 << SIGQUIT) |\
|
|
|
|
(1 << SIGILL) |\
|
|
|
|
(1 << SIGTRAP) |\
|
|
|
|
(1 << SIGABRT) |\
|
|
|
|
(1 << SIGIOT) |\
|
|
|
|
(1 << SIGBUS) |\
|
|
|
|
(1 << SIGFPE) |\
|
|
|
|
(1 << SIGKILL) |\
|
|
|
|
(1 << SIGUSR1) |\
|
|
|
|
(1 << SIGSEGV) |\
|
|
|
|
(1 << SIGUSR2) |\
|
|
|
|
(1 << SIGPIPE) |\
|
|
|
|
(1 << SIGALRM) |\
|
|
|
|
(1 << SIGTERM) |\
|
|
|
|
(1 << SIGXCPU) |\
|
|
|
|
(1 << SIGXFSZ) |\
|
|
|
|
(1 << SIGVTALRM)|\
|
|
|
|
(1 << SIGPROF) |\
|
|
|
|
(1 << SIGPOLL) |\
|
|
|
|
(1 << SIGIO) |\
|
|
|
|
(1 << SIGSYS) |\
|
|
|
|
(1 << SIGUNUSED)|\
|
|
|
|
(1 << SIGSTKFLT)|\
|
|
|
|
(1 << SIGPWR) \
|
|
|
|
)
|
|
|
|
|
|
|
|
static inline int sig_fatal(int sig)
|
|
|
|
{
|
2012-12-04 19:26:54 +04:00
|
|
|
return (sig > 0) && (sig < SIGMAX) && (SIG_FATAL_MASK & (1UL << sig));
|
2012-01-22 20:28:30 +04:00
|
|
|
}
|
|
|
|
|
2012-06-26 14:51:00 +04:00
|
|
|
struct task_entries *task_entries;
|
|
|
|
|
2012-12-04 18:43:28 +03:00
|
|
|
static int restore_one_fake(void)
|
2012-06-22 00:38:00 +04:00
|
|
|
{
|
|
|
|
/* We should wait here, otherwise last_pid will be changed. */
|
|
|
|
futex_wait_while(&task_entries->start, CR_STATE_FORKING);
|
2012-07-02 15:25:00 +04:00
|
|
|
futex_wait_while(&task_entries->start, CR_STATE_RESTORE_PGID);
|
2012-06-22 00:38:00 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-14 14:09:01 +03:00
|
|
|
static int restore_one_zombie(int pid, int exit_code)
|
2012-01-22 20:28:30 +04:00
|
|
|
{
|
|
|
|
pr_info("Restoring zombie with %d code\n", exit_code);
|
|
|
|
|
|
|
|
if (task_entries != NULL) {
|
2012-12-04 16:59:41 +03:00
|
|
|
restore_finish_stage(CR_STATE_RESTORE);
|
2012-01-22 20:28:30 +04:00
|
|
|
zombie_prepare_signals();
|
2012-12-04 16:59:41 +03:00
|
|
|
restore_finish_stage(CR_STATE_RESTORE_SIGCHLD);
|
2012-01-22 20:28:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (exit_code & 0x7f) {
|
|
|
|
int signr;
|
|
|
|
|
|
|
|
signr = exit_code & 0x7F;
|
|
|
|
if (!sig_fatal(signr)) {
|
2012-03-01 18:52:42 +04:00
|
|
|
pr_warn("Exit with non fatal signal ignored\n");
|
2012-01-22 20:28:30 +04:00
|
|
|
signr = SIGABRT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kill(pid, signr) < 0)
|
2012-01-31 15:13:05 +04:00
|
|
|
pr_perror("Can't kill myself, will just exit");
|
2012-01-22 20:28:30 +04:00
|
|
|
|
|
|
|
exit_code = 0;
|
|
|
|
}
|
|
|
|
|
2012-01-30 17:04:24 +04:00
|
|
|
exit((exit_code >> 8) & 0x7f);
|
2012-01-22 20:28:30 +04:00
|
|
|
|
|
|
|
/* never reached */
|
|
|
|
BUG_ON(1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-11-27 22:03:36 +03:00
|
|
|
static int check_core(CoreEntry *core)
|
2012-01-22 20:28:30 +04:00
|
|
|
{
|
2012-11-27 22:03:36 +03:00
|
|
|
int ret = -1;
|
2012-01-22 20:28:30 +04:00
|
|
|
|
2013-01-14 11:25:50 +04:00
|
|
|
if (core->mtype != CORE_ENTRY__MARCH) {
|
2012-07-19 13:23:01 +04:00
|
|
|
pr_err("Core march mismatch %d\n", (int)core->mtype);
|
2012-02-29 13:39:21 +03:00
|
|
|
goto out;
|
2012-01-22 20:28:30 +04:00
|
|
|
}
|
2012-07-20 14:18:53 +04:00
|
|
|
|
|
|
|
if (!core->tc) {
|
|
|
|
pr_err("Core task state data missed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-11-12 12:34:56 +04:00
|
|
|
if (core->tc->task_state != TASK_DEAD) {
|
2013-01-11 18:16:21 +04:00
|
|
|
if (!core->ids && !current->ids) {
|
2012-11-12 12:34:56 +04:00
|
|
|
pr_err("Core IDS data missed for non-zombie\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2012-11-12 12:35:03 +04:00
|
|
|
|
2013-01-14 17:19:06 +04:00
|
|
|
if (!CORE_THREAD_ARCH_INFO(core)) {
|
2012-11-12 12:35:03 +04:00
|
|
|
pr_err("Core info data missed for non-zombie\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2012-07-20 14:18:53 +04:00
|
|
|
}
|
|
|
|
|
2012-07-19 13:23:01 +04:00
|
|
|
ret = 0;
|
2012-02-29 13:39:21 +03:00
|
|
|
out:
|
2012-01-22 20:28:30 +04:00
|
|
|
return ret < 0 ? ret : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int restore_one_task(int pid)
|
|
|
|
{
|
2012-07-19 13:23:01 +04:00
|
|
|
int fd, ret;
|
|
|
|
CoreEntry *core;
|
2012-01-22 20:28:30 +04:00
|
|
|
|
2012-07-19 13:23:01 +04:00
|
|
|
fd = open_image_ro(CR_FD_CORE, pid);
|
|
|
|
if (fd < 0)
|
2012-01-22 20:28:30 +04:00
|
|
|
return -1;
|
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one(fd, &core, PB_CORE);
|
2012-07-19 13:23:01 +04:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-11-27 22:03:36 +03:00
|
|
|
if (check_core(core)) {
|
2012-07-19 13:23:01 +04:00
|
|
|
ret = -1;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ((int)core->tc->task_state) {
|
2012-01-22 20:28:30 +04:00
|
|
|
case TASK_ALIVE:
|
2012-07-19 13:23:01 +04:00
|
|
|
ret = restore_one_alive_task(pid, core);
|
|
|
|
break;
|
2012-01-22 20:28:30 +04:00
|
|
|
case TASK_DEAD:
|
2012-07-19 13:23:01 +04:00
|
|
|
ret = restore_one_zombie(pid, core->tc->exit_code);
|
|
|
|
break;
|
2012-01-22 20:28:30 +04:00
|
|
|
default:
|
2012-07-19 13:23:01 +04:00
|
|
|
pr_err("Unknown state in code %d\n", (int)core->tc->task_state);
|
|
|
|
ret = -1;
|
|
|
|
break;
|
2012-01-22 20:28:30 +04:00
|
|
|
}
|
2012-07-19 13:23:01 +04:00
|
|
|
|
|
|
|
out:
|
|
|
|
core_entry__free_unpacked(core, NULL);
|
|
|
|
return ret;
|
2012-01-22 20:28:30 +04:00
|
|
|
}
|
|
|
|
|
2012-08-28 23:19:28 +04:00
|
|
|
/* All arguments should be above stack, because it grows down */
|
2012-01-26 15:26:00 +04:00
|
|
|
struct cr_clone_arg {
|
2013-01-29 09:21:46 +04:00
|
|
|
char stack[PAGE_SIZE] __attribute__((aligned (8)));
|
2012-08-28 23:19:28 +04:00
|
|
|
char stack_ptr[0];
|
2012-05-31 14:50:00 +04:00
|
|
|
struct pstree_item *item;
|
2012-01-26 15:27:00 +04:00
|
|
|
unsigned long clone_flags;
|
2012-05-31 14:50:00 +04:00
|
|
|
int fd;
|
2012-01-26 15:26:00 +04:00
|
|
|
};
|
|
|
|
|
2012-11-27 21:59:58 +03:00
|
|
|
static void write_pidfile(char *pfname, int pid)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = open(pfname, O_WRONLY | O_TRUNC | O_CREAT, 0600);
|
|
|
|
if (fd == -1) {
|
|
|
|
pr_perror("Can't open %s", pfname);
|
|
|
|
kill(pid, SIGKILL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf(fd, "%d", pid);
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2013-01-19 01:16:19 +04:00
|
|
|
static inline int fork_with_pid(struct pstree_item *item)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-01-26 15:26:00 +04:00
|
|
|
int ret = -1;
|
|
|
|
struct cr_clone_arg ca;
|
2012-06-22 00:38:00 +04:00
|
|
|
pid_t pid = item->pid.virt;
|
2011-12-01 18:21:17 +04:00
|
|
|
|
|
|
|
|
2012-05-31 14:50:00 +04:00
|
|
|
ca.item = item;
|
2013-01-19 01:16:19 +04:00
|
|
|
ca.clone_flags = item->rst->clone_flags;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2013-01-19 01:16:19 +04:00
|
|
|
pr_info("Forking task with %d pid (flags 0x%lx)\n", pid, ca.clone_flags);
|
2013-01-12 00:44:26 +04:00
|
|
|
|
2012-06-19 15:53:00 +04:00
|
|
|
if (!(ca.clone_flags & CLONE_NEWPID)) {
|
2012-08-14 14:09:20 +04:00
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
ca.fd = open(LAST_PID_PATH, O_RDWR);
|
|
|
|
if (ca.fd < 0) {
|
|
|
|
pr_perror("%d: Can't open %s", pid, LAST_PID_PATH);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flock(ca.fd, LOCK_EX)) {
|
|
|
|
close(ca.fd);
|
|
|
|
pr_perror("%d: Can't lock %s", pid, LAST_PID_PATH);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%d", pid - 1);
|
2012-06-19 15:53:00 +04:00
|
|
|
if (write_img_buf(ca.fd, buf, strlen(buf)))
|
|
|
|
goto err_unlock;
|
2012-08-14 14:09:20 +04:00
|
|
|
} else {
|
|
|
|
ca.fd = -1;
|
2012-10-09 19:57:15 +04:00
|
|
|
BUG_ON(pid != INIT_PID);
|
2012-08-14 14:09:20 +04:00
|
|
|
}
|
2011-12-01 18:21:17 +04:00
|
|
|
|
2012-08-10 19:14:36 +04:00
|
|
|
if (ca.clone_flags & CLONE_NEWNET)
|
|
|
|
/*
|
|
|
|
* When restoring a net namespace we need to communicate
|
|
|
|
* with the original (i.e. -- init) one. Thus, prepare for
|
|
|
|
* that before we leave the existing namespaces.
|
|
|
|
*/
|
|
|
|
if (netns_pre_create())
|
|
|
|
goto err_unlock;
|
|
|
|
|
2012-08-28 23:19:28 +04:00
|
|
|
ret = clone(restore_task_with_children, ca.stack_ptr,
|
2012-06-19 15:53:00 +04:00
|
|
|
ca.clone_flags | SIGCHLD, &ca);
|
2011-12-01 18:21:17 +04:00
|
|
|
|
2012-01-26 15:26:00 +04:00
|
|
|
if (ret < 0)
|
2012-01-31 15:13:05 +04:00
|
|
|
pr_perror("Can't fork for %d", pid);
|
2011-12-01 18:21:17 +04:00
|
|
|
|
2012-08-06 18:31:39 +04:00
|
|
|
if (ca.clone_flags & CLONE_NEWPID)
|
|
|
|
item->pid.real = ret;
|
2012-08-14 12:54:00 +04:00
|
|
|
|
2012-11-27 21:59:58 +03:00
|
|
|
if (opts.pidfile && root_item == item)
|
|
|
|
write_pidfile(opts.pidfile, ret);
|
2012-08-14 12:54:00 +04:00
|
|
|
|
2011-12-01 18:21:17 +04:00
|
|
|
err_unlock:
|
2012-08-14 14:09:20 +04:00
|
|
|
if (ca.fd >= 0) {
|
|
|
|
if (flock(ca.fd, LOCK_UN))
|
|
|
|
pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH);
|
2011-12-01 18:21:17 +04:00
|
|
|
|
2012-08-14 14:09:20 +04:00
|
|
|
close(ca.fd);
|
|
|
|
}
|
2011-12-01 18:21:17 +04:00
|
|
|
err:
|
2011-09-23 12:00:45 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-19 01:33:19 +03:00
|
|
|
static void sigchld_handler(int signal, siginfo_t *siginfo, void *data)
|
|
|
|
{
|
2012-06-22 00:38:00 +04:00
|
|
|
struct pstree_item *pi;
|
|
|
|
pid_t pid = siginfo->si_pid;
|
|
|
|
int status;
|
|
|
|
int exit;
|
|
|
|
|
|
|
|
exit = siginfo->si_code & CLD_EXITED;
|
|
|
|
status = siginfo->si_status;
|
2012-09-05 19:52:55 +04:00
|
|
|
if (!current || status)
|
2012-06-22 00:38:00 +04:00
|
|
|
goto err;
|
|
|
|
|
|
|
|
while (pid) {
|
|
|
|
pid = waitpid(-1, &status, WNOHANG);
|
|
|
|
if (pid <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
exit = WIFEXITED(status);
|
|
|
|
status = exit ? WEXITSTATUS(status) : WTERMSIG(status);
|
|
|
|
if (status)
|
|
|
|
break;
|
|
|
|
|
2012-12-06 13:08:56 +03:00
|
|
|
/* Exited (with zero code) helpers are OK */
|
|
|
|
list_for_each_entry(pi, ¤t->children, sibling)
|
2012-06-22 00:38:00 +04:00
|
|
|
if (pi->pid.virt == siginfo->si_pid)
|
|
|
|
break;
|
|
|
|
|
2012-12-06 13:08:56 +03:00
|
|
|
BUG_ON(&pi->sibling == ¤t->children);
|
|
|
|
if (pi->state != TASK_HELPER)
|
|
|
|
break;
|
2012-06-22 00:38:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
err:
|
|
|
|
if (exit)
|
|
|
|
pr_err("%d exited, status=%d\n", pid, status);
|
|
|
|
else
|
|
|
|
pr_err("%d killed by signal %d\n", pid, status);
|
2012-01-19 01:33:19 +03:00
|
|
|
|
2012-04-03 00:52:00 +04:00
|
|
|
futex_abort_and_wake(&task_entries->nr_in_progress);
|
2012-01-19 01:33:19 +03:00
|
|
|
}
|
|
|
|
|
2012-04-11 22:11:41 +04:00
|
|
|
static void restore_sid(void)
|
|
|
|
{
|
|
|
|
pid_t sid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SID can only be reset to pid or inherited from parent.
|
|
|
|
* Thus we restore it right here to let our kids inherit
|
|
|
|
* one in case they need it.
|
|
|
|
*
|
|
|
|
* PGIDs are restored late when all tasks are forked and
|
|
|
|
* we can call setpgid() on custom values.
|
|
|
|
*/
|
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
if (current->pid.virt == current->sid) {
|
|
|
|
pr_info("Restoring %d to %d sid\n", current->pid.virt, current->sid);
|
2012-04-11 22:11:41 +04:00
|
|
|
sid = setsid();
|
2012-09-05 19:52:55 +04:00
|
|
|
if (sid != current->sid) {
|
2012-04-11 22:11:41 +04:00
|
|
|
pr_perror("Can't restore sid (%d)", sid);
|
2012-12-26 18:15:03 +03:00
|
|
|
exit(1);
|
2012-04-11 22:11:41 +04:00
|
|
|
}
|
|
|
|
} else {
|
2012-06-22 00:39:00 +04:00
|
|
|
sid = getsid(getpid());
|
2012-09-05 19:52:55 +04:00
|
|
|
if (sid != current->sid) {
|
2012-06-22 00:39:00 +04:00
|
|
|
/* Skip the root task if it's not init */
|
2012-10-09 19:57:15 +04:00
|
|
|
if (current == root_item && root_item->pid.virt != INIT_PID)
|
2012-06-22 00:39:00 +04:00
|
|
|
return;
|
2012-04-11 22:11:41 +04:00
|
|
|
pr_err("Requested sid %d doesn't match inherited %d\n",
|
2012-09-05 19:52:55 +04:00
|
|
|
current->sid, sid);
|
2012-12-26 18:15:03 +03:00
|
|
|
exit(1);
|
2012-04-11 22:11:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void restore_pgid(void)
|
|
|
|
{
|
|
|
|
pid_t pgid;
|
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
pr_info("Restoring %d to %d pgid\n", current->pid.virt, current->pgid);
|
2012-04-11 22:11:41 +04:00
|
|
|
|
|
|
|
pgid = getpgrp();
|
2012-09-05 19:52:55 +04:00
|
|
|
if (current->pgid == pgid)
|
2012-04-11 22:11:41 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
pr_info("\twill call setpgid, mine pgid is %d\n", pgid);
|
2012-09-05 19:52:55 +04:00
|
|
|
if (setpgid(0, current->pgid) != 0) {
|
|
|
|
pr_perror("Can't restore pgid (%d/%d->%d)", current->pid.virt, pgid, current->pgid);
|
2012-12-26 18:15:03 +03:00
|
|
|
exit(1);
|
2012-04-11 22:11:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-06 18:36:59 +04:00
|
|
|
static int mount_proc(void)
|
2012-06-27 20:57:40 +04:00
|
|
|
{
|
2012-08-01 15:01:13 +04:00
|
|
|
int ret;
|
2012-12-06 15:50:41 +03:00
|
|
|
char proc_mountpoint[] = "crtools-proc.XXXXXX";
|
2012-08-01 15:01:13 +04:00
|
|
|
|
2012-06-27 20:57:40 +04:00
|
|
|
if (mkdtemp(proc_mountpoint) == NULL) {
|
2012-08-06 18:36:59 +04:00
|
|
|
pr_perror("mkdtemp failed %s", proc_mountpoint);
|
|
|
|
return -1;
|
2012-06-27 20:57:40 +04:00
|
|
|
}
|
|
|
|
|
2012-08-01 15:01:13 +04:00
|
|
|
pr_info("Mount procfs in %s\n", proc_mountpoint);
|
2012-08-06 18:36:59 +04:00
|
|
|
if (mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL)) {
|
|
|
|
pr_perror("mount failed");
|
|
|
|
ret = -1;
|
|
|
|
goto out_rmdir;
|
2012-06-27 20:57:40 +04:00
|
|
|
}
|
2012-08-06 18:36:59 +04:00
|
|
|
|
|
|
|
ret = set_proc_mountpoint(proc_mountpoint);
|
|
|
|
|
2012-08-01 15:01:13 +04:00
|
|
|
if (umount2(proc_mountpoint, MNT_DETACH) == -1) {
|
2012-08-06 18:36:59 +04:00
|
|
|
pr_perror("Can't umount %s", proc_mountpoint);
|
|
|
|
return -1;
|
2012-08-01 15:01:13 +04:00
|
|
|
}
|
2012-08-06 18:36:59 +04:00
|
|
|
|
|
|
|
out_rmdir:
|
2012-08-01 15:01:13 +04:00
|
|
|
if (rmdir(proc_mountpoint) == -1) {
|
2012-08-06 18:36:59 +04:00
|
|
|
pr_perror("Can't remove %s", proc_mountpoint);
|
|
|
|
return -1;
|
2012-08-01 15:01:13 +04:00
|
|
|
}
|
2012-08-06 18:36:59 +04:00
|
|
|
|
|
|
|
return ret;
|
2012-06-27 20:57:40 +04:00
|
|
|
}
|
|
|
|
|
2012-01-26 15:26:00 +04:00
|
|
|
static int restore_task_with_children(void *_arg)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-01-26 15:26:00 +04:00
|
|
|
struct cr_clone_arg *ca = _arg;
|
2012-05-31 14:50:00 +04:00
|
|
|
struct pstree_item *child;
|
2012-04-05 15:34:31 +04:00
|
|
|
pid_t pid;
|
2012-05-31 14:50:00 +04:00
|
|
|
int ret;
|
2011-12-02 16:06:00 +04:00
|
|
|
sigset_t blockmask;
|
2012-01-26 15:26:00 +04:00
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
current = ca->item;
|
2012-05-31 14:50:00 +04:00
|
|
|
|
2013-01-15 18:52:57 +04:00
|
|
|
if ( !(ca->clone_flags & CLONE_FILES))
|
2013-01-12 00:44:26 +04:00
|
|
|
close_safe(&ca->fd);
|
|
|
|
|
|
|
|
if (current->state != TASK_HELPER) {
|
|
|
|
ret = clone_service_fd(current->rst->service_fd_id);
|
|
|
|
if (ret)
|
|
|
|
exit(1);
|
|
|
|
}
|
2013-01-11 18:16:24 +04:00
|
|
|
|
2012-04-05 15:34:31 +04:00
|
|
|
pid = getpid();
|
2012-09-05 19:52:55 +04:00
|
|
|
if (current->pid.virt != pid) {
|
|
|
|
pr_err("Pid %d do not match expected %d\n", pid, current->pid.virt);
|
2012-01-26 15:26:00 +04:00
|
|
|
exit(-1);
|
|
|
|
}
|
2011-12-02 16:06:00 +04:00
|
|
|
|
2012-05-02 14:42:00 +04:00
|
|
|
ret = log_init_by_pid();
|
|
|
|
if (ret < 0)
|
|
|
|
exit(1);
|
|
|
|
|
2012-08-06 18:37:13 +04:00
|
|
|
/* Restore root task */
|
2012-09-05 19:52:55 +04:00
|
|
|
if (current->parent == NULL) {
|
2012-07-15 08:43:37 +04:00
|
|
|
if (collect_mount_info())
|
|
|
|
exit(-1);
|
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
if (prepare_namespace(current->pid.virt, ca->clone_flags))
|
2012-01-26 15:27:00 +04:00
|
|
|
exit(-1);
|
2012-06-27 20:57:40 +04:00
|
|
|
|
2012-08-01 15:01:13 +04:00
|
|
|
/*
|
|
|
|
* We need non /proc proc mount for restoring pid and mount
|
|
|
|
* namespaces and do not care for the rest of the cases.
|
|
|
|
* Thus -- mount proc at custom location for any new namespace
|
|
|
|
*/
|
2012-08-06 18:36:59 +04:00
|
|
|
if (mount_proc())
|
|
|
|
exit(-1);
|
2012-01-26 15:27:00 +04:00
|
|
|
|
2012-09-17 20:06:06 +04:00
|
|
|
if (root_prepare_shared())
|
2012-08-02 16:08:06 +04:00
|
|
|
exit(-1);
|
2012-08-06 18:37:13 +04:00
|
|
|
}
|
2012-08-02 16:08:06 +04:00
|
|
|
|
2012-01-20 00:05:22 +04:00
|
|
|
/*
|
|
|
|
* The block mask will be restored in sigresturn.
|
|
|
|
*
|
|
|
|
* TODO: This code should be removed, when a freezer will be added.
|
|
|
|
*/
|
2011-12-02 16:06:00 +04:00
|
|
|
sigfillset(&blockmask);
|
2012-01-19 01:33:19 +03:00
|
|
|
sigdelset(&blockmask, SIGCHLD);
|
2011-12-02 16:06:00 +04:00
|
|
|
ret = sigprocmask(SIG_BLOCK, &blockmask, NULL);
|
|
|
|
if (ret) {
|
2012-09-05 19:52:55 +04:00
|
|
|
pr_perror("%d: Can't block signals", current->pid.virt);
|
2011-12-02 16:06:00 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-11-20 20:39:09 +04:00
|
|
|
if (read_vmas(pid))
|
|
|
|
exit(1);
|
|
|
|
|
2013-01-15 18:52:57 +04:00
|
|
|
if ( !(ca->clone_flags & CLONE_FILES)) {
|
|
|
|
ret = close_old_fds(current);
|
|
|
|
if (ret)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-05-31 14:50:00 +04:00
|
|
|
pr_info("Restoring children:\n");
|
2012-10-08 18:59:26 +04:00
|
|
|
list_for_each_entry(child, ¤t->children, sibling) {
|
2012-06-22 00:39:00 +04:00
|
|
|
if (!restore_before_setsid(child))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
BUG_ON(child->born_sid != -1 && getsid(getpid()) != child->born_sid);
|
|
|
|
|
2013-01-19 01:16:19 +04:00
|
|
|
ret = fork_with_pid(child);
|
2012-02-10 20:18:08 +04:00
|
|
|
if (ret < 0)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-06-22 00:39:00 +04:00
|
|
|
restore_sid();
|
|
|
|
|
|
|
|
pr_info("Restoring children:\n");
|
2012-10-08 18:59:26 +04:00
|
|
|
list_for_each_entry(child, ¤t->children, sibling) {
|
2012-06-22 00:39:00 +04:00
|
|
|
if (restore_before_setsid(child))
|
|
|
|
continue;
|
2013-01-19 01:16:19 +04:00
|
|
|
ret = fork_with_pid(child);
|
2012-06-22 00:39:00 +04:00
|
|
|
if (ret < 0)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
if (current->pgid == current->pid.virt)
|
2012-07-02 15:25:00 +04:00
|
|
|
restore_pgid();
|
|
|
|
|
2012-12-04 16:59:41 +03:00
|
|
|
restore_finish_stage(CR_STATE_FORKING);
|
2012-07-02 15:25:00 +04:00
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
if (current->pgid != current->pid.virt)
|
2012-07-02 15:25:00 +04:00
|
|
|
restore_pgid();
|
2012-07-02 15:25:00 +04:00
|
|
|
|
2012-12-04 18:49:36 +03:00
|
|
|
if (current->state == TASK_HELPER)
|
|
|
|
return restore_one_fake();
|
2012-04-11 22:06:36 +04:00
|
|
|
|
2012-12-04 18:49:36 +03:00
|
|
|
restore_finish_stage(CR_STATE_RESTORE_PGID);
|
2012-09-05 19:52:55 +04:00
|
|
|
return restore_one_task(current->pid.virt);
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-12-04 17:37:13 +03:00
|
|
|
static inline int stage_participants(int next_stage)
|
|
|
|
{
|
|
|
|
switch (next_stage) {
|
|
|
|
case CR_STATE_FORKING:
|
|
|
|
return task_entries->nr_tasks + task_entries->nr_helpers;
|
|
|
|
case CR_STATE_RESTORE_PGID:
|
|
|
|
return task_entries->nr_tasks;
|
|
|
|
case CR_STATE_RESTORE:
|
|
|
|
case CR_STATE_RESTORE_SIGCHLD:
|
|
|
|
return task_entries->nr_threads;
|
|
|
|
}
|
|
|
|
|
|
|
|
BUG();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int restore_switch_stage(int next_stage)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
futex_t *np = &task_entries->nr_in_progress;
|
|
|
|
|
|
|
|
futex_wait_while_gt(np, 0);
|
|
|
|
ret = (int)futex_get(np);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-12-04 17:40:19 +03:00
|
|
|
futex_set(np, stage_participants(next_stage));
|
2012-12-04 17:37:13 +03:00
|
|
|
futex_set_and_wake(&task_entries->start, next_stage);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-31 14:50:00 +04:00
|
|
|
static int restore_root_task(struct pstree_item *init, struct cr_options *opts)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-05-18 15:39:00 +04:00
|
|
|
int ret;
|
2012-01-27 11:07:11 +04:00
|
|
|
struct sigaction act, old_act;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-19 01:33:19 +03:00
|
|
|
ret = sigaction(SIGCHLD, NULL, &act);
|
|
|
|
if (ret < 0) {
|
2012-08-11 21:57:42 +04:00
|
|
|
pr_perror("sigaction() failed\n");
|
2012-01-19 01:33:19 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
act.sa_flags |= SA_NOCLDSTOP | SA_SIGINFO | SA_RESTART;
|
2012-01-19 01:33:19 +03:00
|
|
|
act.sa_sigaction = sigchld_handler;
|
2012-06-22 00:38:00 +04:00
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
sigaddset(&act.sa_mask, SIGCHLD);
|
|
|
|
|
2012-01-27 11:07:11 +04:00
|
|
|
ret = sigaction(SIGCHLD, &act, &old_act);
|
2012-01-19 01:33:19 +03:00
|
|
|
if (ret < 0) {
|
2012-08-11 21:57:42 +04:00
|
|
|
pr_perror("sigaction() failed\n");
|
2012-01-19 01:33:19 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-26 15:27:00 +04:00
|
|
|
/*
|
|
|
|
* FIXME -- currently we assume that all the tasks live
|
|
|
|
* in the same set of namespaces. This is done to debug
|
|
|
|
* the ns contents dumping/restoring. Need to revisit
|
|
|
|
* this later.
|
|
|
|
*/
|
|
|
|
|
2012-10-09 19:57:15 +04:00
|
|
|
if (init->pid.virt == INIT_PID) {
|
2013-01-17 18:14:55 +04:00
|
|
|
if (!(current_ns_mask & CLONE_NEWPID)) {
|
2012-12-06 10:38:46 +03:00
|
|
|
pr_err("This process tree can only be restored "
|
|
|
|
"in a new pid namespace.\n"
|
|
|
|
"crtools should be re-executed with the "
|
|
|
|
"\"--namespace pid\" option.\n");
|
2012-06-22 00:38:00 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2013-01-17 18:14:55 +04:00
|
|
|
} else if (current_ns_mask & CLONE_NEWPID) {
|
2012-06-22 00:38:00 +04:00
|
|
|
pr_err("Can't restore pid namespace without the process init\n");
|
|
|
|
return -1;
|
2012-06-19 15:53:00 +04:00
|
|
|
}
|
|
|
|
|
2012-12-04 17:37:13 +03:00
|
|
|
futex_set(&task_entries->nr_in_progress, stage_participants(CR_STATE_FORKING));
|
2012-06-22 00:38:00 +04:00
|
|
|
|
2013-01-19 01:16:19 +04:00
|
|
|
ret = fork_with_pid(init);
|
2011-09-23 12:00:45 +04:00
|
|
|
if (ret < 0)
|
2011-12-13 15:03:33 +04:00
|
|
|
return -1;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-04-11 22:06:36 +04:00
|
|
|
pr_info("Wait until all tasks are forked\n");
|
2012-12-04 17:37:13 +03:00
|
|
|
ret = restore_switch_stage(CR_STATE_RESTORE_PGID);
|
2012-04-11 22:06:36 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-07-02 15:25:00 +04:00
|
|
|
|
|
|
|
pr_info("Wait until all tasks restored pgid\n");
|
2012-12-04 17:37:13 +03:00
|
|
|
ret = restore_switch_stage(CR_STATE_RESTORE);
|
2012-07-02 15:25:00 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-01-27 19:01:51 +03:00
|
|
|
pr_info("Wait until all tasks are restored\n");
|
2012-12-04 17:37:13 +03:00
|
|
|
ret = restore_switch_stage(CR_STATE_RESTORE_SIGCHLD);
|
2012-09-25 15:54:51 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2012-03-26 23:11:00 +04:00
|
|
|
|
2012-09-17 20:06:14 +04:00
|
|
|
futex_wait_until(&task_entries->nr_in_progress, 0);
|
|
|
|
|
|
|
|
/* Restore SIGCHLD here to skip SIGCHLD from a network sctip */
|
|
|
|
ret = sigaction(SIGCHLD, &old_act, NULL);
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_perror("sigaction() failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
network_unlock();
|
2012-03-21 10:12:00 +04:00
|
|
|
out:
|
2012-01-19 01:33:19 +03:00
|
|
|
if (ret < 0) {
|
2012-04-05 15:34:31 +04:00
|
|
|
struct pstree_item *pi;
|
2012-05-31 14:50:00 +04:00
|
|
|
pr_err("Someone can't be restored\n");
|
2012-04-05 15:34:31 +04:00
|
|
|
|
2013-01-17 18:14:55 +04:00
|
|
|
if (current_ns_mask & CLONE_NEWPID) {
|
2012-08-06 18:31:39 +04:00
|
|
|
/* Kill init */
|
|
|
|
if (root_item->pid.real > 0)
|
|
|
|
kill(root_item->pid.real, SIGKILL);
|
|
|
|
} else {
|
|
|
|
for_each_pstree_item(pi)
|
2012-09-07 18:52:59 +04:00
|
|
|
if (pi->pid.virt > 0)
|
|
|
|
kill(pi->pid.virt, SIGKILL);
|
2012-08-06 18:31:39 +04:00
|
|
|
}
|
2012-01-19 01:33:19 +03:00
|
|
|
return 1;
|
|
|
|
}
|
2012-01-19 01:33:16 +03:00
|
|
|
|
2012-01-16 23:52:15 +03:00
|
|
|
pr_info("Go on!!!\n");
|
2012-03-26 23:11:00 +04:00
|
|
|
futex_set_and_wake(&task_entries->start, CR_STATE_COMPLETE);
|
2012-01-16 23:52:15 +03:00
|
|
|
|
2012-01-26 15:25:00 +04:00
|
|
|
if (!opts->restore_detach)
|
2012-01-18 23:24:37 +04:00
|
|
|
wait(NULL);
|
2011-09-23 12:00:45 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:51:00 +04:00
|
|
|
static int prepare_task_entries()
|
|
|
|
{
|
|
|
|
task_entries = mmap(NULL, TASK_ENTRIES_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0);
|
|
|
|
if (task_entries == MAP_FAILED) {
|
|
|
|
pr_perror("Can't map shmem");
|
|
|
|
return -1;
|
|
|
|
}
|
2012-12-04 17:22:45 +03:00
|
|
|
task_entries->nr_threads = 0;
|
2012-06-26 14:51:00 +04:00
|
|
|
task_entries->nr_tasks = 0;
|
2012-07-02 15:25:00 +04:00
|
|
|
task_entries->nr_helpers = 0;
|
2012-06-26 14:51:00 +04:00
|
|
|
futex_set(&task_entries->start, CR_STATE_FORKING);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-19 17:55:34 +04:00
|
|
|
int cr_restore_tasks(pid_t pid, struct cr_options *opts)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-07-19 17:37:25 +04:00
|
|
|
if (check_img_inventory() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-12-21 17:35:36 +04:00
|
|
|
if (cpu_init() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-06-26 14:51:00 +04:00
|
|
|
if (prepare_task_entries() < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-04-05 15:34:31 +04:00
|
|
|
if (prepare_pstree() < 0)
|
2011-12-13 15:03:33 +04:00
|
|
|
return -1;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2013-01-22 22:45:31 +04:00
|
|
|
if (crtools_prepare_shared(opts) < 0)
|
2012-09-17 20:06:06 +04:00
|
|
|
return -1;
|
|
|
|
|
2012-05-31 14:50:00 +04:00
|
|
|
return restore_root_task(root_item, opts);
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-04-05 14:08:11 +04:00
|
|
|
static long restorer_get_vma_hint(pid_t pid, struct list_head *tgt_vma_list,
|
|
|
|
struct list_head *self_vma_list, long vma_len)
|
2011-11-06 01:49:57 +04:00
|
|
|
{
|
2012-04-07 11:09:00 +04:00
|
|
|
struct vma_area *t_vma, *s_vma;
|
2012-04-05 14:08:11 +04:00
|
|
|
long prev_vma_end = 0;
|
2012-04-07 11:09:00 +04:00
|
|
|
struct vma_area end_vma;
|
|
|
|
|
2013-01-16 19:10:58 +04:00
|
|
|
end_vma.vma.start = end_vma.vma.end = TASK_SIZE;
|
2012-12-21 18:58:14 +04:00
|
|
|
prev_vma_end = PAGE_SIZE * 0x10; /* CONFIG_LSM_MMAP_MIN_ADDR=65536 */
|
2011-11-06 01:49:57 +04:00
|
|
|
|
2012-04-07 11:09:00 +04:00
|
|
|
s_vma = list_first_entry(self_vma_list, struct vma_area, list);
|
|
|
|
t_vma = list_first_entry(tgt_vma_list, struct vma_area, list);
|
2012-03-02 19:28:13 +04:00
|
|
|
|
2012-04-07 11:09:00 +04:00
|
|
|
while (1) {
|
|
|
|
if (prev_vma_end + vma_len > s_vma->vma.start) {
|
|
|
|
if (s_vma->list.next == self_vma_list) {
|
|
|
|
s_vma = &end_vma;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (s_vma == &end_vma)
|
|
|
|
break;
|
|
|
|
if (prev_vma_end < s_vma->vma.end)
|
|
|
|
prev_vma_end = s_vma->vma.end;
|
|
|
|
s_vma = list_entry(s_vma->list.next, struct vma_area, list);
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-02 19:28:13 +04:00
|
|
|
|
2012-04-07 11:09:00 +04:00
|
|
|
if (prev_vma_end + vma_len > t_vma->vma.start) {
|
|
|
|
if (t_vma->list.next == tgt_vma_list) {
|
|
|
|
t_vma = &end_vma;
|
|
|
|
continue;
|
2011-11-06 01:49:57 +04:00
|
|
|
}
|
2012-04-07 11:09:00 +04:00
|
|
|
if (t_vma == &end_vma)
|
|
|
|
break;
|
|
|
|
if (prev_vma_end < t_vma->vma.end)
|
|
|
|
prev_vma_end = t_vma->vma.end;
|
|
|
|
t_vma = list_entry(t_vma->list.next, struct vma_area, list);
|
|
|
|
continue;
|
2012-03-02 19:28:13 +04:00
|
|
|
}
|
|
|
|
|
2012-04-07 11:09:00 +04:00
|
|
|
return prev_vma_end;
|
2011-11-06 01:49:57 +04:00
|
|
|
}
|
2012-04-05 14:08:11 +04:00
|
|
|
|
|
|
|
return -1;
|
2011-11-06 01:49:57 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 16:45:19 +04:00
|
|
|
#define USEC_PER_SEC 1000000L
|
|
|
|
|
|
|
|
static inline int timeval_valid(struct timeval *tv)
|
|
|
|
{
|
|
|
|
return (tv->tv_sec >= 0) && ((unsigned long)tv->tv_usec < USEC_PER_SEC);
|
|
|
|
}
|
|
|
|
|
2012-07-18 16:27:01 +04:00
|
|
|
static inline int itimer_restore_and_fix(char *n, ItimerEntry *ie,
|
2012-01-24 16:45:19 +04:00
|
|
|
struct itimerval *val)
|
|
|
|
{
|
|
|
|
if (ie->isec == 0 && ie->iusec == 0) {
|
|
|
|
memzero_p(val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
val->it_interval.tv_sec = ie->isec;
|
|
|
|
val->it_interval.tv_usec = ie->iusec;
|
|
|
|
|
|
|
|
if (!timeval_valid(&val->it_interval)) {
|
|
|
|
pr_err("Invalid timer interval\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ie->vsec == 0 && ie->vusec == 0) {
|
|
|
|
/*
|
|
|
|
* Remaining time was too short. Set it to
|
|
|
|
* interval to make the timer armed and work.
|
|
|
|
*/
|
|
|
|
val->it_value.tv_sec = ie->isec;
|
|
|
|
val->it_value.tv_usec = ie->iusec;
|
|
|
|
} else {
|
|
|
|
val->it_value.tv_sec = ie->vsec;
|
|
|
|
val->it_value.tv_usec = ie->vusec;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!timeval_valid(&val->it_value)) {
|
|
|
|
pr_err("Invalid timer value\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_info("Restored %s timer to %ld.%ld -> %ld.%ld\n", n,
|
|
|
|
val->it_value.tv_sec, val->it_value.tv_usec,
|
|
|
|
val->it_interval.tv_sec, val->it_interval.tv_usec);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prepare_itimers(int pid, struct task_restore_core_args *args)
|
|
|
|
{
|
|
|
|
int fd, ret = -1;
|
2012-07-18 16:27:01 +04:00
|
|
|
ItimerEntry *ie;
|
2012-01-24 16:45:19 +04:00
|
|
|
|
|
|
|
fd = open_image_ro(CR_FD_ITIMERS, pid);
|
|
|
|
if (fd < 0)
|
|
|
|
return fd;
|
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one(fd, &ie, PB_ITIMERS);
|
2012-07-18 16:27:01 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = itimer_restore_and_fix("real", ie, &args->itimers[0]);
|
|
|
|
itimer_entry__free_unpacked(ie, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
2012-01-24 16:45:19 +04:00
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one(fd, &ie, PB_ITIMERS);
|
2012-07-18 16:27:01 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = itimer_restore_and_fix("virt", ie, &args->itimers[1]);
|
|
|
|
itimer_entry__free_unpacked(ie, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one(fd, &ie, PB_ITIMERS);
|
2012-07-18 16:27:01 +04:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
ret = itimer_restore_and_fix("prof", ie, &args->itimers[2]);
|
|
|
|
itimer_entry__free_unpacked(ie, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
out:
|
2012-02-29 13:39:21 +03:00
|
|
|
close_safe(&fd);
|
2012-01-24 16:45:19 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-07-19 12:35:25 +04:00
|
|
|
static inline int verify_cap_size(CredsEntry *ce)
|
|
|
|
{
|
|
|
|
return ((ce->n_cap_inh == CR_CAP_SIZE) && (ce->n_cap_eff == CR_CAP_SIZE) &&
|
|
|
|
(ce->n_cap_prm == CR_CAP_SIZE) && (ce->n_cap_bnd == CR_CAP_SIZE));
|
|
|
|
}
|
|
|
|
|
2012-01-27 21:43:32 +04:00
|
|
|
static int prepare_creds(int pid, struct task_restore_core_args *args)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
2012-07-19 12:35:25 +04:00
|
|
|
CredsEntry *ce;
|
2012-01-27 21:43:32 +04:00
|
|
|
|
|
|
|
fd = open_image_ro(CR_FD_CREDS, pid);
|
|
|
|
if (fd < 0)
|
|
|
|
return fd;
|
|
|
|
|
2012-08-07 02:42:58 +04:00
|
|
|
ret = pb_read_one(fd, &ce, PB_CREDS);
|
2012-02-29 13:39:21 +03:00
|
|
|
close_safe(&fd);
|
2012-01-27 21:43:32 +04:00
|
|
|
|
2012-07-19 12:35:25 +04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (!verify_cap_size(ce))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
args->creds = *ce;
|
|
|
|
args->creds.cap_inh = args->cap_inh;
|
|
|
|
memcpy(args->cap_inh, ce->cap_inh, sizeof(args->cap_inh));
|
|
|
|
args->creds.cap_eff = args->cap_eff;
|
|
|
|
memcpy(args->cap_eff, ce->cap_eff, sizeof(args->cap_eff));
|
|
|
|
args->creds.cap_prm = args->cap_prm;
|
|
|
|
memcpy(args->cap_prm, ce->cap_prm, sizeof(args->cap_prm));
|
|
|
|
args->creds.cap_bnd = args->cap_bnd;
|
|
|
|
memcpy(args->cap_bnd, ce->cap_bnd, sizeof(args->cap_bnd));
|
|
|
|
|
2012-10-11 16:52:52 +04:00
|
|
|
/*
|
|
|
|
* We can set supplementary groups here. This won't affect any
|
|
|
|
* permission checks for us (we're still root) and will not be
|
|
|
|
* reset by subsequent creds changes in restorer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
BUILD_BUG_ON(sizeof(*ce->groups) != sizeof(gid_t));
|
|
|
|
if (setgroups(ce->n_groups, ce->groups) < 0) {
|
|
|
|
pr_perror("Can't set supplementary groups");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-07-19 12:35:25 +04:00
|
|
|
creds_entry__free_unpacked(ce, NULL);
|
|
|
|
|
2012-01-27 21:43:32 +04:00
|
|
|
/* XXX -- validate creds here? */
|
|
|
|
|
2012-07-19 12:35:25 +04:00
|
|
|
return 0;
|
2012-01-27 21:43:32 +04:00
|
|
|
}
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
static VmaEntry *vma_list_remap(void *addr, unsigned long len, struct vm_area_list *vmas)
|
2012-03-27 16:31:00 +04:00
|
|
|
{
|
2012-07-19 12:43:36 +04:00
|
|
|
VmaEntry *vma, *ret;
|
2012-03-27 16:31:00 +04:00
|
|
|
struct vma_area *vma_area;
|
|
|
|
|
|
|
|
ret = vma = mmap(addr, len, PROT_READ | PROT_WRITE,
|
|
|
|
MAP_PRIVATE | MAP_ANON | MAP_FIXED, 0, 0);
|
|
|
|
if (vma != addr) {
|
|
|
|
pr_perror("Can't remap vma area");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
list_for_each_entry(vma_area, &vmas->h, list) {
|
2012-03-27 16:31:00 +04:00
|
|
|
*vma = vma_area->vma;
|
|
|
|
vma++;
|
|
|
|
}
|
|
|
|
|
|
|
|
vma->start = 0;
|
|
|
|
free_mappings(vmas);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-04-09 14:51:37 +04:00
|
|
|
static int prepare_mm(pid_t pid, struct task_restore_core_args *args)
|
|
|
|
{
|
2013-01-09 17:40:33 +04:00
|
|
|
int fd, exe_fd, i, ret = -1;
|
2012-07-18 20:54:00 +04:00
|
|
|
MmEntry *mm;
|
2012-04-09 14:51:37 +04:00
|
|
|
|
|
|
|
fd = open_image_ro(CR_FD_MM, pid);
|
|
|
|
if (fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
2012-10-24 16:51:50 +04:00
|
|
|
if (pb_read_one(fd, &mm, PB_MM) < 0) {
|
|
|
|
close_safe(&fd);
|
2012-04-09 14:51:37 +04:00
|
|
|
return -1;
|
2012-10-24 16:51:50 +04:00
|
|
|
}
|
2012-04-09 14:51:37 +04:00
|
|
|
|
2012-07-18 20:54:00 +04:00
|
|
|
args->mm = *mm;
|
|
|
|
args->mm.n_mm_saved_auxv = 0;
|
|
|
|
args->mm.mm_saved_auxv = NULL;
|
|
|
|
|
2012-10-29 19:54:12 +04:00
|
|
|
if (mm->n_mm_saved_auxv > AT_VECTOR_SIZE) {
|
2012-07-18 20:54:00 +04:00
|
|
|
pr_err("Image corrupted on pid %d\n", pid);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2013-01-09 17:40:33 +04:00
|
|
|
args->mm_saved_auxv_size = mm->n_mm_saved_auxv*sizeof(auxv_t);
|
|
|
|
for (i = 0; i < mm->n_mm_saved_auxv; ++i) {
|
|
|
|
args->mm_saved_auxv[i] = (auxv_t)mm->mm_saved_auxv[i];
|
|
|
|
}
|
2012-07-18 20:54:00 +04:00
|
|
|
|
2012-04-09 15:52:00 +04:00
|
|
|
exe_fd = open_reg_by_id(args->mm.exe_file_id);
|
|
|
|
if (exe_fd < 0)
|
2012-07-18 20:54:00 +04:00
|
|
|
goto out;
|
2012-04-09 15:52:00 +04:00
|
|
|
|
|
|
|
args->fd_exe_link = exe_fd;
|
2012-07-18 20:54:00 +04:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
mm_entry__free_unpacked(mm, NULL);
|
2012-04-09 14:51:37 +04:00
|
|
|
close(fd);
|
2012-07-18 20:54:00 +04:00
|
|
|
return ret;
|
2012-04-09 14:51:37 +04:00
|
|
|
}
|
|
|
|
|
2012-09-14 14:51:40 +04:00
|
|
|
static void *restorer;
|
|
|
|
static unsigned long restorer_len;
|
|
|
|
|
|
|
|
static int prepare_restorer_blob(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We map anonymous mapping, not mremap the restorer itself later.
|
|
|
|
* Otherwise the resoter vma would be tied to crtools binary which
|
|
|
|
* in turn will lead to set-exe-file prctl to fail with EBUSY.
|
|
|
|
*/
|
|
|
|
|
|
|
|
restorer_len = round_up(sizeof(restorer_blob), PAGE_SIZE);
|
|
|
|
restorer = mmap(NULL, restorer_len,
|
|
|
|
PROT_READ | PROT_WRITE | PROT_EXEC,
|
|
|
|
MAP_PRIVATE | MAP_ANON, 0, 0);
|
|
|
|
if (restorer == MAP_FAILED) {
|
2012-11-23 16:43:33 +04:00
|
|
|
pr_perror("Can't map restorer code");
|
2012-09-14 14:51:40 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(restorer, &restorer_blob, sizeof(restorer_blob));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int remap_restorer_blob(void *addr)
|
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
|
|
|
|
mem = mremap(restorer, restorer_len, restorer_len,
|
|
|
|
MREMAP_FIXED | MREMAP_MAYMOVE, addr);
|
|
|
|
if (mem != addr) {
|
|
|
|
pr_perror("Can't remap restorer blob");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-17 00:23:25 +04:00
|
|
|
static int validate_sched_parm(struct rst_sched_param *sp)
|
|
|
|
{
|
|
|
|
if ((sp->nice < -20) || (sp->nice > 19))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
switch (sp->policy) {
|
|
|
|
case SCHED_RR:
|
|
|
|
case SCHED_FIFO:
|
|
|
|
return ((sp->prio > 0) && (sp->prio < 100));
|
|
|
|
case SCHED_IDLE:
|
|
|
|
case SCHED_OTHER:
|
|
|
|
case SCHED_BATCH:
|
|
|
|
return sp->prio == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prep_sched_info(struct rst_sched_param *sp, ThreadCoreEntry *tc)
|
|
|
|
{
|
|
|
|
if (!tc->has_sched_policy) {
|
|
|
|
sp->policy = SCHED_OTHER;
|
|
|
|
sp->nice = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp->policy = tc->sched_policy;
|
|
|
|
sp->nice = tc->sched_nice;
|
|
|
|
sp->prio = tc->sched_prio;
|
|
|
|
|
|
|
|
if (!validate_sched_parm(sp)) {
|
|
|
|
pr_err("Inconsistent sched params received (%d.%d.%d)\n",
|
|
|
|
sp->policy, sp->nice, sp->prio);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-01-10 20:08:38 +04:00
|
|
|
static unsigned long decode_rlim(u_int64_t ival)
|
|
|
|
{
|
|
|
|
return ival == -1 ? RLIM_INFINITY : ival;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int prepare_rlimits(int pid, struct task_restore_core_args *ta)
|
|
|
|
{
|
|
|
|
int fd, ret;
|
|
|
|
|
|
|
|
ta->nr_rlim = 0;
|
|
|
|
|
|
|
|
fd = open_image_ro(CR_FD_RLIMIT, pid);
|
|
|
|
if (fd < 0) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
pr_info("Skip rlimits for %d\n", pid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int l;
|
|
|
|
RlimitEntry *re;
|
|
|
|
|
|
|
|
ret = pb_read_one_eof(fd, &re, PB_RLIMIT);
|
|
|
|
if (ret <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
l = ta->nr_rlim;
|
|
|
|
if (l == RLIM_NLIMITS) {
|
|
|
|
pr_err("Too many rlimits in image for %d\n", pid);
|
|
|
|
ret = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ta->rlims[l].rlim_cur = decode_rlim(re->cur);
|
|
|
|
ta->rlims[l].rlim_max = decode_rlim(re->max);
|
|
|
|
if (ta->rlims[l].rlim_cur > ta->rlims[l].rlim_max) {
|
|
|
|
pr_err("Can't restore cur > max for %d.%d\n", pid, l);
|
|
|
|
ta->rlims[l].rlim_cur = ta->rlims[l].rlim_max;
|
|
|
|
}
|
|
|
|
|
|
|
|
rlimit_entry__free_unpacked(re, NULL);
|
|
|
|
|
|
|
|
ta->nr_rlim++;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-25 22:43:14 +04:00
|
|
|
extern void __gcov_flush(void) __attribute__((weak));
|
|
|
|
void __gcov_flush(void) {}
|
|
|
|
|
2012-11-20 20:39:08 +04:00
|
|
|
static int sigreturn_restore(pid_t pid, CoreEntry *core)
|
2011-10-24 22:23:06 +04:00
|
|
|
{
|
2012-09-14 14:51:40 +04:00
|
|
|
long restore_task_vma_len;
|
2012-03-27 16:34:00 +04:00
|
|
|
long restore_thread_vma_len, self_vmas_len, vmas_len;
|
2011-11-16 18:19:24 +04:00
|
|
|
|
2012-03-02 19:29:35 +04:00
|
|
|
void *mem = MAP_FAILED;
|
2011-11-12 19:26:40 +04:00
|
|
|
void *restore_thread_exec_start;
|
|
|
|
void *restore_task_exec_start;
|
2011-11-16 18:19:24 +04:00
|
|
|
|
|
|
|
long new_sp, exec_mem_hint;
|
2011-10-25 21:25:42 +04:00
|
|
|
long ret;
|
2012-11-01 14:44:14 +04:00
|
|
|
long restore_bootstrap_len;
|
2011-10-24 22:23:06 +04:00
|
|
|
|
2011-11-16 18:19:24 +04:00
|
|
|
struct task_restore_core_args *task_args;
|
|
|
|
struct thread_restore_args *thread_args;
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
struct vm_area_list self_vmas;
|
2012-03-02 19:30:23 +04:00
|
|
|
int i;
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2012-05-02 14:42:00 +04:00
|
|
|
pr_info("Restore via sigreturn\n");
|
2012-01-01 13:12:37 +04:00
|
|
|
|
2011-11-12 19:26:40 +04:00
|
|
|
restore_task_vma_len = 0;
|
2012-01-01 02:32:32 +04:00
|
|
|
restore_thread_vma_len = 0;
|
2011-10-26 22:50:46 +04:00
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
ret = parse_smaps(pid, &self_vmas, false);
|
2012-06-19 15:53:00 +04:00
|
|
|
close_proc();
|
2012-03-02 19:28:46 +04:00
|
|
|
if (ret < 0)
|
2011-10-26 22:50:46 +04:00
|
|
|
goto err;
|
|
|
|
|
2012-09-07 18:21:04 +04:00
|
|
|
/* required to unmap stack _with_ guard page */
|
2013-03-01 20:11:51 +04:00
|
|
|
mark_stack_vma((long) &self_vmas, &self_vmas.h);
|
2012-09-07 18:21:04 +04:00
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
self_vmas_len = round_up((self_vmas.nr + 1) * sizeof(VmaEntry), PAGE_SIZE);
|
|
|
|
vmas_len = round_up((rst_vmas.nr + 1) * sizeof(VmaEntry), PAGE_SIZE);
|
2012-03-02 19:30:23 +04:00
|
|
|
|
2011-11-16 18:19:24 +04:00
|
|
|
/* pr_info_vma_list(&self_vma_list); */
|
2011-10-27 18:59:21 +04:00
|
|
|
|
2011-11-12 19:26:40 +04:00
|
|
|
BUILD_BUG_ON(sizeof(struct task_restore_core_args) & 1);
|
|
|
|
BUILD_BUG_ON(sizeof(struct thread_restore_args) & 1);
|
2012-01-17 15:28:13 +03:00
|
|
|
BUILD_BUG_ON(SHMEMS_SIZE % PAGE_SIZE);
|
2012-01-16 23:52:15 +03:00
|
|
|
BUILD_BUG_ON(TASK_ENTRIES_SIZE % PAGE_SIZE);
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2012-09-13 03:01:48 +04:00
|
|
|
restore_task_vma_len = round_up(sizeof(*task_args), PAGE_SIZE);
|
|
|
|
restore_thread_vma_len = round_up(sizeof(*thread_args) * current->nr_threads, PAGE_SIZE);
|
2011-10-26 11:16:00 +04:00
|
|
|
|
2012-05-02 14:42:00 +04:00
|
|
|
pr_info("%d threads require %ldK of memory\n",
|
2012-09-05 19:52:55 +04:00
|
|
|
current->nr_threads,
|
2011-11-24 15:07:03 +04:00
|
|
|
KBYTES(restore_thread_vma_len));
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2012-11-01 14:44:14 +04:00
|
|
|
restore_bootstrap_len = restorer_len +
|
|
|
|
restore_task_vma_len +
|
|
|
|
restore_thread_vma_len +
|
|
|
|
SHMEMS_SIZE + TASK_ENTRIES_SIZE +
|
|
|
|
self_vmas_len + vmas_len +
|
|
|
|
rst_tcp_socks_size;
|
2012-11-27 22:16:00 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Restorer is a blob (code + args) that will get mapped in some
|
|
|
|
* place, that should _not_ intersect with both -- current mappings
|
|
|
|
* and mappings of the task we're restoring here. The subsequent
|
|
|
|
* call finds the start address for the restorer.
|
|
|
|
*
|
|
|
|
* After the start address is found we populate it with the restorer
|
|
|
|
* parts one by one (some are remap-ed, some are mmap-ed and copied
|
|
|
|
* or inited from scratch).
|
|
|
|
*/
|
|
|
|
|
2013-03-01 20:11:51 +04:00
|
|
|
exec_mem_hint = restorer_get_vma_hint(pid, &rst_vmas.h, &self_vmas.h,
|
2012-11-01 14:44:14 +04:00
|
|
|
restore_bootstrap_len);
|
2011-11-16 18:19:24 +04:00
|
|
|
if (exec_mem_hint == -1) {
|
2012-01-31 15:31:22 +04:00
|
|
|
pr_err("No suitable area for task_restore bootstrap (%ldK)\n",
|
2012-11-01 14:44:14 +04:00
|
|
|
restore_bootstrap_len);
|
2011-11-06 01:49:57 +04:00
|
|
|
goto err;
|
2011-11-16 18:19:24 +04:00
|
|
|
}
|
2011-10-27 00:57:01 +04:00
|
|
|
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_info("Found bootstrap VMA hint at: 0x%lx (needs ~%ldK)\n", exec_mem_hint,
|
2012-11-01 14:44:14 +04:00
|
|
|
KBYTES(restore_bootstrap_len));
|
2012-03-02 19:28:13 +04:00
|
|
|
|
2012-09-14 14:51:40 +04:00
|
|
|
ret = remap_restorer_blob((void *)exec_mem_hint);
|
|
|
|
if (ret < 0)
|
2011-11-06 01:49:57 +04:00
|
|
|
goto err;
|
2011-10-24 22:23:06 +04:00
|
|
|
|
2011-10-26 11:16:00 +04:00
|
|
|
/*
|
2011-11-16 18:19:24 +04:00
|
|
|
* Prepare a memory map for restorer. Note a thread space
|
|
|
|
* might be completely unused so it's here just for convenience.
|
2011-10-26 11:16:00 +04:00
|
|
|
*/
|
2012-11-13 20:15:13 +03:00
|
|
|
restore_thread_exec_start = restorer_sym(exec_mem_hint, __export_restore_thread);
|
|
|
|
restore_task_exec_start = restorer_sym(exec_mem_hint, __export_restore_task);
|
2012-09-13 03:01:48 +04:00
|
|
|
|
2012-09-14 14:51:40 +04:00
|
|
|
exec_mem_hint += restorer_len;
|
2011-10-26 11:16:00 +04:00
|
|
|
|
2012-09-13 04:10:48 +04:00
|
|
|
/* VMA we need to run task_restore code */
|
|
|
|
mem = mmap((void *)exec_mem_hint,
|
|
|
|
restore_task_vma_len + restore_thread_vma_len,
|
|
|
|
PROT_READ | PROT_WRITE,
|
|
|
|
MAP_PRIVATE | MAP_ANON | MAP_FIXED, 0, 0);
|
|
|
|
if (mem != (void *)exec_mem_hint) {
|
|
|
|
pr_err("Can't mmap section for restore code\n");
|
|
|
|
goto err;
|
|
|
|
}
|
2011-10-26 11:16:00 +04:00
|
|
|
|
2012-09-13 04:10:48 +04:00
|
|
|
memzero(mem, restore_task_vma_len + restore_thread_vma_len);
|
|
|
|
task_args = mem;
|
|
|
|
thread_args = mem + restore_task_vma_len;
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2011-10-26 00:30:41 +04:00
|
|
|
/*
|
2012-01-01 13:10:12 +04:00
|
|
|
* Get a reference to shared memory area which is
|
|
|
|
* used to signal if shmem restoration complete
|
|
|
|
* from low-level restore code.
|
|
|
|
*
|
|
|
|
* This shmem area is mapped right after the whole area of
|
|
|
|
* sigreturn rt code. Note we didn't allocated it before
|
|
|
|
* but this area is taken into account for 'hint' memory
|
|
|
|
* address.
|
2011-10-26 00:30:41 +04:00
|
|
|
*/
|
2012-03-02 19:29:35 +04:00
|
|
|
|
2012-09-13 04:10:48 +04:00
|
|
|
mem += restore_task_vma_len + restore_thread_vma_len;
|
2012-05-03 18:01:05 +04:00
|
|
|
ret = shmem_remap(rst_shmems, mem, SHMEMS_SIZE);
|
2012-01-03 13:05:50 +04:00
|
|
|
if (ret < 0)
|
2011-12-26 21:27:03 +04:00
|
|
|
goto err;
|
2012-03-02 19:29:35 +04:00
|
|
|
task_args->shmems = mem;
|
2011-12-26 21:27:03 +04:00
|
|
|
|
2012-03-02 19:29:35 +04:00
|
|
|
mem += SHMEMS_SIZE;
|
|
|
|
ret = shmem_remap(task_entries, mem, TASK_ENTRIES_SIZE);
|
2012-01-16 23:52:15 +03:00
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
2012-03-02 19:29:35 +04:00
|
|
|
task_args->task_entries = mem;
|
2012-01-16 23:52:15 +03:00
|
|
|
|
2012-03-02 19:30:23 +04:00
|
|
|
mem += TASK_ENTRIES_SIZE;
|
2013-03-01 20:11:51 +04:00
|
|
|
task_args->self_vmas = vma_list_remap(mem, self_vmas_len, &self_vmas);
|
2012-03-27 16:31:00 +04:00
|
|
|
if (!task_args->self_vmas)
|
2012-03-02 19:30:23 +04:00
|
|
|
goto err;
|
|
|
|
|
2012-03-27 16:34:00 +04:00
|
|
|
mem += self_vmas_len;
|
2013-03-01 20:11:51 +04:00
|
|
|
task_args->nr_vmas = rst_vmas.nr;
|
|
|
|
task_args->tgt_vmas = vma_list_remap(mem, vmas_len, &rst_vmas);
|
2012-12-06 13:19:01 +03:00
|
|
|
task_args->premmapped_addr = (unsigned long) current->rst->premmapped_addr;
|
|
|
|
task_args->premmapped_len = current->rst->premmapped_len;
|
2012-03-27 16:34:00 +04:00
|
|
|
if (!task_args->tgt_vmas)
|
|
|
|
goto err;
|
|
|
|
|
2012-09-17 20:02:57 +04:00
|
|
|
mem += vmas_len;
|
|
|
|
if (rst_tcp_socks_remap(mem))
|
|
|
|
goto err;
|
|
|
|
task_args->rst_tcp_socks = mem;
|
|
|
|
task_args->rst_tcp_socks_size = rst_tcp_socks_size;
|
|
|
|
|
2012-01-01 13:10:12 +04:00
|
|
|
/*
|
|
|
|
* Arguments for task restoration.
|
|
|
|
*/
|
2012-07-19 13:23:01 +04:00
|
|
|
|
2013-01-14 11:25:50 +04:00
|
|
|
BUG_ON(core->mtype != CORE_ENTRY__MARCH);
|
2012-07-19 13:23:01 +04:00
|
|
|
|
2012-03-01 18:52:42 +04:00
|
|
|
task_args->logfd = log_get_fd();
|
2012-09-03 14:44:09 +04:00
|
|
|
task_args->loglevel = log_get_loglevel();
|
2012-01-19 01:33:19 +03:00
|
|
|
task_args->sigchld_act = sigchld_act;
|
2011-11-18 16:09:01 +04:00
|
|
|
|
2012-07-19 13:23:01 +04:00
|
|
|
strncpy(task_args->comm, core->tc->comm, sizeof(task_args->comm));
|
|
|
|
|
2013-01-10 20:08:38 +04:00
|
|
|
if (prepare_rlimits(pid, task_args))
|
|
|
|
goto err;
|
|
|
|
|
2012-02-10 20:18:08 +04:00
|
|
|
/*
|
|
|
|
* Fill up per-thread data.
|
|
|
|
*/
|
2012-09-05 19:52:55 +04:00
|
|
|
for (i = 0; i < current->nr_threads; i++) {
|
2012-07-19 13:23:01 +04:00
|
|
|
int fd_core;
|
2012-12-21 18:58:16 +04:00
|
|
|
CoreEntry *tcore;
|
2012-12-21 18:58:23 +04:00
|
|
|
|
2012-09-05 19:52:55 +04:00
|
|
|
thread_args[i].pid = current->threads[i].virt;
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2012-02-10 20:18:08 +04:00
|
|
|
/* skip self */
|
2012-12-21 18:58:23 +04:00
|
|
|
if (thread_args[i].pid == pid) {
|
|
|
|
task_args->t = thread_args + i;
|
|
|
|
tcore = core;
|
|
|
|
} else {
|
|
|
|
fd_core = open_image_ro(CR_FD_CORE, thread_args[i].pid);
|
|
|
|
if (fd_core < 0) {
|
|
|
|
pr_err("Can't open core data for thread %d\n",
|
|
|
|
thread_args[i].pid);
|
|
|
|
goto err;
|
|
|
|
}
|
2012-01-16 00:54:43 +04:00
|
|
|
|
2012-12-21 18:58:23 +04:00
|
|
|
ret = pb_read_one(fd_core, &tcore, PB_CORE);
|
|
|
|
close(fd_core);
|
2012-07-19 13:23:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-21 18:58:23 +04:00
|
|
|
if ((tcore->tc || tcore->ids) && thread_args[i].pid != pid) {
|
2012-07-19 13:23:01 +04:00
|
|
|
pr_err("Thread has optional fields present %d\n",
|
|
|
|
thread_args[i].pid);
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
pr_err("Can't read core data for thread %d\n",
|
|
|
|
thread_args[i].pid);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2012-10-30 10:04:37 +03:00
|
|
|
thread_args[i].ta = task_args;
|
2013-01-14 17:19:06 +04:00
|
|
|
thread_args[i].gpregs = *CORE_THREAD_ARCH_INFO(tcore)->gpregs;
|
|
|
|
thread_args[i].clear_tid_addr = CORE_THREAD_ARCH_INFO(tcore)->clear_tid_addr;
|
2013-01-09 18:48:00 +04:00
|
|
|
core_get_tls(tcore, &thread_args[i].tls);
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2012-12-21 18:58:16 +04:00
|
|
|
if (tcore->thread_core) {
|
2012-08-10 20:29:01 +04:00
|
|
|
thread_args[i].has_futex = true;
|
2012-12-21 18:58:16 +04:00
|
|
|
thread_args[i].futex_rla = tcore->thread_core->futex_rla;
|
|
|
|
thread_args[i].futex_rla_len = tcore->thread_core->futex_rla_len;
|
|
|
|
thread_args[i].has_blk_sigset = tcore->thread_core->has_blk_sigset;
|
|
|
|
thread_args[i].blk_sigset = tcore->thread_core->blk_sigset;
|
2012-10-17 00:23:25 +04:00
|
|
|
|
2012-12-21 18:58:16 +04:00
|
|
|
ret = prep_sched_info(&thread_args[i].sp, tcore->thread_core);
|
2012-10-17 00:23:25 +04:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2012-08-10 20:29:01 +04:00
|
|
|
}
|
|
|
|
|
2013-01-09 18:51:26 +04:00
|
|
|
if (sigreturn_prep_fpu_frame(&thread_args[i], core))
|
2012-12-21 17:35:43 +04:00
|
|
|
goto err;
|
|
|
|
|
2012-12-21 18:58:23 +04:00
|
|
|
if (thread_args[i].pid != pid)
|
|
|
|
core_entry__free_unpacked(tcore, NULL);
|
2011-11-17 00:59:08 +04:00
|
|
|
|
2012-02-10 20:18:08 +04:00
|
|
|
pr_info("Thread %4d stack %8p heap %8p rt_sigframe %8p\n",
|
2012-01-31 15:31:22 +04:00
|
|
|
i, thread_args[i].mem_zone.stack,
|
2011-11-16 18:19:24 +04:00
|
|
|
thread_args[i].mem_zone.heap,
|
|
|
|
thread_args[i].mem_zone.rt_sigframe);
|
2011-11-12 19:26:40 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-12-21 18:58:23 +04:00
|
|
|
task_args->t->blk_sigset = core->tc->blk_sigset;
|
|
|
|
task_args->t->has_blk_sigset = true;
|
2012-12-21 18:58:16 +04:00
|
|
|
|
2012-12-21 18:58:23 +04:00
|
|
|
/*
|
|
|
|
* Adjust stack.
|
|
|
|
*/
|
|
|
|
new_sp = RESTORE_ALIGN_STACK((long)task_args->t->mem_zone.stack,
|
|
|
|
sizeof(task_args->t->mem_zone.stack));
|
2012-12-21 18:58:16 +04:00
|
|
|
|
|
|
|
/* No longer need it */
|
|
|
|
core_entry__free_unpacked(core, NULL);
|
|
|
|
|
|
|
|
ret = prepare_itimers(pid, task_args);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = prepare_creds(pid, task_args);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
ret = prepare_mm(pid, task_args);
|
|
|
|
if (ret < 0)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
mutex_init(&task_args->rst_lock);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now prepare run-time data for threads restore.
|
|
|
|
*/
|
|
|
|
task_args->nr_threads = current->nr_threads;
|
|
|
|
task_args->clone_restore_fn = (void *)restore_thread_exec_start;
|
|
|
|
task_args->thread_args = thread_args;
|
|
|
|
|
2012-03-16 17:24:00 +04:00
|
|
|
close_image_dir();
|
|
|
|
|
2012-12-25 22:43:14 +04:00
|
|
|
__gcov_flush();
|
|
|
|
|
2011-11-16 18:19:24 +04:00
|
|
|
pr_info("task_args: %p\n"
|
|
|
|
"task_args->pid: %d\n"
|
|
|
|
"task_args->nr_threads: %d\n"
|
|
|
|
"task_args->clone_restore_fn: %p\n"
|
|
|
|
"task_args->thread_args: %p\n",
|
2012-12-21 18:58:23 +04:00
|
|
|
task_args, task_args->t->pid,
|
2012-03-02 19:30:23 +04:00
|
|
|
task_args->nr_threads,
|
|
|
|
task_args->clone_restore_fn,
|
2011-11-16 18:19:24 +04:00
|
|
|
task_args->thread_args);
|
|
|
|
|
2011-10-26 17:35:50 +04:00
|
|
|
/*
|
2011-11-12 19:26:40 +04:00
|
|
|
* An indirect call to task_restore, note it never resturns
|
2011-10-26 17:35:50 +04:00
|
|
|
* and restoreing core is extremely destructive.
|
|
|
|
*/
|
2013-01-09 17:39:23 +04:00
|
|
|
|
|
|
|
JUMP_TO_RESTORER_BLOB(new_sp, restore_task_exec_start, task_args);
|
2011-10-26 11:16:00 +04:00
|
|
|
|
2011-10-26 22:50:46 +04:00
|
|
|
err:
|
2013-03-01 20:11:51 +04:00
|
|
|
free_mappings(&self_vmas);
|
2011-11-12 19:26:40 +04:00
|
|
|
|
2011-10-26 17:35:50 +04:00
|
|
|
/* Just to be sure */
|
2012-01-17 10:56:28 +04:00
|
|
|
exit(1);
|
2012-03-21 19:37:00 +04:00
|
|
|
return -1;
|
2011-10-24 22:23:06 +04:00
|
|
|
}
|