-
Notifications
You must be signed in to change notification settings - Fork 953
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
vulkan: Don't use pointer to dropped PhysicalDeviceDriverProperties. #3076
Conversation
5ae0b19
to
4881e0e
Compare
We could avoid those |
4881e0e
to
c413ec9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good as is, but it might be useful to have our own utility function that implements from_bytes_until_nul so that we get the lifetime and don't need the unsafe anymore
Detected by ASAN, but seems impossible to exploit. Since `ash::vk::definitions::PhysicalDeviceDriverProperties` is `Copy`, the statement if let Some(driver) = phd_capabilities.driver { ... } actually makes `driver` a local copy of the struct. The code uses `as_ptr` to create a pointer to the `driver_name` field of this local copy, and then tries to use that pointer outside the `if let`, when the local copy has gone out of scope. This is UB. Taking a reference to the properties struct is correct and more efficient.
Remove a handful of `unsafe` blocks from the Vulkan back end.
c413ec9
to
16f2702
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Music to my eyes!
CI is mad |
Detected by ASAN, but seems impossible to exploit.
Since
ash::vk::definitions::PhysicalDeviceDriverProperties
isCopy
, the statementactually makes
driver
a local copy of the struct. The code usesas_ptr
to create a pointer to thedriver_name
field of this local copy, and then tries to use that pointer outside theif let
, when the local copy has gone out of scope. This is UB.Taking a reference to the properties struct is correct and more efficient.
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
Link to the issues addressed by this PR, or dependent PRs in other repositories
Description
Describe what problem this is solving, and how it's solved.
Testing
Explain how this change is tested.