Skip to content

Conversation

@lyakh
Copy link
Collaborator

@lyakh lyakh commented Aug 21, 2025

module_adapter_free() called in lib_manager_module_free() frees the device object, dereferencing it after that is invalid and can lead to exceptions.

Copilot AI review requested due to automatic review settings August 21, 2025 13:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a use-after-free bug in the library manager module cleanup code. The issue occurs when module_adapter_free() deallocates the device object, but subsequent code attempts to access fields from the freed memory.

  • Extracts the component ID before calling module_adapter_free() to avoid dereferencing freed memory
  • Updates error logging to use the library manager tracer instead of the freed device object
  • Ensures safe cleanup sequence by accessing device data before deallocation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

{
struct processing_module *mod = comp_mod(dev);
const struct comp_ipc_config *const config = &mod->dev->ipc_config;
uint32_t component_id = mod->dev->ipc_config.id;
Copy link

Copilot AI Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component_id is extracted from mod->dev->ipc_config.id, but mod is derived from dev (comp_mod(dev)) and will also be invalidated when module_adapter_free(dev) is called. This still represents a potential use-after-free issue since mod points to memory within the dev structure that gets freed.

Copilot uses AI. Check for mistakes.
module_adapter_free() called in lib_manager_module_free() frees the
device object, dereferencing it after that is invalid and can lead to
exceptions.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
@kv2019i
Copy link
Collaborator

kv2019i commented Aug 22, 2025

FYI @softwarecki

@kv2019i kv2019i merged commit 482047f into thesofproject:main Aug 22, 2025
38 of 45 checks passed
@lyakh lyakh deleted the useafterfree branch August 22, 2025 14:14
@softwarecki
Copy link
Collaborator

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants