<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Sep 23, 2019 at 3:39 PM Pavel Emelianov <<a href="mailto:xemul@virtuozzo.com">xemul@virtuozzo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
On 20.09.2019 11:15, Harshavardhan Unnibhavi wrote:<br>
> This commit restores anonymized images containing their file paths<br>
> maximized.<br>
> <br>
> This commit introduces the following:<br>
> - anon option for the restore action.<br>
> <br>
> This commit modifies the following:<br>
> - pretend anonymized files in question are opened.<br>
> <br>
> Resolve Issue #360.<br>
> <br>
> Signed-off-by: Harshavardhan Unnibhavi <<a href="mailto:hvubfoss@gmail.com" target="_blank">hvubfoss@gmail.com</a>><br>
> ---<br>
> criu/config.c | 5 +++++<br>
> criu/cr-restore.c | 5 +++++<br>
> criu/files-reg.c | 12 ++++++++++--<br>
> criu/files.c | 4 ++--<br>
> criu/include/cr_options.h | 1 +<br>
> criu/include/restorer.h | 1 +<br>
> criu/pie/restorer.c | 4 ++--<br>
> 7 files changed, 26 insertions(+), 6 deletions(-)<br>
> <br>
> diff --git a/criu/config.c b/criu/config.c<br>
> index c9332203..7881f70d 100644<br>
> --- a/criu/config.c<br>
> +++ b/criu/config.c<br>
> @@ -276,6 +276,7 @@ void init_opts(void)<br>
> opts.empty_ns = 0;<br>
> opts.status_fd = -1;<br>
> opts.log_level = DEFAULT_LOGLEVEL;<br>
> + opts.anonymize = false;<br>
> }<br>
> <br>
> bool deprecated_ok(char *what)<br>
> @@ -455,6 +456,7 @@ int parse_options(int argc, char **argv, bool *usage_error,<br>
> { "root", required_argument, 0, 'r' },<br>
> { USK_EXT_PARAM, optional_argument, 0, 'x' },<br>
> { "help", no_argument, 0, 'h' },<br>
> + { "anon", no_argument, 0, 'a' },<br>
> BOOL_OPT(SK_EST_PARAM, &opts.tcp_established_ok),<br>
> { "close", required_argument, 0, 1043 },<br>
> BOOL_OPT("log-pid", &opts.log_file_per_pid),<br>
> @@ -575,6 +577,9 @@ int parse_options(int argc, char **argv, bool *usage_error,<br>
> continue;<br>
> <br>
> switch (opt) {<br>
> + case 'a':<br>
> + opts.anonymize = true;<br>
> + break;<br>
> case 's':<br>
> opts.final_state = TASK_STOPPED;<br>
> break;<br>
> diff --git a/criu/cr-restore.c b/criu/cr-restore.c<br>
> index de0b2cb4..05896ab0 100644<br>
> --- a/criu/cr-restore.c<br>
> +++ b/criu/cr-restore.c<br>
> @@ -882,6 +882,9 @@ static int restore_one_alive_task(int pid, CoreEntry *core)<br>
> <br>
> memzero(ta, args_len);<br>
> <br>
> + if(opts.anonymize)<br>
> + ta->anonymize = true;<br>
> +<br>
> if (prepare_fds(current))<br>
> return -1;<br>
> <br>
> @@ -2268,6 +2271,8 @@ skip_ns_bouncing:<br>
> goto out_kill;<br>
> <br>
> pr_info("Restore finished successfully. Resuming tasks.\n");<br>
> + if(opts.anonymize)<br>
> + return 0;<br>
<br>
Presumably you should abort the stage so that "restored" tasks die?<br></blockquote><div>How would I do this? Using sigreturn( rst_sigreturn(new_sp, rt_sigframe) ) or a sys_exit()? </div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Also, a message about "aborting restore due to --anon given" is also needed.<br></blockquote><div>Sure. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> __restore_switch_stage(CR_STATE_COMPLETE);<br>
> <br>
> if (ret == 0)<br>
> diff --git a/criu/files-reg.c b/criu/files-reg.c<br>
> index 1b51d108..a3a2396d 100644<br>
> --- a/criu/files-reg.c<br>
> +++ b/criu/files-reg.c<br>
> @@ -1745,14 +1745,14 @@ ext:<br>
> return -1;<br>
> }<br>
> <br>
> - if (rfi->rfe->has_size && (st.st_size != rfi->rfe->size)) {<br>
> + if (rfi->rfe->has_size && (st.st_size != rfi->rfe->size) && (!opts.anonymize)) {<br>
> pr_err("File %s has bad size %"PRIu64" (expect %"PRIu64")\n",<br>
> rfi->path, st.st_size,<br>
> rfi->rfe->size);<br>
> return -1;<br>
> }<br>
> <br>
> - if (rfi->rfe->has_mode && (st.st_mode != rfi->rfe->mode)) {<br>
> + if (rfi->rfe->has_mode && (st.st_mode != rfi->rfe->mode) && (!opts.anonymize)) {<br>
> pr_err("File %s has bad mode 0%o (expect 0%o)\n",<br>
> rfi->path, (int)st.st_mode,<br>
> rfi->rfe->mode);<br>
<br>
The whole block with stat()-ing and size/mode checking can be skipped if opts.anonymize.<br>
<br>
> @@ -1793,6 +1793,14 @@ int do_open_reg_noseek_flags(int ns_root_fd, struct reg_file_info *rfi, void *ar<br>
> flags &= ~O_TMPFILE;<br>
> <br>
> fd = openat(ns_root_fd, rfi->path, flags);<br>
> + if(opts.anonymize){<br>
<br>
Plz, check the patch with <a href="http://checkpatch.pl" rel="noreferrer" target="_blank">checkpatch.pl</a> for coding style.<br>
<br>
> + fd = openat(ns_root_fd, "/dev/zero", flags);<br>
<br>
Erm... The original fd has been opened, hasn't it? I think it's better to fix<br>
the do_open_reg_noseek() to open /dev/zero in case of opts.anonymize, not this helper.</blockquote><div>Yes this makes more sense, I will change it. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> + if(fd < 0){<br>
> + pr_perror("Unable to create a fake file descriptor");<br>
> + return fd;<br>
> + }<br>
> + pr_info("Restoring anonymized file paths.\n");<br>
> + }<br>
> if (fd < 0) {<br>
> pr_perror("Can't open file %s on restore", rfi->path);<br>
> return fd;<br>
> diff --git a/criu/files.c b/criu/files.c<br>
> index ffdaa459..a7e76247 100644<br>
> --- a/criu/files.c<br>
> +++ b/criu/files.c<br>
> @@ -1313,7 +1313,7 @@ static int fchroot(int fd)<br>
> * it using fchdir()<br>
> */<br>
> <br>
> - if (fchdir(fd) < 0) {<br>
> + if (fchdir(fd) < 0 && !(opts.anonymize)) {<br>
> pr_perror("Can't chdir to proc");<br>
> return -1;<br>
> }<br>
> @@ -1356,7 +1356,7 @@ int restore_fs(struct pstree_item *me)<br>
> }<br>
> <br>
> ret = fchdir(dd_cwd);<br>
> - if (ret < 0) {<br>
> + if (ret < 0 && !(opts.anonymize)) {<br>
> pr_perror("Can't change cwd");<br>
> goto out;<br>
> }<br>
> diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h<br>
> index 5cbc56f9..516624a3 100644<br>
> --- a/criu/include/cr_options.h<br>
> +++ b/criu/include/cr_options.h<br>
> @@ -112,6 +112,7 @@ struct cr_options {<br>
> int enable_external_masters;<br>
> bool aufs; /* auto-detected, not via cli */<br>
> bool overlayfs;<br>
> + bool anonymize;<br>
> #ifdef CONFIG_BINFMT_MISC_VIRTUALIZED<br>
> bool has_binfmt_misc; /* auto-detected */<br>
> #endif<br>
> diff --git a/criu/include/restorer.h b/criu/include/restorer.h<br>
> index b93807f5..203b1153 100644<br>
> --- a/criu/include/restorer.h<br>
> +++ b/criu/include/restorer.h<br>
> @@ -136,6 +136,7 @@ struct task_restore_args {<br>
> <br>
> int uffd;<br>
> bool has_thp_enabled;<br>
> + bool anonymize;<br>
> <br>
> /* threads restoration */<br>
> int nr_threads; /* number of threads */<br>
> diff --git a/criu/pie/restorer.c b/criu/pie/restorer.c<br>
> index 390c0e1a..87c8ed4a 100644<br>
> --- a/criu/pie/restorer.c<br>
> +++ b/criu/pie/restorer.c<br>
> @@ -1719,12 +1719,12 @@ long __export_restore_task(struct task_restore_args *args)<br>
> */<br>
> ret |= restore_self_exe_late(args);<br>
> } else {<br>
> - if (ret)<br>
> + if (ret && !(args->anonymize))<br>
> pr_err("sys_prctl(PR_SET_MM, PR_SET_MM_MAP) failed with %d\n", (int)ret);<br>
> sys_close(args->fd_exe_link);<br>
> }<br>
> <br>
> - if (ret)<br>
> + if (ret && !(args->anonymize))<br>
> goto core_restore_end;<br>
> <br>
> /* SELinux (1) process context needs to be set before creating threads. */<br>
> <br>
</blockquote></div></div>