Repository navigation
fix(runtime): descriptor installs prove the owner is a GC object before writing its meta edge #11410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix(runtime): descriptor installs prove the owner is a GC object before writing its meta edge #11410
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Descriptor installs prove the owner is a Perry GC allocation before writing | ||
| its meta edge. A descriptor owner can be any address — a registry handle, or | ||
| a native `Box` backing such as an `AsyncResource`'s (#11258) — and the | ||
| magnitude-window header reader admits a native allocation whose preceding | ||
| bytes happen to decode as a cell type (a Map, in the observed case); the | ||
| install then stored an `ObjectMeta` pointer into native memory. The install | ||
| twin (`descriptor_summary_meta_ensure`) now gates on | ||
| `try_read_tracked_gc_header`, so such an owner keeps its entries in the | ||
| descriptor tables only. Lookups are unchanged: installs are rare, and handle | ||
| owners already probe the tables directly (bf16bc752). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
crates/perry-runtime/src/object/descriptor_state/native_owner_tests.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //! A descriptor owner can be a native allocation whose preceding bytes decode | ||
| //! as a cell header. The install must prove ownership before it WRITES the | ||
| //! cell's meta edge. | ||
|
|
||
| use super::*; | ||
|
|
||
| /// Sabotage: dropping the tracked gate in `descriptor_summary_meta_ensure` | ||
| /// lets the install write a meta pointer into the native buffer, and the last | ||
| /// assertion fails. | ||
| #[test] | ||
| fn a_native_owner_that_decodes_as_a_map_keeps_its_bytes() { | ||
| let _lock = crate::gc::global_side_table_test_lock(); | ||
| let meta_word = std::mem::offset_of!(crate::map::MapHeader, meta) / 8; | ||
| // Word 0 decodes as a Map header of plausible size; the "cell" starts at | ||
| // word 1, an ordinary Rust heap allocation. | ||
| let mut buf = vec![0u64; 16]; | ||
| buf[0] = u64::from(crate::gc::GC_TYPE_MAP) | (64u64 << 32); | ||
| let owner = buf.as_ptr() as usize + 8; | ||
| assert!( | ||
| crate::value::addr_class::is_plausible_heap_addr(owner), | ||
| "premise: the native buffer is heap-plausible" | ||
| ); | ||
| set_accessor_descriptor( | ||
| owner, | ||
| "k".to_string(), | ||
| AccessorDescriptor { get: 0, set: 0 }, | ||
| ); | ||
| assert!(get_handle_accessor_descriptor(owner, "k").is_some()); | ||
| clear_accessor_descriptor(owner, "k"); | ||
| assert_eq!( | ||
| buf[1 + meta_word], | ||
| 0, | ||
| "the install must not write a meta edge into a native allocation" | ||
| ); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Prove ownership before the first descriptor write.
When bytes before a native owner decode as
GC_TYPE_OBJECT,set_accessor_descriptorcallsnote_accessor_descriptor_targetbefore this check. That path uses a magnitude-only header read and writesOBJ_FLAG_HAS_DESCRIPTORSinto the apparent header. The new gate therefore prevents the meta-edge write but not this native-memory write. Gate the flag and shape updates on tracked ownership. Add a fake-Object case that checks the header word as well as the meta word. (raw.githubusercontent.com)🤖 Prompt for AI Agents