-
Notifications
You must be signed in to change notification settings - Fork 130
Mark DeviceFd::get_device_attr as unsafe #273
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7e15010 to
926b2e2
Compare
roypat
previously approved these changes
Aug 12, 2024
Member
roypat
left a comment
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.
Thanks!
argh, got ahead of myself, seems like CI found a missing unsafe block somewhere :(
alyssais
added a commit
to alyssais/cloud-hypervisor
that referenced
this pull request
Aug 12, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
alyssais
added a commit
to alyssais/cloud-hypervisor
that referenced
this pull request
Aug 12, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
KVM_GET_DEVICE_ATTR causes the kernel to write to an arbitrary address. This is unsafe, as it can allow writing to an address Rust believes to be immutable. I discovered this because an optimisation change[1] in Rust 1.80.0 caused a Cloud Hypervisor test to start failing when built in release mode, because it was setting the addr passed to get_device_attr() to the address of an immutable variable. [1]: rust-lang/rust@d2d24e3 Fixes: 8ea124b ("Add support for `KVM_GET_DEVICE_ATTR` ioctl") Signed-off-by: Alyssa Ross <[email protected]>
926b2e2 to
69ed458
Compare
roypat
approved these changes
Aug 12, 2024
ShadowCurse
approved these changes
Aug 12, 2024
alyssais
added a commit
to alyssais/cloud-hypervisor
that referenced
this pull request
Aug 12, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
alyssais
added a commit
to alyssais/cloud-hypervisor
that referenced
this pull request
Aug 12, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
github-merge-queue bot
pushed a commit
to cloud-hypervisor/cloud-hypervisor
that referenced
this pull request
Aug 13, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
github-merge-queue bot
pushed a commit
to cloud-hypervisor/cloud-hypervisor
that referenced
this pull request
Aug 13, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
github-merge-queue bot
pushed a commit
to cloud-hypervisor/cloud-hypervisor
that referenced
this pull request
Aug 13, 2024
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]>
blitz
pushed a commit
to blitz/cloud-hypervisor
that referenced
this pull request
Feb 10, 2025
DeviceFd::get_device_attr should be marked as unsafe, because it allows writing to an arbitrary address. I have opened a kvm-ioctls PR[1] to fix this. The hypervisor crate was using the function unsafely by passing it addresses of immutable variables. I noticed this because an optimisation change[2] in Rust 1.80.0 caused the kvm::aarch64::gic::tests::test_get_set_icc_regs test to start failing when built in release mode. To fix this, I've broken up the _access functions into _set and _get variants, with the _get variant using a pointer to a mutable variable. This has the side effect of making these functions a bit nicer to use, because the caller now has no need to use references at all, for either getting or setting. [1]: rust-vmm/kvm#273 [2]: rust-lang/rust@d2d24e3 Signed-off-by: Alyssa Ross <[email protected]> (cherry picked from commit 02f146f)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary of the PR
KVM_GET_DEVICE_ATTRcauses the kernel to write to an arbitrary address. This is unsafe, as it can allow writing to an address Rust believes to be immutable.I discovered this because an optimisation change in Rust 1.80.0 caused a Cloud Hypervisor test to start failing when built in release mode, because it was setting the addr passed to
get_device_attr()to the address of an immutable variable.Requirements
Before submitting your PR, please make sure you addressed the following
requirements:
git commit -s), and the commit message has max 60 characters for thesummary and max 75 characters for each description line.
test.
Release" section of CHANGELOG.md (if no such section exists, please create one).
unsafecode is properly documented.