Add SafeAccess protection and frame type validation for signal handlers#349
Add SafeAccess protection and frame type validation for signal handlers#349
Conversation
Scan-Build Report
Bug Summary
Reports
|
||||||||||||||||||||||||||||||||||||
f6e7585 to
f43433d
Compare
eedf923 to
c394d1d
Compare
3decd33 to
a96bed7
Compare
Benchmarks [x86_64 wall]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 14 metrics, 24 unstable metrics. |
Benchmarks [aarch64 wall]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [x86_64 memleak,alloc]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [x86_64 cpu]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [aarch64 memleak,alloc]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [aarch64 alloc]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 17 metrics, 21 unstable metrics. |
Benchmarks [aarch64 cpu,wall,alloc,memleak]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 16 metrics, 22 unstable metrics. |
Benchmarks [aarch64 memleak]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [aarch64 cpu,wall]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [aarch64 cpu]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 17 metrics, 21 unstable metrics. |
Benchmarks [x86_64 alloc]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
Benchmarks [x86_64 cpu,wall]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 14 metrics, 24 unstable metrics. |
Benchmarks [x86_64 cpu,wall,alloc,memleak]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 16 metrics, 22 unstable metrics. |
Benchmarks [x86_64 memleak]Parameters
See matching parameters
SummaryFound 0 performance improvements and 0 performance regressions! Performance is the same for 15 metrics, 23 unstable metrics. |
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The read_mark() function can be called from signal handler context during stack walking. Direct dereferencing of func->_mark can cause SEGV if the computed pointer happens to be aligned but points to unmapped memory. Use SafeAccess::safeFetch32() to safely read the mark field, extracting the byte at offset 2 from the NativeFunc header. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
9784c62 to
fcdfdd1
Compare
Integration Tests❔ 0 passed, 0 failed out of 0 configurations Test Matrix
Links
|
What does this PR do?:
This PR adds SafeAccess protection to several critical code paths in signal handler context and fixes invalid frame type handling:
SafeAccess for frame pointer walking: Replaces raw pointer dereference with
SafeAccess::load()inStackWalker::walkFP()to prevent ASan stack-buffer-overflow errors during frame pointer chain traversal.Frame type sanitization for J9: Adds validation and clamping for frame types to prevent invalid
FrameTypeIdvalues (e.g., value 48 causing ASAN errors). Implements defensive clamping inFrameType::decode()usingFRAME_TYPE_MAXconstant and properly handles negative BCI values (BCI_WALL, BCI_ERROR, etc.) through<= 0check instead of== 0.SafeAccess for NativeFunc marking: Adds SafeAccess protection to
NativeFunc::read_mark()which is called from signal handler context during stack walking.Test stability improvements: Fixes NPE and timing issues in flaky profiler tests, particularly in
JfrDumpTestandBaseContextWallClockTest.Motivation:
ASan detected multiple issues during signal handler execution:
walkFP()when traversing into stack frames with local variablesNativeFunc::read_mark()when accessing potentially unmapped memoryThe
walkDwarf()function already usesSafeAccess::load()consistently (lines 190, 194), butwalkFP()was inconsistent - using SafeAccess for PC but not for FP.Additional Notes:
safefetch64_impl/safefetch32_implwalkFP()andread_mark()with the protection pattern used inwalkDwarf()FRAME_TYPE_MAXconstant provides future-proof clamping instead of hardcoded bit masksrun_docker_tests.shcan now target J9/OpenJ9 JVMs (8-j9, 11-j9, 17-j9, 21-j9)How to test the change?:
Run ASan tests via CI (testAsan task).
The fixes prevent the following ASan errors that were occurring:
For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance.Unsure? Have a question? Request a review!
🤖 Generated with Claude Code