void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc, void *in_args){ //void pfun(const char *var_ty, const char *var_nm, LocType loc_t, target_ulong loc, void *in_args){ // restore args const char *var_ty = (const char *) var_ty_void; struct args *args = (struct args *) in_args; CPUState *pfun_env = args->env; const char *src_filename = args->src_filename; uint64_t src_linenum = args->src_linenum; target_ulong guest_dword; std::string ty_string = std::string(var_ty); size_t num_derefs = std::count(ty_string.begin(), ty_string.end(), '*'); size_t i; //Panda__SrcInfoPri *si = pandalog_src_info_pri_create(const char *src_filename, uint64_t src_linenum, const char *src_ast_node_name); Panda__SrcInfoPri *si = pandalog_src_info_pri_create(src_filename, src_linenum, var_nm); switch (loc_t){ case LocReg: guest_dword = pfun_env->regs[loc]; if (num_derefs > 0) { for (i = 0; i < num_derefs; i++) { int rc = panda_virtual_memory_rw(pfun_env, guest_dword, (uint8_t *)&guest_dword, sizeof(guest_dword), 0); if (0 != rc) break; } if (0 != taint2_query_ram(panda_virt_to_phys(pfun_env, guest_dword))) { printf("VAR REG: %s %s in Reg %d\n", var_ty, var_nm, loc); printf(" => 0x%x, derefs: %ld\n", guest_dword, i); printf(" ==Location is tainted!==\n"); lava_taint_query(si, guest_dword, 1); } } else { // only query reg taint if the reg number is less than the number of registers if (loc < CPU_NB_REGS) { if (0 != taint2_query_reg(loc, 0)) { printf("VAR REG: %s %s in Reg %d\n", var_ty, var_nm, loc); printf(" => 0x%x, derefs: %d\n", guest_dword, 0); printf(" ==Reg is tainted!==\n"); } } } break; case LocMem: guest_dword = loc; for (i = 0; i < num_derefs; i++) { if (0 != panda_virtual_memory_rw(pfun_env, guest_dword, (uint8_t *)&guest_dword, sizeof(guest_dword), 0)){ break; } } if (0 != taint2_query_ram(panda_virt_to_phys(pfun_env, guest_dword))) { printf("VAR MEM: %s %s @ 0x%x\n", var_ty, var_nm, loc); printf(" => 0x%x, derefs: %ld\n", guest_dword, i); printf(" ==Location is tainted!==\n"); lava_taint_query(si, guest_dword, 1); } break; case LocConst: //printf("VAR CONST: %s %s as 0x%x\n", var_ty, var_nm, loc); break; case LocErr: //printf("VAR does not have a location we could determine. Most likely because the var is split among multiple locations\n"); break; // should not get here default: assert(1==0); } }
// Support all features of label and query program void i386_hypercall_callback(CPUState *env){ #if 0 if (EAX == 0xabcd) { printf ("\n hypercall pc=0x%x\n", (int) panda_current_pc(env)); for (uint32_t i=0; i<8; i++) { printf ("reg[%d] = 0x%x\n", i, (int) env->regs[i]); } } #endif //printf("taint2: Hypercall! B " TARGET_FMT_lx " C " TARGET_FMT_lx " D " TARGET_FMT_lx "\n", // env->regs[R_EBX], env->regs[R_ECX], env->regs[R_EDX]); #if 0 // Label op. // EBX contains addr of that data // ECX contains size of data // EDX contains the label; ~0UL for autoenc. if ((env->regs[R_EAX] == 7 || env->regs[R_EAX] == 8)) { printf ("hypercall -- EAX=0x%x\n", EAX); target_ulong addr = panda_virt_to_phys(env, env->regs[R_EBX]); target_ulong size = env->regs[R_ECX]; target_ulong label = env->regs[R_EDX]; if (!taintEnabled){ printf("taint2: Label operation detected @ %lu\n", rr_get_guest_instr_count()); printf("taint2: Labeling " TARGET_FMT_lx " to " TARGET_FMT_lx " with label " TARGET_FMT_lx ".\n", addr, addr + size, label); __taint2_enable_taint(); } LabelSetP ls = NULL; if (label != (target_ulong)~0UL) { ls = label_set_singleton(label); } // otherwise autoinc. qemu_log_mask(CPU_LOG_TAINT_OPS, "label: %lx[%lx+%lx] <- %lx (%lx)\n", (uint64_t)shadow->ram, (uint64_t)addr, (uint64_t)size, (uint64_t)label, (uint64_t)ls); for (unsigned i = 0; i < size; i++) { //printf("label %u\n", i); shadow->ram->set(addr + i, label_set_singleton(i)); } } #endif if (pandalog && env->regs[R_EAX] == 0xabcd) { // LAVA Hypercall target_ulong addr = panda_virt_to_phys(env, ECX); if ((int)addr == -1) { printf ("panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n", (uint32_t) ECX, (uint32_t) addr); } else { PandaHypercallStruct phs; panda_virtual_memory_rw(env, ECX, (uint8_t *) &phs, sizeof(phs), false); if (phs.action == 11) { // it's a lava query lava_taint_query(phs); } if (phs.action == 12) { // it's an attack point sighting lava_attack_point(phs); } } } }
// Support all features of label and query program void i386_hypercall_callback(CPUState *env){ if (taintEnabled && pandalog) { // LAVA Hypercall #ifdef TAINT_LEGACY_HYPERCALL target_ulong buf_start = EBX; target_ulong buf_len = ECX; long label = EDI; // call to label data // EBX contains addr of that data // ECX contains size of data // EDI is the label integer // EDX = starting offset (for positional labels only) // -mostly not used, this is managed in pirate_utils if (EAX == 7 || EAX == 8){ if (!taintEnabled){ printf("Taint plugin: Label operation detected\n"); printf("Enabling taint processing\n"); __taint2_enable_taint(); } if (EAX == 7){ // Standard buffer label printf("taint2: single taint label\n"); taint2_add_taint_ram_single_label(env, (uint64_t)buf_start, (int)buf_len, label); } else if (EAX == 8){ // Positional buffer label printf("taint2: positional taint label\n"); taint2_add_taint_ram_pos(env, (uint64_t)buf_start, (int)buf_len); } } /* //mz Query taint on this buffer //mz EBX = start of buffer (VA) //mz ECX = size of buffer (bytes) // EDX = starting offset - for file queries // -mostly not used, this is managed in pirate_utils else if (env->regs[R_EAX] == 9){ //Query taint on label if (taintEnabled){ printf("Taint plugin: Query operation detected\n"); Addr a = make_maddr(buf_start); bufplot(env, shadow, &a, (int)buf_len); } //printf("Disabling taint processing\n"); //taintEnabled = false; //taintJustDisabled = true; //printf("Label occurrences on HD: %d\n", shad_dir_occ_64(shadow->hd)); } else if (env->regs[R_EAX] == 10){ // Guest util done - reset positional label counter taint_pos_count = 0; } */ #else target_ulong addr = panda_virt_to_phys(env, EAX); if ((int)addr == -1) { printf ("panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n", (uint32_t) EAX, (uint32_t) addr); } else { PandaHypercallStruct phs; panda_virtual_memory_rw(env, EAX, (uint8_t *) &phs, sizeof(phs), false); if (phs.magic == 0xabcd) { if (phs.action == 11) { // it's a lava query lava_taint_query(phs); } else if (phs.action == 12) { // it's an attack point sighting lava_attack_point(phs); } else { printf("Unknown hypercall action %d\n", phs.action); } } else { printf ("Invalid magic value in PHS struct: %x != 0xabcd.\n", phs.magic); } } #endif // TAINT_LEGACY_HYPERCALL } }