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

uplink: Fix passing dangling stack pointer #91

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

GodTamIt
Copy link
Contributor

There were 2 bugs in the register_gateway_access() code:

  1. Most prominently, the function was constructing and passing a dangling pointer to a temporary EdgeRegisterAccessOptions to the FFI. In fact, that variable doesn't even live to the point that the FFI is made. While this occurs on the stack and may not always be overwritten, the compiler and program is free to reclaim and reuse that stack space for other things -- it's technically UB. This code is somewhat lucky that this doesn't occur very often because the struct is very small, on the stack, and a boolean.
  2. The function was also casting the *const EdgeRegisterAccessOptions pointer as mutable in the unsafe block, which violates Rust's aliasing guarantees and can potentially lead to undefined behavior.

cc @ifraixedes - this may be the root cause of #90.

There were 2 bugs in the `register_gateway_access()` code:

1. Most prominently, the function was constructing and passing a dangling
pointer to a temporary `EdgeRegisterAccessOptions` to the FFI. In fact,
that variable doesn't even live to the point that the FFI is made. While
this occurs on the stack and may not always be overwritten, the compiler
and program is free to reclaim and reuse that stack space for other
things -- it's technically UB. This code is somewhat lucky that this
doesn't occur very often because the struct is very small, on the stack,
and a boolean.
2. The function was also casting the `*const EdgeRegisterAccessOptions`
pointer as mutable in the unsafe block, which violates Rust's aliasing
guarantees and can potentially lead to undefined behavior.
Copy link
Collaborator

@ifraixedes ifraixedes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GodTamIt well spotted

I would have spotted it without having a reproducible case because I don't have enough Rust experience.
Many thanks.

I'm going to make a new release in the following hour.
Let me know if it solves #90 once you use the new release

@ifraixedes ifraixedes merged commit 66f1c62 into storj-thirdparty:main Jan 20, 2025
2 checks passed
@GodTamIt GodTamIt deleted the fix-bad-ptr branch January 20, 2025 15:52
@ifraixedes
Copy link
Collaborator

@GodTamIt the uplink v01.10.2 is released

@GodTamIt GodTamIt restored the fix-bad-ptr branch January 20, 2025 20:50
@GodTamIt GodTamIt deleted the fix-bad-ptr branch January 20, 2025 20:50
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