Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pcode parser rewrite #425

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
e284660
add support for unary operations
Jun 20, 2023
e9632a3
extract pcode operation typing
Jun 20, 2023
e6260e3
add binary operation support
Jun 20, 2023
ef0ba6f
add support for cast operations
Jun 20, 2023
8288bd4
add support for COPY, add varnode changes on implicit load
Jun 20, 2023
d4ea86d
extracted pcodeOpSimple into seperate file
Jun 20, 2023
264236e
add support for pcode operation SUBPICE
Jun 22, 2023
e485c0c
fix bug in create_store()
Jun 22, 2023
535d7ac
extracted tests and pcode_op_simple module
Jun 22, 2023
66ccb46
add tests for creating casts, binary operation, unary operations, sub…
Jun 26, 2023
422d812
code cleanup
Jun 26, 2023
b164776
fix typo
Jun 26, 2023
0f1a1d3
add IR mapping for jumps
Jun 27, 2023
d7011fd
implemented review notes
Jun 29, 2023
c4bcc32
fix doc comment link
Jun 29, 2023
cd03ad1
fix typo
Jun 29, 2023
f78e992
add IR jump primitive creation
Jun 29, 2023
32fc3b1
Merge branch 'pcode_extracting_and_parsing_collection' into pcode_par…
Jul 3, 2023
24986c4
add jump target discovery step
Jul 3, 2023
ae30e00
add check for intra pcode jumps, that target the next machine instruc…
Jul 6, 2023
24a9f8b
begin with block splitting and jump creation
Jul 10, 2023
b4a34ad
Merge branch 'master' into pcode_parser_rewrite
Jul 10, 2023
f124e1d
refactor block IR translation
Aug 10, 2023
39ad272
implement pcode relative jump translation
Aug 14, 2023
634fff4
add tests for block splitting, minor bug fixes
Aug 24, 2023
5d2a658
fix bug in pcode relative branching, add test
Aug 24, 2023
3e59def
fix another bug in pcode relative branch translation, add tests
Aug 24, 2023
2bd9aaf
fixed bug in target extraction, add tests for implicit fallthrough to…
Aug 24, 2023
c887d34
add optimization for jump target redirection, add support for non emp…
Aug 25, 2023
35dbcc7
code cleanup
Aug 25, 2023
2543ca5
Merge branch 'pcode_extracting_and_parsing_collection' into pcode_par…
Aug 25, 2023
56c9425
Merge branch 'pcode_extracting_and_parsing_collection' into pcode_par…
Aug 25, 2023
08b72f6
Limit acceptance tests to PRs to the master branch (#426)
Enkelmann Aug 28, 2023
1bf0954
add fall through information to instructions
Aug 28, 2023
a522005
merge fall through information
Aug 30, 2023
1e99a75
add size information fpr instructions
Aug 30, 2023
aa7ec86
fix tests
Aug 30, 2023
39d9df7
get jump target next instruction in order: fallthrough, consecutive i…
Aug 30, 2023
1e26821
remove todo note
Aug 30, 2023
42d236b
change target tid for indirect branches
Aug 30, 2023
ce42667
extend jump target collection with Tids
Aug 31, 2023
a415e2a
redirect target tid for relative jumps to index 0 for jump target col…
Aug 31, 2023
f82ebc5
parse correct ldef file for Apple Silicon binaries (#427)
Enkelmann Sep 1, 2023
2e11e84
always enforce expression complexity limit (#428)
Enkelmann Sep 4, 2023
fa51876
change approach and pre-collect all jump targets
Sep 4, 2023
270b4d4
refactor CWE-416 check (#429)
Enkelmann Sep 4, 2023
47e62de
refactor into_ir_blk and add notes for handover
Sep 8, 2023
0db462b
partially implemented PR comments and add notes for handover
Sep 8, 2023
a605850
Merge https://github.com/fkie-cad/cwe_checker into pcode_parser_rewrite
Sep 8, 2023
42636e8
Merge branch 'pcode_parser_rewrite' of https://github.com/fkie-cad/cw…
Sep 8, 2023
d169b66
implement operations iterator for block builder
Enkelmann Sep 11, 2023
be6d685
fix bugs and tests
Enkelmann Sep 12, 2023
dc64e35
add missing doc comment, cargo fmt
Enkelmann Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches:
- master
pull_request:
branches:
- master

env:
CARGO_TERM_COLOR: always
Expand Down
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.8-dev
===

- Improve logic and context information generation of CWE-416 (use-after-free) check (PRs #423, #429)

0.7 (2023-06)
====

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["src/cwe_checker_lib", "src/caller", "test", "src/installer"]
resolver = "2"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
</p>

# cwe_checker #
![Acceptance tests](https://github.com/fkie-cad/cwe_checker/actions/workflows/acceptance-tests.yml/badge.svg)
![Unit tests](https://github.com/fkie-cad/cwe_checker/actions/workflows/unit-tests.yml/badge.svg)
![Acceptance tests](https://github.com/fkie-cad/cwe_checker/actions/workflows/acceptance-tests.yml/badge.svg?branch=master)
![Unit tests](https://github.com/fkie-cad/cwe_checker/actions/workflows/unit-tests.yml/badge.svg?branch=master)
![Docker-Pulls](https://img.shields.io/docker/pulls/fkiecad/cwe_checker.svg)
[![Documentation](https://img.shields.io/badge/doc-stable-green.svg)](https://fkie-cad.github.io/cwe_checker/index.html)

Expand Down
16 changes: 13 additions & 3 deletions src/cwe_checker_lib/src/analysis/expression_propagation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,20 @@ pub fn propagate_input_expressions(
var,
value: expression,
} => {
// insert known input expressions
for (input_var, input_expr) in insertable_expressions.iter() {
expression.substitute_input_var(input_var, input_expr);
// Extend the considered expression with already known expressions.
let mut extended_expression = expression.clone();
for input_var in expression.input_vars().into_iter() {
if let Some(expr) = insertable_expressions.get(input_var) {
// We limit the complexity of expressions to insert.
// This prevents extremely large expressions that can lead to extremely high RAM usage.
// FIXME: Right now this limit is quite arbitrary. Maybe there is a better way to achieve the same result?
if expr.recursion_depth() < 10 {
extended_expression.substitute_input_var(input_var, expr)
}
}
}
extended_expression.substitute_trivial_operations();
*expression = extended_expression;
// expressions dependent on the assigned variable are no longer insertable
insertable_expressions.retain(|input_var, input_expr| {
input_var != var && !input_expr.input_vars().into_iter().any(|x| x == var)
Expand Down
12 changes: 2 additions & 10 deletions src/cwe_checker_lib/src/analysis/expression_propagation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ fn inter_block_propagation() {
variable!("X:8"),
expr!("-(42:4)").un_op(UnOpType::BoolNegate),
),
Def::assign(
"entry_jmp_def_2",
variable!("Z:8"),
expr!("-(42:4)").un_op(UnOpType::IntNegate),
)
Def::assign("entry_jmp_def_2", variable!("Z:8"), expr!("42:4"),)
]
)
}
Expand Down Expand Up @@ -290,11 +286,7 @@ fn expressions_inserted() {
variable!("X:8"),
expr!("-(42:4)").un_op(UnOpType::BoolNegate),
),
Def::assign(
"entry_jmp_def_2",
variable!("Z:8"),
expr!("-(42:4)").un_op(UnOpType::IntNegate)
)
Def::assign("entry_jmp_def_2", variable!("Z:8"), expr!("42:4"))
]
);
assert_eq!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a, T: AbstractDomain + DomainInsertion + HasTop + Eq + From<String>> Conte

/// Regex that filters format specifier from a format string.
pub fn re_format_specifier() -> Regex {
Regex::new(r#"%\d{0,2}([c,C,d,i,o,u,x,X,e,E,f,F,g,G,a,A,n,p,s,S]|hi|hd|hu|li|ld|lu|lli|lld|llu|lf|lg|le|la|lF|lG|lE|lA|Lf|Lg|Le|La|LF|LG|LE|LA)"#).expect("No valid regex!")
Regex::new(r"%\d{0,2}([c,C,d,i,o,u,x,X,e,E,f,F,g,G,a,A,n,p,s,S]|hi|hd|hu|li|ld|lu|lli|lld|llu|lf|lg|le|la|lF|lG|lE|lA|Lf|Lg|Le|La|LF|LG|LE|LA)").expect("No valid regex!")
}

/// Merges domains from multiple pointer targets. The merged domain serves as input to a format string.
Expand Down
2 changes: 1 addition & 1 deletion src/cwe_checker_lib/src/checkers/cwe_119/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ fn collect_tids_for_cwe_warning(
&caller_tid,
state.stack_id.get_tid(),
);
tids.extend(call_sequence_tids.into_iter());
tids.extend(call_sequence_tids);
}
// Build a string out of the TID list
tids.iter()
Expand Down
4 changes: 2 additions & 2 deletions src/cwe_checker_lib/src/checkers/cwe_416/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'a> Context<'a> {
state: &mut State,
call_tid: &Tid,
call_params: impl IntoIterator<Item = &'b Arg>,
) -> Option<Vec<(AbstractIdentifier, Tid)>> {
) -> Option<Vec<(AbstractIdentifier, Vec<Tid>)>> {
let mut warnings = Vec::new();
for arg in call_params {
if let Some(arg_value) = self
Expand Down Expand Up @@ -174,7 +174,7 @@ impl<'a> Context<'a> {
name: &str,
description: String,
location: &Tid,
warning_causes: Vec<(AbstractIdentifier, Tid)>,
warning_causes: Vec<(AbstractIdentifier, Vec<Tid>)>,
root_function: &Tid,
) {
let cwe_warning = CweWarning {
Expand Down
Loading
Loading