pstore/ram: fix resource leak when ioremap() fails
PATCH 1/1 pstore/ram: fix resource leak when ioremap() fails
In persistent_ram_iomap(), ioremap() or ioremap_wc() may return NULL on failure. Currently, if this happens, the function returns NULL without releasing the memory region acquired by request_mem_region().
This leads to a resource leak where the memory region remains reserved but unusable.
Additionally, the caller persistent_ram_buffer_map() handles NULL correctly by returning -ENOMEM, but without this check, a NULL return combined with request_mem_region() succeeding leaves resources in an inconsistent state.
This is the ioremap() counterpart to commit 05363abc7625 ("pstore:ram_core: fix incorrect success return when vmap() fails") which fixed a similar issue in the vmap() path.
--- fs/pstore/ram_core.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/pstore/ram_core.c +9 -0
@@ -493,6 +493,15 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,* there is no need handle anything special like we do when the * vmap() case in persistent_ram_vmap() above. */ +/* +* ioremap() may fail. Release the mem region and return NULL +* to let the caller handle the error. +*/ +if (!va) { +release_mem_region (start, size); +return NULL ; + } +return va; }
Signature · 1 line
2.52.0
Kees Cook
maintainerQuoted 8 lines · Cole Leavitt
In
persistent_ram_iomap(),ioremap()orioremap_wc()may return NULL on failure. Currently, if this happens, the function returns NULL without releasing the memory region acquired byrequest_mem_region().This leads to a resource leak where the memory region remains reserved but unusable.
[...]
Thanks! I tweaked the patch a bit and applied to for-next/pstore, thanks!
[1/1] pstore/ram: fix resource leak when ioremap() fails
https://git.kernel.org/kees/c/bb5278a89dad
Take care,
Signature · 1 line
Kees Cook