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