Repository navigation
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 |
| /// | ||
| /// ## Safety | ||
| /// | ||
| /// `physical_address` must point to a valid `T` in physical memory. |
There was a problem hiding this comment.
Could you format this in a bullet list like above?
| /// `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.
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. |
| /// | ||
| /// ## 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.
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
PhysicalMappingsound:PhysicalMappingwithvirtual_startset to an invalid pointer and dereference it. This pr addsPhysicalMapping::newwhich is unsafe.AcpiHandler::unmap_physical_regionno longer takesself. Implementations should usePhysicalMapping::handlerto get the correct mapper. While it wasn't necessarily unsound to callunmap_physical_regionon anotherPhysicalMapperremovingselfmakes it's easier to implementunmap_physical_regionsafely.This is a breaking change.