Bug 295815 - mpi3mr: potential double-free of dma_desc after DATA_OUT copyin failure
Summary: mpi3mr: potential double-free of dma_desc after DATA_OUT copyin failure
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 14.4-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-06-03 11:10 UTC by Haoxiang Li
Modified: 2026-06-03 11:10 UTC (History)
0 users

See Also:


Attachments
Fix mpi3mr dma_desc double free on DATA_OUT copyin failure (428 bytes, patch)
2026-06-03 11:10 UTC, Haoxiang Li
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Haoxiang Li 2026-06-03 11:10:35 UTC
Created attachment 271441 [details]
Fix mpi3mr dma_desc double free on DATA_OUT copyin failure

In sys/dev/mpi3mr/mpi3mr_app.c, mpi3mr_map_data_buffer_dma() allocates dma_buffers->dma_desc before copying DATA_OUT payload data from userspace. If that copyin() fails, the function frees dma_buffers->dma_desc and returns an error, but leaves dma_buffers->dma_desc pointing at the freed allocation.

The caller, mpi3mr_app_mptcmds(), handles the mapping failure by jumping to its common out: cleanup path.  That path iterates over all dma_buffers entries and calls free(dma_buff->dma_desc, M_MPI3MR).  For the DATA_OUT buffer whose copyin() failed, this frees the same dma_desc allocation a second time.

I could not reproduce this with stock QEMU because QEMU does not provide an mpi3mr/SAS4116 device model, but a small logic harness that models the error path reports one double free in the buggy path.

Set dma_buffers->dma_desc to NULL after freeing it in the copyin error branch.