Skip to content
Snippets Groups Projects
Commit 5b4c7ef3 authored by mm8bx's avatar mm8bx
Browse files

Fixed cactusADM bug in scfi_instr.cpp

parent 78e0d563
No related branches found
No related tags found
No related merge requests found
...@@ -370,43 +370,69 @@ void SCFI_Instrument::AddJumpCFI(Instruction_t* insn) ...@@ -370,43 +370,69 @@ void SCFI_Instrument::AddJumpCFI(Instruction_t* insn)
#endif #endif
} }
//TODO: Does not work with coloring
void SCFI_Instrument::AddCallCFIWithExeNonce(Instruction_t* insn) void SCFI_Instrument::AddCallCFIWithExeNonce(Instruction_t* insn)
{ {
// make a stub to call string reg="ecx"; // 32-bit reg
if(firp->GetArchitectureBitWidth()==64)
reg="r11"; // 64-bit reg.
string decoration="";
int nonce_size=GetNonceSize(insn);
int nonce_offset=GetNonceOffset(insn);
unsigned int nonce=GetNonce(insn);
Instruction_t* call=NULL, *jne=NULL, *stub=NULL;
// the stub is:
// push [target]
// ret
string pushbits=change_to_push(insn);
Instruction_t* stub=addNewDatabits(firp,NULL,pushbits);
stub->SetComment(insn->GetComment()+" cfi stub");
string retBits=getRetDataBits(); // convert a call indtarg to:
Instruction_t* ret=insertDataBitsAfter(firp, stub, retBits); // push indtarg ;Calculate target if it has a memory operation
// pop reg ;Calculate it before changing stack ptr with call stub
// call stub ;Easy way to get correct return address on stack
//
//stub: cmp <nonce size> PTR [ecx-<nonce size>], Nonce
// jne slow
// jmp reg
switch(nonce_size)
{
case 1:
decoration="byte ";
break;
case 2: // handle later
case 4: // handle later
default:
cerr<<"Cannot handle nonce of size "<<std::dec<<nonce_size<<endl;
assert(0);
assert(stub->GetFallthrough()==ret); }
AddReturnCFI(ret);
/*string jmpBits=getJumpDataBits(); // insert the pop/checking code.
Instruction_t* jmp=insertDataBitsAfter(firp, stub, jmpBits); string pushbits=change_to_push(insn);
call=insertDataBitsBefore(firp, insn, pushbits);
insertAssemblyAfter(firp,insn,string("pop ")+reg);
assert(stub->GetFallthrough()==jmp); stub=addNewAssembly(firp,stub,string("cmp ")+decoration+
" ["+reg+"-"+to_string(nonce_offset)+"], "+to_string(nonce));
jne=insertAssemblyAfter(firp,stub,"jne 0");
insertAssemblyAfter(firp,jne,string("jmp ")+reg);
// create a reloc so the stub goes to the slow path, eventually // set the jne's target to itself, and create a reloc that zipr/strata will have to resolve.
createNewRelocation(firp,jmp,"slow_cfi_path",0); jne->SetTarget(jne); // needed so spri/spasm/irdb don't freak out about missing target for new insn.
jmp->SetFallthrough(NULL); Relocation_t* reloc=create_reloc(jne);
jmp->SetTarget(jmp); // looks like infinite loop, but will go to slow apth*/ reloc->SetType("slow_cfi_path");
reloc->SetOffset(0);
cout<<"Setting slow path for: "<<"slow_cfi_path"<<endl;
// convert the indirct call to a direct call to the stub. // convert the indirct call to a direct call to the stub.
string call_bits=insn->GetDataBits(); string call_bits=call->GetDataBits();
call_bits.resize(5); call_bits.resize(5);
call_bits[0]=0xe8; call_bits[0]=0xe8;
insn->SetTarget(stub); call->SetTarget(stub);
insn->SetDataBits(call_bits); call->SetDataBits(call_bits);
insn->SetComment("Direct call to cfi stub"); call->SetComment("Direct call to cfi stub");
insn->SetIBTargets(NULL); // lose info about branch targets. call->SetIBTargets(NULL); // lose info about branch targets.
return;
} }
void SCFI_Instrument::AddExecutableNonce(Instruction_t* insn) void SCFI_Instrument::AddExecutableNonce(Instruction_t* insn)
......
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