-
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
[BUG] Heap-Use-After-Free in CASESession during TCP Connection Termination #36732
Labels
Comments
pidarped
added a commit
to pidarped/connectedhomeip
that referenced
this issue
Dec 17, 2024
Set the app_state callback object in the Connection state to null when the CASE session object is being cleared, on top of setting the inner callback methods to null. This prevents the callback object from being accessed later, when the connection is getting closed(after the CASE session has been set up and the session object no longer exists).
Merged
pidarped
added a commit
to pidarped/connectedhomeip
that referenced
this issue
Dec 18, 2024
Set the app_state callback object in the Connection state to null when the CASE session object is being cleared, on top of setting the inner callback methods to null. This prevents the callback object from being accessed later, when the connection is getting closed(after the CASE session has been set up and the session object no longer exists).
mergify bot
pushed a commit
that referenced
this issue
Dec 18, 2024
Set the app_state callback object in the Connection state to null when the CASE session object is being cleared, on top of setting the inner callback methods to null. This prevents the callback object from being accessed later, when the connection is getting closed(after the CASE session has been set up and the session object no longer exists).
pidarped
added a commit
to pidarped/connectedhomeip
that referenced
this issue
Jan 30, 2025
Set the app_state callback object in the Connection state to null when the CASE session object is being cleared, on top of setting the inner callback methods to null. This prevents the callback object from being accessed later, when the connection is getting closed(after the CASE session has been set up and the session object no longer exists).
andy31415
pushed a commit
that referenced
this issue
Jan 31, 2025
* TCP tests: TC-SC-8.x - Use ArmFailsafe as cmd (#37313) * TCP tests: TC-SC-8.x - Use ArmFailsafe as cmd Also add top-level pics * Fix payload capability * Fix for Bug #36732 (#36879) Set the app_state callback object in the Connection state to null when the CASE session object is being cleared, on top of setting the inner callback methods to null. This prevents the callback object from being accessed later, when the connection is getting closed(after the CASE session has been set up and the session object no longer exists). * Fix for Bug #36731. (#36880) Add CloseActiveConnections() call in TCPBase::Close(), which is called as part of Server::Shutdown(). Active connections should be closed as part of Server shutdown. This allows the TCPConnectionState to also close the associated TCPEndpoint object as part of this shutdown flow. Previously, the CloseActiveConnections() call was present in the TCPBase destructor alone. Add test for Connection Close() and checking for TCPEndPoint. --------- Co-authored-by: C Freeman <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reproduction steps
Build the
chip-tool
with AddressSanitizer (ASAN) enabled.Open Terminal 1 and start the
chip-all-clusters-app
:Open Terminal 2 and run the following commands in
chip-tool
:$ ./chip-tool interactive start $ pairing onnetwork-long 1 20202021 3840 $ basicinformation read vendor-name 1 0 --allow-large-payload 1
After the TCP session is established, terminate
chip-all-clusters-app
in Terminal 1 withCtrl+C
.Observe that
chip-tool
receives a FIN packet, triggering heap-use-after-free behavior.ASAN Log.txt
Summary
A heap-use-after-free (UAF) issue occurs when a
CASESession
object is deallocated but its callback remains referenced by theActiveTCPConnectionState
object. This issue introduces undefined behavior, potentially leading to security vulnerabilities under specific conditions.Analysis and Description
The issue arises due to a mismatch in the lifecycle management of the
CASESession
andActiveTCPConnectionState
objects. The following sequence highlights the root cause:Creation and Callback Setup:
During
CASESession::EstablishSession
, theAppTCPConnectionCallbackCtxt
structure is initialized, and itsconnClosedCb
member is set toCASESession::HandleConnectionClosed
:ActiveTCPConnectionState References CASESession:
The
ActiveTCPConnectionState
object is initialized duringTCPBase::StartConnect
, and it retains a reference to theAppTCPConnectionCallbackCtxt
structure via itsmAppState
member:activeConnection->mAppState = appState;
CASESession Deallocation:
After the CASE session is successfully established, the
CASESession
object is deallocated. However,ActiveTCPConnectionState
still holds a dangling reference to theAppTCPConnectionCallbackCtxt
structure.TCP Connection Termination:
When the TCP connection is terminated, the
ActiveTCPConnectionState
invokes theconnClosedCb
callback stored in itsmAppState
. Since the callback references the already-freedCASESession
object, a heap-use-after-free occurs:This UAF condition results from the
ActiveTCPConnectionState
lifecycle extending beyond theCASESession
lifecycle, causing undefined behavior. If the memory previously occupied by theCASESession
is overwritten with controlled data, this could lead to arbitrary code execution.Proposed Solution
CASESession
fromActiveTCPConnectionState
using proxy objects or weak references.By resolving this issue, the framework can eliminate the risk of undefined behavior and proactively mitigate potential security vulnerabilities, ensuring the robustness of the system.
If further information is needed, please do not hesitate to reach out.
Bug prevalence
always
GitHub hash of the SDK that was being used
ffbc362
Platform
core
Platform Version(s)
all versions with TCP support
Anything else?
No response
The text was updated successfully, but these errors were encountered: