lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Fri, 22 Jul 2016 15:45:53 -0600
From:	Shuah Khan <shuahkh@....samsung.com>
To:	shuahkh@....samsung.com
Cc:	linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org
Subject: [PATCH] selftests: media_tests add a new video device test

Add a new video device test that opens user specified Video Device and
calls video ioctls in a loop once every 10 seconds.

This test is intended for testing device removal and driver unbind while
an ioctl is active. Clean device removal and driver unbind is expected
without any use-after-free and panics.

Signed-off-by: Shuah Khan <shuahkh@....samsung.com>
---
 tools/testing/selftests/media_tests/.gitignore     |   1 +
 tools/testing/selftests/media_tests/Makefile       |   4 +-
 .../selftests/media_tests/video_device_test.c      | 100 +++++++++++++++++++++
 3 files changed, 103 insertions(+), 2 deletions(-)
 create mode 100644 tools/testing/selftests/media_tests/video_device_test.c

diff --git a/tools/testing/selftests/media_tests/.gitignore b/tools/testing/selftests/media_tests/.gitignore
index faf5891..8745eba 100644
--- a/tools/testing/selftests/media_tests/.gitignore
+++ b/tools/testing/selftests/media_tests/.gitignore
@@ -1,2 +1,3 @@
 media_device_test
 media_device_open
+video_device_test
diff --git a/tools/testing/selftests/media_tests/Makefile b/tools/testing/selftests/media_tests/Makefile
index 177256a..6b34a01 100644
--- a/tools/testing/selftests/media_tests/Makefile
+++ b/tools/testing/selftests/media_tests/Makefile
@@ -1,7 +1,7 @@
-TEST_PROGS := media_device_test media_device_open
+TEST_PROGS := media_device_test media_device_open video_device_test
 all: $(TEST_PROGS)
 
 include ../lib.mk
 
 clean:
-	rm -fr media_device_test media_device_open
+	rm -fr media_device_test media_device_open video_device_test
diff --git a/tools/testing/selftests/media_tests/video_device_test.c b/tools/testing/selftests/media_tests/video_device_test.c
new file mode 100644
index 0000000..66d419c
--- /dev/null
+++ b/tools/testing/selftests/media_tests/video_device_test.c
@@ -0,0 +1,100 @@
+/*
+ * video_device_test - Video Device Test
+ *
+ * Copyright (c) 2016 Shuah Khan <shuahkh@....samsung.com>
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * This file is released under the GPLv2.
+ */
+
+/*
+ * This file adds a test for Video Device. This test should not be included
+ * in the Kselftest run. This test should be run when hardware and driver
+ * that makes use of V4L2 API is present.
+ *
+ * This test opens user specified Video Device and calls video ioctls in a
+ * loop once every 10 seconds.
+ *
+ * Usage:
+ *	sudo ./video_device_test -d /dev/videoX
+ *
+ *	While test is running, remove the device or unbind the driver and
+ *	ensure there are no use after free errors and other Oops in the
+ *	dmesg.
+ *	When possible, enable KaSan kernel config option for use-after-free
+ *	error detection.
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <linux/videodev2.h>
+
+int main(int argc, char **argv)
+{
+	int opt;
+	char video_dev[256];
+	int count;
+	struct v4l2_tuner vtuner;
+	struct v4l2_capability vcap;
+	int ret;
+	int fd;
+
+	if (argc < 2) {
+		printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
+		exit(-1);
+	}
+
+	/* Process arguments */
+	while ((opt = getopt(argc, argv, "d:")) != -1) {
+		switch (opt) {
+		case 'd':
+			strncpy(video_dev, optarg, sizeof(video_dev) - 1);
+			video_dev[sizeof(video_dev)-1] = '\0';
+			break;
+		default:
+			printf("Usage: %s [-d </dev/videoX>]\n", argv[0]);
+			exit(-1);
+		}
+	}
+
+	/* Generate random number of interations */
+	srand((unsigned int) time(NULL));
+	count = rand();
+
+	/* Open Video device and keep it open */
+	fd = open(video_dev, O_RDWR);
+	if (fd == -1) {
+		printf("Video Device open errno %s\n", strerror(errno));
+		exit(-1);
+	}
+
+	printf("\nNote:\n"
+	       "While test is running, remove the device or unbind\n"
+	       "driver and ensure there are no use after free errors\n"
+	       "and other Oops in the dmesg. When possible, enable KaSan\n"
+	       "kernel config option for use-after-free error detection.\n\n");
+
+	while (count > 0) {
+		ret = ioctl(fd, VIDIOC_QUERYCAP, &vcap);
+		if (ret < 0)
+			printf("VIDIOC_QUERYCAP errno %s\n", strerror(errno));
+		else
+			printf("Video device driver %s\n", vcap.driver);
+
+		ret = ioctl(fd, VIDIOC_G_TUNER, &vtuner);
+		if (ret < 0)
+			printf("VIDIOC_G_TUNER, errno %s\n", strerror(errno));
+		else
+			printf("type %d rangelow %d rangehigh %d\n",
+				vtuner.type, vtuner.rangelow, vtuner.rangehigh);
+		sleep(10);
+		count--;
+	}
+}
-- 
2.7.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