-
Notifications
You must be signed in to change notification settings - Fork 29
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
Unsoundness in the implementation of several functions #571
Comments
linux::virtqueue::Vring::<T>::ring_elem
We consider that there are some other misaligned pointer dereference in this package. The source of unsoundnessFirst of all, in Lines 360 to 361 in 92458f5
addr was cast to u32 and cause to misaligned pointer dereference!
Secondly, the methods implementated for To reproduce the buguse uhyvelib::linux::virtqueue::Vring;
fn main() {
let a: u8 = 1;
let v = Vring::<u8>::new(&a as *const u8);
// println!("{}", v._flags());
println!("{}", v.index());
} This code shows how to trigger undefined behavior with
|
Thank you so much for opening this issue. We are aware that our virtio implementation is problematic, both in the kernel and in Uhyve. We are making plans on addressing those problems in the long term. If you would like to contribute, please tell us, so we can coordinate. It would be helpful if this issue could be split up into two separate issues. The |
@mkroening I would love to help fix the issue in my free time. Feel free to ping me in the future! |
Sounds great! Contributions are always welcome. We have a Zulip for chatting and coordination. :) I have also just added links to Zulip to the organizations README for better discoverability. |
@mkroening Hi, I just noticed that the following two methods Lines 282 to 286 in fcdd579
could have the totally same misaligned pointer issues as described above. Could you explain more about why the clippy warning would be suppressed here? |
Good find! That should definitely be fixed. I can only guess that this was just to silence clippy without being aware of the consequences and opening an issue. |
Yup! I think it would be easy for you to fix it now 👍 |
I can't say how difficult it would be. I did not have a close look yet. :) See aa5758e for the introduction and more such cases. |
Sorry I can't say that. Personally speaking, I suggest to use |
Can I have a go at this? :) |
Sure! Thanks! :) |
I have the feeling, that this issue is vacant as of today 😅 |
The source of unsoundness
uhyve/src/linux/virtqueue.rs
Lines 51 to 54 in 4194357
Hi, we consider that
ring_elem
is unsound because it allowsu8
pointer cast to arbitrary pointer types and dereference the types. It can break the alignment and the validity invariants at the same time.To reproduce the bug
To reproduce the misalignment issue
execute the code and get panic,
The misaligned pointer dereference is triggered here because you cast the type aligned to 1 byte to the one aligned to 2 bytes. If this is what you plan, then you could change dereference to
read_unaligned
.Here, we can also specify
em
asbool
types. Run it can get you the results such as[true, true, true, false]
. However, run with miri then you can find thatmem.offset
already access out-of-bound.It means that our
bool
type points to invalid value actually.The text was updated successfully, but these errors were encountered: