Skip to content

Fix undefined behaviour in LinkedPerCore::get. - #51

Open
qwandor wants to merge 2 commits into
mainfrom
provenance
Open

Fix undefined behaviour in LinkedPerCore::get.#51
qwandor wants to merge 2 commits into
mainfrom
provenance

Conversation

@qwandor

@qwandor qwandor commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Fixes #48.

@imre-kis-arm

Copy link
Copy Markdown
Contributor

Is there a way to create a test that triggers the issue? Maybe with running it with Miri?

@qwandor

qwandor commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Is there a way to create a test that triggers the issue? Maybe with running it with Miri?

I don't think so, as that would require running the test with a linker script for the .percore section and associated symbols.

Comment thread src/derive.rs Outdated
(&raw const self.0)
.expose_provenance()
.cast_signed()
.checked_add(percore_local_offset())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds runtime overhead for each percore access.
It checks for integer overflow and NULL pointer. Based on the safety requirements neither of this should happen.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

The safety requirements of the PercoreLocalOffset trait should make
these unneccessary.
Comment thread src/derive.rs
// `byte_offset` on the pointer to `self.0` because the per-core copy is not part of the
// same allocation.
let percore_ptr = with_exposed_provenance::<T>(
((&raw const self.0).expose_provenance().cast_signed() + percore_local_offset())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I'm wrong, but according to the corresponding section in Rust docs this seems incorrect.

  • expose_provenance [...] adds the provenance of the pointer to a global list of 'exposed' provenances [...]
  • with_exposed_provenance can be used to construct a pointer with one of these previously
    'exposed' provenances

In this line we "save" the provenance of the primary core's pointer, and in the previous line create a new pointer by "retrieving" the saved provenance, but that still only describes the primary core's memory area.

I'm not sure if it's possible, but we should rather save the provenance of the pointer that was passed to percore_copy_secondary_data() and use that when constructing the secondary core's pointer here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LinkedPerCore::get uses an out-of-bounds pointer offset for secondary cores

3 participants