Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1080e51
Starting mimalloc integration with libresolve. This commit contains m…
Jun 1, 2026
d832fb6
Dockerfile: Removed mimalloc build from dockerfile.
Jun 1, 2026
afdb2ce
WIP: Moved mimalloc build into CMake workflow. I will make sure to do…
Jun 1, 2026
d536af5
CMakeLists.txt: Fixed CMake file to correctly pass path to static mim…
Jun 1, 2026
346a4d8
remediate.rs: Fixed test but we need to test this on a small file to …
Jun 1, 2026
7c8081f
shadowobjs.rs: Cleaned up some comments.
Jun 2, 2026
84cc0eb
mimalloc_shadow.c: Modified shim to lookup bounds of mimalloc allocat…
Jun 4, 2026
9f36290
WIP: Testing bounds-checking with mimalloc.
Jun 4, 2026
8091093
remediate.rs: This will not pass CI tests, this is just so that I can…
Jun 5, 2026
e50c2a6
remediate.rs: Adding wrapper for getline function. Testing with chall…
Jun 8, 2026
62148ec
remediate.rs: Fixing Rust errors.
Jun 8, 2026
12557f0
remediate.rs: Removed the plus one and using resolve wrapped malloc a…
Jun 8, 2026
1835171
remediate.rs: Added resolve wrapper for getdelim function.
Jun 8, 2026
dcf0548
remediate.rs: WIP debugging foreign allocation that occurs in depende…
Jun 9, 2026
2f05270
remediate.rs: Make sure all logging is commented out for poller testing.
Jun 12, 2026
835c860
remediate.rs: Comment out all logging.
Jun 12, 2026
cf470f2
remediate.rs: Restored commit 48dbed5 for testing.
Jun 12, 2026
765399f
remediate.rs: Fixing remediate.rs since I lost some of the commits to…
Jun 12, 2026
60c5d46
remediate.rs: Fixing issues in compilation.
Jun 12, 2026
c34cda5
mimalloc_shadow.c: Switching to mi_is_in_heap to better handle arbitr…
Jun 12, 2026
55a8482
WIP: Testing if the unknown pointer comes from C++ new/delete allocator.
Jun 12, 2026
530bfc1
WIP: Fixing compilation issues. Testing if allocation comes from C++ …
Jun 12, 2026
432fbd8
remediate.rs: Debugging __resolve_free.
Jun 15, 2026
6e46373
WIP: Modified Cargo.toml to have cargo build with nightly and added _…
Jun 15, 2026
c91caef
remediate.rs: WIP testing if __resolve_asprintf symbol shows up in li…
Jun 15, 2026
b2c2ebb
remediate.rs: WIP trying to get libresolve to resolve the __resolve_a…
Jun 15, 2026
eb1b1ed
WIP: try adding no_mangle to mimalloc symbols to have libresolve expo…
Jun 15, 2026
679d32d
WIP: Trying to debug why the __resolve_asprintf symbol is not being r…
Jun 15, 2026
4b217e7
remediate.rs: WIP debugging __resolve_asprintf symbol export.
Jun 15, 2026
0ac13d7
WIP: debugging __resolve_asprintf symbol visibility and resolution.
Jun 15, 2026
597823a
Fixing compilation issues. Ready to test __resolve_asprintf symbol re…
Jun 15, 2026
1cf352d
WIP: Debugging ABI mismatch issues.
Jun 15, 2026
a53d664
mimalloc_shadow.c: Removed the plus one from len argument in __resolv…
Jun 15, 2026
5d61f0f
remediate.rs: Adding resolve wrappers for posx_memalign, reallocarray…
Jun 16, 2026
8265795
remediate.rs: Testing without +1 padding.
Jun 16, 2026
fb1840e
mimalloc_shadow.c: Testing __resolve_malloc call in __vasprintf
Jun 16, 2026
aab57b2
mimalloc_shadow.c: Modified mi_is_heap_owned fn to return a boolean i…
Jun 18, 2026
32f5bc8
mimalloc_shadow.c: Adding +1 back to __resolve_malloc call.
Jun 18, 2026
a4d411a
remediate.rs: WIP checking the ptr and return address that is passed …
Jun 18, 2026
9ef80ea
shadowobjs.rs: Fixing compilation issue.
Jun 18, 2026
d724b3e
CMakeLists.txt: Fixing CMakeList file to correctly pass archive path …
Jun 18, 2026
f368462
remediate.rs: Try using the mi_is_in_heap_region function to check if…
Jun 18, 2026
69e20c8
remediate.rs: Removed mi_is_heap_owned condition and modified C shim …
Jun 22, 2026
ea8b508
remediate.rs: Adding debugger function to check if the pointer passed…
Jun 22, 2026
688145f
remediate.rs: Adding logging to the C shim to determine where the poi…
Jun 22, 2026
ac9ed17
remediate.rs: Reverting back to an earlier commit.
Jun 22, 2026
09bd459
remediate.rs: Adding logging to help with debugging.
Jun 22, 2026
75e7444
remediate.rs: Fixing compilation issue.
Jun 22, 2026
f6f9420
remediate.rs: Removed logging from C shim and checking if the weird p…
Jun 22, 2026
526d9bb
mimalloc_shadow.c: WIP updating C shim to use mi_usable_size to get t…
Jun 29, 2026
7290633
Updating name of C shim source file to mi_shim.c
Jun 29, 2026
09c1bdd
remediate.rs: Fixing some issues with rebasing. Updating mimalloc_int…
Jun 30, 2026
fc91e82
remediate.rs: Adding From trait for AllocBounds type, removed some co…
Jun 30, 2026
0ecd2de
remediate.rs: Removed comment from __resolve_malloc wrapper.
Jul 1, 2026
b279a95
remediate.rs: Adding some safety comments to unsafe blocks.
Jul 2, 2026
3345c24
WIP: Pushing updates for mimalloc integration.
Jul 7, 2026
91089e7
InstrumentAllocators.cpp: Updating type variable names.
Aug 28, 2026
6479ed5
Formatting rust files.
Aug 28, 2026
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
38 changes: 35 additions & 3 deletions resolve-cveassert/libresolve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@

