-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Check that dest
is valid for decompression
#3555
Merged
Cyan4973
merged 6 commits into
facebook:dev
from
daniellerozenblit:fix-decompress-ub-for-dstCapacity-0
Apr 1, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4a871a5
add check for valid dest buffer and fuzz on random dest ptr when mall…
daniellerozenblit 1af377b
add uptrval to linux-kernel
daniellerozenblit 6057309
Merge branch 'facebook:dev' into fix-decompress-ub-for-dstCapacity-0
daniellerozenblit 4b1771a
remove bin files
daniellerozenblit 62dd65f
get rid of uptrval
daniellerozenblit 7ca70ef
restrict max pointer value check to platforms where sizeof(size_t) ==…
daniellerozenblit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'll take it,
but note that this formulation essentially replaces
uintptr_t
bysize_t
,which implies that
sizeof(size_t) == sizeof(void*)
.This is often true, for "common" platforms, but not always.
See this comment for an example.
In this specific example, where
sizeof(void*)==16
whilesizeof(size_t)==4
,the proposed test will trigger for any address close enough to a multiple of 4 GB.
To be fair, this is a hard issue to fix "properly" (i.e. without UB), so that's why I accept this fix proposal.
Evaluating the difference between 2 addresses which are not part of the same memory segment is UB to begin with (even if it works fine in a single-plane memory addressing architecture). That makes it hard to check the distance of an address from the end of its address space.
For the same reason, a dangling pointer that randomly points anywhere in memory is also UB, even if there is a second variable that states
size == 0
. So we are trying to fix at runtime a user-side UB. No wonder it's difficult to fix without triggering UB.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.
Yeah I'm not sure of the fully correct way to solve this.
As you said, checking the distance between these two addresses is UB regardless.
I guess the major concern with my solution is that on some unusual platforms where
sizeof(size_t) == 8
butsizeof(void*) != 8
we may produce a lot of false positives. Would it be better to not check at all?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.
That's indeed the question.
It seems that your check
dstCapacity==0
should catch the issues described in #3507, and possibly #3506.In which case, maybe that's enough ?
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.
Correct, the first check catches all of the cases in #3507 and #3506.
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.
So maybe the first check is enough to fix the situation.
The second test is fine as long as
sizeof(size_t) == sizeof(void*)
,maybe that condition could be checked before triggering the second test.