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

ReadableProcessBuffer should be sealed or unsafe trait #3757

Open
kupiakos opened this issue Dec 9, 2023 · 3 comments
Open

ReadableProcessBuffer should be sealed or unsafe trait #3757

kupiakos opened this issue Dec 9, 2023 · 3 comments

Comments

@kupiakos
Copy link
Contributor

kupiakos commented Dec 9, 2023

In order for unsafe code working with generic ReadableProcessBuffer (and WriteableProcessBuffer with #3756 implemented) to trust that their implementations of ptr to be correct, that code needs to either:

  • Constrain implementations to a fixed and auditable set of ReadableProcessBuffer types, or
  • Have an unsafe guarantee from trait implementers that the ptr method returns a pointer with the documented requirements.

See How Safe and Unsafe Interact for more info on when unsafe trait is needed.

@kupiakos
Copy link
Contributor Author

kupiakos commented Dec 11, 2023

Note: #![forbid(unsafe_code)] can generally interact with and use an unsafe trait without issue; it primarily affects implementers of the trait itself.

@alevy
Copy link
Member

alevy commented Dec 15, 2023

This seems right to me. In other words, the implementations of ReadProcessBuffer has to be trusted even if it doesn't happen to require unsafe to write. So marking the trait unsafe would help ensure that only trusted code is allowed to write this trusted code.

@kupiakos
Copy link
Contributor Author

Yes, at the moment any implementer of ReadableProcessBuffer could write fn ptr(&self) -> *const u8 { ptr::null() }. Since there's no safety requirement for trait implementers, that implementation is fine according to soundness rules - thus it's not fine for unsafe code to trust generic ReadableProcessBuffer::ptr output to be a valid pointer.

@alevy alevy pinned this issue Feb 27, 2024
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

2 participants