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
72fbf7e1
Commit
72fbf7e1
authored
8 years ago
by
an7s
Browse files
Options
Downloads
Patches
Plain Diff
Reverted back to shared cfi path
parent
dbf50334
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
scfi_driver.cpp
+8
-26
8 additions, 26 deletions
scfi_driver.cpp
scfi_instr.cpp
+30
-7
30 additions, 7 deletions
scfi_instr.cpp
scfi_instr.hpp
+4
-5
4 additions, 5 deletions
scfi_instr.hpp
with
42 additions
and
38 deletions
scfi_driver.cpp
+
8
−
26
View file @
72fbf7e1
...
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
scfi_instr.cpp
+
30
−
7
View file @
72fbf7e1
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
scfi_instr.hpp
+
4
−
5
View file @
72fbf7e1
...
...
@@ -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
...
...
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