/* * Copyright 2002-2019 Intel Corporation. * * This software is provided to you as Sample Source Code as defined in the accompanying * End User License Agreement for the Intel(R) Software Development Products ("Agreement") * section 1.L. * * This software and the related documents are provided as is, with no express or implied * warranties, other than those that are expressly stated in the License. */ /* * This test verifies that Pin correctly returns EFAULT when emulating a system call * that has an invalid pointer parameter. For example, Pin must not crash when * reading through an invalid pointer that is passed in from the application. * * Note, this test must invoke the system calls directly with syscall() instead of * using the libc wrappers. The libc wrappers don't check for invalid pointers, so * passing an invalid pointer can cause a crash in libc! */ #include #include #include #include #include int main() { int ret; #ifdef SYS_rt_sigsuspend ret = syscall(SYS_rt_sigsuspend, -1, 8); if (ret != -1 || errno != EFAULT) { printf("SYS_rt_sigsuspend did not return EFAULT: ret=%d, errno=%d\n", ret, errno); return 1; } #endif #ifdef SYS_sigsuspend ret = syscall(SYS_sigsuspend, -1); if (ret != -1 || errno != EFAULT) { printf("SYS_sigsuspend did not return EFAULT: ret=%d, errno=%d\n", ret, errno); return 1; } #endif #ifdef SYS_rt_sigprocmask ret = syscall(SYS_rt_sigprocmask, SIG_SETMASK, -1, -1, 8); if (ret != -1 || errno != EFAULT) { printf("SYS_rt_sigprocmask did not return EFAULT: ret=%d, errno=%d\n", ret, errno); return 1; } #endif #ifdef SYS_sigprocmask ret = syscall(SYS_sigprocmask, SIG_SETMASK, -1, -1); if (ret != -1 || errno != EFAULT) { printf("SYS_sigprocmask did not return EFAULT: ret=%d, errno=%d\n", ret, errno); return 1; } #endif #ifdef SYS_rt_sigaction ret = syscall(SYS_rt_sigaction, SIGUSR1, -1, -1, 8); if (ret != -1 || errno != EFAULT) { printf("SYS_rt_sigaction did not return EFAULT: ret=%d, errno=%d\n", ret, errno); return 1; } #endif #ifdef SYS_sigaction ret = syscall(SYS_sigaction, SIGUSR1, -1, -1); if (ret != -1 || errno != EFAULT) { printf("SYS_sigaction did not return EFAULT: ret=%d, errno=%d\n", ret, errno); return 1; } #endif return 0; }