Commit 61c1446
feat(pool): add opt-in debug hardening — poisoning, guard word, safe-linking
Harden the intrusive free list against the classic use-after-free /
pointer-corruption primitives an in-band next-link exposes (ADR-0009 §1),
behind a single compile-time knob `PBR_MEMORY_POOL_HARDENING` (OFF by
default; a `harden` CMake preset turns it on). Three layered protections:
- Freed-block poisoning (0xDE), verified on the next allocation —
use-after-free detection.
- A per-slot trailing guard word: neither-constant on free is a buffer
overflow past block_size, still-freed is a double-free (closing the
ADR-0012 gap). The guard lives in *added* slot stride, so the
user-visible block_size and the ADR-0009 alignment guarantee are
unchanged.
- glibc-style free-list safe-linking (ptr XOR (slot_addr >> 12)): a
leaked/overwritten next-link is neither directly usable nor silently
followed; corruption surfaces as an alignment fault on reveal.
On detection a swappable HardeningViolationHandler fires; the default
prints a diagnostic and abort()s (the ADR-0012 defined-loud-failure
stance), and tests install a recording handler to assert detection
without terminating the process.
The knob is fully compiled out when off, so the default build is
byte-for-byte and cycle-for-cycle unchanged (read_next/write_next/
reveal_next/slot_stride inline to the exact prior load/store). Works
with fixed and dynamic pools across all three thread-safety policies;
composes under the InstrumentedPool decorator. Purely additive and
ABI-compatible (SemVer MINOR, a v1.2.0 candidate); a hardened build is
deliberately not layout-compatible with a non-hardened one.
A `harden` CI matrix cell builds and runs the detection tests on each
Tier-1 platform (the memory-safety net where ASan is unavailable, e.g.
MSVC). Decided in ADR-0043; ROADMAP item 9.2.
Closes #109.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent d4afec5 commit 61c1446
16 files changed
Lines changed: 803 additions & 44 deletions
File tree
- .github/workflows
- docs
- adr
- doxygen
- specs
- src
- main/cpp/it/d4np/memorypool
- test/cpp/it/d4np/memorypool
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
| 75 | + | |
| 76 | + | |
70 | 77 | | |
71 | 78 | | |
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
| 82 | + | |
75 | 83 | | |
76 | 84 | | |
77 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
23 | 41 | | |
24 | 42 | | |
25 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
122 | 137 | | |
123 | 138 | | |
124 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
88 | 97 | | |
89 | 98 | | |
90 | 99 | | |
| |||
104 | 113 | | |
105 | 114 | | |
106 | 115 | | |
| 116 | + | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
111 | 121 | | |
112 | 122 | | |
113 | 123 | | |
114 | | - | |
| 124 | + | |
| 125 | + | |
115 | 126 | | |
116 | 127 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
0 commit comments