Commit e730ac4
authored
YJIT: Fix version_map use-after-free from mutable aliasing UB
Multiple YJIT functions created overlapping `&'static mut IseqPayload`
references by calling `get_iseq_payload()` multiple times for the same
iseq. Overlapping &mut is UB in rust's aliasing model, and as consequence,
we trigered use-after-free on the `version_map` Vec header due to false
claims of LLVM `noalias`.
This manifested as crashes in various YJIT operations (block lookup,
GC marking, block removal) that dereference the stale pointer.
Fix by moving `delayed_deallocation` and `get_or_create_version_list`
from free functions (which each call `get_iseq_payload()` internally)
to methods on `IseqPayload` that operate through `&mut self`. This
lets callers obtain a single payload reference and use it for all
operations without creating overlapping mutable borrows.
The three fixed call sites:
1. `rb_yjit_tracing_invalidate_all` (invariants.rs): The loop called
`delayed_deallocation()` which internally called `get_iseq_payload()`,
creating a second `&mut` overlapping with the outer `payload` reference.
Fix: call `payload.delayed_deallocation()` method instead.
2. `add_block_version` (core.rs): Called `get_or_create_version_list()`
then later `get_iseq_payload()` for pages, creating two references.
Fix: use a single `get_or_create_iseq_payload()` call then call the
`get_or_create_version_list()` method on it for both version_map and
pages access.
Also adds regression tests exercising tracing invalidation with
on-stack methods and suspended fibers.
[alan: edited commit message]
Reviewed-by: Alan Wu <alanwu@ruby-lang.org>1 parent 906176a commit e730ac4
3 files changed
+100
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5486 | 5486 | | |
5487 | 5487 | | |
5488 | 5488 | | |
| 5489 | + | |
| 5490 | + | |
| 5491 | + | |
| 5492 | + | |
| 5493 | + | |
| 5494 | + | |
| 5495 | + | |
| 5496 | + | |
| 5497 | + | |
| 5498 | + | |
| 5499 | + | |
| 5500 | + | |
| 5501 | + | |
| 5502 | + | |
| 5503 | + | |
| 5504 | + | |
| 5505 | + | |
| 5506 | + | |
| 5507 | + | |
| 5508 | + | |
| 5509 | + | |
| 5510 | + | |
| 5511 | + | |
| 5512 | + | |
| 5513 | + | |
| 5514 | + | |
| 5515 | + | |
| 5516 | + | |
| 5517 | + | |
| 5518 | + | |
| 5519 | + | |
| 5520 | + | |
| 5521 | + | |
| 5522 | + | |
| 5523 | + | |
| 5524 | + | |
| 5525 | + | |
| 5526 | + | |
| 5527 | + | |
| 5528 | + | |
| 5529 | + | |
| 5530 | + | |
| 5531 | + | |
| 5532 | + | |
| 5533 | + | |
| 5534 | + | |
| 5535 | + | |
| 5536 | + | |
| 5537 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1769 | 1769 | | |
1770 | 1770 | | |
1771 | 1771 | | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
1772 | 1801 | | |
1773 | 1802 | | |
1774 | 1803 | | |
| |||
2140 | 2169 | | |
2141 | 2170 | | |
2142 | 2171 | | |
2143 | | - | |
2144 | | - | |
2145 | | - | |
2146 | | - | |
2147 | | - | |
2148 | | - | |
2149 | | - | |
2150 | | - | |
2151 | | - | |
2152 | | - | |
2153 | | - | |
2154 | | - | |
2155 | | - | |
2156 | | - | |
2157 | | - | |
2158 | 2172 | | |
2159 | 2173 | | |
2160 | 2174 | | |
| |||
2343 | 2357 | | |
2344 | 2358 | | |
2345 | 2359 | | |
2346 | | - | |
| 2360 | + | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
2347 | 2364 | | |
2348 | | - | |
2349 | | - | |
2350 | | - | |
2351 | | - | |
| 2365 | + | |
| 2366 | + | |
2352 | 2367 | | |
2353 | | - | |
2354 | | - | |
| 2368 | + | |
| 2369 | + | |
| 2370 | + | |
| 2371 | + | |
| 2372 | + | |
| 2373 | + | |
| 2374 | + | |
2355 | 2375 | | |
2356 | 2376 | | |
2357 | 2377 | | |
| |||
2376 | 2396 | | |
2377 | 2397 | | |
2378 | 2398 | | |
2379 | | - | |
2380 | 2399 | | |
2381 | 2400 | | |
2382 | 2401 | | |
| |||
2495 | 2514 | | |
2496 | 2515 | | |
2497 | 2516 | | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
2498 | 2522 | | |
2499 | 2523 | | |
2500 | 2524 | | |
| |||
4298 | 4322 | | |
4299 | 4323 | | |
4300 | 4324 | | |
4301 | | - | |
| 4325 | + | |
| 4326 | + | |
| 4327 | + | |
4302 | 4328 | | |
4303 | 4329 | | |
4304 | 4330 | | |
4305 | 4331 | | |
4306 | 4332 | | |
4307 | 4333 | | |
4308 | 4334 | | |
4309 | | - | |
4310 | | - | |
4311 | | - | |
4312 | | - | |
4313 | | - | |
4314 | | - | |
4315 | | - | |
4316 | | - | |
4317 | | - | |
4318 | | - | |
4319 | | - | |
4320 | | - | |
4321 | | - | |
4322 | | - | |
4323 | | - | |
4324 | | - | |
4325 | | - | |
4326 | | - | |
4327 | | - | |
4328 | | - | |
4329 | | - | |
4330 | | - | |
4331 | | - | |
4332 | 4335 | | |
4333 | 4336 | | |
4334 | 4337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
642 | 642 | | |
643 | 643 | | |
644 | 644 | | |
645 | | - | |
| 645 | + | |
646 | 646 | | |
647 | 647 | | |
648 | 648 | | |
| |||
0 commit comments