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

Hello, I have a question! How to use REAL(malloc) in asan_allocator.cpp ? #1268

Closed
dentiscalprum opened this issue Jun 22, 2020 · 3 comments
Closed

Comments

@dentiscalprum
Copy link

  1. I add this in global area.
    DECLARE_REAL_AND_INTERCEPTOR(void *, malloc, uptr) DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
  2. I add this in struct Allocator
    explicit Allocator(LinkerInitialized)
    : quarantine(LINKER_INITIALIZED),
    fallback_quarantine_cache(LINKER_INITIALIZED) {
    if(INTERCEPT_FUNCTION(free)){
    char buf[] = "free intercept true\n";
    write(STDERR_FILENO, buf, sizeof(buf));
    }
    else{
    char buf[] = "free intercept false\n";
    write(STDERR_FILENO, buf, sizeof(buf));
    }
    if(!INTERCEPT_FUNCTION(malloc)){
    char buf[] = "malloc intercept true\n";
    write(STDERR_FILENO, buf, sizeof(buf));
    }
    else{
    char buf[] = "malloc intercept true\n";
    write(STDERR_FILENO, buf, sizeof(buf));
    }
    }
  3. I want to use REAL(malloc) in function Allocate of struct Allocator

like this
const int rate = 7;
int r = rand() % 10;
if(r <= rate){
uptr needed_size = size + kChunkHeaderSize;
void *allocated = REAL(malloc)(needed_size);
return allocated;
}

question : but failed !
error info :
==20489==ERROR: AddressSanitizer: SEGV on unknown address 0x00000000 (pc 0x00000000 bp 0xbe96796c sp 0xbe967518 T0)
==20489==Hint: pc points to the zero page.
==20489==The signal is caused by a READ memory access.
==20489==Hint: address points to the zero page.
#0 0x0 ()
#1 0xf9344 in ReportDeadlySignalImpl /root/opt/asan_random/lib/sanitizer_common/sanitizer_symbolizer_report.cpp:222:9
#2 0xf9344 in __sanitizer::ReportDeadlySignal(__sanitizer::SignalContext const&, unsigned int, void ()(__sanitizer::SignalContext const&, void const, __sanitizer::BufferedStackTrace*), void const*) /root/opt/asan_random/lib/sanitizer_common/sanitizer_symbolizer_report.cpp:236:27
#3 0xc9f18 in __asan::ErrorDescription::Print() /root/opt/asan_random/lib/asan/asan_errors.h:440:7
#4 0xc9f18 in __asan::ScopedInErrorReport::~ScopedInErrorReport() /root/opt/asan_random/lib/asan/asan_report.cpp:141:55
#5 0xc9f18 in __asan::ReportDeadlySignal(__sanitizer::SignalContext const&) /root/opt/asan_random/lib/asan/asan_report.cpp:211:47
#6 0xc8050 in __asan::AsanOnDeadlySignal(int, void*, void*) /root/opt/asan_random/lib/asan/asan_posix.cpp:37:21
#7 0xb6c8912c /build/glibc-FUvrFr/glibc-2.28/signal/../sysdeps/unix/sysv/linux/arm/sigrestorer.S:77

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ()
==20489==ABORTING

Can you give me a method to avoid this question ? thank you!!!

@kcc
Copy link
Contributor

kcc commented Jun 22, 2020

What are you trying to implement here?

Generally, if you want to be able to call a real function, you should add a line to InitializeAsanInterceptors in compiler-rt/lib/asan/asan_interceptors.cpp, like

ASAN_INTERCEPT_FUNC(malloc);

but you will also need to match those calls with READL(free), which could be tricky.

@dentiscalprum
Copy link
Author

oh! Thank you !
We want to call malloc without redzone in some condition

@kcc
Copy link
Contributor

kcc commented Jun 25, 2020

If you do this, you will have to figure out how to call the system free() on the pointer obtained from the system malloc.
You can't pass such a pointer to asan's deallocation routines.
Various other things may break too.

@kcc kcc closed this as completed Jun 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants