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