// https://syzkaller.appspot.com/bug?id=94848148d09f6c10b27d852949f54f9946ab37d0 #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include int pipe_fd = -1; int marker_fd = -1; void *poll_thread(void *arg) { struct pollfd pfd; pfd.fd = pipe_fd; pfd.events = POLLIN; while (1) { int res = poll(&pfd, 1, 0); if (res < 0) { if (errno == EINTR) continue; printf("[-] Failed to poll: %s\n", strerror(errno)); exit(1); } } return NULL; } void *write_thread(void *arg) { int cpu = (int)(long)arg; cpu_set_t cpuset; CPU_ZERO(&cpuset); long num_cpus = sysconf(_SC_NPROCESSORS_ONLN); if (num_cpus < 1) num_cpus = 1; CPU_SET(cpu % num_cpus, &cpuset); int res = sched_setaffinity(0, sizeof(cpu_set_t), &cpuset); if (res < 0) { printf("[-] Failed to sched_setaffinity: %s\n", strerror(errno)); exit(1); } printf("[+] sched_setaffinity successful for CPU %d.\n", cpu); while (1) { ssize_t wres = write(marker_fd, "a", 1); if (wres < 0) { printf("[-] Failed to write: %s\n", strerror(errno)); exit(1); } } return NULL; } int main(void) { pipe_fd = open("/sys/kernel/tracing/trace_pipe", O_RDONLY); if (pipe_fd < 0) { pipe_fd = open("/sys/kernel/debug/tracing/trace_pipe", O_RDONLY); } if (pipe_fd < 0) { printf("[-] Failed to open trace_pipe: %s\n", strerror(errno)); exit(1); } printf("[+] open trace_pipe successful.\n"); marker_fd = open("/sys/kernel/tracing/trace_marker", O_WRONLY); if (marker_fd < 0) { marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_WRONLY); } if (marker_fd < 0) { printf("[-] Failed to open trace_marker: %s\n", strerror(errno)); exit(1); } printf("[+] open trace_marker successful.\n"); pthread_t p_thread; int res = pthread_create(&p_thread, NULL, poll_thread, NULL); if (res != 0) { printf("[-] Failed to pthread_create poll_thread: %s\n", strerror(res)); exit(1); } printf("[+] pthread_create poll_thread successful.\n"); int num_writers = 2; pthread_t w_threads[2]; for (int i = 0; i < num_writers; i++) { res = pthread_create(&w_threads[i], NULL, write_thread, (void *)(long)i); if (res != 0) { printf("[-] Failed to pthread_create write_thread %d: %s\n", i, strerror(res)); exit(1); } printf("[+] pthread_create write_thread %d successful.\n", i); } // Keep the main thread alive to let the race happen while (1) { sleep(10); } return 0; }