You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the problem is dest.as_ptr() as *const u16/32/64 , indices is u8 which is 1-bytes aligned, and convert it to a higher align type may result in unaligned problem which volited to safety precondition of deference a raw pointer. According to rust's security specifications, any pub function that can cause UB should be marked as unsafe, so I decide to report it.
PS E:\Github\lwz> cargo +nightly miri run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
Running `C:\Users\ROG\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\cargo-miri.exe runner target\miri\x86_64-pc-windows-msvc\debug\lwz.exe`
warning: fields `requested_features` and `mac_addr` are never read
--> src\main.rs:3:2
|
1 | pub struct VirtioNetPciDevice {
| ------------------ fields in this struct
2 | //registers: PciRegisters, //Add more
3 | requested_features: u32,
| ^^^^^^^^^^^^^^^^^^
...
7 | mac_addr: [u8; 6],
| ^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
error: Undefined Behavior: accessing memory based on pointer with alignment 1, but alignment 2 is required
--> src\main.rs:13:13
|
13 | *(dest.as_ptr() as *const u16)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ accessing memory based on pointer with alignment 1, but alignment 2 is required
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `VirtioNetPciDevice::write_selected_queue` at src\main.rs:13:13: 13:43
note: inside `main`
--> src\main.rs:31:5
|
31 | device.write_selected_queue(&dest);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error; 1 warning emitted
error: process didn't exit successfully: `C:\Users\ROG\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\bin\cargo-miri.exe runner target\miri\x86_64-pc-windows-msvc\debug\lwz.exe` (exit code: 1)
PS E:\Github\lwz>
The text was updated successfully, but these errors were encountered:
Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
the problem is dest.as_ptr() as *const u16/32/64 , indices is u8 which is 1-bytes aligned, and convert it to a higher align type may result in unaligned problem which volited to safety precondition of deference a raw pointer. According to rust's security specifications, any pub function that can cause UB should be marked as unsafe, so I decide to report it.
POC
result:
The text was updated successfully, but these errors were encountered: