-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 ResolverProxy use-after-free in HandleNodeBrowse #13291
Merged
Merged
Conversation
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
pullapprove
bot
requested review from
anush-apple,
austinh0,
balducci-apple,
Byungjoo-Lee,
bzbarsky-apple,
carol-apple,
cecille,
chrisdecenzo,
chshu,
chulspro,
Damian-Nordic,
dhrishi,
electrocucaracha,
emargolis,
franck-apple,
gjc13,
hawk248,
holbrookt,
jelderton,
jepenven-silabs,
jmartinez-silabs,
LuDuda,
lzgrablic02,
mrjerryjohns,
pan-apple,
robszewczyk,
sagar-apple,
saurabhst and
selissia
December 30, 2021 14:10
pullapprove
bot
requested review from
tecimovic,
turon,
vijs,
vivien-apple,
wbschiller,
woody-apple,
xylophone21,
yufengwangca and
yunhanw-google
December 30, 2021 14:10
msandstedt
force-pushed
the
bugfix/13289
branch
from
December 30, 2021 14:15
2abaada
to
3ae2d08
Compare
PR #13291: Size comparison from 99c1985 to 3ae2d08 Increases (13 builds for efr32, k32w, linux, p6, qpg, telink)
Full report (14 builds for efr32, k32w, linux, p6, qpg, telink)
|
HandleNodeBrowse decrements the ResolverProxy reference count, which will cause the object to be destructed if the counter reaches 0. It then increments the counter and accesses the object, which can be a use-after-free. This commit fixes the problem by ordering Release to occur after Retain. This commit also adds an abort to ReferenceCounted::Retain to check for cases like this when kInitRefCount is non-zero. For objects that are initialized with a non-zero reference count, we don't ever expect to call Retain when the count has already decremented to 0 because this indicates the object has been deleted. Fixes project-chip#13289
msandstedt
force-pushed
the
bugfix/13289
branch
from
December 30, 2021 15:03
3ae2d08
to
c50811c
Compare
PR #13291: Size comparison from 99c1985 to c50811c Increases (17 builds for efr32, esp32, linux, mbed, nrfconnect, p6, qpg, telink)
Full report (31 builds for efr32, esp32, k32w, linux, mbed, nrfconnect, p6, qpg, telink)
|
mdamle
reviewed
Jan 4, 2022
andy31415
approved these changes
Jan 4, 2022
wbschiller
reviewed
Jan 4, 2022
wbschiller
approved these changes
Jan 4, 2022
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.
Looks correct to me.
saurabhst
approved these changes
Jan 4, 2022
step0035
pushed a commit
to hank820/connectedhomeip
that referenced
this pull request
Feb 8, 2022
) HandleNodeBrowse decrements the ResolverProxy reference count, which will cause the object to be destructed if the counter reaches 0. It then increments the counter and accesses the object, which can be a use-after-free. This commit fixes the problem by ordering Release to occur after Retain. This commit also adds an abort to ReferenceCounted::Retain to check for cases like this when kInitRefCount is non-zero. For objects that are initialized with a non-zero reference count, we don't ever expect to call Retain when the count has already decremented to 0 because this indicates the object has been deleted. Fixes project-chip#13289
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
HandleNodeBrowse decrements the ResolverProxy reference count, which will cause the object to be destructed if the counter reaches 0. But then it increments the counter and accesses the object, which can be a use-after-free.
Fixes #13289
Change overview
This fixes the problem by ordering Release to occur after Retain. This also adds an abort to ReferenceCounted::Retain to check for cases like this when kInitRefCount is non-zero. For objects that are initialized with a non-zero reference count, we don't ever expect to call Retain when the count has already decremented to 0 because this indicates the object has been deleted.
Testing
Tested locally with a modified chip-tool that dynamically creates and initializes ResolverProxy objects for resolve calls, and calls their Shutdown method from within the OnNodeDiscoveryComplete callback. This reliably caused segfault without the fix and did not after. Additional instrumentation was added to log reference counts during testing and it was verified that these were now as expected.
The abort that has been added for ReferenceCounted::Retain should also provide significant coverage.