title: linux setting uid_map under sudo
body: <p>Suppose I have some process <code>A</code> which <code>clone</code>s process <code>B</code> with flags <code>CLONE_NEWUSER | CLONE_NEWPID | CLONE_NEWNS</code> and this process <code>B</code> has pid=PID. Then in process <code>A</code> I write to <code>/proc/PID/uid_map</code> string <code>0 1000 1</code> (1000 is uid of my user).</p>
  
  <p>If I run <code>A</code> just under my user <code>./A</code> this works fine and in process <code>B</code> <code>getuid()</code> gives me <code>0</code>. But if I run <code>A</code> like <code>sudo ./A</code> then <code>getuid()</code> in <code>B</code> gives me 65534 (<code>nobody</code>).</p>
  
  <p>As I searched through <code>sudo</code> code it does not create any new namespaces. So my question is what is happening here and why under sudo I can not set mapping <code>0 1000 1</code> properly?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Also, if I add suid to <code>A</code>:</p>
  
  <pre><code>$ sudo su
  # chown 0:0 A
  # chmod u+s A
  # exit
  $ ./A
  </code></pre>
  
  <p>Then <code>B</code> gives me <code>0</code> again.</p>