[PATCH v2] ioctl: fix conflicts command number decoding in case of conflicts

Gabriel Laskar gabriel at lse.epita.fr
Wed Sep 23 08:11:55 UTC 2015


When a command number was decoded through ioctl_decode_command_number(),
there was no check for conflicts with other potential ioctls numbers.

For example:
	ioctl(fd, MCE_GET_RECORD_LEN, &i);
output:
	ioctl(3, MIXER_READ(1), 0x7ffddce74a58) = 0
instead of:
	ioctl(3, MIXER_READ(1) or MCE_GET_RECORD_LEN, 0x7ffee435ce08) = 0

* ioctl.c (SYS_FUNC(ioctl)): fix ioctl command number decoding in case of conflicts
* tests/ioctl.c: add case for conflicts

Signed-off-by: Gabriel Laskar <gabriel at lse.epita.fr>
---

v2:
* changed the test to be able to handle iop == NULL && ret != NULL
* add suggested test

 ioctl.c       | 19 ++++++++++---------
 tests/ioctl.c |  1 +
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/ioctl.c b/ioctl.c
index 284828a..adce986 100644
--- a/ioctl.c
+++ b/ioctl.c
@@ -277,15 +277,16 @@ SYS_FUNC(ioctl)
 	if (entering(tcp)) {
 		printfd(tcp, tcp->u_arg[0]);
 		tprints(", ");
-		if (!ioctl_decode_command_number(tcp)) {
-			iop = ioctl_lookup(tcp->u_arg[1]);
-			if (iop) {
-				tprints(iop->symbol);
-				while ((iop = ioctl_next_match(iop)))
-					tprintf(" or %s", iop->symbol);
-			} else {
-				ioctl_print_code(tcp->u_arg[1]);
-			}
+		ret = ioctl_decode_command_number(tcp);
+		iop = ioctl_lookup(tcp->u_arg[1]);
+		if (iop) {
+			if (ret)
+				tprints(" or ");
+			tprints(iop->symbol);
+			while ((iop = ioctl_next_match(iop)))
+				tprintf(" or %s", iop->symbol);
+		} else if (!ret) {
+			ioctl_print_code(tcp->u_arg[1]);
 		}
 		ret = ioctl_decode(tcp);
 	} else {
diff --git a/tests/ioctl.c b/tests/ioctl.c
index d2807f5..5f52797 100644
--- a/tests/ioctl.c
+++ b/tests/ioctl.c
@@ -38,6 +38,7 @@ main(void )
 	    ioctl(-1, HIDIOCGVERSION, &data) != -1 ||
 	    ioctl(-1, HIDIOCGPHYS(8), &data) != -1 ||
 	    ioctl(-1, EVIOCGBIT(EV_KEY, 8), &data) != -1 ||
+	    ioctl(-1, _IOW('M', 14, int), &data) != -1 ||
 	    ioctl(-1, _IOR(0xde, 0xad, data), &data) != -1)
 		return 77;
 
-- 
2.5.0





More information about the Strace-devel mailing list