The Problem
Recently on Linux Kernels 6.6.6 and higher it was discovered that thread sanitizer will always lead to this error:
FATAL: ThreadSanitizer: unexpected memory mapping 0x5c9bd4d2b000-0x5c9bd4d4b000
I can reproduce this by writing a hello world example in C
#include <stdio.h>
int main(void)
{
printf("Hello, World!\n");
}
And compiling it with tsan + running it on Arch Linux (Kernel 6.7.0) with:
clang -o play -fsanitize=thread -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer src/play.c
./play
This will produce the above error (with different memory addresses).
According to the github issue this will also occur in c++ files that just define an empty main() function.
The question
What are your options for dealing with this?
I have only recently started diving deeper into low-level operations and can barely use thread-sanitizer at my current knowledge levels. ASLR (which appears to be the cause of the problem) is entirely foreign to me, as are options to manipulate it and what the consequences are.
The github issue mentions 2 potential workarounds:
- Disabling ASLR (I only found this SO question for this )
- Reducing ASLR via
sudo sysctl vm.mmap_rnd_bits=30
I have tried 2. and compiled + ran the example again as described, this did not resolve the issue.
I am hesitant to disable ASLR as per 1., as I wouldn't know what the implications of that are or how to "undo" that change.
What other general options to approach this are out there?
vm.mmap_rnd_bits=32
by default and so it would always require the custom sysctl setting to make TSAN work. – Plain