Skip to content

Commit

Permalink
dump: preserve the dumpable flag on criu dump/restore
Browse files Browse the repository at this point in the history
Preserve the dumpable flag, which affects whether a core dump will be
generated, but also affects the ownership of the virtual files under
/proc/$pid after restoring a process.

Tested: Restored a process with a criu including this patch and looked
at /proc/$pid to confirm that the virtual files were no longer all owned
by root:root.

zdtm tests pass except for cow01 which seems to be broken.
(see https://bugzilla.openvz.org/show_bug.cgi?id=2967 for details.)

This patch fixes https://bugzilla.openvz.org/show_bug.cgi?id=2968

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Change-Id: I8c386508448a84368a86666f2d7500b252a78bbf
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
  • Loading branch information
filbranden authored and xemul committed May 13, 2014
1 parent 1a1b501 commit d5bb7e9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cr-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,9 @@ static int dump_task_mm(pid_t pid, const struct proc_pid_stat *stat,

mme.mm_brk = misc->brk;

mme.dumpable = misc->dumpable;
mme.has_dumpable = true;

mme.n_mm_saved_auxv = AT_VECTOR_SIZE;
mme.mm_saved_auxv = xmalloc(pb_repeated_size(&mme, mm_saved_auxv));
if (!mme.mm_saved_auxv)
Expand Down
2 changes: 2 additions & 0 deletions include/parasite.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ struct parasite_dump_misc {
u32 umask;

struct parasite_dump_thread ti;

int dumpable;
};

#define PARASITE_MAX_GROUPS (PAGE_SIZE / sizeof(unsigned int) - 2 * sizeof(unsigned))
Expand Down
6 changes: 6 additions & 0 deletions include/prctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#ifndef PR_SET_SECUREBITS
# define PR_SET_SECUREBITS 28
#endif
#ifndef PR_GET_DUMPABLE
# define PR_GET_DUMPABLE 3
#endif
#ifndef PR_SET_DUMPABLE
# define PR_SET_DUMPABLE 4
#endif

#ifndef PR_SET_MM
#define PR_SET_MM 35
Expand Down
1 change: 1 addition & 0 deletions pie/parasite.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ static int dump_misc(struct parasite_dump_misc *args)
args->pgid = sys_getpgid(0);
args->umask = sys_umask(0);
sys_umask(args->umask); /* never fails */
args->dumpable = sys_prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);

return dump_thread_common(&args->ti);
}
Expand Down
21 changes: 21 additions & 0 deletions pie/restorer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "restorer.h"

#include "protobuf/creds.pb-c.h"
#include "protobuf/mm.pb-c.h"

#include "asm/restorer.h"

Expand Down Expand Up @@ -187,6 +188,21 @@ static int restore_creds(CredsEntry *ce)
return 0;
}

static int restore_dumpable_flag(MmEntry *mme)
{
int ret;

if (mme->has_dumpable) {
ret = sys_prctl(PR_SET_DUMPABLE, mme->dumpable, 0, 0, 0);
if (ret) {
pr_err("Unable to set PR_SET_DUMPABLE: %d\n", ret);
return -1;
}
}

return 0;
}

static void restore_sched_info(struct rst_sched_param *p)
{
struct sched_param parm;
Expand Down Expand Up @@ -295,6 +311,10 @@ long __export_restore_thread(struct thread_restore_args *args)
if (ret)
goto core_restore_end;

ret = restore_dumpable_flag(&args->ta->mm);
if (ret)
goto core_restore_end;

pr_info("%ld: Restored\n", sys_gettid());

restore_finish_stage(CR_STATE_RESTORE);
Expand Down Expand Up @@ -918,6 +938,7 @@ long __export_restore_task(struct task_restore_args *args)
*/

ret = restore_creds(&args->creds);
ret = ret || restore_dumpable_flag(&args->mm);

futex_set_and_wake(&thread_inprogress, args->nr_threads);

Expand Down
2 changes: 2 additions & 0 deletions protobuf/mm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ message mm_entry {
repeated uint64 mm_saved_auxv = 13;

repeated vma_entry vmas = 14;

optional int32 dumpable = 15;
}

0 comments on commit d5bb7e9

Please sign in to comment.