Google has published the source code for the toolkit. GWPSan, designed to identify errors during the execution of applications built for x86-64 and ARM64 architectures. GWPSan is built as a shared library, which is linked at application startup using LD_PRELOAD and uses To analyze the operation of the program, the stopping mechanisms (PERF_TYPE_BREAKPOINT) and process sampling available in the Linux kernel. The code is written in C++ and distributed by licensed under Apache 2.0.
GWPSan issued in the form of a modular framework that supports the connection of modules with the implementation of detectors of various classes of errors. GWPSan performs dynamic analysis, activated through signal handlers, which eliminates the need to change the application's executable code. For most detectors to work effectively, the application must be built with certain compiler flags that add the necessary metadata. Requires at least Clang 18 and Linux kernel 6.4.
Currently available three detectors:
- UAR (Use-after-return) – detects errors caused by using an object on the stack after exiting the function in which this object was defined. Protection is organized through the interception of entry and exit points for a function – upon entry, the stack is replaced with a copy for use during the execution of the function, and upon exit, the old state of the stack is returned.
- TSan (Thread Sanitizer) – detects race conditions between threads (Data-race), which occurs when different concurrently executing threads can read or modify shared memory areas without using primitives to synchronize work. Protection is based on the use of hardware breakpoints tied to shared memory areas. The triggered handler pauses the execution of a thread for a short period of time when accessing memory and, during this suspension, checks whether a breakpoint has been triggered for another thread.
- LMSan (Lightweight Memory Sanitizer) – determines the use of uninitialized data in memory. The detector is marked as experimental and not recommended for use.
GWPSan analyzes executable program code using the framework DynamoRIO to decode machine code into abstract ISA instructions, which are then executed using emulation. The handler is called through periodic signals from the timer unified, which, with each call, executes a certain portion of instructions for the analyzed thread. If detected during the execution of certain instructions, a problem detector specific to these instructions is launched, for example, for instructions accessing memory, a race condition detector is launched.
Thanks for reading: