Skip to content

Commit f091422

Browse files
mihalicynrst0git
authored andcommitted
criu/pie/restorer: add madvise(MADV_GUARD_INSTALL) restore logic
Signed-off-by: Alexander Mikhalitsyn <[email protected]>
1 parent 556d1c4 commit f091422

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

criu/pie/restorer.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <compel/plugins/std/syscall.h>
2929
#include <compel/plugins/std/log.h>
3030
#include <compel/ksigset.h>
31+
#include "mman.h"
3132
#include "signal.h"
3233
#include "prctl.h"
3334
#include "criu-log.h"
@@ -1665,6 +1666,30 @@ static int restore_membarrier_registrations(int mask)
16651666
return ret;
16661667
}
16671668

1669+
static int restore_madv_guard_regions(struct task_restore_args *args)
1670+
{
1671+
int i, ret;
1672+
1673+
for (i = 0; i < args->vmas_n; i++) {
1674+
VmaEntry *vma_entry = args->vmas + i;
1675+
size_t len;
1676+
1677+
if (!vma_entry_is(vma_entry, VMA_AREA_GUARD))
1678+
continue;
1679+
1680+
len = vma_entry->end - vma_entry->start;
1681+
ret = sys_madvise(vma_entry->start, len, MADV_GUARD_INSTALL);
1682+
if (ret) {
1683+
pr_err("madvise(%" PRIx64 ", %zu, MADV_GUARD_INSTALL) "
1684+
"failed with %d\n",
1685+
vma_entry->start, len, ret);
1686+
return -1;
1687+
}
1688+
}
1689+
1690+
return 0;
1691+
}
1692+
16681693
/*
16691694
* The main routine to restore task via sigreturn.
16701695
* This one is very special, we never return there
@@ -1972,6 +1997,13 @@ __visible long __export_restore_task(struct task_restore_args *args)
19721997
}
19731998
}
19741999

2000+
/*
2001+
* Restore madvise(MADV_GUARD_INSTALL)
2002+
*/
2003+
ret = restore_madv_guard_regions(args);
2004+
if (ret)
2005+
goto core_restore_end;
2006+
19752007
/*
19762008
* Tune up the task fields.
19772009
*/

0 commit comments

Comments
 (0)