-
Notifications
You must be signed in to change notification settings - Fork 274
Use OBJECT_SIZE(p) for dynamic memory bounds checking #5247
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
Conversation
cbddb64
to
2129b2f
Compare
Codecov Report
@@ Coverage Diff @@
## develop #5247 +/- ##
===========================================
- Coverage 67.42% 67.41% -0.02%
===========================================
Files 1162 1162
Lines 95637 95637
===========================================
- Hits 64484 64473 -11
- Misses 31153 31164 +11
Continue to review full report at Codecov.
|
0d509c9
to
8f0f289
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say I really understand much about the code change, but the tests look robust. I assume it is already tested, but it is worth having a test using --pointer-check
and so some dynamically allocated memory?
{ | ||
int *x = malloc(2); | ||
int *y = malloc(2); | ||
assert(__CPROVER_r_ok(x, 3) == __CPROVER_r_ok(y, 3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Not sure I understand the purpose of the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was reported in issue #5194. It checks that two uses of __CPROVER_r_ok()
can return false simultaneously. Previously only one call could return false at a time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Please add to the desc file 🙂
assert(__CPROVER_r_ok(p, 2)); | ||
assert(!__CPROVER_r_ok(p, 2)); | ||
|
||
assert(__CPROVER_r_ok(p, 3)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice - not obvious so good to check it works
8f0f289
to
f1fa849
Compare
@thk123 Ok, addressed all the comments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - looks great.
regression/cbmc/r_w_ok8/test.desc
Outdated
simultaneously in the encoding of the program. Previously, at most one call | ||
could be false at a time. This was imprecise, however, it was sufficient to | ||
guarantee soundness when the __CPROVER_r_ok() primitive was used directly in an | ||
assertion (i.e., as assert(__CPROVER_r_ok(p, size)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could link to the relevant issue so people can find more context
^EXIT=10$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Still missing an explanation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one is simple enough to not need an explanation
f1fa849
to
e05d813
Compare
This changes the dynamic memory bounds checking predicate in address_check(). It now uses OBJECT_SIZE() instead of the variables __CPROVER_malloc_size and __CPROVER_malloc_object that are set in the malloc() model. This also means that the predicates __CPROVER_r_ok()/__CPROVER_w_ok() will be more precise. In the previous approach, the following assertion could not be proven for example: void main() { char *c = malloc(1); assert(!__CPROVER_r_ok(c, 2)); }
This changes the dynamic memory bounds checking predicate in
address_check()
.It now uses
OBJECT_SIZE()
instead of the variables__CPROVER_malloc_size
and__CPROVER_malloc_object
that are set in themalloc()
model. This also means thatthe predicates
__CPROVER_r_ok()
/__CPROVER_w_ok()
will be more precise. In theprevious approach, the following assertion could not be proven for example:
void main() { char *c = malloc(1); assert(!__CPROVER_r_ok(c, 2)); }