Fix unsoundness in our representation of the MADT #223
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.
As reported in #218, we had a glaring soundness hole in the way we represented the MADT, which allowed an
Madt
to be moved away from its following entries. WhenMadt::entries
was called, this would lead to arbitrary memory being read from after wherever theMadt
ended up.Moving the structures representing the tables is unlikely if the library is used as intended (and structures were
Copy
only because this was required byrepr(packed)
, but this is not actually required in the case ofMadt
), but this should obviously still be closed.We make this sound by making
Madt: !Unpin
, which prevents the structure from being moved if in aPin
. To minimise difficulty usingPhysicalMapping
, we continue to allow mappings to deref to normal references if the underlyingT: Unpin
, but only allow access throughPin<&T>
ifT: !Unpin
(ideally we'd just produce aPin
through deref but I don't think is possible?).This feels like it should address the soundness issue from my end, but my knowledge surrounding
Pin
is still dubious at times, so anyone more knowledgeable who feels this is not correct please do let me know.This would unfortunately be a breaking change.
cc @pyelias