Hello,
I have implemented NS_* ioctls. Should I use common ioctlent interface to
print them with additional argument or should I print them without it?

On Tue, Mar 14, 2017 at 9:21 AM, Dmitry V. Levin <l...@altlinux.org> wrote:

> Hi,
>
> On Tue, Mar 14, 2017 at 08:35:45AM +0700, Николай Марчук wrote:
> > Hello,
> > my name is Nikolay Marchuk and I am a first-year student in NSU, Russia.
> I
> > want to implement advanced filtering syntax for strace. I am familiar
> with
> > c and c++ and have an experience of making parsers.
>
> Thanks for showing interest in strace GSoC projects.
>
> > I wanted to add support of new ioctl commands from linux 4.9 - 4.11 as my
> > introduction microproject, but I cannot understand, what kind of support
> is
> > needed. I have tested them on linux 4.9 and output is correct.
>
> I understand your confusion.  The output is not incorrect but at the same
> time it's incomplete.  For example,
> - both NS_GET_USERNS and NS_GET_PARENT return descriptors,
>   but does strace -y show them properly?
> - NS_GET_NSTYPE returns a namespace type, but does strace print it
>   in symbolic form like it does for setns syscall?
>
>
> --
> ldv
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Strace-devel mailing list
> Strace-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/strace-devel
>
>
From 0f1ada8f73b93e3ca542e04c5271df87850f9be8 Mon Sep 17 00:00:00 2001
From: Marchuk Nikolay <marchuk.nikola...@gmail.com>
Date: Wed, 15 Mar 2017 11:53:49 +0700
Subject: [PATCH 1/2] Add ioctl namespace entries from Linux 4.11

Signed-off-by: Nikolay Marchuk <marchuk.nikola...@gmail.com>
---
 linux/32/ioctls_inc_align16.h | 2 ++
 linux/32/ioctls_inc_align32.h | 2 ++
 linux/32/ioctls_inc_align64.h | 2 ++
 linux/64/ioctls_inc.h         | 2 ++
 linux/x32/ioctls_inc0.h       | 2 ++
 5 files changed, 10 insertions(+)

diff --git a/linux/32/ioctls_inc_align16.h b/linux/32/ioctls_inc_align16.h
index 71c9d18..4e90801 100644
--- a/linux/32/ioctls_inc_align16.h
+++ b/linux/32/ioctls_inc_align16.h
@@ -1455,6 +1455,8 @@
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },
+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },
+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },
 { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },
 { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },
 { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },
diff --git a/linux/32/ioctls_inc_align32.h b/linux/32/ioctls_inc_align32.h
index 699eb90..4fcada1 100644
--- a/linux/32/ioctls_inc_align32.h
+++ b/linux/32/ioctls_inc_align32.h
@@ -1455,6 +1455,8 @@
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },
+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },
+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },
 { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },
 { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },
 { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },
diff --git a/linux/32/ioctls_inc_align64.h b/linux/32/ioctls_inc_align64.h
index fcd9d8c..3734082 100644
--- a/linux/32/ioctls_inc_align64.h
+++ b/linux/32/ioctls_inc_align64.h
@@ -1455,6 +1455,8 @@
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },
+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },
+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },
 { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },
 { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },
 { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },
diff --git a/linux/64/ioctls_inc.h b/linux/64/ioctls_inc.h
index f59fe11..b75abec 100644
--- a/linux/64/ioctls_inc.h
+++ b/linux/64/ioctls_inc.h
@@ -1455,6 +1455,8 @@
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },
+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },
+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },
 { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },
 { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },
 { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },
diff --git a/linux/x32/ioctls_inc0.h b/linux/x32/ioctls_inc0.h
index 46303d1..81dd21c 100644
--- a/linux/x32/ioctls_inc0.h
+++ b/linux/x32/ioctls_inc0.h
@@ -1455,6 +1455,8 @@
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_ALLOC_RANGE", _IOC_WRITE, 0x6e8c, 0x10 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SET_SUINFO", _IOC_WRITE, 0x6e8d, 0x18 },
 { "linux/nilfs2_api.h", "NILFS_IOCTL_SYNC", _IOC_READ, 0x6e8a, 0x08 },
+{ "linux/nsfs.h", "NS_GET_NSTYPE", _IOC_NONE, 0xb703, 0x00 },
+{ "linux/nsfs.h", "NS_GET_OWNER_UID", _IOC_NONE, 0xb704, 0x00 },
 { "linux/nsfs.h", "NS_GET_PARENT", _IOC_NONE, 0xb702, 0x00 },
 { "linux/nsfs.h", "NS_GET_USERNS", _IOC_NONE, 0xb701, 0x00 },
 { "linux/nvme_ioctl.h", "NVME_IOCTL_ADMIN_CMD", _IOC_READ|_IOC_WRITE, 0x4e41, 0x48 },
