15
15
#include " callstack_instr/callstack_instr.h"
16
16
17
17
extern " C" {
18
+ // hypercalls
19
+ #include < hypercaller/hypercaller.h>
18
20
19
21
#include " panda/rr/rr_log.h"
20
22
#include " panda/plog.h"
@@ -37,10 +39,11 @@ extern "C" {
37
39
bool init_plugin (void *);
38
40
void uninit_plugin (void *);
39
41
40
- int get_loglevel () ;
42
+ int get_loglevel ();
41
43
void set_loglevel (int new_loglevel);
42
44
}
43
45
46
+ #define LAVA_MAGIC 0xabcd
44
47
const char *global_src_filename = NULL ;
45
48
uint64_t global_src_linenum;
46
49
unsigned global_ast_loc_id;
@@ -308,6 +311,8 @@ void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc
308
311
}
309
312
// free(si);
310
313
}
314
+ #endif
315
+
311
316
/*
312
317
void on_line_change(CPUState *cpu, target_ulong pc, const char *file_Name, const char *funct_name, unsigned long long lno){
313
318
if (taint2_enabled()){
@@ -334,63 +339,69 @@ void hypercall_log_trace(unsigned ast_loc_id) {
334
339
*/
335
340
#ifdef TARGET_I386
336
341
// Support all features of label and query program
337
- bool i386_hypercall_callback (CPUState *cpu) {
342
+ void i386_hypercall_callback (CPUState *cpu) {
338
343
if (debug) {
339
344
printf (" [pri_taint] Calling i386 hypercall callback!\n " );
340
345
}
341
- bool ret = false ;
342
- CPUArchState *env = (CPUArchState*)cpu->env_ptr ;
346
+ CPUArchState *env = (CPUArchState*) cpu->env_ptr ;
343
347
if (taint2_enabled ()) {
344
348
// LAVA Hypercall
345
- target_ulong addr = panda_virt_to_phys (cpu, env->regs [R_EAX]);
346
- if ((int )addr == -1 ) {
347
- printf (" [pri_taint] panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n " ,
348
- (uint32_t ) env->regs [R_EAX], (uint32_t ) addr);
349
+ #ifdef TARGET_X86_64
350
+ target_ulong addr = panda_virt_to_phys (cpu, env->regs [R_EDI]);
351
+ #else
352
+ target_ulong addr = panda_virt_to_phys (cpu, env->regs [R_EBX]);
353
+ #endif
354
+
355
+ if ((int ) addr == -1 ) {
356
+ #ifdef TARGET_X86_64
357
+ printf (" [pri_taint] panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n " ,
358
+ (uint32_t ) env->regs [R_EDI], (uint32_t ) addr);
359
+ #else
360
+ printf (" [pri_taint] panda hypercall with ptr to invalid PandaHypercallStruct: vaddr=0x%x paddr=0x%x\n " ,
361
+ (uint32_t ) env->regs [R_EBX], (uint32_t ) addr);
362
+ #endif
349
363
}
350
364
else if (pandalog) {
351
365
if (debug) {
352
366
printf (" [pri_taint] Hypercall is OK and Panda Log is set\n " );
353
367
}
354
368
PandaHypercallStruct phs;
355
- panda_virtual_memory_read (cpu, env->regs [R_EAX], (uint8_t *) &phs, sizeof (phs));
369
+ #ifdef TARGET_X86_64
370
+ panda_virtual_memory_read (cpu, env->regs [R_EDI], (uint8_t *) &phs, sizeof (phs));
371
+ #else
372
+ panda_virtual_memory_read (cpu, env->regs [R_EBX], (uint8_t *) &phs, sizeof (phs));
373
+ #endif
356
374
357
375
// To be used for chaff bugs?
358
376
uint64_t funcaddr = 0 ;
359
377
panda_virtual_memory_read (cpu, phs.info , (uint8_t *)&funcaddr, sizeof (target_ulong));
360
378
361
- if (phs.magic == 0xabcd ) {
362
- // if the phs action is a pri_query point, see
363
- // lava/include/pirate_mark_lava.h
364
- if (phs.action == 13 ) {
365
- target_ulong pc = panda_current_pc (cpu);
366
- SrcInfo info;
367
- int rc = pri_get_pc_source_info (cpu, pc, &info);
368
- if (!rc) {
369
- struct args args = {cpu, info.filename , info.line_number , phs.src_filename , funcaddr};
370
- dprintf (" [pri_taint] panda hypercall: [%s], "
371
- " ln: %4ld, pc @ 0x" TARGET_FMT_lx " \n " ,
372
- info.filename ,
373
- info.line_number ,pc);
374
- pri_funct_livevar_iter (cpu, pc, (liveVarCB) pfun, (void *)&args);
375
- // lava_attack_point(phs);
376
- }
377
- else {
378
- if (debug) {
379
- printf (" [pri_taint] pri_get_pc_src_info has failed: %d != 0.\n " , rc);
380
- }
381
- }
382
- ret = true ;
383
- // hypercall_log_trace(phs.src_filename);
379
+ // if the phs action is a pri_query point, see
380
+ // lava/include/pirate_mark_lava.h
381
+ if (phs.action == 13 ) {
382
+ target_ulong pc = panda_current_pc (cpu);
383
+ SrcInfo info;
384
+ int rc = pri_get_pc_source_info (cpu, pc, &info);
385
+ if (!rc) {
386
+ struct args args = {cpu, info.filename , info.line_number , phs.src_filename , funcaddr};
387
+ dprintf (" [pri_taint] panda hypercall: [%s], "
388
+ " ln: %4ld, pc @ 0x" TARGET_FMT_lx " \n " ,
389
+ info.filename ,
390
+ info.line_number ,pc);
391
+ pri_funct_livevar_iter (cpu, pc, (liveVarCB) pfun, (void *)&args);
384
392
}
385
393
else {
386
394
if (debug) {
387
- printf (" [pri_taint] Invalid action value in PHS struct : %d != 13 .\n " , phs. action );
388
- }
395
+ printf (" [pri_taint] pri_get_pc_src_info has failed : %d != 0 .\n " , rc );
396
+ }
389
397
}
398
+ // hypercall_log_trace(phs.src_filename);
390
399
}
391
400
else {
392
- printf (" [pri_taint] Invalid magic value in PHS struct: %x != 0xabcd.\n " , phs.magic );
393
- }
401
+ if (debug) {
402
+ printf (" [pri_taint] Invalid action value in PHS struct: %d != 13.\n " , phs.action );
403
+ }
404
+ }
394
405
}
395
406
else {
396
407
if (debug) {
@@ -403,24 +414,9 @@ bool i386_hypercall_callback(CPUState *cpu) {
403
414
printf (" [pri_taint] taint2 is not enabled (hypercall)\n " );
404
415
}
405
416
}
406
- return ret;
407
417
}
408
418
#endif // TARGET_I386
409
419
410
-
411
- bool guest_hypercall_callback (CPUState *cpu) {
412
- #ifdef TARGET_I386
413
- return i386_hypercall_callback (cpu);
414
- #endif
415
-
416
- #ifdef TARGET_ARM
417
- // not implemented for now
418
- // arm_hypercall_callback(cpu);
419
- #endif
420
-
421
- return false ;
422
- }
423
- #endif
424
420
/*
425
421
void on_taint_change(Addr a, uint64_t size){
426
422
uint32_t num_tainted = 0;
@@ -448,26 +444,27 @@ bool init_plugin(void *self) {
448
444
panda_require (" taint2" );
449
445
assert (init_taint2_api ());
450
446
451
- panda_cb pcb;
452
- pcb.guest_hypercall = guest_hypercall_callback;
453
- panda_register_callback (self, PANDA_CB_GUEST_HYPERCALL, pcb);
454
- printf (" [pri_taint] This plugin is activated!\n " );
455
-
456
447
// If taint isn't already enabled, turn it on.
457
448
if (!taint2_enabled ()) {
458
449
printf (" [pri_taint] enabling taint now!\n " );
459
450
taint2_enable_taint ();
460
451
}
452
+
453
+ panda_require (" hypercaller" );
454
+ void * hypercaller = panda_get_plugin_by_name (" hypercaller" );
455
+ register_hypercall_t register_hypercall = (register_hypercall_t ) dlsym (hypercaller, " register_hypercall" );
456
+ register_hypercall (LAVA_MAGIC, i386_hypercall_callback);
457
+
458
+ printf (" [pri_taint] This plugin is activated!\n " );
461
459
return true ;
462
460
#else
463
461
printf (" [pri_taint] This plugin is only supported on x86\n " );
464
462
return false ;
465
- // taint2_track_taint_state();
466
463
#endif
467
464
}
468
465
469
-
470
-
471
466
void uninit_plugin (void *self) {
467
+ // unregister_hypercall(LAVA_MAGIC);
468
+ printf (" [pri_taint] Unloading plugin\n " );
472
469
}
473
470
0 commit comments