-
Notifications
You must be signed in to change notification settings - Fork 273
__CPROVER_w_ok is wrong with large object offsets #5096
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
Comments
I do wonder whether this actually is a bug. Pointer offsets are signed in general (in C) as subtraction from a pointer is well-defined (while within an object). That said, a negative object in CBMC's pointer representation not necessarily makes sense. @chrisr-diffblue Would you be able to kick off a discussion with @kroening to figure out whether treating offsets in the object:offset model as signed really is the intended behaviour? If it is, then users need to make sure they only use bitwidth-objectbits-1 bits for object sizes. |
Any progress? The effect of this issue is that proofs are weaker (hold for smaller objects). |
Also repair CBMC proof of HTTP AddHeaders method until there is a fix to diffblue/cbmc#5096 The key insight to removing buffer length assumptions is that the code accesses all buffers via pointers in the message headers, the code does not depend on the fact that buffers follow the message headers in memory (there is no pointer arithmetic to access the start of the buffers).
* Remove all buffer length assumptions from HTTP proofs. Also repair CBMC proof of HTTP AddHeaders method until there is a fix to diffblue/cbmc#5096 The key insight to removing buffer length assumptions is that the code accesses all buffers via pointers in the message headers, the code does not depend on the fact that buffers follow the message headers in memory (there is no pointer arithmetic to access the start of the buffers).
There is significant value in negative offsets in the representation: they enable you to neatly distinguish the case where a pointer gets decremented too much from the one where it gets incremented too much. The real fix for this issue should be to remove the limitation to anything less than the width of pointers for offsets. |
Tracked internally as ADA-566. Currently not planning to fix this as we don’t know of a reasonable way to remove this limitation. |
@hannes-steffenhagen-diffblue @markrtuttle @kroening is there any updates from this issue? Should we close it? |
The example still performs as described with cbmc 3.37, but running with the new flag --pointer-primitive-check now generates "pointer outside object bounds" errors for the value initializing the three show_buffer_* definitions at the end of the example. |
Closing as a known consequence of offsets being modeled as a signed integer. |
CBMC version: CBMC version 5.12 (cbmc-5.12-d8598f8-979-gfc0a0cd57) 64-bit x86_64 macos
Operating system: MacOS
Exact command line resulting in the issue: cbmc --object-bits 7 --32 --trace demo.c
What behaviour did you expect: verification successful
What happened instead: verification failure
The final
__CPROVER_w_ok
assertion in the attached demo.c fails when run withcbmc --object-bits 7 --32 demo.c
.The arguments to cbmc ask for the top 7 bits of a pointer to be used for the object id, and the bottom 25 bits to be used for the object offset.
The trace (summarized below) shows that the bytes
buffer_next
throughbuffer_next + length
fit within the buffer, so the assertion should be true: offset1 + length = 20125093u + 668989u = 20794082 < 25545442u = buffer_lengthIt seems significant to me that in these offsets into buffer, the top bit of the 25 offset bits is
set to 1. It surprised me that
__CPROVER_POINTER_OFFSET
displays the offset ofbuffer_next
with sign extension making to first byte 0xFF. It surprised me that the type of
__CPROVER_POINTER_OFFSET
incprover_builtin_headers.h
is__CPROVER_ssize_t
and not__CPROVER_size_t
.If I replace
with
to ensure that the top bit in all offsets is 0, then the problem goes away.
The text was updated successfully, but these errors were encountered: