Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

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>

authored by

Cole Leavitt and committed by
Kees Cook
2ddb69f6 b22462c7

+4
+4
fs/pstore/ram_core.c
··· 487 487 else 488 488 va = ioremap_wc(start, size); 489 489 490 + /* We must release the mem region if ioremap fails. */ 491 + if (!va) 492 + release_mem_region(start, size); 493 + 490 494 /* 491 495 * Since request_mem_region() and ioremap() are byte-granularity 492 496 * there is no need handle anything special like we do when the