Skip to content

Commit 4370445

Browse files
committed
Fix asan's user-poisoning flags bug
It add utils_annotate_memory_defined() (which does unpoison on memory region) after all mmap(). This should be unnecessary change but pairs of mmap/munmap do not reset asan's user-poisoning flags, leading to invalid error reports. This bug is describe here - 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
1 parent 9a44668 commit 4370445

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.github/workflows/sanitizers.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ jobs:
6868
working-directory: ${{env.BUILD_DIR}}
6969
run: >
7070
${{ matrix.compiler.cxx == 'icpx' && '. /opt/intel/oneapi/setvars.sh &&' || ''}}
71-
GTEST_FILTER="-*umfProviderTest.alloc_page64_align_0*" ctest --output-on-failure
72-
# TO DO: fix umf-provider_os_memory test for sanitizers
73-
# issue 581: https://github.com/oneapi-src/unified-memory-framework/issues/581
71+
ctest --output-on-failure
7472
7573
windows-build:
7674
name: cl and clang-cl on Windows

src/base_alloc/base_alloc_linux.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ static UTIL_ONCE_FLAG Page_size_is_initialized = UTIL_ONCE_FLAG_INIT;
1919
static size_t Page_size;
2020

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

2631
void ba_os_free(void *ptr, size_t size) {

src/provider/provider_os_memory_posix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "provider_os_memory_internal.h"
1818
#include "utils_log.h"
19+
#include "utils_sanitizers.h"
1920

2021
// maximum value of the off_t type
2122
#define OFF_T_MAX \
@@ -74,7 +75,10 @@ void *os_mmap(void *hint_addr, size_t length, int prot, int flag, int fd,
7475
if (ptr == MAP_FAILED) {
7576
return NULL;
7677
}
77-
78+
// this should be unnecessary but pairs of mmap/munmap do not reset
79+
// asan's user-poisoning flags, leading to invalid error reports
80+
// Bug 81619: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81619
81+
utils_annotate_memory_defined(ptr, length);
7882
return ptr;
7983
}
8084

0 commit comments

Comments
 (0)