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

UB checks should fail verification for harnesses annotated with #[should_panic] #3571

Open
Tracked by #3566
celinval opened this issue Oct 4, 2024 · 0 comments
Open
Tracked by #3566
Assignees
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] User Experience An UX enhancement for an existing feature. Including deprecation of an existing one.

Comments

@celinval
Copy link
Contributor

celinval commented Oct 4, 2024

I believe we need to create a new UB check property category, and audit the compiler to use the new category for UB instrumentation. The #[should_panic] implementation should take this new category into consideration. Note that this is already the case for some UB's checks.

The motivation is to allow users to write safety harness that succeed as long as no UB is detected.

Here is a small example of how Kani inconsistencyt:

#[kani::proof]
#[kani::should_panic]
pub fn rust_ub_fails() {
    let ptr = 0 as *const u32;
    let _invalid_ref = unsafe { &*ptr };
}

#[kani::proof]
#[kani::should_panic]
pub fn rust_ub_should_fail() {
    let ptr = 10 as *const u32;
    let _invalid_read = unsafe { *ptr };
}

Running this with kani:

$ kani --output-format terse ub_checks.rs
Kani Rust Verifier 0.55.0 (standalone)
Checking harness rust_ub_should_fail...

VERIFICATION RESULT:
 ** 1 of 2 failed
Failed Checks: misaligned pointer dereference: address must be a multiple of its type's alignment
 File: "ub_checks.rs", line 12, in rust_ub_should_fail

VERIFICATION:- SUCCESSFUL (encountered one or more panics as expected)
Verification Time: 0.020638932s

Checking harness rust_ub_fails...

VERIFICATION RESULT:
 ** 1 of 2 failed
Failed Checks: dereference failure: pointer invalid
 File: "ub_checks.rs", line 5, in rust_ub_fails

VERIFICATION:- FAILED (encountered failures other than panics, which were unexpected)
Verification Time: 0.018083837s

Summary:
Verification failed for - rust_ub_fails
Complete - 1 successfully verified harnesses, 1 failures, 2 total.
@celinval celinval changed the title Create a new UB check property category that fails verification even in the presence of #[should_panic]. This will allow users to write safety harness that succeed as long as no UB is detected. UB checks should fail verification for harnesses annotated with #[should_panic] Oct 4, 2024
@celinval celinval added [C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] User Experience An UX enhancement for an existing feature. Including deprecation of an existing one. labels Oct 4, 2024
@tautschnig tautschnig self-assigned this Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C] Feature / Enhancement A new feature request or enhancement to an existing feature. [E] User Experience An UX enhancement for an existing feature. Including deprecation of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants