Skip to content

ipc4: helper: guard TLV loop against NULL from tlv_next()#10780

Merged
lgirdwood merged 2 commits into
thesofproject:mainfrom
abonislawski:fix/ipc4-tlv-null-guard
May 15, 2026
Merged

ipc4: helper: guard TLV loop against NULL from tlv_next()#10780
lgirdwood merged 2 commits into
thesofproject:mainfrom
abonislawski:fix/ipc4-tlv-null-guard

Conversation

@abonislawski
Copy link
Copy Markdown
Member

Add 'tlvs &&' to the for-loop condition in ipc4_find_dma_config_multiple(). tlv_next() returns NULL on malformed TLV (length not a multiple of 4). The existing loop condition '(uint32_t)tlvs < end_addr' does not catch NULL (0 < end_addr is always true), causing a NULL pointer dereference.

Add 'tlvs &&' to the for-loop condition in ipc4_find_dma_config_multiple().
tlv_next() returns NULL on malformed TLV (length not a multiple of 4).
The existing loop condition '(uint32_t)tlvs < end_addr' does not catch
NULL (0 < end_addr is always true), causing a NULL pointer dereference
in the next iteration via tlv_value_ptr_get() or tlv_next().

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
Copilot AI review requested due to automatic review settings May 15, 2026 09:16
Copy link
Copy Markdown
Contributor

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

Guards a TLV iteration loop against a NULL return from tlv_next() to prevent a NULL pointer dereference when parsing malformed TLVs.

Changes:

  • Add tlvs && to the for-loop condition in ipc4_find_dma_config_multiple() so the loop terminates when tlv_next() returns NULL.

Copy link
Copy Markdown
Collaborator

@lyakh lyakh left a comment

Choose a reason for hiding this comment

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

@abonislawski are other uses of tlv_next() safe or is the data there guaranteed well formed? E.g. in base_fw.c? If tlv_next() returns NULL there we'll crash too.

Add 'tlv &&' to the while-loop condition in tlv_value_get().
tlv_next() returns NULL on malformed TLV (length not a multiple of 4).
The existing condition '(uint32_t)tlv < end_addr' does not catch NULL,
causing a NULL dereference on the next iteration.

This is reachable from host IPC via copier_host_create() which parses
optional TLV data appended to the copier module configuration blob.

Signed-off-by: Adrian Bonislawski <adrian.bonislawski@intel.com>
@abonislawski
Copy link
Copy Markdown
Member Author

@lyakh yes, data in base_fw.c and base_fw_intel.c is well-formed and guaranteed by FW. But there is one more vulnerable spot in tlv_value_get() called from copier_host_create() on host IPC data, same fix applied in follow-up commit.

@lgirdwood lgirdwood merged commit 26acb54 into thesofproject:main May 15, 2026
43 of 44 checks passed
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.

5 participants