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 calling convention preconditions #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nspin
Copy link
Member

@nspin nspin commented Dec 13, 2024

Before this fix, the preconditions for function calls at the assembly level were too weak. In particular, in the case of a function which returns a large value on the stack, they allowed for a return value region in high memory that wraps around 0, potentially clobbering a stack in low memory. This prevented the tool from being able to verify refinement in a few specific cases, as the SMT solver was able to find counterexamples where this clobbering happens.

This fix strengthens the preconditions to forbid such clobbering, aligning with the calling convention we are modeling.

This fix effectively changes part of the precondition from sp <= r0 && sp <= r0 + len(var_c_rets) to sp <= r0 <= r0 + len(var_c_rets). The former permits the problematic case where r0 + len(var_c_rets) < r0, whereas the latter does not.

Before this fix, the preconditions were too weak. In particular, in the
case of a function which returns a large value on the stack, they
allowed for a return value region in high memory that wraps around 0,
potentially clobbering a stack in low memory.

This fix strengthens the preconditions to forbid this.

Signed-off-by: Nick Spinale <[email protected]>
@nspin
Copy link
Member Author

nspin commented Dec 13, 2024

I know that this branch isn't under development, I just wanted to document this bug with a concrete fix.

As far as I can tell, this bug is also present in the decompilation-test branch, but I haven't been able to experiment due to other confounding bugs.

@Xaphiosis
Copy link
Member

I'd suggest a first-line of "disallow stack value return wrap-around" or something, but other than that thumbs up. Sad to hear that it sounds like there are many other confounding bugs, but nice to see improvement!

Copy link
Member

@lsf37 lsf37 left a comment

Choose a reason for hiding this comment

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

Cool, nice to see improvements on this. The style checker is complaining because the entire file is probably non-compliant. Would you mind adding a separate commit that applied the style fix?

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.

3 participants