Commit 0dfe40c
committed
gh-143228: Fix UAF in perf trampoline during finalization
When toggling perf trampoline while threads are running, or during
interpreter finalization with daemon threads active, a use-after-free
occurs. The munmap call in free_code_arenas releases executable memory
while other threads may still be executing within trampolines or
unwinding through them, causing SIGSEGV or SystemError.
The fix uses reference counting with a code watcher. Each code object
that receives a trampoline increments a refcount. When code objects are
destroyed, the watcher decrements the refcount and frees arenas only
when it reaches zero. This ensures trampolines are never freed while
any code object could still reference them.1 parent 61ee048 commit 0dfe40c
File tree
4 files changed
+44
-10
lines changed- Include/internal
- Python
4 files changed
+44
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | 106 | | |
108 | 107 | | |
109 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
207 | 232 | | |
208 | 233 | | |
209 | 234 | | |
| |||
407 | 432 | | |
408 | 433 | | |
409 | 434 | | |
| 435 | + | |
410 | 436 | | |
411 | 437 | | |
412 | 438 | | |
| |||
433 | 459 | | |
434 | 460 | | |
435 | 461 | | |
| 462 | + | |
436 | 463 | | |
437 | 464 | | |
438 | 465 | | |
| |||
487 | 514 | | |
488 | 515 | | |
489 | 516 | | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
490 | 521 | | |
491 | 522 | | |
492 | 523 | | |
| |||
504 | 535 | | |
505 | 536 | | |
506 | 537 | | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
507 | 544 | | |
508 | 545 | | |
509 | 546 | | |
| |||
525 | 562 | | |
526 | 563 | | |
527 | 564 | | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
528 | 569 | | |
529 | 570 | | |
530 | 571 | | |
531 | 572 | | |
532 | 573 | | |
533 | 574 | | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | 575 | | |
542 | 576 | | |
543 | 577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1944 | 1944 | | |
1945 | 1945 | | |
1946 | 1946 | | |
1947 | | - | |
1948 | 1947 | | |
1949 | 1948 | | |
1950 | 1949 | | |
| |||
0 commit comments