-
Notifications
You must be signed in to change notification settings - Fork 24
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
Implementing From<&mut AsciiStr>
for &mut str
and &mut [u8]
is unsound
#64
Comments
You can file a security advisory at https://github.com/RustSec/advisory-db Out-of-bounds indexing in safe code is usually an exploitable vulnerability, so I would strongly recommend filing a security advisory. |
I think Shnatsels idea is good, we should file an advisory. I've yanked the affected versions already. |
I've filed advisory, so this can be closed now :) |
@tomprogrammer hi, I am confused about the purpose of PoC provided here. arr[ascii[0] as u8 as usize] I understand that here Therefore, I can't understand why your PoC can prove the unsoundness. Could you give some more explanation, thanks? |
@shinmao: @KisaragiEffective: |
@tomprogrammer thanks for the response. The reason why I feel confused is that this OOB case could never be checked by compiler statically. For example, let arr = [0u8, 1, 2, 3, 4, 5];
println!("{}", arr[ arr[4] as u8 as usize ] ); This code can be compiled and have a runtime panic because compiler couldn't understand the value of However, maybe this is the only way to show unsoundness here? |
In your example there is no OOB indexing or UB because the inserted check will panic and prevent the OOB indexing from occurring.
In my example the unsoundness happens in the I hope this explains it. |
@tormol sorry I ping the wrong person hahaha Thanks for your clear answer. It really helps solve my question! |
They allow writing non-ASCII values to an AsciiStr which when read out as an AsciiChar will produce values outside the valid niche.
These impls were added by me in 4fbd050, so 0.9, 0.8 and 0.7 are affected.
Here's an example using these impls to create out-of-bounds array indexing in safe code (when compiled in release mode):
I don't see any good way to tell users of the crate to stop using these impls:
Deprecation notices on trait impls are ignored (by both Rust 1.38 and Rust 1.9).
Changing the impls to panic or return an empty slice could break working code (that never writes non-ASCII values) at run-time.
The only fix we could make appears to be to remove the impls, telling users of them to do the unsafe pointer casting explicitly. On one hand this will make any accidental users of it aware of the problem when they update Cargo.lock, but it will also break any use that happened to be OK with a minor release, and any reverse dependencies of these uses.
On the other hand doing nothing and hoping nobody accidentally uses these impls feels irresponsible. What do you think @tomprogrammer?
In any case I don't think we need to fix 0.7 and 0.8, as Rust didn't backport the security fix in 1.29.1 to previous affected versions.
The text was updated successfully, but these errors were encountered: