Skip to content
Snippets Groups Projects
Commit 72fbf7e1 authored by an7s's avatar an7s
Browse files

Reverted back to shared cfi path

parent dbf50334
No related branches found
No related tags found
No related merge requests found
......@@ -36,12 +36,11 @@ using namespace libIRDB;
void usage(char* name)
{
cerr<<" Usage: "<<name<<" <variant_id> \n"
" [--clamp-mask <mask>] -- In hex, defaults to 0xffffffff\n"
" [--color|--no-color] -- defaults to no-color\n"
" [--protect-jumps|--no-protect-jumps] -- defaults to protect-jumps \n"
" [--protect-rets|--no-protect-rets] -- defaults to protect-rets \n"
" [--protect-safefn|--no-protect-safefn] -- defaults to no-protect-safefn\n"
" [ --common-slow-path | --no-common-slow-path ] -- defaults to common-slow-path\n"
" [--color|--no-color] \n"
" [--protect-jumps|--no-protect-jumps] \n"
" [--protect-rets|--no-protect-rets] \n"
" [--protect-safefn|--no-protect-safefn] \n"
" [ --common-slow-path | --no-common-slow-path ] \n"
" \n"
"default: --no-color --protect-jumps --protect-rets --no-protect-safefn --common-slow-path\n";
}
......@@ -60,7 +59,6 @@ int main(int argc, char **argv)
exit(1);
}
uint32_t clampmask=(uint32_t)-1;
bool do_coloring=false;
bool do_common_slow_path=true;
bool do_jumps=true;
......@@ -68,24 +66,7 @@ int main(int argc, char **argv)
bool do_safefn=false;
for(int i=2;i<argc;i++)
{
if(string(argv[i])=="--clamp-mask")
{
if(i<argc)
{
i++;
clampmask=strtol(argv[i], NULL, 0); // interpret argv[i] as a variable base string
cout<<"Using clamp mask = "<<hex<<clampmask<<endl;
}
else
{
cerr<<"--clamp-mask must take a (hex) value"<<endl;
usage(argv[0]);
exit(1);
}
}
else if(string(argv[i])=="--color")
if(string(argv[i])=="--color")
{
cout<<"Using coloring..."<<endl;
do_coloring=true;
......@@ -171,7 +152,8 @@ int main(int argc, char **argv)
try
{
SCFI_Instrument scfii(firp, do_coloring, do_common_slow_path, do_jumps, do_rets, do_safefn, clampmask);
SCFI_Instrument scfii(firp, do_coloring, do_common_slow_path, do_jumps, do_rets, do_safefn);
int success=scfii.execute();
......
......@@ -416,6 +416,19 @@ void SCFI_Instrument::AddJumpCFI(Instruction_t* insn)
string pushbits=change_to_push(insn);
cout<<"Converting ' "<<insn->getDisassembly()<<"' to '";
Instruction_t* after=insertDataBitsBefore(firp,insn,pushbits);
#ifdef CGC
// insert the pop/checking code.
cout<<insn->getDisassembly()<<"+jmp slowpath'"<<endl;
string jmpBits=getJumpDataBits();
after->SetDataBits(jmpBits);
after->SetComment(insn->getDisassembly()+" ; scfi");
assert(do_common_slow_path); /* fixme: this defaults to the slow_cfi path. need to color accordingly */
createNewRelocation(firp,after,"slow_cfi_path",0);
after->SetFallthrough(NULL);
after->SetTarget(after);
return;
#else
after->SetDataBits(getRetDataBits());
cout <<insn->getDisassembly()<<" + ret' "<<endl ;
......@@ -428,6 +441,7 @@ void SCFI_Instrument::AddJumpCFI(Instruction_t* insn)
AddReturnCFI(after,v);
// cout<<"Warning, JUMPS not CFI's yet"<<endl;
return;
#endif
}
......@@ -500,6 +514,21 @@ void SCFI_Instrument::AddReturnCFI(Instruction_t* insn, ColoredSlotValue_t *v)
#ifdef CGC
// insert the pop/checking code.
Instruction_t* after=insn;
string jmpBits=getJumpDataBits();
after->SetDataBits(jmpBits);
after->SetComment(insn->getDisassembly()+" ; scfi");
createNewRelocation(firp,after,slow_cfi_path_reloc_string,0);
after->SetFallthrough(NULL);
after->SetTarget(after);
return;
#else
string decoration="";
int nonce_size=GetNonceSize(insn);
int nonce_offset=GetNonceOffset(insn);
......@@ -537,13 +566,6 @@ void SCFI_Instrument::AddReturnCFI(Instruction_t* insn, ColoredSlotValue_t *v)
cout<<"Converting "<<dec<<tmp->GetFallthrough()->GetBaseID()<<":"<<tmp->GetFallthrough()->getDisassembly()<<"to jmp+reg"<<endl;
setInstructionAssembly(firp,tmp->GetFallthrough(), string("jmp ")+reg, NULL,NULL);
// insert before jmp reg instruction a clamp, if one is specified.
if(clampmask!=0xffffffff)
{
string clamp_str="and "+reg+", "+to_string(clampmask);
insertAssemblyBefore(firp,tmp->GetFallthrough(),clamp_str);
}
// set the jne's target to itself, and create a reloc that zipr/strata will have to resolve.
jne->SetTarget(jne); // needed so spri/spasm/irdb don't freak out about missing target for new insn.
Relocation_t* reloc=create_reloc(jne);
......@@ -552,6 +574,7 @@ void SCFI_Instrument::AddReturnCFI(Instruction_t* insn, ColoredSlotValue_t *v)
cout<<"Setting slow path for: "<<slow_cfi_path_reloc_string<<endl;
return;
#endif
}
static void display_histogram(std::ostream& out, std::string attr_label, std::map<int,int> & p_map)
......
......@@ -34,16 +34,14 @@ class SCFI_Instrument
bool p_do_common_slow_path=true,
bool p_do_jumps=true,
bool p_do_rets=true,
bool p_do_safefn=true,
uint32_t p_clampmask=0xffffffff)
bool p_do_safefn=true)
: firp(the_firp),
do_coloring(p_do_coloring),
do_common_slow_path(p_do_common_slow_path),
do_jumps(p_do_jumps),
do_rets(p_do_rets),
do_safefn(p_do_safefn),
color_map(NULL),
clampmask(p_clampmask) {}
color_map(NULL) {}
bool execute();
private:
......@@ -83,7 +81,8 @@ class SCFI_Instrument
bool do_rets;
bool do_safefn;
ColoredInstructionNonces_t *color_map;
uint32_t clampmask;
};
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment