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

Rethink (im)mutabiltiy of device paths (DevicePathBuilder / install_protocol_interface) #970

Closed
phip1611 opened this issue Oct 23, 2023 · 4 comments

Comments

@phip1611
Copy link
Contributor

phip1611 commented Oct 23, 2023

DevicePathBuilder::finalize() returns a &DevicePath. If one wants to install this to a handle using install_protocol_interface, one has to cast that to a *mut c_void. It feels unhandy to change the mutability here.

Also, I'm not sure if install_protocol_interface could just consume a *const`. In the spec, I don't find something that says that this needs to be mutable:

https://uefi.org/specs/UEFI/2.10/07_Services_Boot_Services.html?highlight=install_protocol_interface

Code that uses this functionality can be found here: nix-community/lanzaboote#194

@phip1611 phip1611 changed the title Rething (im)mutabiltiy of device paths (DevicePathBuilder / install_protocol_interface) Rethink (im)mutabiltiy of device paths (DevicePathBuilder / install_protocol_interface) Oct 23, 2023
@blitz
Copy link
Contributor

blitz commented Oct 23, 2023

It would be nice to be able to build device paths as global constants as well. This would sidestep the use-after-free issues from nix-community/lanzaboote#194.

@phip1611
Copy link
Contributor Author

phip1611 commented Oct 24, 2023

🔝 I wonder if this is possible without (procedural) macros but only const functions 🤔

I have to take a closer look at device paths.

nicholasbishop added a commit to nicholasbishop/uefi-rs that referenced this issue Oct 29, 2023
A protocol's interface may mutate itself, but the void pointer passed to the
`{install,reinstall,uninstall}_protocol_interface` functions is opaque to the
firmware, so there's no need for it to be a mut pointer.

Note that from a Rust safety perspective there's no difference here -- mut and
const pointers are interchangeable.

rust-osdev#970
@nicholasbishop
Copy link
Member

I agree with you that install_protocol_interface could just take a const pointer. Put up #981 for that.

Interesting idea about constructing const device paths. It's tricky in the general case since some nodes are rather dynamic. We'd also have to change our current trait-based approach (https://docs.rs/uefi/latest/uefi/proto/device_path/build/trait.BuildNode.html), since I don't think there's any way to declare const fns in traits yet.

@nicholasbishop
Copy link
Member

I opened #983 for building device paths as constants. install_protocol_interface & co have been updated to take a const pointer, so closing this issue.

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

No branches or pull requests

3 participants