// https://syzkaller.appspot.com/bug?id=036436b77a8670492f8424eaab00d075c652c45a #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include char vivid_dev[256]; char other_dev[256]; volatile int stop = 0; int write_file(const char *path, const char *val) { int fd = open(path, O_WRONLY); if (fd < 0) return -1; int len = strlen(val); int ret = write(fd, val, len); close(fd); return ret == len ? 0 : -1; } void *thread1(void *arg) { char bind_path[256]; char unbind_path[256]; snprintf(bind_path, sizeof(bind_path), "/sys/bus/platform/drivers/vivid/bind"); snprintf(unbind_path, sizeof(unbind_path), "/sys/bus/platform/drivers/vivid/unbind"); while (!stop) { write_file(bind_path, vivid_dev); write_file(unbind_path, vivid_dev); } return NULL; } void *thread2(void *arg) { char bind_path[256]; char unbind_path[256]; snprintf(bind_path, sizeof(bind_path), "/sys/bus/platform/drivers/vivid/bind"); snprintf(unbind_path, sizeof(unbind_path), "/sys/bus/platform/drivers/vivid/unbind"); while (!stop) { write_file(bind_path, other_dev); write_file(unbind_path, other_dev); } return NULL; } int main() { DIR *dir = opendir("/sys/bus/platform/devices"); if (!dir) { printf("[-] opendir failed: %s\n", strerror(errno)); return 1; } struct dirent *ent; while ((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == '.') continue; if (strncmp(ent->d_name, "vivid", 5) == 0) { strcpy(vivid_dev, ent->d_name); } else if (strcmp(ent->d_name, "reg-dummy") == 0) { strcpy(other_dev, ent->d_name); } } if (other_dev[0] == '\0') { rewinddir(dir); while ((ent = readdir(dir)) != NULL) { if (ent->d_name[0] == '.') continue; if (strncmp(ent->d_name, "vivid", 5) == 0) continue; if (strncmp(ent->d_name, "serial", 6) == 0) continue; if (strncmp(ent->d_name, "pcspkr", 6) == 0) continue; if (strncmp(ent->d_name, "i8042", 5) == 0) continue; if (strncmp(ent->d_name, "rtc", 3) == 0) continue; if (strncmp(ent->d_name, "ACPI", 4) == 0) continue; if (strncmp(ent->d_name, "PNP", 3) == 0) continue; if (strncmp(ent->d_name, "QEMU", 4) == 0) continue; if (strncmp(ent->d_name, "microcode", 9) == 0) continue; if (strncmp(ent->d_name, "regulatory", 10) == 0) continue; if (strncmp(ent->d_name, "vesa-framebuffer", 16) == 0) continue; if (strncmp(ent->d_name, "efi-framebuffer", 15) == 0) continue; if (strncmp(ent->d_name, "efivars", 7) == 0) continue; if (strstr(ent->d_name, "clk") != NULL) continue; if (strstr(ent->d_name, "mdio") != NULL) continue; if (strstr(ent->d_name, "MDIO") != NULL) continue; strcpy(other_dev, ent->d_name); break; } } closedir(dir); if (vivid_dev[0] == '\0') { printf("[-] vivid device not found\n"); return 1; } if (other_dev[0] == '\0') { printf("[-] other device not found\n"); return 1; } printf("[+] vivid_dev: %s\n", vivid_dev); printf("[+] other_dev: %s\n", other_dev); char path[256]; // Unbind other_dev from its current driver snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/driver/unbind", other_dev); write_file(path, other_dev); // Set driver_override for other_dev snprintf(path, sizeof(path), "/sys/bus/platform/devices/%s/driver_override", other_dev); if (write_file(path, "vivid\n") < 0) { printf("[-] Failed to set driver_override for %s\n", other_dev); return 1; } printf("[+] driver_override set for %s\n", other_dev); pthread_t t1, t2; pthread_create(&t1, NULL, thread1, NULL); pthread_create(&t2, NULL, thread2, NULL); sleep(10); stop = 1; pthread_join(t1, NULL); pthread_join(t2, NULL); printf("[+] Done\n"); return 0; }