Skip to content

Commit 7da7565

Browse files
svilenkovavagin
authored andcommitted
x86/criu: shstk: restore SHSTK via premap loops
* call shstk_vma_restore() for VMA_AREA_SHSTK in both premap loops * delete map/copy/unmap from shstk_restore() and keep token setup + finalize * before the loop naturally stopped at cet->ssp-8, so a -8 nudge is required here Signed-off-by: Igor Svilenkov Bozic <svilenkov@gmail.com> Co-Authored-By: Andrei Vagin <avagin@gmail.com>
1 parent 0dfc85d commit 7da7565

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

criu/arch/x86/include/asm/shstk.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,11 @@ static always_inline int shstk_vma_restore(unsigned long *shstk_data, unsigned l
201201
*/
202202
static always_inline int shstk_restore(struct rst_shstk_info *cet)
203203
{
204-
unsigned long *shstk_data = (unsigned long *)cet->premmaped_addr;
205-
unsigned long ssp = cet->vma_start + cet->vma_size - 8;
206-
unsigned long shstk_top = cet->vma_size / 8 - 1;
207-
unsigned long val;
208-
long ret;
204+
unsigned long ssp, val;
209205

210206
if (!(cet->cet & ARCH_SHSTK_SHSTK))
211207
return 0;
212208

213-
if (shstk_map(cet->vma_start, cet->vma_size))
214-
return -1;
215-
216-
/*
217-
* Switch shadow stack from temporary location to the actual task's
218-
* shadow stack VMA
219-
*/
220-
shstk_switch_ssp(ssp);
221-
222-
/* restore shadow stack contents */
223-
for (; ssp >= cet->ssp; ssp -= 8, shstk_top--)
224-
wrssq(ssp, shstk_data[shstk_top]);
225-
226209
/*
227210
* Add tokens for sigreturn frame and for switch of the shadow stack.
228211
* The sigreturn token will be checked by the kernel during
@@ -232,6 +215,7 @@ static always_inline int shstk_restore(struct rst_shstk_info *cet)
232215
*/
233216

234217
/* token for sigreturn frame */
218+
ssp = cet->ssp - 8;
235219
val = ALIGN_DOWN(cet->ssp, 8) | SHSTK_DATA_BIT;
236220
wrssq(ssp, val);
237221

@@ -243,12 +227,6 @@ static always_inline int shstk_restore(struct rst_shstk_info *cet)
243227
/* reset shadow stack pointer to the proper location */
244228
shstk_switch_ssp(ssp);
245229

246-
ret = sys_munmap(shstk_data, cet->vma_size + PAGE_SIZE);
247-
if (ret < 0) {
248-
pr_err("Failed to unmap premmaped shadow stack\n");
249-
return ret;
250-
}
251-
252230
return shstk_finalize();
253231
}
254232
#define arch_shstk_restore shstk_restore

criu/pie/restorer.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,12 +1811,11 @@ __visible long __export_restore_task(struct task_restore_args *args)
18111811
if (vma_entry->start > vma_entry->shmid)
18121812
break;
18131813

1814-
/*
1815-
* shadow stack VMAs cannot be remapped, they must be
1816-
* recreated with map_shadow_stack system call
1817-
*/
1818-
if (vma_entry_is(vma_entry, VMA_AREA_SHSTK))
1814+
if (vma_entry_is(vma_entry, VMA_AREA_SHSTK)) {
1815+
if (shstk_vma_restore((void *)vma_premmaped_start(vma_entry), vma_entry->start, vma_entry_len(vma_entry)))
1816+
goto core_restore_end;
18191817
continue;
1818+
}
18201819

18211820
if (vma_remap(vma_entry, args->uffd))
18221821
goto core_restore_end;
@@ -1835,12 +1834,11 @@ __visible long __export_restore_task(struct task_restore_args *args)
18351834
if (vma_entry->start < vma_entry->shmid)
18361835
break;
18371836

1838-
/*
1839-
* shadow stack VMAs cannot be remapped, they must be
1840-
* recreated with map_shadow_stack system call
1841-
*/
1842-
if (vma_entry_is(vma_entry, VMA_AREA_SHSTK))
1837+
if (vma_entry_is(vma_entry, VMA_AREA_SHSTK)) {
1838+
if (shstk_vma_restore((void *)vma_premmaped_start(vma_entry), vma_entry->start, vma_entry_len(vma_entry)))
1839+
goto core_restore_end;
18431840
continue;
1841+
}
18441842

18451843
if (vma_remap(vma_entry, args->uffd))
18461844
goto core_restore_end;

0 commit comments

Comments
 (0)