Skip to content
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

Undefined behavior in Rand #149

Merged
merged 8 commits into from Jul 24, 2020
Merged

Undefined behavior in Rand #149

merged 8 commits into from Jul 24, 2020

Conversation

vks
Copy link
Contributor

@vks vks commented Sep 4, 2019

No description provided.

@Shnatsel
Copy link
Member

Shnatsel commented Sep 4, 2019

Is there any practical impact out of this? I'm not aware of unaligned accesses being exploitable in practice.

Does "provenance rules" mean "2 mutable pointers to the same thing"?

@dhardy
Copy link
Contributor

dhardy commented Sep 5, 2019

Considering that the code in question should have been thoroughly tested on all our CI platforms to produce correct results, I think it quite unlikely there was any exploitable bug.

@vks
Copy link
Contributor Author

vks commented Sep 6, 2019

Does "provenance rules" mean "2 mutable pointers to the same thing"?

No, they mean in this case that &mut slice[0] as *mut _ is a raw pointer that can only be used to access the first element. However, Rand used this pointer to access higher elements as well. slice.as_mut_ptr() has to be used instead.

@RalfJung
Copy link
Contributor

RalfJung commented Sep 17, 2019

Does this refer to rust-random/rand#780 or to rust-random/rand#784?

The former (rust-random/rand#780) is, to my knowledge, not de-facto UB with any existing Rust versions. Whether it is de jure UB is hard to say as Rust does not have an aliasing model at this point, but the code might become de jure and also de facto UB in the future. The provenance violation comes up in an experimental pointer provenance model for Rust (Stacked Borrows). While we do exploit provenance to some extend with noalias, I do not think rand violated noalias (but I will not make any definite statement about noalias; the LLVM spec is extremely fuzzy in that regard and likely inconsistent).

The latter (rust-random/rand#784) is de-facto UB as we tell LLVM that those accesses are aligned. It has nothing to do with pointer provenance though. Whether this UB actually leads to bad code generation or is exploitable, I do not know. (This comes back to the question I raised a while ago: is UB [de facto or de jure] sufficient for an advisory?)

EDIT: Oh I see, this adds advisories for both. Btw, it might be a good idea to also link to the issue and/or pull request so that one can get a better idea of what the flaw and fix look like. Not sure if the url field can be used multiple times?

@vks
Copy link
Contributor Author

vks commented Sep 17, 2019

Btw, it might be a good idea to also link to the issue and/or pull request so that one can get a better idea of what the flaw and fix look like. Not sure if the url field can be used multiple times?

I added a link to the changelog, with contains the issue numbers. I'm also not sure whether I can specify multiple URLs instead.

@tarcieri
Copy link
Member

tarcieri commented Sep 17, 2019

We've had a few tough calls on whether something deserves an advisory in the past. In #124, the more we studied it, the more it looked exploitable. As I look at this one, I feel the opposite: with more analysis I'm less and less convinced there's anything exploitable here. My feeling on this is it isn't worth an advisory unless someone can present a credible threat (even if hypothetical and far fetched).

@tarcieri
Copy link
Member

Closing this as unexploitable. Please reopen or refile if there is a credible threat.

@tarcieri tarcieri closed this Sep 18, 2019
thomcc pushed a commit to thomcc/advisory-db that referenced this pull request Apr 23, 2020
thomcc pushed a commit to thomcc/advisory-db that referenced this pull request Apr 23, 2020
@RalfJung
Copy link
Contributor

Would it make sense to reopen this an an "informational (unsound)" advisory?

@tarcieri tarcieri reopened this Jun 23, 2020
@tarcieri
Copy link
Member

@RalfJung reopened for discussion at least

@vks
Copy link
Contributor Author

vks commented Jun 24, 2020

I guess it would encourage people to upgrade Rand. Does RustSec have a policy for "informational" advisories?

The pointer provenance rules are not yet properly defined for Rust.
@vks
Copy link
Contributor Author

vks commented Jun 30, 2020

I rebased on master and removed the mention of pointer provenance rules.

Co-authored-by: Ralf Jung <post@ralfj.de>

The flaw was corrected by Ralf Jung and Diggory Hardy.
"""
patched_versions = [">= 0.4.2"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look like the right toml format (maybe it changed); see https://github.com/RustSec/advisory-db#advisory-format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vks that is probably also the cause of the CI failure, though the message is quite cryptic:

error: error loading advisory DB repo from .: RustSec error: parse error: missing field `versions` at line 1 column 1

@tarcieri tarcieri merged commit 6d23861 into rustsec:master Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants