socsvn commit: r268638 - in soc2014/op/tests/smap-tester: . kmod smap-test
op at FreeBSD.org
op at FreeBSD.org
Mon May 26 14:11:10 UTC 2014
Author: op
Date: Mon May 26 14:11:08 2014
New Revision: 268638
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=268638
Log:
added basic kernel module framework for SMAP testing
Signed-off-by: Oliver Pinter <oliver.pntr at gmail.com>
Added:
soc2014/op/tests/smap-tester/
soc2014/op/tests/smap-tester/Makefile
soc2014/op/tests/smap-tester/kmod/
soc2014/op/tests/smap-tester/kmod/.clang_complete
soc2014/op/tests/smap-tester/kmod/Makefile
soc2014/op/tests/smap-tester/kmod/smap-tester-vuln-kld.c
soc2014/op/tests/smap-tester/smap-test/
soc2014/op/tests/smap-tester/smap-test/Makefile
soc2014/op/tests/smap-tester/smap-test/smap-test.c
Added: soc2014/op/tests/smap-tester/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/op/tests/smap-tester/Makefile Mon May 26 14:11:08 2014 (r268638)
@@ -0,0 +1,3 @@
+SUBDIR= kmod smap-test
+
+.include <bsd.subdir.mk>
Added: soc2014/op/tests/smap-tester/kmod/.clang_complete
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/op/tests/smap-tester/kmod/.clang_complete Mon May 26 14:11:08 2014 (r268638)
@@ -0,0 +1,6 @@
+-D_KERNEL
+-DKERNEL
+-I/usr/src
+-I/usr/src/sys
+-I/usr/src/sys/amd64
+-I/usr/src/sys/x86
Added: soc2014/op/tests/smap-tester/kmod/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/op/tests/smap-tester/kmod/Makefile Mon May 26 14:11:08 2014 (r268638)
@@ -0,0 +1,4 @@
+KMOD= smap-tester-vuln-kld
+SRCS= smap-tester-vuln-kld.c
+
+.include <bsd.kmod.mk>
Added: soc2014/op/tests/smap-tester/kmod/smap-tester-vuln-kld.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/op/tests/smap-tester/kmod/smap-tester-vuln-kld.c Mon May 26 14:11:08 2014 (r268638)
@@ -0,0 +1,89 @@
+#include <sys/types.h>
+#include <sys/module.h>
+#include <sys/systm.h>
+#include <sys/param.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/uio.h>
+#include <sys/malloc.h>
+#include <vm/vm.h>
+
+const char *agreement = "shoot my foot!!!11oneone!!";
+static bool allow_tests = false;
+static char *buf = NULL;
+static caddr_t us_addr=NULL;
+
+MALLOC_DECLARE(M_SMAP_TEST);
+MALLOC_DEFINE(M_SMAP_TEST, "smap test", "Intel SMAP test malloc area");
+
+SYSCTL_DECL(_debug);
+SYSCTL_NODE(_debug, OID_AUTO, smap, CTLFLAG_RD, 0,
+ "Intel SMAP test cases.");
+
+static int
+sysctl_debug_smap_agreement(SYSCTL_HANDLER_ARGS)
+{
+ int error=0;
+
+ error = sysctl_handle_string(oidp, buf, 4096, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+
+ if (strcmp(buf, agreement) == 0) {
+ printf("SMAP test enabled!\n");
+ allow_tests = true;
+ } else {
+ printf("SMAP test disabled!\n");
+ allow_tests = false;
+ }
+
+ return (error);
+}
+
+SYSCTL_PROC(_debug_smap, OID_AUTO, agreement_string, CTLTYPE_STRING | CTLFLAG_RW,
+ 0, 0, sysctl_debug_smap_agreement,
+ "A", "shoot my foot!!!11oneone!!");
+
+static int
+sysctl_debug_smap_us_addr(SYSCTL_HANDLER_ARGS)
+{
+ int error=0;
+
+ error = sysctl_handle_long(oidp, &us_addr, 0, req);
+ if (error != 0 || req->newptr == NULL)
+ return (error);
+
+ printf("us_addr set to %p\n", us_addr);
+
+ return (error);
+}
+
+SYSCTL_PROC(_debug_smap, OID_AUTO, us_addr, CTLTYPE_LONG | CTLFLAG_RW,
+ 0, 0, sysctl_debug_smap_us_addr,
+ "L", "user-space address");
+
+
+
+static int
+smap_tester_vuln_kld_loader(struct module *m __unused, int what, void *arg __unused)
+{
+ int error = 0;
+
+ switch (what) {
+ case MOD_LOAD:
+ buf = malloc(4096, M_SMAP_TEST, M_WAITOK | M_ZERO);
+ printf("SMAP tester loaded.\n");
+ break;
+ case MOD_UNLOAD:
+ free(buf, M_SMAP_TEST);
+ printf("SMAP tester unloaded.\n");
+ break;
+ default:
+ error = EOPNOTSUPP;
+ break;
+ }
+ return (error);
+}
+
+DEV_MODULE(smap_tester_vuln_kld, smap_tester_vuln_kld_loader, NULL);
Added: soc2014/op/tests/smap-tester/smap-test/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/op/tests/smap-tester/smap-test/Makefile Mon May 26 14:11:08 2014 (r268638)
@@ -0,0 +1,5 @@
+PROG= smap-test
+
+NO_MAN=
+
+.include <bsd.prog.mk>
Added: soc2014/op/tests/smap-tester/smap-test/smap-test.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2014/op/tests/smap-tester/smap-test/smap-test.c Mon May 26 14:11:08 2014 (r268638)
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char **argv)
+{
+ printf("NI!\n");
+
+ return (0);
+}
More information about the svn-soc-all
mailing list