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