Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CFI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Source Software
CFI
Commits
5b4c7ef3
Commit
5b4c7ef3
authored
6 years ago
by
mm8bx
Browse files
Options
Downloads
Patches
Plain Diff
Fixed cactusADM bug in scfi_instr.cpp
parent
78e0d563
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scfi_instr.cpp
+52
-26
52 additions, 26 deletions
scfi_instr.cpp
with
52 additions
and
26 deletions
scfi_instr.cpp
+
52
−
26
View file @
5b4c7ef3
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment