<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 15, 2014 at 2:59 AM, Andrew Vagin <span dir="ltr">&lt;<a href="mailto:avagin@parallels.com" target="_blank">avagin@parallels.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="">On Fri, Aug 15, 2014 at 12:22:15PM +0400, Andrew Vagin wrote:<br>


&gt; Hi Sophie,<br>
&gt;<br>
&gt; On Wed, Aug 13, 2014 at 07:47:49PM -0700, Sophie Blee-Goldman wrote:<br>
&gt; &gt; Needed for future user namespace support. Capabilities will have to be<br>
&gt; &gt; dumped from the parasite, ie from inside the namespace since there is no<br>
&gt; &gt; obvious way to &#39;translate&#39; capabilities from the global namespace (unlike<br>
&gt; &gt; with uids and gids, where the id mappings can be used for translation).<br>
&gt;<br>
&gt; &quot;capabilities&quot; are not translated between namespaces. They can exist<br>
&gt; only in one userns, where a process lives. If a process is created in a<br>
&gt; new userns, it gets a full set of capabilities in this userns, and<br>
&gt; loses all caps in a parent userns.<br>
&gt;<br>
&gt; So if capabilities are not shown in /proc/pid/stat, we have no way to<br>
&gt; get it except of using parasite code.<br></div></blockquote><div><br></div><div>Yes sorry, my explanation was poorly phrased but that is what I meant.</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="">
&gt; The patch looks mostly good, but I have a few comments below.<br>
<br>
</div>It&#39;s obvious how to fix the last comment. All other comments are cosmetic.<br></blockquote><div><br></div><div>This patch needs to be applied on top of <a href="http://lists.openvz.org/pipermail/criu/2014-August/015572.html">[PATCH 2/4] Move function definition</a>,</div>

<div>which should take care of the compiler error.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">


