Skip to content

Protocol safety improvements #460

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

Merged
merged 11 commits into from
Jul 15, 2022

Conversation

nicholasbishop
Copy link
Member

Overview:

  • Add BootServices::get_handle_for_protocol. This is a convenience method for finding one arbitrary handle that supports a protocol.
  • Mark locate_protocol as unsafe and deprecated, as it has the same safety problems as handle_protocol.
  • Mark handle_protocol as unsafe (it's already deprecated).
  • Update all the test code to use open_protocol instead of locate_protocol.

Using open_protocol is now the only undeprecated way of opening a protocol. There's still some more safety work to do here -- if the protocol isn't opened in exclusive mode, or if the agent parameter isn't set correctly, UB could result. But pushing all users towards open_protocol is a good first step.

This is a partial fix for #359

This is a convenience method to get any arbitrary handle that supports a
particular `Protocol`.
Rather than opening the Output protocol, which isn't important for this
test, just write through the context pointer and assert that the
expected data was written.
This function is already marked deprecated, mark it unsafe as well and
update the documentation to describe why.
This method has the same problems as `handle_protocol`; it does not mark
the handle and protocol as in use. Calls to `locate_protocol` can be
replaced by calling `get_handle_for_protocol` and `open_protocol`.

rust-osdev#359
@GabrielMajeri
Copy link
Collaborator

The PR looks great! The new get_handle_for_protocol helps a lot with safety without sacrificing usability. Let's hope it won't be too much effort for downstream crate users to switch to the new method of opening protocols.

@GabrielMajeri GabrielMajeri merged commit d3206d6 into rust-osdev:main Jul 15, 2022
@nicholasbishop nicholasbishop deleted the bishop-proto-safety branch July 15, 2022 14:33
e820 pushed a commit to e820/uefi-rs that referenced this pull request Jul 30, 2022
* Add BootServices::get_handle_for_protocol

This is a convenience method to get any arbitrary handle that supports a
particular `Protocol`.

* Use open_protocol in shim-lock test

* Use open_protocol in multiprocessor test

* Use open_protocol in device path test

* Use open_protocol in pointer test

* Use open_protocol in graphics test

* Use open_protocol in file system test

* Use open_protocol in the serial device test

* Simplify event callback with context test

Rather than opening the Output protocol, which isn't important for this
test, just write through the context pointer and assert that the
expected data was written.

* Mark handle_protocol as unsafe

This function is already marked deprecated, mark it unsafe as well and
update the documentation to describe why.

* Deprecate BootServices::locate_protocol and mark it unsafe

This method has the same problems as `handle_protocol`; it does not mark
the handle and protocol as in use. Calls to `locate_protocol` can be
replaced by calling `get_handle_for_protocol` and `open_protocol`.

rust-osdev#359
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