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