]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pstore/ram: fix resource leak when ioremap() fails
authorCole Leavitt <cole@unwrap.rs>
Wed, 25 Feb 2026 23:54:06 +0000 (16:54 -0700)
committerKees Cook <kees@kernel.org>
Tue, 31 Mar 2026 21:52:26 +0000 (14:52 -0700)
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.

Fixes: 404a6043385d ("staging: android: persistent_ram: handle reserving and mapping memory")
Signed-off-by: Cole Leavitt <cole@unwrap.rs>
Link: https://patch.msgid.link/20260225235406.11790-1-cole@unwrap.rs
Signed-off-by: Kees Cook <kees@kernel.org>
fs/pstore/ram_core.c

index d47ba14e47bdea0dcdb93db2b8bd991ca573a2bf..05048c6f787aad101ea93ed897a5d3beb530174d 100644 (file)
@@ -487,6 +487,10 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,
        else
                va = ioremap_wc(start, size);
 
+       /* We must release the mem region if ioremap fails. */
+       if (!va)
+               release_mem_region(start, size);
+
        /*
         * Since request_mem_region() and ioremap() are byte-granularity
         * there is no need handle anything special like we do when the