-- 
2.1.4


From f03f6cea9ff2f1ca6fc38c0068844658180c5032 Mon Sep 17 00:00:00 2001
From: Marchuk Nikolay <marchuk.nikola...@gmail.com>
Date: Wed, 15 Mar 2017 11:59:26 +0700
Subject: [PATCH 2/2] Add ioctl namespace entries from Linux 4.11

Signed-off-by: Nikolay Marchuk <marchuk.nikola...@gmail.com>
---
 Makefile.am           |  1 +
 configure.ac          |  1 +
 defs.h                |  1 +
 ioctl.c               |  4 +++
 nsfs.c                | 38 ++++++++++++++++++++++++++++
 tests/.gitignore      |  1 +
 tests/Makefile.am     |  2 ++
 tests/ioctl_nsfs.c    | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/ioctl_nsfs.test | 13 ++++++++++
 xlat/nsfs_types.in    |  6 +++++
 10 files changed, 137 insertions(+)
 create mode 100644 nsfs.c
 create mode 100644 tests/ioctl_nsfs.c
 create mode 100755 tests/ioctl_nsfs.test
 create mode 100644 xlat/nsfs_types.in

diff --git a/Makefile.am b/Makefile.am
index c77f463..c673faa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -172,6 +172,7 @@ strace_SOURCES =	\
 	net.c		\
 	netlink.c       \
 	nsig.h		\
+	nsfs.c      \
 	numa.c		\
 	oldstat.c	\
 	open.c		\
diff --git a/configure.ac b/configure.ac
index 9e5087b..dc49fdc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -366,6 +366,7 @@ AC_CHECK_HEADERS(m4_normalize([
 	linux/ipc.h
 	linux/mmtimer.h
 	linux/msg.h
+	linux/nsfs.h
 	linux/perf_event.h
 	linux/quota.h
 	linux/seccomp.h
diff --git a/defs.h b/defs.h
index 793971e..0f3ec14 100644
--- a/defs.h
+++ b/defs.h
@@ -640,6 +640,7 @@ name ## _ioctl(struct tcb *, unsigned int request, kernel_ulong_t arg)
 DECL_IOCTL(dm);
 DECL_IOCTL(file);
 DECL_IOCTL(fs_x);
+DECL_IOCTL(nsfs);
 DECL_IOCTL(ptp);
 DECL_IOCTL(scsi);
 DECL_IOCTL(term);
diff --git a/ioctl.c b/ioctl.c
index aa1880f..d972c38 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -280,6 +280,10 @@ ioctl_decode(struct tcb *tcp)
 	case 0x94:
 		return btrfs_ioctl(tcp, code, arg);
 #endif
+#ifdef HAVE_LINUX_NSFS_H
+	case 0xb7:
+		return nsfs_ioctl(tcp, code, arg);
+#endif
 #ifdef HAVE_LINUX_DM_IOCTL_H
 	case 0xfd:
 		return dm_ioctl(tcp, code, arg);
diff --git a/nsfs.c b/nsfs.c
new file mode 100644
index 0000000..de98ca9
--- /dev/null
+++ b/nsfs.c
@@ -0,0 +1,38 @@
+#include "defs.h"
+
+#ifdef HAVE_LINUX_NSFS_H
+
+#include "xlat/nsfs_types.h"
+#include <linux/ioctl.h>
+#include <linux/nsfs.h>
+
+/* Definitions for command which have been added later */
+#ifndef NS_GET_NSTYPE
+#define NS_GET_NSTYPE		_IO(NSIO, 0x3)
+#endif
+#ifndef NS_GET_OWNER_UID
+#define NS_GET_OWNER_UID	_IO(NSIO, 0x4)
+#endif
+
+int
+nsfs_ioctl(struct tcb * tcp, unsigned int code, kernel_ulong_t arg){
+	char *outstr;
+	if (entering(tcp) || syserror(tcp))
+		return 0;
+	switch(code){
+		case NS_GET_USERNS:
+		case NS_GET_PARENT:
+			return RVAL_DECODED | RVAL_FD;
+		case NS_GET_OWNER_UID:
+			return RVAL_UDECIMAL | RVAL_DECODED;
+		case NS_GET_NSTYPE:
+			outstr = xlookup(nsfs_types, tcp->u_rval);
+			if(outstr){
+				tcp->auxstr = outstr;
+				return RVAL_STR | RVAL_DECODED;
+			}
+		default:
+			return 0;
+	}
+}
+#endif /* HAVE_LINUX_NSFS_H */
diff --git a/tests/.gitignore b/tests/.gitignore
index a7754b6..060a391 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -121,6 +121,7 @@ ioctl_loop
 ioctl_loop-nv
 ioctl_loop-v
 ioctl_mtd
+ioctl_nsfs
 ioctl_rtc
 ioctl_rtc-v
 ioctl_scsi
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c5c124c..bc0c621 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -184,6 +184,7 @@ check_PROGRAMS = \
 	ioctl_loop-nv \
 	ioctl_loop-v \
 	ioctl_mtd \
+	ioctl_nsfs \
 	ioctl_rtc \
 	ioctl_rtc-v \
 	ioctl_scsi \
@@ -593,6 +594,7 @@ DECODER_TESTS = \
 	ioctl_loop-v.test \
 	ioctl_loop.test \
 	ioctl_mtd.test \
+	ioctl_nsfs.test \
 	ioctl_rtc-v.test \
 	ioctl_rtc.test \
 	ioctl_scsi.test \
diff --git a/tests/ioctl_nsfs.c b/tests/ioctl_nsfs.c
new file mode 100644
index 0000000..beea729
--- /dev/null
+++ b/tests/ioctl_nsfs.c
@@ -0,0 +1,70 @@
+/*
+ * Check decoding of NS_* commands of ioctl syscall.
+ *
+ * Copyright (c) 2017 Nikolay Marchuk <marchuk.nikola...@gmail.com>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h" 
+
+#ifdef HAVE_LINUX_NSFS_H
+
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <linux/ioctl.h>
+#include <linux/nsfs.h>
+
+/* Definitions for command which have been added later */
+#ifndef NS_GET_NSTYPE
+#define NS_GET_NSTYPE		_IO(NSIO, 0x3)
+#endif
+#ifndef NS_GET_OWNER_UID
+#define NS_GET_OWNER_UID	_IO(NSIO, 0x4)
+#endif
+
+int
+main(void)
+{
+	static kernel_ulong_t dummy_arg =
+		(kernel_ulong_t) 0xbadc0dedda7a1057ULL;
+	ioctl(-1, NS_GET_USERNS, dummy_arg);
+	printf("ioctl(-1, NS_GET_USERNS, %#lx) = -1 EBADF (%m)\n", dummy_arg);
+	ioctl(-1, NS_GET_PARENT, dummy_arg);
+	printf("ioctl(-1, NS_GET_PARENT, %#lx) = -1 EBADF (%m)\n", dummy_arg);
+	ioctl(-1, NS_GET_NSTYPE, dummy_arg);
+	printf("ioctl(-1, NS_GET_NSTYPE, %#lx) = -1 EBADF (%m)\n", dummy_arg);
+	ioctl(-1, NS_GET_OWNER_UID, dummy_arg);
+	printf("ioctl(-1, NS_GET_OWNER_UID, %#lx) = -1 EBADF (%m)\n", dummy_arg);
+
+	puts("+++ exited with 0 +++");
+	return 0;
+}
+
+
+#else /* !HAVE_LINUX_DM_IOCTL_H */
+
+SKIP_MAIN_UNDEFINED("HAVE_LINUX_NSFS_H")
+
+#endif /* HAVE_LINUX_DM_IOCTL_H */
\ No newline at end of file
diff --git a/tests/ioctl_nsfs.test b/tests/ioctl_nsfs.test
new file mode 100755
index 0000000..b4604ed
--- /dev/null
+++ b/tests/ioctl_nsfs.test
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# Check decoding of NS_* ioctls.
+
+. "${srcdir=.}/init.sh"
+
+run_prog > /dev/null
+run_strace -a16 -eioctl $args > "$EXP"
+check_prog grep
+grep -v '^ioctl([012],' < "$LOG" > "$OUT"
+match_diff "$OUT" "$EXP"
+
+rm -f "$EXP" "$OUT"
\ No newline at end of file
diff --git a/xlat/nsfs_types.in b/xlat/nsfs_types.in
new file mode 100644
index 0000000..249935e
--- /dev/null
+++ b/xlat/nsfs_types.in
@@ -0,0 +1,6 @@
+CLONE_NEWCGROUP	0x02000000
+CLONE_NEWUTS	0x04000000
+CLONE_NEWIPC	0x08000000
+CLONE_NEWUSER	0x10000000
+CLONE_NEWPID	0x20000000
+CLONE_NEWNET	0x40000000 
-- 
2.1.4

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to