Skip to content

Commit c16ffdb

Browse files
committed
Update pri_taint hypercall for LAVA - Just dwarf2 fix now
1 parent 0336e19 commit c16ffdb

File tree

3 files changed

+31
-37
lines changed

3 files changed

+31
-37
lines changed

panda/plugins/hypercaller/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ This was designed primarily for Python use cases:
5151
MAGIC = 0x12345678
5252
@panda.hypercall(MAGIC)
5353
def hypercall(cpu):
54-
print("Hello from my hypercall!"
54+
print("Hello from my hypercall!")
5555

5656
```
5757

@@ -64,7 +64,7 @@ It's much easier to handle this from Python, but here's an example of how you mi
6464
#include <panda/plugin.h>
6565
#include <hypercaller/hypercaller.h>
6666

67-
hypercall_t* register_hypercall;
67+
register_hypercall_t register_hypercall;
6868

6969
void my_hypercall(CPUState *cpu) {
7070
printf("Hello from my hypercall!\n");
@@ -76,7 +76,7 @@ bool init_plugin(void *self) {
7676
panda_require("hypercaller");
7777
hypercaller = panda_get_plugin_by_name("hypercaller");
7878
}
79-
register_hypercall = (hypercall_t*)dlsym(hypercaller, "register_hypercall");
79+
register_hypercall_t register_hypercall = (register_hypercall_t) dlsym(hypercaller, "register_hypercall");
8080
register_hypercall(0x12345678, my_hypercall);
8181
return true;
8282
}

panda/plugins/hypercaller/hypercaller.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// files in this directory that contain subsections like this one.
77

88
typedef void (*hypercall_t)(CPUState *cpu);
9+
typedef void (*register_hypercall_t)(uint32_t, hypercall_t);
910
void register_hypercall(uint32_t magic, hypercall_t);
1011
void unregister_hypercall(uint32_t magic);
1112

panda/plugins/pri_taint/pri_taint.cpp

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "callstack_instr/callstack_instr.h"
1616

1717
extern "C" {
18+
#include <hypercaller/hypercaller.h>
1819

1920
#include "panda/rr/rr_log.h"
2021
#include "panda/plog.h"
@@ -37,14 +38,15 @@ extern "C" {
3738
bool init_plugin(void *);
3839
void uninit_plugin(void *);
3940

40-
int get_loglevel() ;
41+
int get_loglevel();
4142
void set_loglevel(int new_loglevel);
4243
}
4344

45+
#define LAVA_MAGIC 0xabcd
4446
const char *global_src_filename = NULL;
4547
uint64_t global_src_linenum;
4648
unsigned global_ast_loc_id;
47-
uint64_t global_funcaddr;
49+
// uint64_t global_funcaddr;
4850
bool debug = false;
4951

5052
#define dprintf(...) if (debug) { printf(__VA_ARGS__); fflush(stdout); }
@@ -237,7 +239,7 @@ struct args {
237239
const char *src_filename;
238240
uint64_t src_linenum;
239241
unsigned ast_loc_id;
240-
uint64_t funcaddr;
242+
// uint64_t funcaddr;
241243
};
242244

243245
#if defined(TARGET_I386)
@@ -264,7 +266,7 @@ void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc
264266
global_src_filename = args->src_filename;
265267
global_src_linenum = args->src_linenum;
266268
global_ast_loc_id = args->ast_loc_id;
267-
global_funcaddr = args->funcaddr;
269+
// global_funcaddr = args->funcaddr;
268270
//target_ulong guest_dword;
269271
//std::string ty_string = std::string(var_ty);
270272
//size_t num_derefs = std::count(ty_string.begin(), ty_string.end(), '*');
@@ -289,8 +291,9 @@ void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc
289291
default:
290292
assert(1==0);
291293
}
292-
// free(si);
293294
}
295+
#endif
296+
294297
/*
295298
void on_line_change(CPUState *cpu, target_ulong pc, const char *file_Name, const char *funct_name, unsigned long long lno){
296299
if (taint2_enabled()){
@@ -319,7 +322,6 @@ void hypercall_log_trace(unsigned ast_loc_id) {
319322
// Support all features of label and query program
320323
void i386_hypercall_callback(CPUState *cpu) {
321324
dprintf("[pri_taint] Calling lava hypercall!\n");
322-
323325
CPUArchState *env = (CPUArchState*) cpu->env_ptr;
324326
if (taint2_enabled()) {
325327
// LAVA Hypercall
@@ -335,17 +337,21 @@ void i386_hypercall_callback(CPUState *cpu) {
335337
(uint32_t) env->regs[R_EDI], (uint32_t) addr);
336338
#else
337339
dprintf("[pri_taint] panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n",
338-
(uint32_t) env->regs[R_EBX], (uint32_t) addr);
340+
(uint32_t) env->regs[R_EBX], (uint32_t) addr);
339341
#endif
340342
}
341343
else if (pandalog) {
342344
dprintf("[pri_taint] Hypercall is OK and Panda Log is set\n");
343345
PandaHypercallStruct phs;
344-
panda_virtual_memory_read(cpu, env->regs[R_EAX], (uint8_t *) &phs, sizeof(phs));
346+
#ifdef TARGET_X86_64
347+
panda_virtual_memory_read(cpu, env->regs[R_EDI], (uint8_t *) &phs, sizeof(phs));
348+
#else
349+
panda_virtual_memory_read(cpu, env->regs[R_EBX], (uint8_t *) &phs, sizeof(phs));
350+
#endif
345351

346352
// To be used for chaff bugs?
347-
uint64_t funcaddr = 0;
348-
panda_virtual_memory_read(cpu, phs.info, (uint8_t*)&funcaddr, sizeof(target_ulong));
353+
// uint64_t funcaddr = 0;
354+
// panda_virtual_memory_read(cpu, phs.info, (uint8_t*)&funcaddr, sizeof(target_ulong));
349355
// if the phs action is a pri_query point, see
350356
// lava/include/pirate_mark_lava.h
351357
if (phs.action == 13) {
@@ -360,6 +366,7 @@ void i386_hypercall_callback(CPUState *cpu) {
360366
"ln: %4ld, pc @ 0x" TARGET_FMT_lx "\n",
361367
info.filename,
362368
info.line_number,pc);
369+
363370
// Calls 'pri_funct_livevar_iter' in pri.c, which calls 'on_funct_livevar_iter'
364371
// In Dwarf2, the function 'on_funct_livevar_iter' is mapped to 'dwarf_funct_livevar_iter'
365372
// This is passing the function 'pfun' to 'pri_funct_livevar_iter', which is called at the end
@@ -368,6 +375,7 @@ void i386_hypercall_callback(CPUState *cpu) {
368375
else {
369376
dprintf("[pri_taint] pri_get_pc_src_info has failed: %d != 0.\n", rc);
370377
}
378+
// hypercall_log_trace(phs.src_filename);
371379
}
372380
else {
373381
dprintf("[pri_taint] Invalid action value in PHS struct: %d != 13.\n", phs.action);
@@ -380,24 +388,9 @@ void i386_hypercall_callback(CPUState *cpu) {
380388
else {
381389
dprintf("[pri_taint] taint2 is not enabled (hypercall)\n");
382390
}
383-
return ret;
384391
}
385392
#endif // TARGET_I386
386393

387-
388-
bool guest_hypercall_callback(CPUState *cpu) {
389-
#ifdef TARGET_I386
390-
return i386_hypercall_callback(cpu);
391-
#endif
392-
393-
#ifdef TARGET_ARM
394-
// not implemented for now
395-
//arm_hypercall_callback(cpu);
396-
#endif
397-
398-
return false;
399-
}
400-
#endif
401394
/*
402395
void on_taint_change(Addr a, uint64_t size){
403396
uint32_t num_tainted = 0;
@@ -425,26 +418,26 @@ bool init_plugin(void *self) {
425418
panda_require("taint2");
426419
assert(init_taint2_api());
427420

428-
panda_cb pcb;
429-
pcb.guest_hypercall = guest_hypercall_callback;
430-
panda_register_callback(self, PANDA_CB_GUEST_HYPERCALL, pcb);
431-
printf("[pri_taint] This plugin is activated!\n");
432-
433421
// If taint isn't already enabled, turn it on.
434422
if (!taint2_enabled()) {
435423
printf("[pri_taint] enabling taint now!\n");
436424
taint2_enable_taint();
437425
}
426+
427+
panda_require("hypercaller");
428+
void * hypercaller = panda_get_plugin_by_name("hypercaller");
429+
register_hypercall_t register_hypercall = (register_hypercall_t) dlsym(hypercaller, "register_hypercall");
430+
register_hypercall(LAVA_MAGIC, i386_hypercall_callback);
431+
432+
printf("[pri_taint] This plugin is activated!\n");
438433
return true;
439434
#else
440435
printf("[pri_taint] This plugin is only supported on x86\n");
441436
return false;
442-
//taint2_track_taint_state();
443437
#endif
444438
}
445439

446-
447-
448440
void uninit_plugin(void *self) {
441+
// You don't need to unregister the hypercall!
442+
printf("[pri_taint] Unloading plugin complete!\n");
449443
}
450-

0 commit comments

Comments
 (0)