<br>
Acked-by: Andrew Vagin &lt;<a href="mailto:avagin@parallels.com">avagin@parallels.com</a>&gt;<br>
<div><div class="h5"><br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt; Signed-off-by: Sophie Blee-Goldman &lt;<a href="mailto:ableegoldman@google.com">ableegoldman@google.com</a>&gt;<br>
&gt; &gt; ---<br>
&gt; &gt;  arch/arm/syscall.def        |  1 +<br>
&gt; &gt;  arch/x86/syscall-x86-64.def |  1 +<br>
&gt; &gt;  cr-dump.c                   | 17 +++--------------<br>
&gt; &gt;  include/parasite.h          | 15 +++++++++++++--<br>
&gt; &gt;  include/prctl.h             |  3 +++<br>
&gt; &gt;  kerndat.c                   |  2 ++<br>
&gt; &gt;  parasite-syscall.c          | 11 +++++++++++<br>
&gt; &gt;  pie/parasite.c              | 36 +++++++++++++++++++++++++++++++++++-<br>
&gt; &gt;  8 files changed, 69 insertions(+), 17 deletions(-)<br>
&gt; &gt;<br>
&gt; &gt; diff --git a/arch/arm/syscall.def b/arch/arm/syscall.def<br>
&gt; &gt; index c539e3e..02eaa65 100644<br>
&gt; &gt; --- a/arch/arm/syscall.def<br>
&gt; &gt; +++ b/arch/arm/syscall.def<br>
&gt; &gt; @@ -59,6 +59,7 @@ getpgid                           155     132     (pid_t pid)<br>
&gt; &gt;  setfsuid                   151     138     (int fsuid)<br>
&gt; &gt;  setfsgid                   152     139     (int fsgid)<br>
&gt; &gt;  getsid                             156     147     (void)<br>
&gt; &gt; +capget                             90      184     (struct cap_header *h, struct cap_data *d)<br>
&gt; &gt;  capset                             91      185     (struct cap_header *h, struct cap_data *d)<br>
&gt; &gt;  rt_sigqueueinfo                    138     178     (pid_t pid, int sig, siginfo_t *info)<br>
&gt; &gt;  setpriority                        140     97      (int which, int who, int nice)<br>
&gt; &gt; diff --git a/arch/x86/syscall-x86-64.def b/arch/x86/syscall-x86-64.def<br>
&gt; &gt; index 878cf79..ec86dfe 100644<br>
&gt; &gt; --- a/arch/x86/syscall-x86-64.def<br>
&gt; &gt; +++ b/arch/x86/syscall-x86-64.def<br>
&gt; &gt; @@ -59,6 +59,7 @@ __NR_getpgid              121             sys_getpgid             (pid_t pid)<br>
&gt; &gt;  __NR_setfsuid              122             sys_setfsuid            (int fsuid)<br>
&gt; &gt;  __NR_setfsgid              123             sys_setfsgid            (int fsgid)<br>
&gt; &gt;  __NR_getsid                124             sys_getsid              (void)<br>
&gt; &gt; +__NR_capget                125             sys_capget              (struct cap_header *h, struct cap_data *d)<br>
&gt; &gt;  __NR_capset                126             sys_capset              (struct cap_header *h, struct cap_data *d)<br>
&gt; &gt;  __NR_rt_sigqueueinfo       129             sys_rt_sigqueueinfo     (pid_t pid, int sig, siginfo_t *info)<br>
&gt; &gt;  __NR_sigaltstack   131             sys_sigaltstack         (const void *uss, void *uoss)<br>
&gt; &gt; diff --git a/cr-dump.c b/cr-dump.c<br>
&gt; &gt; index 1700d9d..f52af65 100644<br>
&gt; &gt; --- a/cr-dump.c<br>
&gt; &gt; +++ b/cr-dump.c<br>
&gt; &gt; @@ -502,10 +502,6 @@ static int dump_task_creds(struct parasite_ctl *ctl,<br>
&gt; &gt;  {<br>
&gt; &gt;     CredsEntry ce = CREDS_ENTRY__INIT;<br>
&gt; &gt;<br>
&gt; &gt; -   pr_info(&quot;\n&quot;);<br>
&gt; &gt; -   pr_info(&quot;Dumping creds for %d)\n&quot;, ctl-&gt;pid.real);<br>
&gt; &gt; -   pr_info(&quot;----------------------------------------\n&quot;);<br>
&gt; &gt; -<br>
&gt; &gt;     ce.uid   = cr-&gt;uids[0];<br>
&gt; &gt;     ce.gid   = cr-&gt;gids[0];<br>
&gt; &gt;     ce.euid  = cr-&gt;uids[1];<br>
&gt; &gt; @@ -515,16 +511,9 @@ static int dump_task_creds(struct parasite_ctl *ctl,<br>
&gt; &gt;     ce.fsuid = cr-&gt;uids[3];<br>
&gt; &gt;     ce.fsgid = cr-&gt;gids[3];<br>
&gt; &gt;<br>
&gt; &gt; -   BUILD_BUG_ON(CR_CAP_SIZE != PROC_CAP_SIZE);<br>
&gt; &gt; -<br>
&gt; &gt; -   ce.n_cap_inh = CR_CAP_SIZE;<br>
&gt; &gt; -   ce.cap_inh = cr-&gt;cap_inh;<br>
&gt; &gt; -   ce.n_cap_prm = CR_CAP_SIZE;<br>
&gt; &gt; -   ce.cap_prm = cr-&gt;cap_prm;<br>
&gt; &gt; -   ce.n_cap_eff = CR_CAP_SIZE;<br>
&gt; &gt; -   ce.cap_eff = cr-&gt;cap_eff;<br>
&gt; &gt; -   ce.n_cap_bnd = CR_CAP_SIZE;<br>
&gt; &gt; -   ce.cap_bnd = cr-&gt;cap_bnd;<br>
&gt; &gt; +   pr_info(&quot;\n&quot;);<br>
&gt; &gt; +   pr_info(&quot;Dumping creds for %d)\n&quot;, ctl-&gt;pid.real);<br>
&gt; &gt; +   pr_info(&quot;----------------------------------------\n&quot;);<br>
&gt; &gt;<br>
&gt; &gt;     if (parasite_dump_creds(ctl, &amp;ce) &lt; 0)<br>
&gt; &gt;             return -1;<br>
&gt; &gt; diff --git a/include/parasite.h b/include/parasite.h<br>
&gt; &gt; index af81d85..d6d243d 100644<br>
&gt; &gt; --- a/include/parasite.h<br>
&gt; &gt; +++ b/include/parasite.h<br>
&gt; &gt; @@ -166,10 +166,21 @@ struct parasite_dump_misc {<br>
&gt; &gt;   * Calculate how long we can make the groups array in parasite_dump_creds<br>
&gt; &gt;   * and still fit the struct in one page<br>
&gt; &gt;   */<br>
&gt; &gt; -#define PARASITE_MAX_GROUPS        \<br>
&gt; &gt; -   ((PAGE_SIZE - 2 * sizeof(unsigned int)) / sizeof(unsigned int))<br>
&gt; &gt; +#define PARASITE_MAX_GROUPS                                                        \<br>
&gt; &gt; +   (PAGE_SIZE                                                              \<br>
&gt; &gt; +    - sizeof(unsigned int)                 /* cap_last_cap */              \<br>
&gt; &gt; +    - 4 * CR_CAP_SIZE * sizeof(u32)        /* cap_{inh,prm,eff,bnd} */     \<br>
&gt; &gt; +    - 2 * sizeof(unsigned int)             /* secbits, ngroups*/           \<br>
&gt; &gt; +   ) / sizeof(unsigned int)                /* groups */<br>
&gt; &gt;<br>
&gt; &gt;  struct parasite_dump_creds {<br>
&gt; &gt; +   unsigned int            cap_last_cap;<br>
&gt; &gt; +<br>
&gt; &gt; +   u32                     cap_inh[CR_CAP_SIZE];<br>
&gt; &gt; +   u32                     cap_prm[CR_CAP_SIZE];<br>
&gt; &gt; +   u32                     cap_eff[CR_CAP_SIZE];<br>
&gt; &gt; +   u32                     cap_bnd[CR_CAP_SIZE];<br>
&gt; &gt; +<br>
&gt; &gt;     unsigned int            secbits;<br>
&gt; &gt;     unsigned int            ngroups;<br>
&gt; &gt;     unsigned int            groups[PARASITE_MAX_GROUPS];<br>
&gt;<br>
&gt; Maybe we may rewrite this code like this:<br>
&gt;<br>
&gt; struct parasite_dump_creds {<br>
&gt;         unsigned int            cap_last_cap;<br>
&gt;<br>
&gt;         u32                     cap_inh[CR_CAP_SIZE];<br>
&gt;         u32                     cap_prm[CR_CAP_SIZE];<br>
&gt;         u32                     cap_eff[CR_CAP_SIZE];<br>
&gt;         u32                     cap_bnd[CR_CAP_SIZE];<br>
&gt;<br>
&gt;         unsigned int            secbits;<br>
&gt;         unsigned int            ngroups;<br>
&gt;         unsigned int            groups[0];<br>
&gt; };<br>
&gt;<br>
&gt; #define PARASITE_MAX_GROUPS (PAGE_SIZE - sizeof(struct parasite_dump_creds)) /<br>
&gt;                               sizeof(unsigned int)<br>
&gt;<br>
&gt; &gt; diff --git a/include/prctl.h b/include/prctl.h<br>
&gt; &gt; index b815b96..70db7b9 100644<br>
&gt; &gt; --- a/include/prctl.h<br>
&gt; &gt; +++ b/include/prctl.h<br>
&gt; &gt; @@ -7,6 +7,9 @@<br>
&gt; &gt;  #ifndef PR_GET_NAME<br>
&gt; &gt;  # define PR_GET_NAME               16<br>
&gt; &gt;  #endif<br>
&gt; &gt; +#ifndef PR_CAPBSET_READ<br>
&gt; &gt; +# define PR_CAPBSET_READ   23<br>
&gt; &gt; +#endif<br>
&gt; &gt;  #ifndef PR_CAPBSET_DROP<br>
&gt; &gt;  # define PR_CAPBSET_DROP   24<br>
&gt; &gt;  #endif<br>
&gt; &gt; diff --git a/kerndat.c b/kerndat.c<br>
&gt; &gt; index 0fee20b..3c87f6c 100644<br>
&gt; &gt; --- a/kerndat.c<br>
&gt; &gt; +++ b/kerndat.c<br>
&gt; &gt; @@ -229,6 +229,8 @@ int kerndat_init(void)<br>
&gt; &gt;             ret = kerndat_get_dirty_track();<br>
&gt; &gt;     if (!ret)<br>
&gt; &gt;             ret = init_zero_page_pfn();<br>
&gt; &gt; +   if (!ret)<br>
&gt; &gt; +           ret = get_last_cap();<br>
&gt;<br>
&gt;<br>
&gt; &gt;C       kerndat.o<br>
&gt; kerndat.c: In function ‘kerndat_init’:<br>
&gt; kerndat.c:221:3: error: implicit declaration of function ‘get_last_cap’<br>
&gt; [-Werror=implicit-function-declaration]<br>
&gt;    ret = get_last_cap();<br>
&gt;    ^<br>
&gt; cc1: all warnings being treated as errors<br>
&gt;<br>
&gt; &gt;     return ret;<br>
&gt; &gt;  }<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Andrew<br>
</div></div>&gt; _______________________________________________<br>
&gt; CRIU mailing list<br>
&gt; <a href="mailto:CRIU@openvz.org">CRIU@openvz.org</a><br>
&gt; <a href="https://lists.openvz.org/mailman/listinfo/criu" target="_blank">https://lists.openvz.org/mailman/listinfo/criu</a><br>
</blockquote></div><br></div></div>