include(GNUInstallDirs)
include(ExternalProject)
include(FetchContent)

#### Fetching and building mimalloc project
FetchContent_Declare(
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
GIT_TAG v3.3.2
)

## Force static build
set(MI_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(MI_BUILD_STATIC ON CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(mimalloc)

# Add the shim source to the mimalloc proj
target_sources(mimalloc-static PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/mi_shim.c
)

## mimalloc proj must be PIC to ensure compatibility with libresolve
set_target_properties(mimalloc-static PROPERTIES
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME mimalloc
)

# Map CMake build type to Cargo flags
if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "")
Expand All @@ -24,17 +49,24 @@ file(GLOB_RECURSE RUST_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/sr
add_custom_command(
OUTPUT ${RUST_LIB}
COMMAND
${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${RUST_OUT_DIR} cargo build ${CARGO_FLAGS}
${CMAKE_COMMAND} -E env
CARGO_TARGET_DIR=${RUST_OUT_DIR}
MIMALLOC_LIB_DIR=$<TARGET_FILE_DIR:mimalloc-static>
cargo build ${CARGO_FLAGS}
WORKING_DIRECTORY ${RUST_CRATE_DIR}
COMMENT "Building libresolve.so" VERBATIM
DEPENDS ${RUST_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.lock ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml ${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml
DEPENDS mimalloc-static ${RUST_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.lock ${CMAKE_CURRENT_SOURCE_DIR}/Cargo.toml ${CMAKE_CURRENT_SOURCE_DIR}/rust-toolchain.toml
)

add_custom_target(test-libresolve
COMMAND cargo test
COMMAND
${CMAKE_COMMAND} -E env
MIMALLOC_LIB_DIR=${MIMALLOC_LIB_DIR} # Note: Pass the static mimalloc loc so that build.rs does not panic
cargo test
WORKING_DIRECTORY ${RUST_CRATE_DIR}
COMMENT "Running regression tests for libresolve"
)

add_custom_target(libresolve ALL DEPENDS ${RUST_LIB})
add_dependencies(libresolve mimalloc-static)
install(FILES ${RUST_LIB} DESTINATION ${CMAKE_INSTALL_LIBDIR})
23 changes: 23 additions & 0 deletions resolve-cveassert/libresolve/Cargo.lock

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

2 changes: 2 additions & 0 deletions resolve-cveassert/libresolve/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
[package]
name = "resolve"
build = "src/build.rs"
version = "0.1.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]

[dependencies]
cc = "1.2.63"
env_logger = "0.11.8"
libc = "0.2.174"
log = "0.4.29"
Expand Down
106 changes: 106 additions & 0 deletions resolve-cveassert/libresolve/mi_shim.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Copyright (c) 2025 Riverside Research.
// LGPL-3; See LICENSE.txt in the repo root for details.

#include "mimalloc.h"
#include "mimalloc/internal.h"
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>

extern void* __resolve_malloc(size_t);
extern void __resolve_free(void*);


typedef struct {
void *base;
void *limit;
size_t size;
} mi_alloc_bounds_t;


mi_alloc_bounds_t mi_get_alloc_bounds(void* p) {
mi_alloc_bounds_t bounds;
mi_alloc_bounds_t empty = { .base = (void*) -1, .limit = (void*)-1, .size = 0 };

// Check if ptr is owned by mimalloc
if (!mi_is_in_heap_region(p)) {
return empty;
}

// Recover the page information for the pointer.
mi_page_t *page = _mi_ptr_page(p);

if (page == NULL) {
return empty;
}

// _mi_page_ptr_unalign recovers the corresponding
// block for base and interior pointers
mi_block_t *base = _mi_page_ptr_unalign(page, p);
if (!base) { return empty; }

bounds.base = (void *)base;
bounds.size = mi_usable_size(base);
bounds.limit = (void *)base + bounds.size;
return bounds;
}

bool mi_is_heap_owned(const void* p) {
return _mi_ptr_page(p) != NULL;
}

int __vasprintf(char **strp, const char *fmt, va_list ap)
{
va_list ap_copy;
va_copy(ap_copy, ap);

int len = vsnprintf(NULL, 0, fmt, ap_copy);
va_end(ap_copy);

if (len < 0) {
// to match glibc behavior
*strp = NULL;
return -1;
}

char *buf = __resolve_malloc((size_t)len + 1);
if (!buf) { return -1; }

va_copy(ap_copy, ap);

int written = vsnprintf(buf, (size_t)len + 1, fmt, ap_copy);

va_end(ap_copy);

if (written < 0) {
__resolve_free(buf);
return -1;
}

*strp = buf;
return written;
}

/* debugging function to help check if a pointer the
base address or an offset into the block
*/
bool mi_is_block_start(void *p) {
if (p == NULL) { return false; }

// Recover page information
mi_page_t *page = _mi_ptr_page(p);

if (page == NULL) { return false; }

// Compute the block index
const size_t block_size = page->block_size;
uintptr_t page_start = (uintptr_t)page->page_start;
size_t block_index = ((uintptr_t)p - page_start) / block_size;

// Compute the canonical base.
uintptr_t base = page_start + block_index * block_size;

// Compare to pointer
return base == (uintptr_t)p;
}

6 changes: 6 additions & 0 deletions resolve-cveassert/libresolve/src/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let dir = std::env::var("MIMALLOC_LIB_DIR").unwrap();
println!("cargo::warning=LINKING_MIMALLOC_ARCHIVE");
println!("cargo::rustc-link-search=native={}", dir);
println!("cargo::rustc-link-lib=static=mimalloc");
}
Loading
Loading