diff --git a/cr-restore.c b/cr-restore.c index cec310460..a47580266 100644 --- a/cr-restore.c +++ b/cr-restore.c @@ -2893,6 +2893,8 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) task_args->premmapped_addr = (unsigned long)rsti(current)->premmapped_addr; task_args->premmapped_len = rsti(current)->premmapped_len; + task_args->task_size = kdat.task_size; + #define remap_array(name, nr, cpos) do { \ task_args->name##_n = nr; \ task_args->name = rst_mem_remap_ptr(cpos, RM_PRIVATE); \ diff --git a/include/restorer.h b/include/restorer.h index 97a012c0f..56b9938a0 100644 --- a/include/restorer.h +++ b/include/restorer.h @@ -139,6 +139,7 @@ struct task_restore_args { unsigned int zombies_n; /* * * * * * * * * * * * * * * * * * * * */ + unsigned long task_size; unsigned long premmapped_addr; unsigned long premmapped_len; rt_sigaction_t sigchld_act; diff --git a/pie/restorer.c b/pie/restorer.c index d84a5c075..3e582cc2c 100644 --- a/pie/restorer.c +++ b/pie/restorer.c @@ -727,16 +727,17 @@ void __export_unmap(void) * and arguments and the one with private vmas of the tasks we restore * (a.k.a. premmaped area): * - * 0 TASK_SIZE + * 0 task_size * +----+====+----+====+---+ * * Thus to unmap old memory we have to do 3 unmaps: * [ 0 -- 1st area start ] * [ 1st end -- 2nd start ] - * [ 2nd start -- TASK_SIZE ] + * [ 2nd start -- task_size ] */ static int unmap_old_vmas(void *premmapped_addr, unsigned long premmapped_len, - void *bootstrap_start, unsigned long bootstrap_len) + void *bootstrap_start, unsigned long bootstrap_len, + unsigned long task_size) { unsigned long s1, s2; void *p1, *p2; @@ -766,10 +767,10 @@ static int unmap_old_vmas(void *premmapped_addr, unsigned long premmapped_len, return -1; } - ret = sys_munmap(p2 + s2, (void *) TASK_SIZE - (p2 + s2)); + ret = sys_munmap(p2 + s2, task_size - (unsigned long)(p2 + s2)); if (ret) { pr_err("Unable to unmap (%p-%p): %d\n", - p2 + s2, (void *)TASK_SIZE, ret); + p2 + s2, (void *)task_size, ret); return -1; } @@ -870,7 +871,7 @@ long __export_restore_task(struct task_restore_args *args) goto core_restore_end; if (unmap_old_vmas((void *)args->premmapped_addr, args->premmapped_len, - bootstrap_start, bootstrap_len)) + bootstrap_start, bootstrap_len, args->task_size)) goto core_restore_end; /* Shift private vma-s to the left */ @@ -880,7 +881,7 @@ long __export_restore_task(struct task_restore_args *args) if (!vma_entry_is_private(vma_entry)) continue; - if (vma_entry->end >= TASK_SIZE) + if (vma_entry->end >= args->task_size) continue; if (vma_entry->start > vma_entry->shmid) @@ -898,7 +899,7 @@ long __export_restore_task(struct task_restore_args *args) if (!vma_entry_is_private(vma_entry)) continue; - if (vma_entry->start > TASK_SIZE) + if (vma_entry->start > args->task_size) continue; if (vma_entry->start < vma_entry->shmid)