acdb: fix dangling payload and stale tail references - #115
shijlin-1224 wants to merge 1 commit into
Conversation
A freed payload pointer could remain visible to concurrent readers, and removing a tail node could leave p_tail pointing to a detached list node. Invalidate freed payload pointers and update p_tail when removing the current tail node to prevent dangling references and potential heap corruption. Signed-off-by: Shijie Lin <shijlin@qti.qualcomm.com>
Qualcomm AI ReviewClick to expand Code ReviewReviewed Commits: 2e56ea9
A freed payload pointer could remain visible to Signed-off-by: Shijie Lin shijlin@qti.qualcomm.com Pull Request OverviewThis PR introduces critical bug fixes for memory management and linked list operations in the ACDB (Audio Calibration Database) software. Files Changed Summary
Key Changes
Critical Issues Identified
Overall AssessmentThe changes address important memory safety issues. However, one critical bug was introduced in the list removal logic that needs immediate attention before merge. [FUNCTIONALITY] Missing tail pointer update in AcdbListRemove - High SeverityIn the The condition Impact: This can lead to a dangling tail pointer or NULL tail pointer when the list still has elements, causing crashes or memory corruption on subsequent list operations. Fixed Code Snippet: else if (list->p_tail == node)
{
list->length--;
if (!IsNull(prev))
{
prev->p_next = NULL;
list->p_tail = prev;
}
else
{
// If prev is NULL and we're removing tail, list becomes empty or invalid
list->p_tail = NULL;
list->p_head = NULL;
}
node->p_next = NULL;
return AR_EOK;
}[SECURITY] Potential use-after-free in heap calibration data update - High SeverityIn The code should validate Impact: If Fixed Code Snippet: // Validate request data before modifying heap data
if (IsNull(req_caldata->param_payload) && req_caldata->param_size > 0)
{
ACDB_ERR("Error: Request calibration data has NULL payload with non-zero size");
continue; // Skip this update
}
// Remove old param data from heap map
heap_map->map_size -= heap_caldata->param_size;
heap_sg_data->subgraph_data_size -= heap_caldata->param_size;
heap_sg_data->non_global_data.data_size -= heap_caldata->param_size;
//Add request maps data size
heap_map->map_size += req_caldata->param_size;
heap_sg_data->subgraph_data_size += req_caldata->param_size;
heap_sg_data->non_global_data.data_size += req_caldata->param_size;
ACDB_FREE(heap_caldata->param_payload);
heap_caldata->param_payload = req_caldata->param_payload;
heap_caldata->param_size = req_caldata->param_size;
req_caldata->param_payload = NULL;
req_caldata->param_size = 0; |
A freed payload pointer could remain visible to
concurrent readers, and removing a tail node could leave p_tail pointing to a detached list node.
Invalidate freed payload pointers and update p_tail when removing the current tail node to prevent
dangling references and potential heap corruption.