You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
offset intrinsic doesn't check that pointers stay within bounds #1233
Both the starting and resulting pointer must be either in bounds or one byte past the end of the same allocated object.
At present, the standard library prevents us from adding this check because otherwise we run into spurious failures (i.e., offsets that go out-of-bounds, are frequently used).
Removing the soundness label since this is not strictly a soundness issue.
Adding this check would introduce many failures that aren't part of the user code, because offset operations often go out-of-bounds (in the standard library and other projects), but that's not an issue unless the pointer gets used. Let me illustrate with an example in C:
int*p=malloc(10);
p=p+50; // pointer has been offset 50 units (out of bounds) - not an error since the pointer is not usedintx=*p// this is an error, the index points to somewhere out of the bounds for the object
Rust allows manipulations as in line (2), so there's no soundness concerns about that. On the other hand, de-referencing the pointer in line (3) should raise an error, which Kani does.
I think we need to revisit these cases. This is a potential soundness issue since Kani would not be able to detect a pointer going out of bounds. From what I can recall, the spurious CEX would only happen for cases where the offset started from a dangling pointer and the count was 0, which is what should handle. Note that the offset documentation has been updated:
If the computed offset is non-zero, then self must be derived from a pointer to some allocated object (...)
Activity
adpaco commentedon Jul 14, 2022
Removing the soundness label since this is not strictly a soundness issue.
Adding this check would introduce many failures that aren't part of the user code, because offset operations often go out-of-bounds (in the standard library and other projects), but that's not an issue unless the pointer gets used. Let me illustrate with an example in C:
Rust allows manipulations as in line (2), so there's no soundness concerns about that. On the other hand, de-referencing the pointer in line (3) should raise an error, which Kani does.
giltho commentedon Sep 12, 2022
Do you have an example of that? The stdlib is tested with MIRI I believe, and MIRI detects creating OOB pointers as UB.
Not always, see #1665
celinval commentedon Nov 6, 2024
I think we need to revisit these cases. This is a potential soundness issue since Kani would not be able to detect a pointer going out of bounds. From what I can recall, the spurious CEX would only happen for cases where the offset started from a dangling pointer and the count was 0, which is what should handle. Note that the
offsetdocumentation has been updated:Add out of bounds check for `offset` intrinsics (#3755)