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

Fix longjmp crash on Uninitialized #1210

Merged
merged 4 commits into from
Oct 16, 2023
Merged

Fix longjmp crash on Uninitialized #1210

merged 4 commits into from
Oct 16, 2023

Conversation

sim642
Copy link
Member

@sim642 sim642 commented Oct 9, 2023

On concrat/pigz the longjmp analysis crashes because it takes a jmp_buf out from a pthread_getspecific which currently gives top results.
This PR replaces the crash with a message and a top value.

longjmp(*buf_ptr, 1); // NO CRASH: problem?!
}
else {
__goblint_check(1); // reachable
Copy link
Member Author

Choose a reason for hiding this comment

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

The crash on longjmp is fixed but apparently this doesn't still become reachable?

Copy link
Member

Choose a reason for hiding this comment

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

Returning top here doesn't make code that is otherwise unreachable reachable iirc... I think this is a fundamental limitation that I am not sure how to address best.

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought a top jmpbuf would just jump back to every setjmp without filtering by node/context, but apparently all we do is warn:

let handle_target target = match target with
| JmpBufDomain.BufferEntryOrTop.AllTargets ->
M.warn ~category:Imprecise "Longjmp to potentially invalid target, as contents of buffer %a may be unknown! (imprecision due to heap?)" d_exp env

Maybe we should have an option to do that?

Copy link
Member

Choose a reason for hiding this comment

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

The problem is a bit where one wants to propagate things to... Just up the call stack, assuming the invocation was not UB? Also down the callstack because someone might be trying to implement co-routines? Also to completely unrelated places?
The other problem is that quite often the local state propagated somewhere because of an unknown longjmp will not be suitable for incorporation by join, as it is incorporated into an unsuitable function. This might lead to a huge precision loss.
My idea would be to leave this as is, but make this type of warning one of the severe top-level warnings that is reported separately at the end of the analysis (in the sense of #1190 ).

Copy link
Member Author

Choose a reason for hiding this comment

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

The problem is a bit where one wants to propagate things to... Just up the call stack, assuming the invocation was not UB? Also down the callstack because someone might be trying to implement co-routines? Also to completely unrelated places?

To the same places we normally do: in the same function and up the call stack. It could just be that all setjmps incorporate the unknown jump target instead of the same node and context check that normally happens. So unknown jump buffer would mean "all jumpbuffers that we normally could jump to".

The other problem is that quite often the local state propagated somewhere because of an unknown longjmp will not be suitable for incorporation by join, as it is incorporated into an unsuitable function. This might lead to a huge precision loss.

Of course it would be very imprecise, but I'm not sure if it'd cause anything incompatible per se. Ambiguous longjmps to multiple possible targets should be similar. The compatibility is ensured by each upwards propagation of the jumps doing the appropriate returns and combine_envs.

My idea would be to leave this as is, but make this type of warning one of the severe top-level warnings that is reported separately at the end of the analysis (in the sense of #1190 ).

I added that, so let's leave it at that.

Copy link
Member

@michael-schwarz michael-schwarz Oct 16, 2023

Choose a reason for hiding this comment

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

To the same places we normally do: in the same function and up the call stack.

In this case, the clean solution would be to warn and then replace the top set of possible targets with the set of legal jumptargets (which we have at hand anyway), which indeed seems reasonable and also prevents any issues with propagation to ill-suited locations.

@sim642 sim642 added this to the v2.3.0 milestone Oct 16, 2023
@sim642 sim642 merged commit 2125370 into master Oct 16, 2023
17 checks passed
@sim642 sim642 deleted the longjmp-top branch October 16, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants