RDKB-65948: [8.6p1s2]Observed CcspLMLite Crash due to Presence Detection with Fingerprint 44028269#83
Open
im1308 wants to merge 2 commits into
Open
RDKB-65948: [8.6p1s2]Observed CcspLMLite Crash due to Presence Detection with Fingerprint 44028269#83im1308 wants to merge 2 commits into
im1308 wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent a CcspLMLite crash caused by stale (use-after-free) host instance handles being cached by the CCSP framework and later dereferenced in Host_GetParamStringValue().
Changes:
- Adds
IsValidHostHandle()to validatehInsContext(asPLmObjectHost) againstlmHosts.hostArray[]underLmHostObjectMutex. - Adds a guard in
Host_GetParamStringValue()to bail out early when a stale host handle is detected. - Updates
GetParamStringValue_common()to usestrnlen()(but this currently breaks required-size reporting semantics).
Comments suppressed due to low confidence (1)
source/lm/cosa_hosts_dml.c:156
strnlen(value, *pUlSize)breaks the TR-181/CCSP GetParamStringValue contract for required-size reporting: when the string is longer than the buffer,strnlenreturns*pUlSize, so the code only bumps*pUlSizeby 1 instead of returning the full required length. Callers that reallocate and retry once will still fail for long strings.
len = strnlen(value, *pUlSize);
if (len >= *pUlSize)
{
*pUlSize = len + 1;
rc = 1;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+170
to
+182
| /* | ||
| Generic exit processing for XXX_GetParamStringValue() functions. | ||
| If rc is 0 then return value string (or an empty string if value is NULL) | ||
| with appropriate size limit checks. Otherwise just return the value in rc | ||
| (which is expected to be -1). | ||
| */ | ||
| /* | ||
| Returns TRUE if pHost still points to a live entry in the Hosts table. | ||
| Must be called with LmHostObjectMutex held. This guards against stale | ||
| instance handles (use-after-free): the CCSP framework caches the row | ||
| handle returned by Host_GetEntry after the mutex is released, so the | ||
| entry may have been removed/reallocated before the Get*Value call runs. | ||
| */ |
Comment on lines
+184
to
+188
| static BOOL IsValidHostHandle(PLmObjectHost pHost) | ||
| { | ||
| int i; | ||
|
|
||
| if (pHost == NULL) |
This file contains hidden or 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
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.
RDKB-65948: [8.6p1s2]Observed CcspLMLite Crash due to Presence Detection with Fingerprint 44028269
RootCause and Fix:
The crash at len = strlen(value) is a stale-handle use-after-free. Host_GetEntry returns the row handle after releasing LmHostObjectMutex; the CCSP framework caches it and later calls Host_GetParamStringValue. If the LM background thread deletes/reallocates that host in between, pHost->pStringParaValue[i] is a non-NULL garbage pointer, so strlen faults. The value == NULL check can't catch it.
Adding a new helper IsValidHostHandle() to verify that the PLmObjectHost received through hInsContext still exists in lmHosts.hostArray[].
The validation is performed while holding LmHostObjectMutex, before dereferencing the host object.
If the handle is no longer valid, the function logs a warning, unlocks the mutex, and returns an error instead of dereferencing a potentially stale pointer.
Purpose: Prevent access to a stale PLmObjectHost in case the host entry was removed or replaced after Host_GetEntry() returned the handle.