Commit 55626f7
Fix use-after-free in moveForSlabRelease chained item path
Summary:
Investigation doc: https://fburl.com/gdoc/oxsftkii
Fix a use-after-free race condition in `CacheAllocator::moveForSlabRelease()`
for chained items. After `parentItem->unmarkMoving()`, another thread can
evict and free the parent item's memory. The subsequent calls to
`findInternal(parentKey)` and `wakeUpWaiters(parentItem->getKey(), ...)`
would then read freed memory through the dangling `Key` (which is a
`folly::StringPiece` — a non-owning view into the item's data buffer).
If the freed memory is reused with different content, `wakeUpWaiters` fails
to find the MoveCtx entry in the MoveMap (hash/equality mismatch on garbage
bytes), leaving the waiter's Baton permanently unposted. This causes threads
blocked on `ItemWaitContext::wait()` to deadlock indefinitely.
The fix copies the parent key to an owning `std::string` before calling
`unmarkMoving()`, ensuring all subsequent key uses reference valid memory.
Also fixes a typo: "Parnet" → "Parent" in a comment.
Reviewed By: stuclar, AlnisM
Differential Revision: D98565055
fbshipit-source-id: ea88bd4fbeaa4fc7cd992eca06af549b99633d301 parent b956d38 commit 55626f7
1 file changed
Lines changed: 10 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5216 | 5216 | | |
5217 | 5217 | | |
5218 | 5218 | | |
5219 | | - | |
| 5219 | + | |
| 5220 | + | |
| 5221 | + | |
| 5222 | + | |
| 5223 | + | |
| 5224 | + | |
5220 | 5225 | | |
5221 | 5226 | | |
5222 | 5227 | | |
5223 | 5228 | | |
5224 | | - | |
| 5229 | + | |
5225 | 5230 | | |
5226 | 5231 | | |
5227 | | - | |
| 5232 | + | |
5228 | 5233 | | |
5229 | 5234 | | |
5230 | | - | |
| 5235 | + | |
5231 | 5236 | | |
5232 | 5237 | | |
5233 | 5238 | | |
5234 | 5239 | | |
5235 | 5240 | | |
5236 | 5241 | | |
5237 | 5242 | | |
5238 | | - | |
| 5243 | + | |
5239 | 5244 | | |
5240 | 5245 | | |
5241 | 5246 | | |
| |||
0 commit comments