From 1ccc55eed2e92fef71b157d26c1a36fc89a42161 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Sun, 1 Jan 2017 21:59:12 +0300 Subject: [PATCH] tests: add more checks of unknown ioctl command formatting * tests/ioctl.c (main): Additional check for unknown ioctl command decoding. * tests/ioctl_evdev.c (main): Likewise. * tests/ioctl_dm.c: Include for _IOC_SIZE and _IOC_NR. (main) : New constants. Add more checks for unknown command formatting. --- tests/ioctl.c | 4 ++++ tests/ioctl_dm.c | 17 +++++++++++++++++ tests/ioctl_evdev.c | 4 ++++ 3 files changed, 25 insertions(+) diff --git a/tests/ioctl.c b/tests/ioctl.c index 6897890a..92a3191d 100644 --- a/tests/ioctl.c +++ b/tests/ioctl.c @@ -88,6 +88,10 @@ main(void ) printf("ioctl(-1, MIXER_READ(13) or OTPSELECT, [MTD_OTP_OFF])" " = -1 EBADF (%m)\n"); + (void) ioctl(-1, _IOC(_IOC_WRITE, 0xde, 0, 0), (kernel_ulong_t) -1ULL); + printf("ioctl(-1, _IOC(_IOC_WRITE, 0xde, 0, 0), %#lx)" + " = -1 EBADF (%m)\n", -1UL); + (void) ioctl(-1, _IOR(0xde, 0xad, data), &data); printf("ioctl(-1, _IOC(_IOC_READ, 0xde, 0xad, 0x8), %p)" " = -1 EBADF (%m)\n", &data); diff --git a/tests/ioctl_dm.c b/tests/ioctl_dm.c index f4e59962..08f036c6 100644 --- a/tests/ioctl_dm.c +++ b/tests/ioctl_dm.c @@ -39,6 +39,7 @@ # include # include # include +# include # include # ifndef VERBOSE @@ -160,6 +161,12 @@ print_dm_target_spec(struct dm_target_spec *ptr, uint32_t id) int main(void) { + static kernel_ulong_t dummy_dm_ioctl1 = + _IOC(_IOC_READ, DM_IOCTL, 0, 0x1fff); + static kernel_ulong_t dummy_dm_ioctl2 = + _IOC(_IOC_READ|_IOC_WRITE, DM_IOCTL, 0xed, 0); + static kernel_ulong_t dummy_dm_arg = + (kernel_ulong_t) 0xbadc0dedda7a1057ULL; /* We can't check these properly for now */ static struct args dummy_check_cmds_nodev[] = { { ARG_STR(DM_REMOVE_ALL), false }, @@ -200,6 +207,16 @@ main(void) "-1 EBADF (%m)\n", DM_IOCTL, sizeof(int), dm_arg); + ioctl(-1, dummy_dm_ioctl1, 0); + printf("ioctl(-1, _IOC(_IOC_READ, %#x, 0, %#x), 0) = -1 EBADF (%m)\n", + DM_IOCTL, (unsigned int) _IOC_SIZE(dummy_dm_ioctl1)); + + ioctl(-1, dummy_dm_ioctl2, dummy_dm_arg); + printf("ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, %#x, %#x, 0), %#lx) = " + "-1 EBADF (%m)\n", + DM_IOCTL, (unsigned int) _IOC_NR(dummy_dm_ioctl2), + (unsigned long) dummy_dm_arg); + /* DM_VERSION */ /* Incorrect pointer */ diff --git a/tests/ioctl_evdev.c b/tests/ioctl_evdev.c index b21a962d..74aac0d3 100644 --- a/tests/ioctl_evdev.c +++ b/tests/ioctl_evdev.c @@ -274,6 +274,10 @@ main(void) printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0xfe, 0xff)", lmagic); + ioctl(-1, _IOC(_IOC_READ|_IOC_WRITE, 0x45, 0, 0), lmagic); + printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", + "_IOC(_IOC_READ|_IOC_WRITE, 0x45, 0, 0)", lmagic); + puts("+++ exited with 0 +++"); return 0; }