AD3038: EnableUBSan¶
Summary¶
| Property | Value |
|---|---|
| ID | AD3038 |
| Name | EnableUBSan |
| Category | Security |
| Severity | Note |
| Applies to | ELF (Linux/Unix) |
Description¶
ELF binaries used for testing should consider enabling UndefinedBehaviorSanitizer (UBSAN) to detect undefined behavior that can lead to security vulnerabilities.
Note: This is an informational rule. UBSAN is typically used in testing, not production.
How It Works¶
The rule checks for UBSAN runtime symbols:
__ubsan_handle_*functions- UBSAN runtime library linkage
- Sanitizer metadata sections
Why This Matters¶
Undefined behavior in C/C++ is a major source of security vulnerabilities. UBSAN detects these issues at runtime.
What UBSAN Detects¶
| Issue | Security Impact |
|---|---|
| Signed integer overflow | Exploitable calculations |
| Null pointer dereference | Crashes, potential RCE |
| Division by zero | Denial of service |
| Invalid shift amounts | Incorrect bit operations |
| Out-of-bounds array access | Memory corruption |
| Type mismatch | Undefined casts |
UBSAN Checks¶
# All undefined behavior
-fsanitize=undefined
# Specific checks
-fsanitize=signed-integer-overflow
-fsanitize=null
-fsanitize=bounds
-fsanitize=alignment
Example Detection¶
int arr[10];
arr[15] = 42; // Undefined behavior
// UBSAN output:
// runtime error: index 15 out of bounds for type 'int [10]'
Performance¶
| Mode | Overhead |
|---|---|
| Full UBSAN | 10-100% |
| Integer only | 5-20% |
| Null checks | <5% |
Resolution¶
Enable UBSAN in test builds: