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

Miri: relax fn ptr check #94270

Merged
merged 1 commit into from
Feb 24, 2022
Merged

Miri: relax fn ptr check #94270

merged 1 commit into from
Feb 24, 2022

Conversation

RalfJung
Copy link
Member

As discussed in rust-lang/unsafe-code-guidelines#72 (comment), the function pointer check done by Miri is currently overeager: contrary to our usual principle of only checking rather uncontroversial validity invariants, we actually check that the pointer points to a real function.

So, this relaxes the check to what the validity invariant probably will be (and what the reference already says it is): the function pointer must be non-null, and that's it.

The check that CTFE does on the final value of a constant is unchanged -- CTFE recurses through references, so it makes some sense to also recurse through function pointers. We might still want to relax this in the future, but that would be a separate change.

r? @oli-obk

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 22, 2022
@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 22, 2022
@RalfJung RalfJung force-pushed the fn-ptrs branch 2 times, most recently from 9065caf to 346b8fa Compare February 23, 2022 00:01
let _fn = try_validation!(
self.ecx.memory.get_fn(ptr),
self.path,
err_ub!(DanglingIntPointer(..)) |
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have tests for these two errors? At least the test you edited doesn't have them, though it tests similar things for regular references

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point, this is a good opportunity to increase our test coverage.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 23, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 23, 2022

📌 Commit 182d335 has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 23, 2022
@RalfJung
Copy link
Member Author

You are too quick, I just wanted to write that I added more tests...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 24, 2022
…askrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#89887 (Change `char` type in debuginfo to DW_ATE_UTF)
 - rust-lang#94267 (Remove unused ordering derivations and bounds for `SimplifiedTypeGen`)
 - rust-lang#94270 (Miri: relax fn ptr check)
 - rust-lang#94273 (add matching doc to errorkind)
 - rust-lang#94283 (remove feature gate in control_flow examples)
 - rust-lang#94288 (Cleanup a few Decoder methods)
 - rust-lang#94292 (riscv32imc_esp_espidf: set max_atomic_width to 64)
 - rust-lang#94296 (:arrow_up: rust-analyzer)
 - rust-lang#94300 (Fix a typo in documentation of `array::IntoIter::new_unchecked`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3cd1dc1 into rust-lang:master Feb 24, 2022
@rustbot rustbot added this to the 1.61.0 milestone Feb 24, 2022
@RalfJung RalfJung deleted the fn-ptrs branch February 24, 2022 15:44
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 25, 2022
Miri fn ptr check: don't use conservative null check

In rust-lang#94270 I used the wrong NULL check for function pointers: `memory.ptr_may_be_null` is conservative even on machines that support ptr-to-int casts, leading to false errors in Miri.

This fixes that problem, and also replaces that foot-fun of a method with `scalar_may_be_null` which is never unnecessarily conservative.

r? `@oli-obk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants