Skip to content

Incorrect verification success on print statement #194

Closed

Description

@avanhatt

RMC run with bound checking says verification is successful on this function, which actually seg faults.

Command: rmc --keep-temps --gen-c src/test/cbmc/DynTrait/fixme_offset.rs --pointer-check --bounds-check

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT

struct Foo {}
trait Trait {
    fn func(&self) -> i32;
}

impl Trait for Foo {
    fn func(&self) -> i32 {
        1 as i32
    }
}

fn foo() -> Box<dyn Trait> {
    Box::new(Foo {}) 
}

fn main() {
    let f = foo();
    unsafe {
        let f_ptr = Box::into_raw(f) as *const usize;
        println!("{}", *(f_ptr.offset(100000)));
    }
}

RMC result:

/Users/avanhatt/research/rmc/src/test/cbmc/DynTrait/fixme_offset.rs function main
[main.assertion.3] line 20 resume instruction: SUCCESS
[main.assertion.1] line 22 Non-null virtual function call for "::Trait::func": SUCCESS
[main.pointer_dereference.1] line 22 dereference failure: pointer NULL in var_3.vtable->::Trait::func: SUCCESS
[main.pointer_dereference.2] line 22 dereference failure: pointer invalid in var_3.vtable->::Trait::func: SUCCESS
[main.pointer_dereference.3] line 22 dereference failure: deallocated dynamic object in var_3.vtable->::Trait::func: SUCCESS
[main.pointer_dereference.4] line 22 dereference failure: dead object in var_3.vtable->::Trait::func: SUCCESS
[main.pointer_dereference.5] line 22 dereference failure: pointer outside object bounds in var_3.vtable->::Trait::func: SUCCESS
[main.pointer_dereference.6] line 22 dereference failure: invalid integer address in var_3.vtable->::Trait::func: SUCCESS
[main.assertion.2] line 23 assertion failed: x == 1: SUCCESS

<builtin-library-malloc> function malloc
[malloc.assertion.1] line 26 max allocation size exceeded: SUCCESS
[malloc.assertion.2] line 31 max allocation may fail: SUCCESS

** 0 of 78 failed (1 iterations)
VERIFICATION SUCCESSFUL

Rust result:

timeout: the monitored command dumped core
/playground/tools/entrypoint.sh: line 11:     9 Segmentation fault      timeout --signal=KILL ${timeout} "$@"

Activity

  1. added
    [C] Bug
    [F] Soundness
    on Jun 10, 2021
  2. avanhatt commented on Jun 11, 2021

    @avanhatt
    ContributorAuthor

    Looks like this is a slightly different issue: if you change the dereference to this, it fails as expected:

    let bad = *(f_ptr.offset(100000));
  3. self-assigned this
    on Jun 11, 2021
  4. changed the title [-]Incorrect verification success on offset from dyn trait[/-] [+]Incorrect verification success on dyn trait print statement[/+] on Jun 14, 2021
  5. changed the title [-]Incorrect verification success on dyn trait print statement[/-] [+]Incorrect verification success on print statement[/+] on Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

[C] Bug[F] Soundness

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions