[PATCH] Implement decoding of IOCTL_VM_SOCKETS_GET_LOCAL_CID

Alyssa Ross hi at alyssa.is
Thu Jul 25 13:06:40 UTC 2024


This is the only ioctl on /dev/vsock.  It decodes like this:

     ioctl(5, IOCTL_VMCI_SOCKETS_GET_LOCAL_CID or IOCTL_VM_SOCKETS_GET_LOCAL_CID, VMADDR_CID_ANY) = 0

(The two names are aliases for each other, so there's not any
disambiguation to do.)
---
I don't think it's really possible to write a meaningful test for this 
— when we called ioctl(), we'd have no idea in advance what we'd 
expect it to return, so the bulk of the test would end up being an xlat 
implementation rather than anything useful.

 src/Makefile.am   |  1 +
 src/defs.h        |  1 +
 src/ioctl.c       |  2 ++
 src/vsock_ioctl.c | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 44 insertions(+)
 create mode 100644 src/vsock_ioctl.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 913767f8f..41ac79a36 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -404,6 +404,7 @@ libstrace_a_SOURCES =	\
 	utime.c		\
 	utimes.c	\
 	v4l2.c		\
+	vsock_ioctl.c	\
 	wait.c		\
 	wait.h		\
 	watchdog_ioctl.c \
diff --git a/src/defs.h b/src/defs.h
index 6b57a8990..21afcbb9c 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -1468,6 +1468,7 @@ DECL_IOCTL(tee);
 DECL_IOCTL(term);
 DECL_IOCTL(ubi);
 DECL_IOCTL(uffdio);
+DECL_IOCTL(vsock);
 DECL_IOCTL(watchdog);
 # undef DECL_IOCTL
 
diff --git a/src/ioctl.c b/src/ioctl.c
index 8ebaea10a..602f23798 100644
--- a/src/ioctl.c
+++ b/src/ioctl.c
@@ -361,6 +361,8 @@ ioctl_decode(struct tcb *tcp, const struct finfo *finfo)
 	switch (_IOC_TYPE(code)) {
 	case 0x03:
 		return hdio_ioctl(tcp, code, arg);
+	case 0x07:
+		return vsock_ioctl(tcp, code, arg);
 	case 0x12:
 		return block_ioctl(tcp, code, arg);
 	case '!': /* 0x21 */
diff --git a/src/vsock_ioctl.c b/src/vsock_ioctl.c
new file mode 100644
index 000000000..331a7baa7
--- /dev/null
+++ b/src/vsock_ioctl.c
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2024 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+
+#include <linux/vm_sockets.h>
+
+#include "xlat/vsock_cids.h"
+
+int
+vsock_ioctl(struct tcb *const tcp, const unsigned int code,
+	    const kernel_ulong_t arg)
+{
+	unsigned int cid;
+
+	switch (code) {
+	case IOCTL_VM_SOCKETS_GET_LOCAL_CID:
+		if (entering(tcp)) {
+			tprint_arg_next();
+			return 0;
+		}
+
+		if (umove_or_printaddr(tcp, arg, &cid))
+			break;
+
+		printxval(vsock_cids, cid, NULL);
+
+		break;
+	default:
+		return RVAL_DECODED;
+	}
+	return RVAL_IOCTL_DECODED;
+}

base-commit: 9f428a691d59fea01ec29b2cf359433d555ce24f
-- 
2.45.1



More information about the Strace-devel mailing list