newuidmap and newgidmap: support passing pid as fd
Closes #635 newuidmap and newgidmap currently take an integner pid as the first argument, determining the process id on which to act. Accept also "fd:N", where N must be an open file descriptor to the /proc/pid directory for the process to act upon. This way, if you exec 10</proc/99 newuidmap fd:10 100000 0 65536 and pid 99 dies and a new process happens to take pid 99 before newuidmap happens to do its work, then since newuidmap will use openat() using fd 10, it won't change the mapping for the new process. Example: // terminal 1: serge@jerom ~/src/nsexec$ ./nsexec -W -s 0 -S 0 -U about to unshare with 10000000 Press any key to exec (I am 129176) // terminal 2: serge@jerom ~/src/shadow$ exec 10</proc/129176 serge@jerom ~/src/shadow$ sudo chown root src/newuidmap src/newgidmap serge@jerom ~/src/shadow$ sudo chmod u+s src/newuidmap serge@jerom ~/src/shadow$ sudo chmod u+s src/newgidmap serge@jerom ~/src/shadow$ ./src/newuidmap fd:10 0 100000 10 serge@jerom ~/src/shadow$ ./src/newgidmap fd:10 0 100000 10 // Terminal 1: uid=0(root) gid=0(root) groups=0(root) Signed-off-by: Serge Hallyn <serge@hallyn.com>
This commit is contained in:
@@ -116,6 +116,17 @@
|
||||
<para>
|
||||
Note that newgidmap may be used only once for a given process.
|
||||
</para>
|
||||
<para>
|
||||
Instead of an integer process id, the first argument may be
|
||||
specified as <replaceable>fd:N</replaceable>, where the integer N
|
||||
is the file descriptor number for the calling process's opened
|
||||
file for <filename>/proc/[pid[</filename>. In this case,
|
||||
<command>newgidmap</command> will use
|
||||
<refentrytitle>openat</refentrytitle><manvolnum>2</manvolnum>
|
||||
to open the <filename>gid_map</filename> file under that
|
||||
directory, avoiding a TOCTTOU in case the process exits and
|
||||
the pid is immediately reused.
|
||||
</para>
|
||||
|
||||
</refsect1>
|
||||
|
||||
|
@@ -116,6 +116,17 @@
|
||||
<para>
|
||||
Note that newuidmap may be used only once for a given process.
|
||||
</para>
|
||||
<para>
|
||||
Instead of an integer process id, the first argument may be
|
||||
specified as <replaceable>fd:N</replaceable>, where the integer N
|
||||
is the file descriptor number for the calling process's opened
|
||||
file for <filename>/proc/[pid[</filename>. In this case,
|
||||
<command>newuidmap</command> will use
|
||||
<refentrytitle>openat</refentrytitle><manvolnum>2</manvolnum>
|
||||
to open the <filename>uid_map</filename> file under that
|
||||
directory, avoiding a TOCTTOU in case the process exits and
|
||||
the pid is immediately reused.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 id='options'>
|
||||
|
Reference in New Issue
Block a user