Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upASLR on Windows breaks thread-local variables #17684
Comments
thestinger
added
the
A-security
label
Oct 1, 2014
thestinger
added
the
O-windows
label
Oct 1, 2014
This comment has been minimized.
This comment has been minimized.
|
Triage: I am not sure if there has been any change, nor steps to reproduce. |
This comment has been minimized.
This comment has been minimized.
|
If this was a mingw-specific bug, we may be able to reactivate it on the msvc builds. |
This comment has been minimized.
This comment has been minimized.
|
According to MSDN |
thestinger
changed the title
ASLR on Windows breaks TLS
ASLR on Windows breaks thread-local variables
Jun 23, 2016
laanwj
referenced this issue
Jun 23, 2016
Open
ASLR seems not to be working as it should on Windows #8248
This comment has been minimized.
This comment has been minimized.
|
Can someone comment on whether thread locals are broken on Windows MinGW-w64 today? What are the reproduction steps? |
retep998
added
O-windows-gnu
and removed
O-windows
labels
May 6, 2017
Mark-Simulacrum
added
the
C-bug
label
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
sipsorcery
commented
Oct 2, 2017
•
|
I've done a cursory check of TLS with 64 bit binaries compiled with msvc and mingw32-g++ and both are working correctly. // http://en.cppreference.com/w/cpp/language/storage_duration
// msvc on win64: cl tls.cpp /link
// mingw on linux64: x86_64-w64-mingw32-g++ tls.cpp -static -static-libstdc++
#include <iostream>
#include <string>
#include <thread>
#include <mutex>
thread_local unsigned int rage = 1;
std::mutex cout_mutex;
void increase_rage(const std::string& thread_name)
{
++rage; // modifying outside a lock is okay; this is a thread-local variable
std::lock_guard<std::mutex> lock(cout_mutex);
std::cout << "Rage counter for " << thread_name << ": " << rage << '\n';
}
int main()
{
std::thread a(increase_rage, "a"), b(increase_rage, "b");
{
std::lock_guard<std::mutex> lock(cout_mutex);
std::cout << "Rage counter for main: " << rage << '\n';
}
a.join();
b.join();
getchar();
}msvc output:
mingw32-g++ output:
64 bit binaries on Windows use ASLR by default unless explicitly disabled with a linker option. Both binaries in this test had the NX Compatible flag set in the executable image header. Happy to test further if anyone has a pointer to the problem code. |
This comment has been minimized.
This comment has been minimized.
|
@sipsorcery The key thing is |
thestinger commentedOct 1, 2014
This appears to be a MinGW-w64 linker bug.