<div dir="ltr"><div>From 33d0341f2705e067b7617a6ec30e442d707714d0 Mon Sep 17 00:00:00 2001</div><div>From: Nikolay Marchuk <<a href="mailto:marchuk.nikolay.a@gmail.com">marchuk.nikolay.a@gmail.com</a>></div><div>Date: Thu, 16 Mar 2017 17:49:25 +0700</div><div>Subject: [PATCH 1/2] Add ioctl namespace entries from Linux 4.11</div><div><br></div><div>---</div><div> linux/32/ioctls_inc_align16.h | 2 ++</div><div> linux/32/ioctls_inc_align32.h | 2 ++</div><div> linux/32/ioctls_inc_align64.h | 2 ++</div><div> linux/64/ioctls_inc.h         | 2 ++</div><div> linux/x32/ioctls_inc0.h       | 2 ++</div><div> 5 files changed, 10 insertions(+)</div><div><br></div><div>diff --git a/linux/32/ioctls_inc_align16.h b/linux/32/ioctls_inc_align16.h</div><div>index 71c9d18..4e90801 100644</div><div>--- a/linux/32/ioctls_inc_align16.h</div><div>+++ b/linux/32/ioctls_inc_align16.h</div><div>@@ -1455,6 +1455,8 @@</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },</div><div>+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },</div><div>+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },</div><div> { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },</div><div>diff --git a/linux/32/ioctls_inc_align32.h b/linux/32/ioctls_inc_align32.h</div><div>index 699eb90..4fcada1 100644</div><div>--- a/linux/32/ioctls_inc_align32.h</div><div>+++ b/linux/32/ioctls_inc_align32.h</div><div>@@ -1455,6 +1455,8 @@</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },</div><div>+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },</div><div>+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },</div><div> { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },</div><div>diff --git a/linux/32/ioctls_inc_align64.h b/linux/32/ioctls_inc_align64.h</div><div>index fcd9d8c..3734082 100644</div><div>--- a/linux/32/ioctls_inc_align64.h</div><div>+++ b/linux/32/ioctls_inc_align64.h</div><div>@@ -1455,6 +1455,8 @@</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },</div><div>+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },</div><div>+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },</div><div> { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },</div><div>diff --git a/linux/64/ioctls_inc.h b/linux/64/ioctls_inc.h</div><div>index f59fe11..b75abec 100644</div><div>--- a/linux/64/ioctls_inc.h</div><div>+++ b/linux/64/ioctls_inc.h</div><div>@@ -1455,6 +1455,8 @@</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },</div><div>+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },</div><div>+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },</div><div> { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },</div><div>diff --git a/linux/x32/ioctls_inc0.h b/linux/x32/ioctls_inc0.h</div><div>index 46303d1..81dd21c 100644</div><div>--- a/linux/x32/ioctls_inc0.h</div><div>+++ b/linux/x32/ioctls_inc0.h</div><div>@@ -1455,6 +1455,8 @@</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },</div><div> { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },</div><div>+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },</div><div>+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },</div><div> { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },</div><div> { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },</div><div>-- </div><div>2.1.4</div><div><br></div><div><br></div><div>From 994940e890a539143311a97050bf7024caeb3c7b Mon Sep 17 00:00:00 2001</div><div>From: Nikolay Marchuk <<a href="mailto:marchuk.nikolay.a@gmail.com">marchuk.nikolay.a@gmail.com</a>></div><div>Date: Sat, 18 Mar 2017 15:49:27 +0700</div><div>Subject: [PATCH 2/2] Implemented parser for NS_* ioctl commands.</div><div><br></div><div>---</div><div> Makefile.am           |   1 +</div><div> <a href="http://configure.ac">configure.ac</a>          |   1 +</div><div> defs.h                |   1 +</div><div> ioctl.c               |   2 +</div><div> nsfs.c                |  93 ++++++++++++++++++++++++++++++++++</div><div> tests/.gitignore      |   1 +</div><div> tests/Makefile.am     |   2 +</div><div> tests/ioctl_nsfs.c    | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++</div><div> tests/ioctl_nsfs.test |  13 +++++</div><div> 9 files changed, 252 insertions(+)</div><div> create mode 100644 nsfs.c</div><div> create mode 100644 tests/ioctl_nsfs.c</div><div> create mode 100755 tests/ioctl_nsfs.test</div><div><br></div><div>diff --git a/Makefile.am b/Makefile.am</div><div>index c77f463..338fb62 100644</div><div>--- a/Makefile.am</div><div>+++ b/Makefile.am</div><div>@@ -172,6 +172,7 @@ strace_SOURCES =<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>\</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>net.c<span class="gmail-Apple-tab-span" style="white-space:pre">         </span>\</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>netlink.c       \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>nsig.h<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>\</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>nsfs.c<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>\</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>numa.c<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>\</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>oldstat.c<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>\</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>open.c<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>\</div><div>diff --git a/<a href="http://configure.ac">configure.ac</a> b/<a href="http://configure.ac">configure.ac</a></div><div>index 9e5087b..dc49fdc 100644</div><div>--- a/<a href="http://configure.ac">configure.ac</a></div><div>+++ b/<a href="http://configure.ac">configure.ac</a></div><div>@@ -366,6 +366,7 @@ AC_CHECK_HEADERS(m4_normalize([</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">     </span>linux/ipc.h</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>linux/mmtimer.h</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">      </span>linux/msg.h</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>linux/nsfs.h</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>linux/perf_event.h</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">   </span>linux/quota.h</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">        </span>linux/seccomp.h</div><div>diff --git a/defs.h b/defs.h</div><div>index 793971e..0f3ec14 100644</div><div>--- a/defs.h</div><div>+++ b/defs.h</div><div>@@ -640,6 +640,7 @@ name ## _ioctl(struct tcb *, unsigned int request, kernel_ulong_t arg)</div><div> DECL_IOCTL(dm);</div><div> DECL_IOCTL(file);</div><div> DECL_IOCTL(fs_x);</div><div>+DECL_IOCTL(nsfs);</div><div> DECL_IOCTL(ptp);</div><div> DECL_IOCTL(scsi);</div><div> DECL_IOCTL(term);</div><div>diff --git a/ioctl.c b/ioctl.c</div><div>index aa1880f..4511e0b 100644</div><div>--- a/ioctl.c</div><div>+++ b/ioctl.c</div><div>@@ -280,6 +280,8 @@ ioctl_decode(struct tcb *tcp)</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">     </span>case 0x94:</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">           </span>return btrfs_ioctl(tcp, code, arg);</div><div> #endif</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>case 0xb7:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">            </span>return nsfs_ioctl(tcp, code, arg);</div><div> #ifdef HAVE_LINUX_DM_IOCTL_H</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">      </span>case 0xfd:</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">           </span>return dm_ioctl(tcp, code, arg);</div><div>diff --git a/nsfs.c b/nsfs.c</div><div>new file mode 100644</div><div>index 0000000..508716d</div><div>--- /dev/null</div><div>+++ b/nsfs.c</div><div>@@ -0,0 +1,93 @@</div><div>+/*</div><div>+ * Support for decoding of NS_* ioctl commands.</div><div>+ *</div><div>+ * Copyright (c) 2017 Nikolay Marchuk <<a href="mailto:marchuk.nikolay.a@gmail.com">marchuk.nikolay.a@gmail.com</a>></div><div>+ * All rights reserved.</div><div>+ *</div><div>+ * Redistribution and use in source and binary forms, with or without</div><div>+ * modification, are permitted provided that the following conditions</div><div>+ * are met:</div><div>+ * 1. Redistributions of source code must retain the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer.</div><div>+ * 2. Redistributions in binary form must reproduce the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer in the</div><div>+ *    documentation and/or other materials provided with the distribution.</div><div>+ * 3. The name of the author may not be used to endorse or promote products</div><div>+ *    derived from this software without specific prior written permission.</div><div>+ *</div><div>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR</div><div>+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</div><div>+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</div><div>+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,</div><div>+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT</div><div>+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</div><div>+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</div><div>+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</div><div>+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF</div><div>+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</div><div>+ */</div><div>+</div><div>+#include "defs.h"</div><div>+</div><div>+#include <linux/ioctl.h></div><div>+</div><div>+/* Definitions for commands */</div><div>+#ifdef HAVE_LINUX_NSFS_H</div><div>+# include <linux/nsfs.h></div><div>+#else</div><div>+# ifndef NSIO</div><div>+#  define NSIO<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>0xb7</div><div>+# endif</div><div>+# ifndef NS_GET_USERNS</div><div>+#  define NS_GET_USERNS<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>_IO(NSIO, 0x1)</div><div>+# endif</div><div>+# ifndef NS_GET_PARENT</div><div>+#  define NS_GET_PARENT <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>_IO(NSIO, 0x2)</div><div>+# endif</div><div>+# ifndef NS_GET_NSTYPE</div><div>+#  define NS_GET_NSTYPE<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>_IO(NSIO, 0x3)</div><div>+# endif</div><div>+# ifndef NS_GET_OWNER_UID</div><div>+#  define NS_GET_OWNER_UID<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>_IO(NSIO, 0x4)</div><div>+# endif</div><div>+#endif</div><div>+</div><div>+#include <sys/types.h></div><div>+#include "xlat/setns_types.h"</div><div>+</div><div>+int</div><div>+nsfs_ioctl(struct tcb *tcp, unsigned int code, kernel_ulong_t arg)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>const char *outstr;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>uid_t uid;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>if (entering(tcp)) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>switch (code) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">               </span>case NS_GET_USERNS:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>case NS_GET_PARENT:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                   </span>return RVAL_DECODED | (1 + RVAL_FD);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">          </span>default:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                      </span>return 0;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>}</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>} else {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>switch (code) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">               </span>case NS_GET_NSTYPE:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                   </span>if (!syserror(tcp)) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                         </span>outstr = xlookup(setns_types, tcp->u_rval);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>if (outstr) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                                 </span>tcp->auxstr = outstr;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                                      </span>return 1 + RVAL_STR;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                          </span>}</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                     </span>}</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                     </span>return 1 + RVAL_DECIMAL;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>case NS_GET_OWNER_UID:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>tprints(", ");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                      </span>if (!umove_or_printaddr(tcp, arg, &uid)) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                                </span>printuid("[", uid);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                         </span>tprints("]");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>}</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                     </span>return 1 + RVAL_DECIMAL;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>default:</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                      </span>return 0;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>}</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>}</div><div>+}</div><div>diff --git a/tests/.gitignore b/tests/.gitignore</div><div>index a7754b6..060a391 100644</div><div>--- a/tests/.gitignore</div><div>+++ b/tests/.gitignore</div><div>@@ -121,6 +121,7 @@ ioctl_loop</div><div> ioctl_loop-nv</div><div> ioctl_loop-v</div><div> ioctl_mtd</div><div>+ioctl_nsfs</div><div> ioctl_rtc</div><div> ioctl_rtc-v</div><div> ioctl_scsi</div><div>diff --git a/tests/Makefile.am b/tests/Makefile.am</div><div>index c5c124c..bc0c621 100644</div><div>--- a/tests/Makefile.am</div><div>+++ b/tests/Makefile.am</div><div>@@ -184,6 +184,7 @@ check_PROGRAMS = \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">   </span>ioctl_loop-nv \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">      </span>ioctl_loop-v \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl_mtd \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>ioctl_nsfs \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre"> </span>ioctl_rtc \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>ioctl_rtc-v \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl_scsi \</div><div>@@ -593,6 +594,7 @@ DECODER_TESTS = \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">     </span>ioctl_loop-v.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>ioctl_loop.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>ioctl_mtd.test \</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>ioctl_nsfs.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">    </span>ioctl_rtc-v.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">   </span>ioctl_rtc.test \</div><div> <span class="gmail-Apple-tab-span" style="white-space:pre">     </span>ioctl_scsi.test \</div><div>diff --git a/tests/ioctl_nsfs.c b/tests/ioctl_nsfs.c</div><div>new file mode 100644</div><div>index 0000000..38c161b</div><div>--- /dev/null</div><div>+++ b/tests/ioctl_nsfs.c</div><div>@@ -0,0 +1,138 @@</div><div>+/*</div><div>+ * Check decoding of NS_* commands of ioctl syscall.</div><div>+ *</div><div>+ * Copyright (c) 2017 Nikolay Marchuk <<a href="mailto:marchuk.nikolay.a@gmail.com">marchuk.nikolay.a@gmail.com</a>></div><div>+ * All rights reserved.</div><div>+ *</div><div>+ * Redistribution and use in source and binary forms, with or without</div><div>+ * modification, are permitted provided that the following conditions</div><div>+ * are met:</div><div>+ * 1. Redistributions of source code must retain the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer.</div><div>+ * 2. Redistributions in binary form must reproduce the above copyright</div><div>+ *    notice, this list of conditions and the following disclaimer in the</div><div>+ *    documentation and/or other materials provided with the distribution.</div><div>+ * 3. The name of the author may not be used to endorse or promote products</div><div>+ *    derived from this software without specific prior written permission.</div><div>+ *</div><div>+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR</div><div>+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES</div><div>+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.</div><div>+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,</div><div>+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT</div><div>+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,</div><div>+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY</div><div>+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT</div><div>+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF</div><div>+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</div><div>+ */</div><div>+</div><div>+#include "tests.h"</div><div>+</div><div>+/* Definitions for commands */</div><div>+#ifdef HAVE_LINUX_NSFS_H</div><div>+# include <linux/nsfs.h></div><div>+#else</div><div>+# ifndef NSIO</div><div>+#  define NSIO<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>0xb7</div><div>+# endif</div><div>+# ifndef NS_GET_USERNS</div><div>+#  define NS_GET_USERNS<span class="gmail-Apple-tab-span" style="white-space:pre">             </span>_IO(NSIO, 0x1)</div><div>+# endif</div><div>+# ifndef NS_GET_PARENT</div><div>+#  define NS_GET_PARENT <span class="gmail-Apple-tab-span" style="white-space:pre">  </span>_IO(NSIO, 0x2)</div><div>+# endif</div><div>+# ifndef NS_GET_NSTYPE</div><div>+#  define NS_GET_NSTYPE<span class="gmail-Apple-tab-span" style="white-space:pre">           </span>_IO(NSIO, 0x3)</div><div>+# endif</div><div>+# ifndef NS_GET_OWNER_UID</div><div>+#  define NS_GET_OWNER_UID<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>_IO(NSIO, 0x4)</div><div>+# endif</div><div>+#endif</div><div>+</div><div>+# include <fcntl.h></div><div>+# include <linux/ioctl.h></div><div>+# include <sched.h></div><div>+# include <stdio.h></div><div>+# include <stdlib.h></div><div>+# include <sys/ioctl.h></div><div>+# include <sys/types.h></div><div>+# include <sys/wait.h></div><div>+# include <unistd.h></div><div>+</div><div>+/* Definitions for command which have been added later */</div><div>+# ifndef NS_GET_NSTYPE</div><div>+#  define NS_GET_NSTYPE<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>_IO(NSIO, 0x3)</div><div>+# endif</div><div>+# ifndef NS_GET_OWNER_UID</div><div>+#  define NS_GET_OWNER_UID<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>_IO(NSIO, 0x4)</div><div>+# endif</div><div>+</div><div>+static void</div><div>+test_no_namespace(void)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>uid_t uid = 1;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ioctl(-1, NS_GET_USERNS);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, NS_GET_USERNS) = -1 EBADF (%m)\n");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl(-1, NS_GET_PARENT);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, NS_GET_PARENT) = -1 EBADF (%m)\n");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl(-1, NS_GET_NSTYPE);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>printf("ioctl(-1, NS_GET_NSTYPE) = -1 EBADF (%m)\n");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>ioctl(-1, NS_GET_OWNER_UID, NULL);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>printf("ioctl(-1, NS_GET_OWNER_UID, NULL) = -1 EBADF (%m)\n");</div><div>+}</div><div>+</div><div>+static void</div><div>+test_user_namespace(void)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>int ns_fd, userns_fd, parent_ns_fd, nstype, rc;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>uid_t uid;</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>const char *errstr;</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>rc = unshare(CLONE_NEWUSER);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>if (rc == -1)</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">         </span>perror_msg_and_skip("Unshare user namespace error");</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>ns_fd = open("/proc/self/ns/user", O_RDONLY);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>if (rc == -1)</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">         </span>perror_msg_and_skip("Open user namespace file error");</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>userns_fd = ioctl(ns_fd, NS_GET_USERNS);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>errstr = sprintrc(userns_fd);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>printf("ioctl(%d, NS_GET_USERNS) = %s\n", ns_fd, errstr);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">   </span>parent_ns_fd = ioctl(userns_fd, NS_GET_PARENT);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>errstr = sprintrc(parent_ns_fd);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>printf("ioctl(%d, NS_GET_PARENT) = %s\n", userns_fd, errstr);</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>nstype = ioctl(userns_fd, NS_GET_NSTYPE);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>errstr = sprintrc(nstype);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>if (nstype == CLONE_NEWUSER) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                </span>printf("ioctl(%d, NS_GET_NSTYPE) = %d (CLONE_NEWUSER)\n", userns_fd,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                        </span>   nstype);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>} else {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>printf("ioctl(%d, NS_GET_NSTYPE) = %s\n", userns_fd, errstr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">       </span>}</div><div>+</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">     </span>rc = ioctl(userns_fd, NS_GET_OWNER_UID, &uid);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">    </span>errstr = sprintrc(rc);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>if (rc == -1) {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">               </span>printf("ioctl(%d, NS_GET_OWNER_UID, %p) = %s\n", userns_fd, &uid,</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>   errstr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>} else {</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>printf("ioctl(%d, NS_GET_OWNER_UID, [", userns_fd, &uid);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">               </span>if ((uid_t) -1U == (uid_t) uid)</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                       </span>printf("-1]) = %s\n", errstr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">              </span>else</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">                  </span>printf("%u]) = %s\n", uid, errstr);</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre"> </span>}</div><div>+}</div><div>+</div><div>+int</div><div>+main(void)</div><div>+{</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>test_no_namespace();</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">  </span>test_user_namespace();</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">        </span>puts("+++ exited with 0 +++");</div><div>+<span class="gmail-Apple-tab-span" style="white-space:pre">      </span>return 0;</div><div>+}</div><div>diff --git a/tests/ioctl_nsfs.test b/tests/ioctl_nsfs.test</div><div>new file mode 100755</div><div>index 0000000..8fe8da5</div><div>--- /dev/null</div><div>+++ b/tests/ioctl_nsfs.test</div><div>@@ -0,0 +1,13 @@</div><div>+#!/bin/sh</div><div>+</div><div>+# Check decoding of NS_* ioctls.</div><div>+</div><div>+. "${srcdir=.}/init.sh"</div><div>+</div><div>+run_prog > /dev/null</div><div>+run_strace -a16 -eioctl $args > "$EXP"</div><div>+check_prog grep</div><div>+grep -v '^ioctl([012],' < "$LOG" > "$OUT"</div><div>+match_diff "$OUT" "$EXP"</div><div>+</div><div>+rm -f "$EXP" "$OUT"</div><div>-- </div><div>2.1.4</div><div><br></div></div>