connectedhomeip
connectedhomeip copied to clipboard
Use after free of SessionHandle with SecureSession
Problem
(revised description in light of initial investigation)
Using a heap ObjectPool
for SecureSessionTable::mEntries
lets ASAN tracking catch use-after-free:
-
SessionHandle
uses aReferenceCountedHandle
, which callsRetain()
andRelease()
on theSession
— butSecureSession
inherits theSession
default implementations, which are empty, so there is in fact no reference counting. -
~SecureSession()
(called e.g. fromExpireInactiveSessions
) does callNotifySessionReleased()
, butSessionHandle
does not register for notification, so its reference becomes stale.
Proposed Solution
Either actually reference counting or using notification to invalidate SessionHandle
s would solve the use-after-free, but have different implications for SecureSession
lifetime.
Either way, SecureSessionTable::mEntries
should be converted to a (build-configurable) ObjectPool
so that ASAN can catch regressions.
@kghost @mrjerryjohns is this still an issue?
Issue Scrub: Assigning to @kpschoedel to confirm if this is still happening.
This case can't be happening any more; the code is now using ObjectPool
, so ASAN would catch any use-after-free.