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 soundness issues with MMIO and shared memory #18

Merged
merged 8 commits into from
Sep 29, 2022

Conversation

qwandor
Copy link
Collaborator

@qwandor qwandor commented Sep 23, 2022

The way the volatile crate handles MMIO regions is not sound, because it creates references to memory which shouldn't be considered dereferenceable. There is an attempt to fix this in rust-osdev/volatile#22 (and lots of discussion), but that PR has been open since May 2021 and doesn't seem near being submitted. Instead, I've implemented the functionality we need in a new volatile module here using the addr_of! and addr_of_mut! macros, keeping all MMIO regions as pointers and never creating references.

This works for the MMIO transport and config regions. For the Virtqueue, I don't think we need volatile access at all because it's just shared memory, not MMIO. We still shouldn't be using references, however, as DMA to these shared regions by the device violates Rust's aliasing rules, so I've changed the implementation to use pointers instead.

Copy link
Member

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

LGTM. I didn't realize this problem before. Thanks for your work!

@wangrunji0408 wangrunji0408 merged commit e28a1e0 into rcore-os:master Sep 29, 2022
@qwandor qwandor deleted the mmio_soundness branch January 12, 2023 12:45
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.

2 participants