Skip to content

Double Free Issue #41

@testfuna20230406

Description

@testfuna20230406

Overview

A double free may occur in the STM32 USBX host controller code when ux_stm32_ed_setup and ux_stm32_ed_data point to the same memory.


Step 1: Memory freed in control transfer

In ux_hcd_stm32_request_control_transfer() (file: ux_hcd_stm32_request_control_transfer.c, around line 239), the following code frees ed->ux_stm32_ed_setup:

_ux_utility_memory_free(ed -> ux_stm32_ed_setup);
ed -> ux_stm32_ed_setup = UX_NULL;

Step 2: Memory freed again in interrupt

Later, _ux_hcd_stm32_request_trans_finish() (in ux_hcd_stm32_request_trans_finish.c) is called in interrupt context.
It contains this code:

if (ed -> ux_stm32_ed_data != ed -> ux_stm32_ed_setup)
{
    _ux_utility_memory_free(ed -> ux_stm32_ed_data);
    ed -> ux_stm32_ed_data = UX_NULL;
}

However, if ed->ux_stm32_ed_data and ed->ux_stm32_ed_setup were originally the same address (e.g., 0x12345678), the same memory is freed twice:

  1. Once in request_control_transfer
  2. Once again in request_trans_finish

This causes a double free, which may lead to memory corruption or crash.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

Status
To do

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions