// https://syzkaller.appspot.com/bug?id=86ced160b3c394018a4d5dd1db69824b7b1b6734 #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include const char *tracefs_path = NULL; int stop = 0; int write_file(const char *path, const char *val) { int fd = open(path, O_WRONLY); if (fd < 0) return -1; ssize_t res = write(fd, val, strlen(val)); close(fd); return res > 0 ? 0 : -1; } void *writer_thread(void *arg) { char path[256]; snprintf(path, sizeof(path), "%s/events/sched/sched_process_exit/enable", tracefs_path); while (!__atomic_load_n(&stop, __ATOMIC_RELAXED)) { write_file(path, "1"); write_file(path, "0"); } return NULL; } void *reader_thread(void *arg) { while (!__atomic_load_n(&stop, __ATOMIC_RELAXED)) { usleep(1); } return NULL; } int main() { const char *paths[] = { "/sys/kernel/tracing", "/sys/kernel/debug/tracing" }; for (int i = 0; i < 2; i++) { char test_path[256]; snprintf(test_path, sizeof(test_path), "%s/events/sched/sched_process_fork/enable", paths[i]); int fd = open(test_path, O_RDWR); if (fd >= 0) { close(fd); tracefs_path = paths[i]; break; } } if (!tracefs_path) { printf("[-] Failed to find tracefs.\n"); exit(1); } printf("[+] Found tracefs at %s\n", tracefs_path); char baseline_path[256]; snprintf(baseline_path, sizeof(baseline_path), "%s/events/sched/sched_process_fork/enable", tracefs_path); if (write_file(baseline_path, "1") < 0) { printf("[-] Failed to enable baseline event: %s\n", strerror(errno)); exit(1); } printf("[+] Baseline event enabled.\n"); pthread_t writer; if (pthread_create(&writer, NULL, writer_thread, NULL) != 0) { printf("[-] Failed to create writer thread: %s\n", strerror(errno)); exit(1); } printf("[+] Writer thread created.\n"); pthread_t readers[8]; for (int i = 0; i < 8; i++) { if (pthread_create(&readers[i], NULL, reader_thread, NULL) != 0) { printf("[-] Failed to create reader thread %d: %s\n", i, strerror(errno)); exit(1); } } printf("[+] Reader threads created.\n"); sleep(10); __atomic_store_n(&stop, 1, __ATOMIC_RELAXED); pthread_join(writer, NULL); for (int i = 0; i < 8; i++) { pthread_join(readers[i], NULL); } // Disable baseline event write_file(baseline_path, "0"); printf("[+] Done.\n"); return 0; }