Skip to content

Symex wrongly nondets local variable inherited after START_THREAD #1630

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

Closed
cesaro opened this issue Nov 27, 2017 · 2 comments
Closed

Symex wrongly nondets local variable inherited after START_THREAD #1630

cesaro opened this issue Nov 27, 2017 · 2 comments

Comments

@cesaro
Copy link
Contributor

cesaro commented Nov 27, 2017

When cbmc as in current develop is given this program:

int __CPROVER_thread_local thlocal = 4;

int test3 ()
{
  int loc;

  loc = 123;

  __CPROVER_ASYNC_3:
    thlocal = loc,
    __CPROVER_assert (thlocal == 123, "hello");
}

it finds a violation to the assertion using the following equation:

VERIFICATION CONDITIONS:

file test.c line 71 function test3
hello
[...]
{-10} __CPROVER_thread_id!0#1 == 0ul
{-11} __CPROVER_threads_exited#1 == ARRAY_OF(FALSE)
{-12} thlocal!0#1 == 4
{-13} loc!0@1#2 == 123
{-14} __CPROVER_rounding_mode!1#1 == 0
{-15} __CPROVER_thread_id!1#1 == 0ul
{-16} thlocal!1#1 == 4
{-17} main#return_value!1#1 == 0
{-18} test3#return_value!1#1 == 0
{-19} test3#return_value!0#1 == nondet_symbol(symex::nondet0)
{-20} main#return_value!0#1 == 0
{-21} return'!0#1 == 0
{-22} thlocal!1#2 == loc!1@0#0
{-23} !(__CPROVER_dead_object#1$wclk$8 >= __CPROVER_deallocated#1$wclk$8)
{-24} !(__CPROVER_deallocated#1$wclk$8 >= __CPROVER_malloc_is_new_array#1$wclk$8)
{-25} !(__CPROVER_malloc_is_new_array#1$wclk$8 >= __CPROVER_malloc_object#1$wclk$8)
{-26} !(__CPROVER_malloc_object#1$wclk$8 >= __CPROVER_malloc_size#1$wclk$8)
{-27} !(__CPROVER_malloc_size#1$wclk$8 >= __CPROVER_memory_leak#1$wclk$8)
{-28} !(__CPROVER_memory_leak#1$wclk$8 >= __CPROVER_next_thread_id#1$wclk$8)
{-29} !(__CPROVER_next_thread_id#1$wclk$8 >= __CPROVER_pipe_count#1$wclk$8)
{-30} !(__CPROVER_pipe_count#1$wclk$8 >= __CPROVER_threads_exited#1$wclk$8)
{-31} !(__CPROVER_threads_exited#1$wclk$8 >= t1$9$spwnclk$8)
|--------------------------
{1} thlocal!1#2 == 123

in which it is possible to see that the copy of variable loc in thread 1 that is being assigned to the thread-local variable thlocal is a free variable in the equation (loc!1@0#0), which therefore can be assigned any value, thus triggering the assertion violation.

Now, an almost identical code is used in the internal model of pthread_create in src/ansi-c/library to compute a thread id right before a new thread started, and pass it to the thread. There, reading a local variable (loc here, this_thread_id there) from the "host" function (test3 here, pthread_create there) rightly transfers the value from the host function (123 here) to the thread.

@tautschnig, could you explain why this mechanism works correctly in pthread_create but not here?

@tautschnig
Copy link
Collaborator

I'm not sure why this loop isn't creating a copy of loc!0 into loc!1 in your example.

@tautschnig
Copy link
Collaborator

This will be fixed once #2220 is merged - I'll add it as a regression test.

tautschnig added a commit to tautschnig/cbmc that referenced this issue Dec 1, 2018
…object

With level-2 counters incremented on declaration and non-deterministic
initialisation upon allocation, the only remaining sources are pointer
dereferencing, where uninitialised objects necessarily refer to invalid objects.

This is a cleaner implementation of 369f077. Removing only the code
introduced in 369f077 would yield a wrong result for
regression/cbmc/Local_out_of_scope3.

Fixes: diffblue#1630
tautschnig added a commit to tautschnig/cbmc that referenced this issue Dec 2, 2018
…object

With level-2 counters incremented on declaration and non-deterministic
initialisation upon allocation, the only remaining sources are pointer
dereferencing, where uninitialised objects necessarily refer to invalid objects.

This is a cleaner implementation of 369f077. Removing only the code
introduced in 369f077 would yield a wrong result for
regression/cbmc/Local_out_of_scope3.

Fixes: diffblue#1630
tautschnig added a commit to tautschnig/cbmc that referenced this issue Dec 6, 2018
…object

With level-2 counters incremented on declaration and non-deterministic
initialisation upon allocation, the only remaining sources are pointer
dereferencing, where uninitialised objects necessarily refer to invalid objects.

This is a cleaner implementation of 369f077. Removing only the code
introduced in 369f077 would yield a wrong result for
regression/cbmc/Local_out_of_scope3.

Fixes: diffblue#1630
tautschnig added a commit to tautschnig/cbmc that referenced this issue Dec 14, 2018
…object

With level-2 counters incremented on declaration and non-deterministic
initialisation upon allocation, the only remaining sources are pointer
dereferencing, where uninitialised objects necessarily refer to invalid objects.

This is a cleaner implementation of 369f077. Removing only the code
introduced in 369f077 would yield a wrong result for
regression/cbmc/Local_out_of_scope3.

Fixes: diffblue#1630
tautschnig added a commit to tautschnig/cbmc that referenced this issue Dec 19, 2018
…object

With level-2 counters incremented on declaration and non-deterministic
initialisation upon allocation, the only remaining sources are pointer
dereferencing, where uninitialised objects necessarily refer to invalid objects.

This is a cleaner implementation of 369f077. Removing only the code
introduced in 369f077 would yield a wrong result for
regression/cbmc/Local_out_of_scope3.

It also fixes the problem of extern symbols not having an initial value, and
thus being skipped.

Fixes: diffblue#1630
tautschnig added a commit to tautschnig/cbmc that referenced this issue Dec 19, 2018
…object

With level-2 counters incremented on declaration and non-deterministic
initialisation upon allocation, the only remaining sources are pointer
dereferencing, where uninitialised objects necessarily refer to invalid objects.

This is a cleaner implementation of 369f077. Removing only the code
introduced in 369f077 would yield a wrong result for
regression/cbmc/Local_out_of_scope3.

Fixes: diffblue#1630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants