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 physical mapping soundness #102
Fix physical mapping soundness #102
Conversation
Ouch - this is an embarrassing oversight on my part. My thought process was that the library only accepted So while breaking, I think I'm for the first change. Implementing |
rsdp/src/handler.rs
Outdated
/// | ||
/// ## Safety | ||
/// | ||
/// `physical_address` must point to a valid `T` in physical memory. |
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.
Could you format this in a bullet list like above?
rsdp/src/handler.rs
Outdated
/// ## Safety | ||
/// | ||
/// `physical_address` must point to a valid `T` in physical memory. | ||
/// `size` must be at least `size_of::<T>()`. | ||
unsafe fn map_physical_region<T>(&self, physical_address: usize, size: usize) -> PhysicalMapping<Self, T>; | ||
|
||
/// Unmap the given physical mapping. This is called when a `PhysicalMapping` is dropped. |
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.
I think we should either add some docs here about how to access the handler and why it works like that, or just that you should not call this yourself, because it is called automatically when a mapping is dropped.
I agree that it's very unlikely that a user would use this api wrongly, however as someone implementing I agree that the docs should be improved - what do you think of the following docs? /// Unmap the given physical mapping. This is called when a `PhysicalMapping` is dropped, you should **not** manually call this.
///
/// Note: A reference to the handler used to construct `region` can be acquired by calling [`PhysicalMapping::handler`].
fn unmap_physical_region<T>(region: &PhysicalMapping<Self, T>); Ultimately, if you want me to undo the second change, I'd understand, it's a bit weird in that it makes implementing the trait slightly easier though slightly more confusing at first. |
rsdp/src/handler.rs
Outdated
/// | ||
/// ## Safety | ||
/// | ||
/// This function must only be called by the `AcpiHandler` `H` to make sure that it's safe to unmap the mapping. |
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.
I think saying "must only be called by an AcpiHandler
of type H
to..." would be clearer
Hm, I think I'm convinced. With the doc changes (those are great, thanks!), I don't think this is particularly confusing and does prevent a footgun, that as you say I'd hate to try and protect against from when implementing If you add the docs and address that last formatting nit, I think this is ready to merge. Thanks for these changes! |
Great, thanks! This will be published as a breaking change to |
No need to rush, I'm fine just using a patched version until then, thanks. |
This pr makes
PhysicalMapping
sound:PhysicalMapping
withvirtual_start
set to an invalid pointer and dereference it. This pr addsPhysicalMapping::new
which is unsafe.AcpiHandler::unmap_physical_region
no longer takesself
. Implementations should usePhysicalMapping::handler
to get the correct mapper. While it wasn't necessarily unsound to callunmap_physical_region
on anotherPhysicalMapper
removingself
makes it's easier to implementunmap_physical_region
safely.This is a breaking change.