-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Show the offset, length and memory of uninit read errors #142673
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
base: master
Are you sure you want to change the base?
Conversation
throw_ub!(InvalidUninitBytes(None)); | ||
throw_ub!(InvalidUninitBytes(match op.to_op(self)?.as_mplace_or_imm() { | ||
Left(mplace) => mplace.ptr().provenance.and_then(|prov| { | ||
let start = mplace.ptr().into_parts().1; | ||
let size = op.layout().size; | ||
let range = alloc_range(start, size); | ||
Some((prov.get_alloc_id()?, BadBytesAccess { access: range, bad: range })) | ||
}), | ||
Right(_) => None, | ||
})) |
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.
This one doesn't show up in diagnostics, but it seemed good to change it, too
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.
Why doesn't it show up in diagnostics? Aren't all the miri output diffs caused by exactly this?
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.
Ah no, that diff is probably caused by the read_scalar
change.
If this logic here can't be tested, I'd rather remove it, given that it is currently wrong due to how it uses into_parts
.
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.
#142839 gets rid of it
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.
This is read_immediate
, #142839 does nothing there...?
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.
oh right, I mixed up things.
hmm. yea I think I just tried this one because I thought it should be hit somewhere. So I'll turn it into a span_bug
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.
ok, digging into this got more interesting. I added two more commits. TLDR: we only ever use Immediate::Uninit
for zsts or for uninit locals. But reading uninit locals only happens by converting them to Operand
, which handles uninit immediates if processed by erroring.
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.
That's kind of an accidental invariant though, I think... is it worth relying on?
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.
It allows some simplifications. lmk what you think about the latest commits and I can either restore the previous zst/uninit design, or we keep it and revisit if we notice there's something better to do with it (or matthias manages to fuzz us examples of how that code is actually reachable for non-zsts)
This comment has been minimized.
This comment has been minimized.
grml. I haven't been able to run miri's dep tests in-tree in forever. Always sth about libc not found. Will try to bless the others and hope none of these need blessing |
The Miri subtree was changed cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
ff2e26b
to
0120c8e
Compare
throw_ub!(InvalidUninitBytes(None)); | ||
throw_ub!(InvalidUninitBytes(match op.to_op(self)?.as_mplace_or_imm() { | ||
Left(mplace) => mplace.ptr().provenance.and_then(|prov| { | ||
let start = mplace.ptr().into_parts().1; | ||
let size = op.layout().size; | ||
let range = alloc_range(start, size); | ||
Some((prov.get_alloc_id()?, BadBytesAccess { access: range, bad: range })) | ||
}), | ||
Right(_) => None, | ||
})) |
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.
Why doesn't it show up in diagnostics? Aren't all the miri output diffs caused by exactly this?
throw_ub!(InvalidUninitBytes(None)); | ||
throw_ub!(InvalidUninitBytes(match op.to_op(self)?.as_mplace_or_imm() { | ||
Left(mplace) => mplace.ptr().provenance.and_then(|prov| { | ||
let start = mplace.ptr().into_parts().1; |
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.
This is not correct -- depending on which type of provenance this is, start
will be either relative to the allocation, or absolute. into_parts
has a doc comment warning about this. :) Maybe we should rename it into_raw_parts
or so to make it more clear that this API is somewhat dicey.
☔ The latest upstream changes (presumably #143091) made this pull request unmergeable. Please resolve the merge conflicts. |
@rustbot author |
Reminder, once the PR becomes ready for a review, use |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #142839) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @RalfJung
I want to improve memory dumps in general. Not sure yet how to do so best within rust diagnostics, but in a perfect world I could generate a dummy in-memory file (that contains the rendered memory dump) that we then can then provide regular rustc
Span
s to. So we'd basically report normal diagnostics for them with squiggly lines and everything.