1*1b191cb5SApple OSS Distributions #pragma clang diagnostic ignored "-Wdeprecated-declarations" 2*1b191cb5SApple OSS Distributions 3*1b191cb5SApple OSS Distributions #include <sys/codesign.h> 4*1b191cb5SApple OSS Distributions #include <signal.h> 5*1b191cb5SApple OSS Distributions 6*1b191cb5SApple OSS Distributions #include <darwintest.h> 7*1b191cb5SApple OSS Distributions #include <darwintest_utils.h> 8*1b191cb5SApple OSS Distributions 9*1b191cb5SApple OSS Distributions T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true)); 10*1b191cb5SApple OSS Distributions 11*1b191cb5SApple OSS Distributions T_DECL(static_binary, 12*1b191cb5SApple OSS Distributions "Verify that static binaries have CS_NO_UNTRUSTED_HELPERS set") { 13*1b191cb5SApple OSS Distributions int ret; 14*1b191cb5SApple OSS Distributions pid_t pid; 15*1b191cb5SApple OSS Distributions char *launch_argv[] = {"./static_binary", NULL}; 16*1b191cb5SApple OSS Distributions ret = dt_launch_tool(&pid, launch_argv, /*start_suspended*/ true, NULL, NULL); 17*1b191cb5SApple OSS Distributions T_QUIET; 18*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(ret, "dt_launch_tool on static binary"); 19*1b191cb5SApple OSS Distributions 20*1b191cb5SApple OSS Distributions uint32_t status = 0; 21*1b191cb5SApple OSS Distributions ret = csops(pid, CS_OPS_STATUS, &status, sizeof(status)); 22*1b191cb5SApple OSS Distributions T_QUIET; 23*1b191cb5SApple OSS Distributions T_EXPECT_POSIX_SUCCESS(ret, "request CS_OPS_STATUS on static binary"); 24*1b191cb5SApple OSS Distributions 25*1b191cb5SApple OSS Distributions if (!ret) { 26*1b191cb5SApple OSS Distributions T_EXPECT_BITS_SET(status, CS_NO_UNTRUSTED_HELPERS, "CS_NO_UNTRUSTED_HELPERS should be set on static binary"); 27*1b191cb5SApple OSS Distributions } 28*1b191cb5SApple OSS Distributions 29*1b191cb5SApple OSS Distributions ret = kill(pid, SIGCONT); 30*1b191cb5SApple OSS Distributions T_QUIET; 31*1b191cb5SApple OSS Distributions T_ASSERT_POSIX_SUCCESS(ret, "SIGCONT on static binary"); 32*1b191cb5SApple OSS Distributions 33*1b191cb5SApple OSS Distributions int exitstatus, signal; 34*1b191cb5SApple OSS Distributions dt_waitpid(pid, &exitstatus, &signal, 30); 35*1b191cb5SApple OSS Distributions T_QUIET; 36*1b191cb5SApple OSS Distributions T_ASSERT_EQ(signal, 0, "static binary exited"); 37*1b191cb5SApple OSS Distributions T_QUIET; 38*1b191cb5SApple OSS Distributions T_ASSERT_EQ(exitstatus, 42, "static binary exited with code 42"); 39*1b191cb5SApple OSS Distributions } 40