Skip to content

Fix asan bug #610

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

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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
4 changes: 1 addition & 3 deletions .github/workflows/sanitizers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ jobs:
working-directory: ${{env.BUILD_DIR}}
run: >
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh &&' || ''}}
GTEST_FILTER="-*umfProviderTest.alloc_page64_align_0*" ctest --output-on-failure
# TO DO: fix umf-provider_os_memory test for sanitizers
# issue 581: https://github.com/oneapi-src/unified-memory-framework/issues/581
ctest --output-on-failure

windows-build:
name: cl and clang-cl on Windows
Expand Down
2 changes: 0 additions & 2 deletions src/base_alloc/base_alloc_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,12 @@ void umf_ba_global_free(void *ptr) {

int ac_index = size_to_idx(total_size);
if (ac_index >= NUM_ALLOCATION_CLASSES) {
utils_annotate_memory_inaccessible(ptr, total_size);
ba_os_free(ptr, total_size);
return;
}

if (!BASE_ALLOC.ac[ac_index]) {
// if creating ac failed, memory must have been allocated by os
utils_annotate_memory_inaccessible(ptr, total_size);
ba_os_free(ptr, total_size);
return;
}
Expand Down
9 changes: 7 additions & 2 deletions src/base_alloc/base_alloc_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ static UTIL_ONCE_FLAG Page_size_is_initialized = UTIL_ONCE_FLAG_INIT;
static size_t Page_size;

void *ba_os_alloc(size_t size) {
return mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
// this should be unnecessary but pairs of mmap/munmap do not reset
// asan's user-poisoning flags, leading to invalid error reports
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
utils_annotate_memory_defined(ptr, size);
return ptr;
}

void ba_os_free(void *ptr, size_t size) {
Expand Down
14 changes: 12 additions & 2 deletions src/provider/provider_os_memory_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "provider_os_memory_internal.h"
#include "utils_log.h"
#include "utils_sanitizers.h"

// maximum value of the off_t type
#define OFF_T_MAX \
Expand Down Expand Up @@ -74,11 +75,20 @@ void *os_mmap(void *hint_addr, size_t length, int prot, int flag, int fd,
if (ptr == MAP_FAILED) {
return NULL;
}

// this should be unnecessary but pairs of mmap/munmap do not reset
// asan's user-poisoning flags, leading to invalid error reports
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
utils_annotate_memory_defined(ptr, length);
return ptr;
}

int os_munmap(void *addr, size_t length) { return munmap(addr, length); }
int os_munmap(void *addr, size_t length) {
// this should be unnecessary but pairs of mmap/munmap do not reset
// asan's user-poisoning flags, leading to invalid error reports
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
utils_annotate_memory_defined(addr, length);
return munmap(addr, length);
}

size_t os_get_page_size(void) { return sysconf(_SC_PAGE_SIZE); }

Expand Down
Loading