Skip to content

Commit 0ca00bb

Browse files
committed
Add LAVA attack points manually
1 parent 0579a4b commit 0ca00bb

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

panda/plugins/pri_taint/pri_taint.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,40 @@ void pfun(void *var_ty_void, const char *var_nm, LocType loc_t, target_ulong loc
301301
}
302302
}
303303

304+
// Taken from taint2_hypercalls.cpp, not sure why but at the moment
305+
// AttackPoints is never populated.
306+
Panda__SrcInfo *pandalog_src_info_create(PandaHypercallStruct phs) {
307+
Panda__SrcInfo *si = (Panda__SrcInfo *) malloc(sizeof(Panda__SrcInfo));
308+
*si = PANDA__SRC_INFO__INIT;
309+
si->filename = phs.src_filename;
310+
si->astnodename = phs.src_ast_node_name;
311+
si->linenum = phs.src_linenum;
312+
si->has_insertionpoint = 0;
313+
if (phs.insertion_point) {
314+
si->has_insertionpoint = 1;
315+
si->insertionpoint = phs.insertion_point;
316+
}
317+
si->has_ast_loc_id = 1;
318+
si->ast_loc_id = phs.src_filename;
319+
return si;
320+
}
321+
322+
void lava_attack_point(PandaHypercallStruct phs) {
323+
if (pandalog) {
324+
Panda__AttackPoint *ap = (Panda__AttackPoint *)malloc(sizeof(Panda__AttackPoint));
325+
*ap = PANDA__ATTACK_POINT__INIT;
326+
ap->info = phs.info;
327+
Panda__LogEntry ple = PANDA__LOG_ENTRY__INIT;
328+
ple.attack_point = ap;
329+
ple.attack_point->src_info = pandalog_src_info_create(phs);
330+
ple.attack_point->call_stack = pandalog_callstack_create();
331+
pandalog_write_entry(&ple);
332+
free(ple.attack_point->src_info);
333+
pandalog_callstack_free(ple.attack_point->call_stack);
334+
free(ap);
335+
}
336+
}
337+
304338
/*
305339
// Trace logging in the level of source code
306340
void hypercall_log_trace(unsigned ast_loc_id) {
@@ -363,22 +397,24 @@ void lava_hypercall(CPUState *cpu) {
363397
// lava/include/pirate_mark_lava.h
364398
if (phs.action == 13) {
365399
target_ulong pc = panda_current_pc(cpu);
366-
SrcInfo info;
367400
// Calls 'pri_get_pc_source_info' in pri.c, which calls 'on_get_pc_source_info'
368401
// In Dwarf2, the function 'on_get_pc_source_info' is mapped to 'dwarf_get_pc_source_info'
402+
SrcInfo info;
369403
int rc = pri_get_pc_source_info(cpu, pc, &info);
370404
if (!rc) {
371405
struct args args = {cpu, info.filename, info.line_number, phs.src_filename};
372406
dprintf("[pri_taint] panda hypercall: [%s], "
373407
"ln: %4ld, pc @ 0x" TARGET_FMT_lx "\n",
374408
info.filename,
375409
info.line_number, pc);
376-
377410
// Calls 'pri_funct_livevar_iter' in pri.c, which calls 'on_funct_livevar_iter'
378411
// In Dwarf2, the function 'on_funct_livevar_iter' is mapped to 'dwarf_funct_livevar_iter'
379412
// This is passing the function 'pfun' to 'pri_funct_livevar_iter', which is called at the end
380413
pri_funct_livevar_iter(cpu, pc, (liveVarCB) pfun, (void *)&args);
381414
}
415+
else if (phs.action == 12) {
416+
lava_attack_point(phs);
417+
}
382418
else {
383419
dprintf("[pri_taint] pri_get_pc_src_info has failed: %d != 0.\n", rc);
384420
}

0 commit comments

Comments
 (0)