]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
pstore: ram_core: fix incorrect success return when vmap() fails
authorRuipeng Qi <ruipengqi3@gmail.com>
Tue, 3 Feb 2026 02:03:58 +0000 (10:03 +0800)
committerKees Cook <kees@kernel.org>
Sat, 7 Feb 2026 00:50:35 +0000 (16:50 -0800)
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>
Link: https://patch.msgid.link/20260203020358.3315299-1-ruipengqi3@gmail.com
Signed-off-by: Kees Cook <kees@kernel.org>
fs/pstore/ram_core.c

index f1848cdd6d34855f9d32986d7e8d0c407823a625..f8b9b47e8b24444fb765bea68bae70abed2816c4 100644 (file)
@@ -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