Skip to content

Replace fake ZeroInit lattice with flat lattice#2035

Merged
sim642 merged 5 commits into
masterfrom
blob-zeroinit-join
May 28, 2026
Merged

Replace fake ZeroInit lattice with flat lattice#2035
sim642 merged 5 commits into
masterfrom
blob-zeroinit-join

Conversation

@sim642

@sim642 sim642 commented May 15, 2026

Copy link
Copy Markdown
Member

This is to potentially fix the issue from #2030 (comment).

The added test shows a handcrafted case where a malloc blob is joined with a calloc blob, which requires the joining of their ZeroInit values.
Previously, this raised an exception and even caused unsoundness because of the fake lattice being used.

This PR replaces that with a flat boolean lattice which can represent top.

TODO

@sim642 sim642 added this to the SV-COMP 2027 milestone May 15, 2026
@sim642 sim642 self-assigned this May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 07:57
@sim642 sim642 added bug unsound sv-comp SV-COMP (analyses, results), witnesses labels May 15, 2026
Comment on lines +911 to +914
if x = Bot then
zero_init_value t (* This should be zero initialized *)
else
x (* This already contains some value *)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This already existing logic seems suspicious: seems it could be non-monotonic and unsound that zero_init_value isn't always included.
Maybe this was fine because the malloc and calloc cases were mutually exclusive before, but now with the top possibility, I'm not so sure anymore. If an initialized malloc blob (so not bot) is joined with an uninitialized calloc blob, then this doesn't add the zero-initialization.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Extracted from SV-COMP where it even crashed instead of being unsound.
@sim642

sim642 commented May 19, 2026

Copy link
Copy Markdown
Member Author

In addition to fixing the exceptions introduced by #2030 (comment), this fixes an existing exception Lattice.TopValue verdict on ldv-linux-4.2-rc1/linux-4.2-rc1.tar.xz-43_2a-drivers--net--ethernet--mellanox--mlx5--core--mlx5_core.ko-entry_point.cil.out.
All of these happen on a memcpy which is what the second new test is about.

@sim642 sim642 removed their assignment May 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread src/framework/analyses.ml
Comment on lines 900 to +919
let zero_init_calloced_memory zeroinit x t =
if ZeroInit.is_malloc zeroinit then
(* This Blob came from malloc *)
x
else if x = Bot then
(* This Blob came from calloc *)
zero_init_value t (* This should be zero initialized *)
else
x (* This already contains some value *)
let malloc =
if ZeroInit.may_malloc zeroinit then
(* This Blob came from malloc *)
x
else
Bot
in
let calloc =
if ZeroInit.may_calloc zeroinit then (
(* This Blob came from calloc *)
if x = Bot then
zero_init_value t (* This should be zero initialized *)
else
x (* This already contains some value *)
)
else
Bot
in
join malloc calloc

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the dual of #2035 (comment).

Comment thread tests/regression/11-heap/21-blob-zeroinit-join-memcpy.c
@michael-schwarz

Copy link
Copy Markdown
Member

Can you elaborate on why calloc and malloc blobs ever need to be merged? Should we not try to keep these mutually exclusive?

@sim642

sim642 commented May 19, 2026

Copy link
Copy Markdown
Member Author

I think we've tried to keep it that way for so long and been surprisingly successful at it. The added tests show cases where such joins are already happening. In one case it caused unsoundness, in the other a crash.

I don't know how else we could fix those. I guess being path-sensitive w.r.t. the kind of allocation for each one in the state would avoid it but that can be exponentially expensive.

@sim642

sim642 commented May 20, 2026

Copy link
Copy Markdown
Member Author

I don't know how else we could fix those. I guess being path-sensitive w.r.t. the kind of allocation for each one in the state would avoid it but that can be exponentially expensive.

Another option would be to replace blobs with sets of blobs in the ValueDomain variant to keep both around. But this is a significantly bigger change because it requires lifting all the handling of blobs everywhere.
Given how rarely these actually come up in 1-3 SV-COMP tasks, I don't think it's worth the complexity.

@sim642

sim642 commented May 28, 2026

Copy link
Copy Markdown
Member Author

I left a TODO with the possibly strange behavior of top ZeroInit.
Even if it's not ideal, it's slightly better than before because it fixes some unsoundness and a crash, and allows us to make progress cleaning up/improving the memOutOfBounds analysis: #2030 (comment).

I suspect the reason a few more instances where this happens came up in #2030 is a temporary situation. While staring at memOutOfBounds I discovered another significant imprecision in it: for a given points-to-set, it joins all the pointed abstract values and all of their sizes and then does the bounds check, as opposed to checking per-pointee.
It might be that joining of the blobs corresponding to different alloc variables that triggers such situations in the first place. Once that's cleaned up it should be more precise and avoid this occurring there as well.

Although in general it might not be entirely avoidable due to mallocWrappers collapsing things, as seen in one of the tests added here.
This PR should only really change things for the handful of cases that crashed before.

@sim642 sim642 merged commit 3f5f3dd into master May 28, 2026
19 checks passed
@sim642 sim642 deleted the blob-zeroinit-join branch May 28, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug sv-comp SV-COMP (analyses, results), witnesses unsound

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants