Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 resolve-cveassert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ add_library(CVEAssert SHARED
src/OperationMasking.cpp
)

target_compile_definitions(CVEAssert PRIVATE LLVM_FORCE_ENABLE_STATS=1)

# LLVM is normally built without RTTI. Be consistent with that.
if(NOT LLVM_ENABLE_RTTI)
target_compile_options(CVEAssert PRIVATE -fno-rtti)
Expand Down
70 changes: 68 additions & 2 deletions resolve-cveassert/libresolve/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions resolve-cveassert/libresolve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ crate-type = ["cdylib"]
env_logger = "0.11.8"
libc = "0.2.174"
log = "0.4.29"
parking_lot = "0.12.5"

[profile.release]
panic = "abort"
Expand Down
5 changes: 3 additions & 2 deletions resolve-cveassert/libresolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::fmt::Display;
use std::fs::{self, File};
use std::path::PathBuf;
use std::io::{self, Seek, Write};
use parking_lot::{Mutex, MutexGuard};
use std::sync::{LazyLock, Mutex};
use std::{env, process};

Expand All @@ -28,8 +29,8 @@ impl<T> MutexWrap<T> {
}

// Abort if the mutex is poisoned
pub fn lock(&self) -> std::sync::MutexGuard<'_, T> {
self.mutex.lock().expect("Not poisoned")
pub fn lock(&self) -> MutexGuard<'_, T> {
self.mutex.lock()
}
}

Expand Down
82 changes: 41 additions & 41 deletions resolve-cveassert/libresolve/src/remediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub extern "C" fn __resolve_alloca(ptr: *mut c_void, size: usize) -> () {
ss.add_shadow_object(base, size)
);

info!("[STACK] Object allocated with size: {size}, address: 0x{base:x}");
// info!("[STACK] Object allocated with size: {size}, address: 0x{base:x}");
}

#[unsafe(no_mangle)]
Expand All @@ -39,7 +39,7 @@ pub extern "C" fn __resolve_invalidate_stack_range(base: *mut c_void, size: usiz
ss.invalidate_at(base, size)
);

info!("[STACK] Free addr 0x{base:x} size {size}");
// info!("[STACK] Free addr 0x{base:x} size {size}");
}

/**
Expand All @@ -60,10 +60,10 @@ pub extern "C" fn __resolve_malloc(size: usize) -> *mut c_void {
obj_list.add_shadow_object(AllocType::Heap, ptr as Vaddr, size);
}

info!(
"[HEAP] Object allocated with size: {size}, address: 0x{:x}",
ptr as Vaddr
);
// info!(
// "[HEAP] Object allocated with size: {size}, address: 0x{:x}",
// ptr as Vaddr
// );

ptr
}
Expand All @@ -78,10 +78,10 @@ pub extern "C" fn __resolve_free(ptr: *mut c_void) -> () {
// Insert a function to find the object and return the pointer size
// Do I need to handle if the sobj cannot be found?

info!(
"[FREE] Allocated object freed at address: 0x{:x}",
ptr as Vaddr
);
// info!(
// "[FREE] Allocated object freed at address: 0x{:x}",
// ptr as Vaddr
// );

let ptr_size = {
let mut obj_list = ALIVE_OBJ_LIST.lock();
Expand All @@ -93,20 +93,20 @@ pub extern "C" fn __resolve_free(ptr: *mut c_void) -> () {
};

// Check if the shadow object exists
match ptr_size {
Some(size) => {
info!(
"[FREE] Found shadow object for allocated object, 0x{:x}, size = {size}",
ptr as Vaddr,
);
}
None => {
warn!(
"[FREE] No shadow object found for allocated object: 0x{:x}",
ptr as Vaddr
);
}
}
// match ptr_size {
// Some(size) => {
// info!(
// "[FREE] Found shadow object for allocated object, 0x{:x}, size = {size}",
// ptr as Vaddr,
// );
// }
// None => {
// warn!(
// "[FREE] No shadow object found for allocated object: 0x{:x}",
// ptr as Vaddr
// );
// }
// }

{
// Insert shadow object into freed object list
Expand Down Expand Up @@ -147,10 +147,10 @@ pub extern "C" fn __resolve_realloc(ptr: *mut c_void, size: usize) -> *mut c_voi
obj_list.add_shadow_object(AllocType::Heap, realloc_ptr as Vaddr, size);
}

info!(
"[HEAP] Allocated object reallocated mem from src: {ptr:?}, size: {size}, dst ptr: 0x{:x}",
realloc_ptr as Vaddr
);
// info!(
// "[HEAP] Allocated object reallocated mem from src: {ptr:?}, size: {size}, dst ptr: 0x{:x}",
// realloc_ptr as Vaddr
// );

realloc_ptr
}
Expand All @@ -176,10 +176,10 @@ pub extern "C" fn __resolve_calloc(n_items: usize, item_size: usize) -> *mut c_v
obj_list.add_shadow_object(AllocType::Heap, ptr as Vaddr, size);
}

info!(
"[HEAP] Logging allocation with {n_items} items, size (bytes): {size}, dst ptr: 0x{:x}",
ptr as Vaddr
);
// info!(
// "[HEAP] Logging allocation with {n_items} items, size (bytes): {size}, dst ptr: 0x{:x}",
// ptr as Vaddr
// );

ptr
}
Expand Down Expand Up @@ -207,10 +207,10 @@ pub extern "C" fn __resolve_strdup(ptr: *mut c_char) -> *mut c_char {
obj_list.add_shadow_object(AllocType::Heap, string_ptr as Vaddr, sizeofstr);
}

info!(
"[HEAP] Logging 'strdup' function call with dst ptr: 0x{:x}",
string_ptr as Vaddr
);
// info!(
// "[HEAP] Logging 'strdup' function call with dst ptr: 0x{:x}",
// string_ptr as Vaddr
// );

string_ptr
}
Expand Down Expand Up @@ -243,10 +243,10 @@ pub extern "C" fn __resolve_strndup(ptr: *mut c_char, size: usize) -> *mut c_cha
obj_list.add_shadow_object(AllocType::Heap, string_ptr as Vaddr, sizeofstr);
}

info!(
"[HEAP] Logging 'strndup' function call with size (bytes): {size}, dst ptr: {:?}",
string_ptr as Vaddr
);
// info!(
// "[HEAP] Logging 'strndup' function call with size (bytes): {size}, dst ptr: {:?}",
// string_ptr as Vaddr
// );

string_ptr
}
Expand Down Expand Up @@ -357,7 +357,7 @@ pub extern "C" fn resolve_obj_type(base_ptr: *mut c_void) -> AllocType {
*/
#[unsafe(no_mangle)]
pub extern "C" fn __resolve_report_violation() -> () {
info!("[RESOLVE] sanitizer triggered");
// info!("[RESOLVE] sanitizer triggered");
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions resolve-cveassert/src/CVEAssert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ struct LabelCVEPass : public PassInfoMixin<LabelCVEPass> {
out << F;
out << "[CVEAssert] === Inserted Sanitizer Helpers === \n";

if (vuln.UndesirableFunction.has_value()) {
if (vuln.Operation.has_value()) {
/* NOTE: We are using '0' as a temporary this will be updated future PRs
*/
sanitizeUndesirableOperationInFunction(&F, *vuln.UndesirableFunction, 0);
sanitizeContract(&F, *vuln.Operation, 0);
result = PreservedAnalyses::none();
out << "[CVEAssert] === Post Sanitization of Undesirable Operation IR "
"=== \n";
Expand Down
Loading
Loading