-
Notifications
You must be signed in to change notification settings - Fork 180
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
Problems with multiple allocation sites #215
Comments
Hi @peckto, thanks for reaching out. Unfortunately, this is a limitation of the analysis. If I remember correctly, this is because we store the size and whether the memory is allocated in hidden variables, so from a low level perspective we see this:
Those implicit variables are then considered like normal variables by the analysis.
We could fix this by treating those variables differently than "traditional" variables. The reason you get a possible use after free warning is because the buffer overflow checker performs the checks in this order:
Here we fail at step 2 because we cannot prove that Hence there are 2 things we could improve:
|
Hi @arthaud, thank you for the detailed explanation! Taking your example: if (cond) {
data = &dynamic_alloc_line_10;
size_dynamic_alloc_line_10 = 11;
dynamic_alloc_line_10_is_allocated = true;
} else {
data = &dynamic_alloc_line_15;
size_dynamic_alloc_line_15 = 10;
dynamic_alloc_line_15_is_allocated = true;
}
memcpy(data, source, sizeof(source)); Does this mean, that after join, data points to I understand why you do the join the way you do, it's sound. Regarding the join operation, could you preserve a little bit more precession if you merge only with the values of the branches?
In this case, we don't have path sensitivity, but the approximation should still be sound? |
Yes.
Yes.
The transfer function is done by the NumericalExecutionEngine:
Yes that's what we should do, but that requires changing a bit our domains.
If we want to fix this, we need to either:
Now that I'm writing this, I realized we also have another problem, we only set the information for those |
Ah ok, that's why the problem is independent of the abstract domain. If changing the domain value space is not possible, it sounds like the "hacky logic" to handle the special situation is the best option. |
The following c code has two allocation sites for the memory referenced by pointer
data
, with different size values:When analyzing this code with IKOS, the buffer overflow bug in case of the else branch (
malloc(10)
) is not detected.Instead, IKOS reports a possible use after free and a possible double free bug:
The listed allocations sites are correct, but the memory is not freed.
(Is there any way, that IKOS reports where it thinks the free happens?)
I tried all available abstract domains (including APRON), with the same results, except
congruence
domain.With the
congruence
domain, additionally the following error is reported:Either the finding is indeed related to
data
instead ofsource
and the message is wrong, or the finding is false positive.A similar issue is #52, but in my case no pointer to int conversion happens.
When I modify the example to have only one allocation site, with two possible size values, IKOS successfully detects the bug:
I know, dynamically allocated memory is not the main priority of IKOS,
still I'm confused why it works in the one case and not in the other.
Can you describe, why this is the case?
Is this a known limitation, or a bug?
Do I need some additional analyzer options?
Or have I missed something else?
The text was updated successfully, but these errors were encountered: