mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pstore: ram_core: fix incorrect success return when vmap() fails
@ 2026-02-03  2:03 ruipengqi
  2026-02-07  0:51 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: ruipengqi @ 2026-02-03  2:03 UTC (permalink / raw)
  To: kees; +Cc: tony.luck, gpiccoli, linux-hardening, linux-kernel, Ruipeng Qi

From: Ruipeng Qi <ruipengqi3@gmail.com>

In persistent_ram_vmap(), vmap() may return NULL on failure.

If offset is non-zero, adding offset_in_page(start) causes the function
to return a non-NULL pointer even though the mapping failed.
persistent_ram_buffer_map() therefore incorrectly returns success.

Subsequent access to prz->buffer may dereference an invalid address
and cause crashes.

Add proper NULL checking for vmap() failures.

Signed-off-by: Ruipeng Qi <ruipengqi3@gmail.com>
---
 fs/pstore/ram_core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index f1848cdd6d34..f8b9b47e8b24 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -446,6 +446,13 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
 	vaddr = vmap(pages, page_count, VM_MAP | VM_IOREMAP, prot);
 	kfree(pages);
 
+	/*
+	 * vmap() may fail and return NULL. Do not add the offset in this
+	 * case, otherwise a NULL mapping would appear successful.
+	 */
+	if (!vaddr)
+		return NULL;
+
 	/*
 	 * Since vmap() uses page granularity, we must add the offset
 	 * into the page here, to get the byte granularity address
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] pstore: ram_core: fix incorrect success return when vmap() fails
  2026-02-03  2:03 [PATCH] pstore: ram_core: fix incorrect success return when vmap() fails ruipengqi
@ 2026-02-07  0:51 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2026-02-07  0:51 UTC (permalink / raw)
  To: ruipengqi; +Cc: Kees Cook, tony.luck, gpiccoli, linux-hardening, linux-kernel

On Tue, 03 Feb 2026 10:03:58 +0800, ruipengqi wrote:
> In persistent_ram_vmap(), vmap() may return NULL on failure.
> 
> If offset is non-zero, adding offset_in_page(start) causes the function
> to return a non-NULL pointer even though the mapping failed.
> persistent_ram_buffer_map() therefore incorrectly returns success.
> 
> Subsequent access to prz->buffer may dereference an invalid address
> and cause crashes.
> 
> [...]

Applied to for-next/pstore, thanks!

[1/1] pstore: ram_core: fix incorrect success return when vmap() fails
      https://git.kernel.org/kees/c/05363abc7625

Take care,

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-02-07  0:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-03  2:03 [PATCH] pstore: ram_core: fix incorrect success return when vmap() fails ruipengqi
2026-02-07  0:51 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®