Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cwe_checker
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
cwe_checker
Commits
37fb78a4
Unverified
Commit
37fb78a4
authored
Apr 20, 2021
by
Melvin Klimke
Committed by
GitHub
Apr 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Callee saved return targets in CWE78 check (#167)
parent
4bdf6504
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
181 deletions
+205
-181
mod.rs
src/cwe_checker_lib/src/checkers/cwe_78/context/mod.rs
+71
-70
tests.rs
src/cwe_checker_lib/src/checkers/cwe_78/context/tests.rs
+97
-92
mod.rs
src/cwe_checker_lib/src/checkers/cwe_78/state/mod.rs
+24
-6
tests.rs
src/cwe_checker_lib/src/checkers/cwe_78/state/tests.rs
+13
-13
No files found.
src/cwe_checker_lib/src/checkers/cwe_78/context/mod.rs
View file @
37fb78a4
...
@@ -7,7 +7,7 @@ use petgraph::graph::NodeIndex;
...
@@ -7,7 +7,7 @@ use petgraph::graph::NodeIndex;
use
super
::{
state
::
State
,
BlockMaps
,
SymbolMaps
,
CWE_MODULE
};
use
super
::{
state
::
State
,
BlockMaps
,
SymbolMaps
,
CWE_MODULE
};
use
crate
::{
use
crate
::{
abstract_domain
::
AbstractDomain
,
abstract_domain
::
{
AbstractDomain
,
DataDomain
,
IntervalDomain
}
,
analysis
::{
analysis
::{
forward_interprocedural_fixpoint
::
Context
as
PiContext
,
graph
::
Graph
,
forward_interprocedural_fixpoint
::
Context
as
PiContext
,
graph
::
Graph
,
interprocedural_fixpoint_generic
::
NodeValue
,
interprocedural_fixpoint_generic
::
NodeValue
,
...
@@ -147,25 +147,37 @@ impl<'a> Context<'a> {
...
@@ -147,25 +147,37 @@ impl<'a> Context<'a> {
panic!
(
"Missing parameters for string related function!"
);
panic!
(
"Missing parameters for string related function!"
);
};
};
if
relevant_fuction_call
{
if
relevant_fuction_call
{
for
parameter
in
string_symbol
.parameters
.iter
()
{
self
.taint_function_arguments
(
match
parameter
{
&
mut
new_state
,
Arg
::
Register
(
var
)
=>
{
pi_state
,
new_state
.set_register_taint
(
var
,
Taint
::
Tainted
(
var
.size
))
string_symbol
.parameters
.clone
(),
}
);
Arg
::
Stack
{
size
,
..
}
=>
{
}
if
let
Ok
(
address
)
=
pi_state
.eval_parameter_arg
(
}
parameter
,
new_state
&
self
.project.stack_pointer_register
,
}
self
.runtime_memory_image
,
)
{
/// Taints register and stack function arguments.
new_state
.save_taint_to_memory
(
&
address
,
Taint
::
Tainted
(
*
size
))
pub
fn
taint_function_arguments
(
}
&
self
,
}
state
:
&
mut
State
,
pi_state
:
&
PointerInferenceState
,
parameters
:
Vec
<
Arg
>
,
)
{
for
parameter
in
parameters
.iter
()
{
match
parameter
{
Arg
::
Register
(
var
)
=>
state
.set_register_taint
(
var
,
Taint
::
Tainted
(
var
.size
)),
Arg
::
Stack
{
size
,
..
}
=>
{
if
let
Ok
(
address
)
=
pi_state
.eval_parameter_arg
(
parameter
,
&
self
.project.stack_pointer_register
,
self
.runtime_memory_image
,
)
{
state
.save_taint_to_memory
(
&
address
,
Taint
::
Tainted
(
*
size
))
}
}
}
}
}
}
}
}
new_state
}
}
/// Checks whether the firt parameter of a string related function points to a taint.
/// Checks whether the firt parameter of a string related function points to a taint.
...
@@ -176,18 +188,50 @@ impl<'a> Context<'a> {
...
@@ -176,18 +188,50 @@ impl<'a> Context<'a> {
state
:
&
mut
State
,
state
:
&
mut
State
,
parameter
:
&
Arg
,
parameter
:
&
Arg
,
)
->
bool
{
)
->
bool
{
let
mut
points_to_memory_taint
:
bool
=
false
;
if
let
Ok
(
address
)
=
pi_state
.eval_parameter_arg
(
if
let
Ok
(
address
)
=
pi_state
.eval_parameter_arg
(
parameter
,
parameter
,
&
self
.project.stack_pointer_register
,
&
self
.project.stack_pointer_register
,
self
.runtime_memory_image
,
self
.runtime_memory_image
,
)
{
)
{
if
state
.check_if_address_points_to_taint
(
address
.clone
(),
pi_state
)
{
let
temp_mem_taints
:
Vec
<
DataDomain
<
IntervalDomain
>>
=
self
.add_temporary_callee_saved_register_taints_to_mem_taints
(
pi_state
,
state
);
if
state
.address_points_to_taint
(
address
.clone
(),
pi_state
)
{
state
.remove_mem_taint_at_target
(
&
address
);
state
.remove_mem_taint_at_target
(
&
address
);
return
true
;
points_to_memory_taint
=
true
;
}
temp_mem_taints
.iter
()
.for_each
(|
addr
|
state
.remove_mem_taint_at_target
(
addr
));
}
points_to_memory_taint
}
/// Takes taints of callee saved registers and adds them temporarily to the corresponding memory
/// taints if possible.
pub
fn
add_temporary_callee_saved_register_taints_to_mem_taints
(
&
self
,
pi_state
:
&
PointerInferenceState
,
state
:
&
mut
State
,
)
->
Vec
<
DataDomain
<
IntervalDomain
>>
{
let
mut
temp_mem_taints
:
Vec
<
DataDomain
<
IntervalDomain
>>
=
Vec
::
new
();
if
let
Some
(
standard_cconv
)
=
self
.project
.get_standard_calling_convention
()
{
for
(
var
,
_
)
in
state
.get_callee_saved_register_taints
(
standard_cconv
)
.iter
()
{
let
address
=
pi_state
.eval
(
&
Expression
::
Var
(
var
.clone
()));
if
!
state
.address_points_to_taint
(
address
.clone
(),
pi_state
)
{
temp_mem_taints
.push
(
address
.clone
());
state
.save_taint_to_memory
(
&
address
,
Taint
::
Tainted
(
var
.size
));
}
}
}
}
}
false
temp_mem_taints
}
}
/// This function taints the registers and stack positions of the parameter pointers of external functions
/// This function taints the registers and stack positions of the parameter pointers of external functions
...
@@ -236,57 +280,14 @@ impl<'a> Context<'a> {
...
@@ -236,57 +280,14 @@ impl<'a> Context<'a> {
&
new_state
.get_current_sub
()
.as_ref
()
.unwrap
()
.term.name
,
&
new_state
.get_current_sub
()
.as_ref
()
.unwrap
()
.term.name
,
);
);
}
}
return
self
.taint_parameters
(
if
let
Some
(
NodeValue
::
Value
(
pi_state
))
=
self
&
new_state
,
.pointer_inference_results
symbol
.parameters
.clone
(),
.get_node_value
(
call_source_node
)
call_source_node
,
{
);
self
.taint_function_arguments
(
}
&
mut
new_state
,
}
pi_state
,
symbol
.parameters
.clone
(),
new_state
}
/// Taints a stack parameter given a size and an offset
pub
fn
taint_stack_parameters
(
&
self
,
state
:
State
,
call_source_node
:
NodeIndex
,
offset
:
i64
,
size
:
ByteSize
,
)
->
State
{
let
mut
new_state
=
state
;
if
let
Some
(
NodeValue
::
Value
(
pi_state
))
=
self
.pointer_inference_results
.get_node_value
(
call_source_node
)
{
let
address_exp
=
Expression
::
Var
(
self
.project.stack_pointer_register
.clone
())
.plus_const
(
offset
);
let
address
=
pi_state
.eval
(
&
address_exp
);
new_state
.save_taint_to_memory
(
&
address
,
Taint
::
Tainted
(
size
));
}
new_state
}
/// Iterates over the given parameters of a function and returns an updated state
pub
fn
taint_parameters
(
&
self
,
state
:
&
State
,
parameters
:
Vec
<
Arg
>
,
call_source_node
:
NodeIndex
,
)
->
State
{
let
mut
new_state
=
state
.clone
();
for
parameter
in
parameters
{
match
parameter
{
Arg
::
Register
(
param
)
=>
{
new_state
.set_register_taint
(
&
param
,
Taint
::
Tainted
(
param
.size
))
}
Arg
::
Stack
{
offset
,
size
}
=>
{
new_state
=
self
.taint_stack_parameters
(
new_state
.clone
(),
call_source_node
,
offset
,
size
,
);
);
}
}
}
}
...
...
src/cwe_checker_lib/src/checkers/cwe_78/context/tests.rs
View file @
37fb78a4
...
@@ -220,11 +220,11 @@ fn tainting_string_function_parameters() {
...
@@ -220,11 +220,11 @@ fn tainting_string_function_parameters() {
context
.taint_string_function_parameters
(
&
setup
.state
,
&
setup
.string_sym
,
*
node_id
);
context
.taint_string_function_parameters
(
&
setup
.state
,
&
setup
.string_sym
,
*
node_id
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
new_state
.address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
true
true
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
false
false
);
);
assert_eq!
(
assert_eq!
(
...
@@ -242,6 +242,91 @@ fn tainting_string_function_parameters() {
...
@@ -242,6 +242,91 @@ fn tainting_string_function_parameters() {
}
}
#[test]
#[test]
fn
tainting_function_arguments
()
{
let
mut
setup
=
Setup
::
new
();
let
rdi_reg
=
Variable
::
mock
(
"RDI"
,
8
);
let
args
=
vec!
[
Arg
::
Register
(
rdi_reg
.clone
()),
Arg
::
Stack
{
offset
:
24
,
size
:
ByteSize
::
from
(
8
),
},
];
let
mem_image
=
RuntimeMemoryImage
::
mock
();
let
graph
=
crate
::
analysis
::
graph
::
get_program_cfg
(
&
setup
.project.program
,
HashSet
::
new
());
let
mut
pi_results
=
PointerInferenceComputation
::
mock
(
&
setup
.project
,
&
mem_image
,
&
graph
);
pi_results
.compute
();
let
context
=
Context
::
mock
(
&
setup
.project
,
HashMap
::
new
(),
&
pi_results
,
&
mem_image
);
setup
.pi_state
.write_to_address
(
&
Expression
::
BinOp
{
op
:
BinOpType
::
IntAdd
,
lhs
:
Box
::
new
(
Expression
::
Var
(
Variable
{
name
:
String
::
from
(
"RSP"
),
size
:
ByteSize
::
new
(
8
),
is_temp
:
false
,
})),
rhs
:
Box
::
new
(
Expression
::
Const
(
Bitvector
::
from_u64
(
24
))),
},
&
Data
::
Pointer
(
PointerDomain
::
new
(
setup
.pi_state.stack_id
.clone
(),
bv
(
32
))),
context
.runtime_memory_image
,
)
.expect
(
"Failed to write to address."
);
context
.taint_function_arguments
(
&
mut
setup
.state
,
&
setup
.pi_state
,
args
);
assert_eq!
(
setup
.state
.get_register_taint
(
&
rdi_reg
),
Some
(
&
Taint
::
Tainted
(
rdi_reg
.size
))
);
assert
!
(
setup
.state
.address_points_to_taint
(
Data
::
Pointer
(
PointerDomain
::
new
(
setup
.pi_state.stack_id
.clone
(),
bv
(
32
))),
&
setup
.pi_state
));
}
#[test]
fn
adding_temporary_callee_saved_register_taints_to_mem_taints
()
{
let
mut
setup
=
Setup
::
new
();
let
rbp_reg
=
Variable
::
mock
(
"RBP"
,
8
as
u64
);
let
rcx_reg
=
Variable
::
mock
(
"RCX"
,
8
as
u64
);
setup
.pi_state
.set_register
(
&
rbp_reg
,
setup
.base_eight_offset
.clone
());
setup
.pi_state
.set_register
(
&
rcx_reg
,
setup
.base_sixteen_offset
.clone
());
setup
.state
.set_register_taint
(
&
rbp_reg
,
Taint
::
Tainted
(
rbp_reg
.size
));
setup
.state
.set_register_taint
(
&
rcx_reg
,
Taint
::
Tainted
(
rcx_reg
.size
));
let
mem_image
=
RuntimeMemoryImage
::
mock
();
let
graph
=
crate
::
analysis
::
graph
::
get_program_cfg
(
&
setup
.project.program
,
HashSet
::
new
());
let
mut
pi_results
=
PointerInferenceComputation
::
mock
(
&
setup
.project
,
&
mem_image
,
&
graph
);
pi_results
.compute
();
let
context
=
Context
::
mock
(
&
setup
.project
,
HashMap
::
new
(),
&
pi_results
,
&
mem_image
);
let
result
=
context
.add_temporary_callee_saved_register_taints_to_mem_taints
(
&
setup
.pi_state
,
&
mut
setup
.state
,
);
assert
!
(
result
.len
()
==
1
);
assert
!
(
setup
.state
.address_points_to_taint
(
result
.get
(
0
)
.unwrap
()
.clone
(),
&
setup
.pi_state
))
}
#[test]
fn
first_param_pointing_to_memory_taint
()
{
fn
first_param_pointing_to_memory_taint
()
{
let
mut
setup
=
Setup
::
new
();
let
mut
setup
=
Setup
::
new
();
...
@@ -268,7 +353,7 @@ fn first_param_pointing_to_memory_taint() {
...
@@ -268,7 +353,7 @@ fn first_param_pointing_to_memory_taint() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
false
false
);
);
}
}
...
@@ -362,86 +447,6 @@ fn tainting_generic_function_parameters_and_removing_non_callee_saved() {
...
@@ -362,86 +447,6 @@ fn tainting_generic_function_parameters_and_removing_non_callee_saved() {
}
}
#[test]
#[test]
fn
tainting_stack_parameters
()
{
let
setup
=
Setup
::
new
();
let
offset
=
4
as
i64
;
let
size
=
ByteSize
::
new
(
8
);
let
stack_id
=
setup
.pi_state.stack_id
.clone
();
let
mem_image
=
RuntimeMemoryImage
::
mock
();
let
graph
=
crate
::
analysis
::
graph
::
get_program_cfg
(
&
setup
.project.program
,
HashSet
::
new
());
let
mut
pi_results
=
PointerInferenceComputation
::
mock
(
&
setup
.project
,
&
mem_image
,
&
graph
);
pi_results
.compute
();
let
context
=
Context
::
mock
(
&
setup
.project
,
HashMap
::
new
(),
&
pi_results
,
&
mem_image
);
let
call_source_node
=
context
.block_maps
.jmp_to_blk_end_node_map
.get
(
&
(
Tid
::
new
(
"call_string"
),
Tid
::
new
(
"func"
)))
.unwrap
();
let
new_state
=
context
.taint_stack_parameters
(
setup
.state
,
call_source_node
.clone
(),
offset
,
size
);
assert_eq!
(
new_state
.check_if_address_points_to_taint
(
Data
::
Pointer
(
PointerDomain
::
new
(
stack_id
.clone
(),
bv
(
4
))),
&
setup
.pi_state
),
true
);
}
#[test]
fn
tainting_parameters
()
{
let
setup
=
Setup
::
new
();
let
rdi_reg
=
Variable
::
mock
(
"RDI"
,
8
as
u64
);
let
rsi_reg
=
Variable
::
mock
(
"RSI"
,
8
as
u64
);
let
params
=
vec!
[
Arg
::
Register
(
rdi_reg
.clone
()),
Arg
::
Register
(
rsi_reg
.clone
()),
Arg
::
Stack
{
offset
:
4
,
size
:
ByteSize
::
new
(
8
),
},
];
let
stack_id
=
setup
.pi_state.stack_id
.clone
();
let
mem_image
=
RuntimeMemoryImage
::
mock
();
let
graph
=
crate
::
analysis
::
graph
::
get_program_cfg
(
&
setup
.project.program
,
HashSet
::
new
());
let
mut
pi_results
=
PointerInferenceComputation
::
mock
(
&
setup
.project
,
&
mem_image
,
&
graph
);
pi_results
.compute
();
let
context
=
Context
::
mock
(
&
setup
.project
,
HashMap
::
new
(),
&
pi_results
,
&
mem_image
);
let
call_source_node
=
context
.block_maps
.jmp_to_blk_end_node_map
.get
(
&
(
Tid
::
new
(
"call_string"
),
Tid
::
new
(
"func"
)))
.unwrap
();
let
new_state
=
context
.taint_parameters
(
&
setup
.state
,
params
,
call_source_node
.clone
());
assert_eq!
(
new_state
.get_register_taint
(
&
rdi_reg
),
Some
(
&
Taint
::
Tainted
(
rdi_reg
.size
))
);
assert_eq!
(
new_state
.get_register_taint
(
&
rsi_reg
),
Some
(
&
Taint
::
Tainted
(
rsi_reg
.size
))
);
assert_eq!
(
new_state
.check_if_address_points_to_taint
(
Data
::
Pointer
(
PointerDomain
::
new
(
stack_id
.clone
(),
bv
(
4
))),
&
setup
.pi_state
),
true
);
}
#[test]
fn
creating_pi_def_map
()
{
fn
creating_pi_def_map
()
{
let
setup
=
Setup
::
new
();
let
setup
=
Setup
::
new
();
let
rdi_reg
=
Variable
::
mock
(
"RDI"
,
8
as
u64
);
let
rdi_reg
=
Variable
::
mock
(
"RDI"
,
8
as
u64
);
...
@@ -662,7 +667,7 @@ fn handling_assign_and_load() {
...
@@ -662,7 +667,7 @@ fn handling_assign_and_load() {
new_state
=
context
.update_def
(
&
new_state
,
&
mock_assign_stack
)
.unwrap
();
new_state
=
context
.update_def
(
&
new_state
,
&
mock_assign_stack
)
.unwrap
();
assert_eq!
(
new_state
.get_register_taint
(
&
r9_reg
),
None
);
assert_eq!
(
new_state
.get_register_taint
(
&
r9_reg
),
None
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
new_state
.address_points_to_taint
(
Data
::
Pointer
(
PointerDomain
::
new
(
stack_id
.clone
(),
bv
(
0
))),
Data
::
Pointer
(
PointerDomain
::
new
(
stack_id
.clone
(),
bv
(
0
))),
&
setup
.pi_state
&
setup
.pi_state
),
),
...
@@ -740,7 +745,7 @@ fn updating_def() {
...
@@ -740,7 +745,7 @@ fn updating_def() {
new_state
=
context
.update_def
(
&
new_state
,
&
mock_assign_stack
)
.unwrap
();
new_state
=
context
.update_def
(
&
new_state
,
&
mock_assign_stack
)
.unwrap
();
assert_eq!
(
new_state
.get_register_taint
(
&
r9_reg
),
None
);
assert_eq!
(
new_state
.get_register_taint
(
&
r9_reg
),
None
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
new_state
.address_points_to_taint
(
Data
::
Pointer
(
PointerDomain
::
new
(
stack_id
.clone
(),
bv
(
0
))),
Data
::
Pointer
(
PointerDomain
::
new
(
stack_id
.clone
(),
bv
(
0
))),
&
setup
.pi_state
&
setup
.pi_state
),
),
...
@@ -769,7 +774,7 @@ fn updating_def() {
...
@@ -769,7 +774,7 @@ fn updating_def() {
Some
(
&
Taint
::
Tainted
(
rdi_reg
.size
))
Some
(
&
Taint
::
Tainted
(
rdi_reg
.size
))
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
,),
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
,),
false
false
);
);
}
}
...
@@ -811,7 +816,7 @@ fn updating_jumpsite() {
...
@@ -811,7 +816,7 @@ fn updating_jumpsite() {
Some
(
&
Taint
::
Tainted
(
r9_reg
.size
))
Some
(
&
Taint
::
Tainted
(
r9_reg
.size
))
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
setup
.base_eight_offset
,
new_state
new_state
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
...
@@ -944,7 +949,7 @@ fn splitting_call_stub() {
...
@@ -944,7 +949,7 @@ fn splitting_call_stub() {
Some
(
&
Taint
::
Tainted
(
r9_reg
.size
))
Some
(
&
Taint
::
Tainted
(
r9_reg
.size
))
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
setup
.base_eight_offset
,
new_state
new_state
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
...
@@ -993,7 +998,7 @@ fn splitting_return_stub() {
...
@@ -993,7 +998,7 @@ fn splitting_return_stub() {
Some
(
&
Taint
::
Tainted
(
rax_reg
.size
))
Some
(
&
Taint
::
Tainted
(
rax_reg
.size
))
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
setup
.base_eight_offset
,
new_state
new_state
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
...
@@ -1042,11 +1047,11 @@ fn updating_call_stub() {
...
@@ -1042,11 +1047,11 @@ fn updating_call_stub() {
let
new_state
=
context
.update_call_stub
(
&
setup
.state
,
&
mock_call
)
.unwrap
();
let
new_state
=
context
.update_call_stub
(
&
setup
.state
,
&
mock_call
)
.unwrap
();
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
new_state
.address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
true
true
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
false
false
);
);
assert_eq!
(
assert_eq!
(
...
@@ -1094,7 +1099,7 @@ fn specializing_conditional() {
...
@@ -1094,7 +1099,7 @@ fn specializing_conditional() {
Some
(
&
Taint
::
Tainted
(
r9_reg
.size
))
Some
(
&
Taint
::
Tainted
(
r9_reg
.size
))
);
);
assert_eq!
(
assert_eq!
(
new_state
.
check_if_
address_points_to_taint
(
new_state
.address_points_to_taint
(
setup
.base_eight_offset
,
setup
.base_eight_offset
,
new_state
new_state
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
.get_pointer_inference_state_at_def
(
&
Tid
::
new
(
"initial"
))
...
...
src/cwe_checker_lib/src/checkers/cwe_78/state/mod.rs
View file @
37fb78a4
...
@@ -183,6 +183,28 @@ impl State {
...
@@ -183,6 +183,28 @@ impl State {
self
.register_taint
.iter
()
self
.register_taint
.iter
()
}
}
/// Gets the callee saved taints from the register taints.
pub
fn
get_callee_saved_register_taints
(
&
self
,
calling_conv
:
&
CallingConvention
,
)
->
HashMap
<
Variable
,
Taint
>
{
self
.register_taint
.clone
()
.iter
()
.filter_map
(|(
register
,
taint
)|
{
if
calling_conv
.callee_saved_register
.iter
()
.any
(|
callee_saved_reg
|
register
.name
==
*
callee_saved_reg
)
{
Some
((
register
.clone
(),
*
taint
))
}
else
{
None
}
})
.collect
()
}
/// Gets the string constant saved at the given address and saves it to the string constants field.
/// Gets the string constant saved at the given address and saves it to the string constants field.
pub
fn
evaluate_constant
(
&
mut
self
,
constant
:
Bitvector
)
{
pub
fn
evaluate_constant
(
&
mut
self
,
constant
:
Bitvector
)
{
// TODO: check whether the constant is a valid memory address in the binary
// TODO: check whether the constant is a valid memory address in the binary
...
@@ -232,7 +254,7 @@ impl State {
...
@@ -232,7 +254,7 @@ impl State {
if
let
Some
(
pid_map
)
=
self
.pi_def_map
.as_ref
()
{
if
let
Some
(
pid_map
)
=
self
.pi_def_map
.as_ref
()
{
if
let
Some
(
pi_state
)
=
pid_map
.get
(
def_tid
)
{
if
let
Some
(
pi_state
)
=
pid_map
.get
(
def_tid
)
{
let
address
=
pi_state
.eval
(
target
);
let
address
=
pi_state
.eval
(
target
);
if
self
.
check_if_
address_points_to_taint
(
address
.clone
(),
&
pi_state
)
{
if
self
.address_points_to_taint
(
address
.clone
(),
&
pi_state
)
{
self
.taint_def_input_register
(
value
,
stack_pointer_register
,
def_tid
);
self
.taint_def_input_register
(
value
,
stack_pointer_register
,
def_tid
);
self
.remove_mem_taint_at_target
(
&
address
);
self
.remove_mem_taint_at_target
(
&
address
);
}
}
...
@@ -332,11 +354,7 @@ impl State {
...
@@ -332,11 +354,7 @@ impl State {
/// return true if and only if the value at that stack position is tainted.
/// return true if and only if the value at that stack position is tainted.
/// If the given address points to a non-stack memory object,
/// If the given address points to a non-stack memory object,
/// return true if the memory object contains any tainted value (at any position).
/// return true if the memory object contains any tainted value (at any position).
pub
fn
check_if_address_points_to_taint
(
pub
fn
address_points_to_taint
(
&
self
,
address
:
Data
,
pi_state
:
&
PointerInferenceState
)
->
bool
{
&
self
,
address
:
Data
,
pi_state
:
&
PointerInferenceState
,
)
->
bool
{
use
crate
::
analysis
::
pointer_inference
::
object
::
ObjectType
;
use
crate
::
analysis
::
pointer_inference
::
object
::
ObjectType
;
if
let
Data
::
Pointer
(
pointer
)
=
address
{
if
let
Data
::
Pointer
(
pointer
)
=
address
{
for
(
target
,
offset
)
in
pointer
.targets
()
{
for
(
target
,
offset
)
in
pointer
.targets
()
{
...
...
src/cwe_checker_lib/src/checkers/cwe_78/state/tests.rs
View file @
37fb78a4
...
@@ -166,7 +166,7 @@ fn setting_expression_and_constants() {
...
@@ -166,7 +166,7 @@ fn setting_expression_and_constants() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.stack_pointer
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.stack_pointer
,
&
setup
.pi_state
),
true
true
);
);
...
@@ -186,7 +186,7 @@ fn setting_expression_and_constants() {
...
@@ -186,7 +186,7 @@ fn setting_expression_and_constants() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
true
true
);
);
...
@@ -234,7 +234,7 @@ fn tainting_values_to_be_stored() {
...
@@ -234,7 +234,7 @@ fn tainting_values_to_be_stored() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
false
false
);
);
assert_eq!
(
assert_eq!
(
...
@@ -286,7 +286,7 @@ fn tainting_def_input_register() {
...
@@ -286,7 +286,7 @@ fn tainting_def_input_register() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.stack_pointer
.clone
(),
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.stack_pointer
.clone
(),
&
setup
.pi_state
),
true
true
);
);
...
@@ -344,7 +344,7 @@ fn tainting_variable_input() {
...
@@ -344,7 +344,7 @@ fn tainting_variable_input() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.stack_pointer
.clone
(),
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.stack_pointer
.clone
(),
&
setup
.pi_state
),
true
true
);
);
}
}
...
@@ -360,7 +360,7 @@ fn removing_memory_taint_at_target() {
...
@@ -360,7 +360,7 @@ fn removing_memory_taint_at_target() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
.clone
(),
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
.clone
(),
&
setup
.pi_state
),
true
true
);
);
setup
setup
...
@@ -369,7 +369,7 @@ fn removing_memory_taint_at_target() {
...
@@ -369,7 +369,7 @@ fn removing_memory_taint_at_target() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
false
false
);
);
...
@@ -377,7 +377,7 @@ fn removing_memory_taint_at_target() {
...
@@ -377,7 +377,7 @@ fn removing_memory_taint_at_target() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_sixteen_offset
.clone
(),
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_sixteen_offset
.clone
(),
&
setup
.pi_state
),
false
false
);
);
setup
setup
...
@@ -386,7 +386,7 @@ fn removing_memory_taint_at_target() {
...
@@ -386,7 +386,7 @@ fn removing_memory_taint_at_target() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
false
false
);
);
}
}
...
@@ -398,7 +398,7 @@ fn saving_taint_to_memory() {
...
@@ -398,7 +398,7 @@ fn saving_taint_to_memory() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
.clone
(),
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
.clone
(),
&
setup
.pi_state
),
false
false
);
);
setup
setup
...
@@ -407,7 +407,7 @@ fn saving_taint_to_memory() {
...
@@ -407,7 +407,7 @@ fn saving_taint_to_memory() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
.clone
(),
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
.clone
(),
&
setup
.pi_state
),
true
true
);
);
}
}
...
@@ -494,13 +494,13 @@ fn checking_if_address_points_to_taint() {
...
@@ -494,13 +494,13 @@ fn checking_if_address_points_to_taint() {
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_eight_offset
,
&
setup
.pi_state
),
true
true
);
);
assert_eq!
(
assert_eq!
(
setup
setup
.state
.state
.
check_if_
address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
.address_points_to_taint
(
setup
.base_sixteen_offset
,
&
setup
.pi_state
),
false
false
);
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment