Skip to content

Replace fake ZeroInit lattice with flat lattice#2035

Open
sim642 wants to merge 4 commits into
masterfrom
blob-zeroinit-join
Open

Replace fake ZeroInit lattice with flat lattice#2035
sim642 wants to merge 4 commits into
masterfrom
blob-zeroinit-join

Conversation

@sim642
Copy link
Copy Markdown
Member

@sim642 sim642 commented May 15, 2026

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
Copy link
Copy Markdown
Member Author

sim642 commented May 19, 2026

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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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
Copy link
Copy Markdown
Member Author

sim642 commented May 19, 2026

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.

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