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

Don't treat struct padding as invalid memory with stable-symbolic #998

Merged
merged 2 commits into from
Jun 28, 2022

Conversation

RyanGlScott
Copy link
Contributor

When laxLoadsAndStores + stable-symbolic are enabled, all allocations are backed by fresh SMT arrays. When writing a struct to one of these arrays, we traverse through the array byte-by-byte, loading each byte in the struct and updating the array's value accordingly.

Things went awry in the case where the struct has padding, however, as the code in crucible-llvm assumed that loading struct padding should always be an error. Not only is this possible with stable-symbolic, it has a sensible interpretation: whenever loading a byte of struct padding, just skip updating the array value corresponding to that byte.

See GaloisInc/saw-script#1684 for the motivation behind this bugfix. I haven't found a way to trigger the same bug with crux-llvm, but I can trigger it programatically using the crucible-llvm API. I've added a test case to the crucible-llvm test suite to ensure that the bug remains fixed.

Copy link
Contributor

@robdockins robdockins left a comment

Choose a reason for hiding this comment

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

Looks good to me! Tricky bug, good job tracking that down.

This will be required in a subsequent commit that changes the behavior of
`writeMemWithAllocationCheck` to behave differently depending on whether
`laxLoadsAndStores` is enabled or not.

This requires adding implicit constraints in several functions that did not
previously require them, so I have added mention of this in the affected
libraries' changelogs.
When `laxLoadsAndStores` + `stable-symbolic` are enabled, all allocations are
backed by fresh SMT arrays. When writing a struct to one of these arrays, we
traverse through the array byte-by-byte, loading each byte in the struct and
updating the array's value accordingly.

Things went awry in the case where the struct has padding, however, as the code
in `crucible-llvm` assumed that loading struct padding should always be an
error. Not only is this possible with `stable-symbolic`, it has a sensible
interpretation: whenever loading a byte of struct padding, just skip updating
the array value corresponding to that byte.

See GaloisInc/saw-script#1684 for the motivation behind this bugfix. I haven't
found a way to trigger the same bug with `crux-llvm`, but I can trigger it
programatically using the `crucible-llvm` API. I've added a test case to the
`crucible-llvm` test suite to ensure that the bug remains fixed.
@RyanGlScott RyanGlScott merged commit 994b4f9 into master Jun 28, 2022
@RyanGlScott RyanGlScott deleted the saw-T1684 branch June 28, 2022 12:19
RyanGlScott added a commit to GaloisInc/semmc that referenced this pull request Jun 28, 2022
This bumps the `crucible` submodule to bring in the changes from
GaloisInc/crucible#998, which adds `?memOpts :: MemOptions` constraints to
a handful of additional functions. This requires adding constraints to
some functions in `semmc-synthesis` to accommodate.

The `crucible-llvm` submodule now depends on a more recent `llvm-pretty`
submodule commit to build, so this patch also bumps the `llvm-pretty` submodule.
RyanGlScott added a commit to GaloisInc/semmc that referenced this pull request Jun 28, 2022
This bumps the `crucible` submodule to bring in the changes from
GaloisInc/crucible#998, which adds `?memOpts :: MemOptions` constraints to
a handful of additional functions. This requires adding constraints to
some functions in `semmc-synthesis` to accommodate.

The `crucible-llvm` submodule now depends on a more recent `llvm-pretty`
submodule commit to build, so this patch also bumps the `llvm-pretty` submodule.
RyanGlScott added a commit to GaloisInc/semmc that referenced this pull request Jun 28, 2022
This bumps the `crucible` submodule to bring in the changes from
GaloisInc/crucible#998, which adds `?memOpts :: MemOptions` constraints to
a handful of additional functions. This requires adding constraints to
some functions in `semmc-synthesis` to accommodate.

The `crucible-llvm` submodule now depends on a more recent `llvm-pretty`
submodule commit to build, so this patch also bumps the `llvm-pretty` submodule.
RyanGlScott added a commit to GaloisInc/macaw that referenced this pull request Jun 28, 2022
This bumps the `crucible` submodule to bring in the changes from
GaloisInc/crucible#998, which adds `?memOpts :: MemOptions` constraints to
a handful of additional functions. This requires adding constraints to
some functions in `macaw-symbolic` to accommodate, as well as bumping the
`semmc` submodule to bring in analogous changes from GaloisInc/semmc#76.
RyanGlScott added a commit to GaloisInc/macaw that referenced this pull request Jun 28, 2022
This bumps the `crucible` submodule to bring in the changes from
GaloisInc/crucible#998, which adds `?memOpts :: MemOptions` constraints to
a handful of additional functions. This requires adding constraints to
some functions in `macaw-symbolic` to accommodate, as well as bumping the
`semmc` submodule to bring in analogous changes from GaloisInc/semmc#76.
RyanGlScott added a commit to GaloisInc/saw-script that referenced this pull request Jun 28, 2022
Now that the `crucible-llvm` memory model can reason about struct padding
with `lax-loads-and-stores` enabled, bumping the `crucible` submodule to bring
in that change fixes #1684 as a consequence. I have also added a regression
test.
RyanGlScott added a commit to GaloisInc/saw-script that referenced this pull request Jun 28, 2022
Now that the `crucible-llvm` memory model can reason about struct padding
with `lax-loads-and-stores` enabled, bumping the `crucible` submodule to bring
in that change fixes #1684 as a consequence. I have also added a regression
test.
mergify bot added a commit to GaloisInc/saw-script that referenced this pull request Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants