Skip to content
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

fix(cordyceps): pin list::IterMut items #209

Merged
merged 2 commits into from
Jun 8, 2022
Merged

fix(cordyceps): pin list::IterMut items #209

merged 2 commits into from
Jun 8, 2022

Conversation

hawkw
Copy link
Owner

@hawkw hawkw commented Jun 8, 2022

Currently, there is a potential safety issue when using
cordyceps::list::IterMut: the iterator's item type is &mut T.
&mut Ts may be mem::replaced or mem::takeen, moving them out of
the list to a different memory location. This would invalidate any
pointers in the list that point to that node.

Therefore, to ensure that the mutable iterator cannot corrupt the list
(potentially leading to dangling pointers or use-after-frees), this PR
changes list::IterMut's Item type from &'list mut T to
Pin<&'list mut T. This ensures that the iterator cannot be used to
corrupt the list.

Currently, there is a potential safety issue when using
`cordyceps::list::IterMut`: the iterator's item type is `&mut T`.
`&mut T`s may be `mem::replace`d or `mem::take`en, moving them out of
the list to a different memory location. This would invalidate any
pointers in the list that point to that node.

Therefore, to ensure that the mutable iterator cannot corrupt the list
(potentially leading to dangling pointers or use-after-frees), this PR
changes `list::IterMut`'s `Item` type from `&'list mut T` to `Pin<&'list
mut T`. This ensures that the iterator cannot be used to corrupt the
list.
@hawkw hawkw requested a review from jamesmunns June 8, 2022 15:59
@jamesmunns
Copy link
Collaborator

No objections from me. It might make sense to do a sit-down review together at some point, and figure out all the ownership/iteration requirements for List? it seems like there's been a couple of conceptual issues that have popped up, it might make sense to make the high level docs/reqs more clear so it's easier to review on this.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw enabled auto-merge (squash) June 8, 2022 17:59
@hawkw hawkw merged commit 2e5a270 into main Jun 8, 2022
@hawkw hawkw deleted the eliza/iter-mut-pin branch June 8, 2022 18:05
hawkw added a commit that referenced this pull request Jun 23, 2022
Currently, the `Item` type of `list::CursorMut`'s `Iterator` impl is
`&mut T`. This is incorrect, as it allows the items to be moved out of
the list without unlinking them. Instead, the iterator's item type must
be `Pin`ned. PR #209 made this change for the `IterMut` type, but did
not make the same change for `CursorMut`, so this commit fixes
`CursorMut` similarly.

BREAKING CHANGE:

This changes the type signature of the `Iterator` impl for
`list::CursorMut`.
hawkw added a commit that referenced this pull request Jun 23, 2022
Currently, the `Item` type of `list::CursorMut`'s `Iterator` impl is
`&mut T`. This is incorrect, as it allows the items to be moved out of
the list without unlinking them. Instead, the iterator's item type must
be `Pin`ned. PR #209 made this change for the `IterMut` type, but did
not make the same change for `CursorMut`, so this commit fixes
`CursorMut` similarly.

BREAKING CHANGE:

This changes the type signature of the `Iterator` impl for
`list::CursorMut`.
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.

None yet

2 participants