xref: /xnu-11215/tests/stack_chk_tests.c (revision e7776783)
1 #include <darwintest.h>
2 #include <sys/sysctl.h>
3 
4 T_GLOBAL_META(
5 	T_META_NAMESPACE("xnu"),
6 	T_META_RADAR_COMPONENT_NAME("xnu"),
7 	T_META_RADAR_COMPONENT_VERSION("security"),
8 	T_META_OWNER("chrisjd")
9 	);
10 
11 T_DECL(stack_chk_tests, "invoke the kernel stack check tests",
12     T_META_ASROOT(true),
13     T_META_REQUIRES_SYSCTL_EQ("kern.development", 1),
14     T_META_REQUIRES_SYSCTL_NE("kern.kasan.available", 1))
15 {
16 	int ret, dummy = 1;
17 	ret = sysctlbyname("kern.run_stack_chk_tests", NULL, NULL, &dummy, sizeof(dummy));
18 
19 	if (ret == -1 && errno == ENOENT) {
20 		/* sysctl not present, so skip. */
21 		T_PASS("kern.run_stack_chk_tests not on this platform/configuration");
22 	} else {
23 		T_ASSERT_POSIX_SUCCESS(ret, "run stack check tests");
24 	}
25 }
26