Skip to content

Commit 05363ab

Browse files
Ruipeng Qikees
authored andcommitted
pstore: ram_core: fix incorrect success return when vmap() fails
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>
1 parent 9448598 commit 05363ab

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

fs/pstore/ram_core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ static void *persistent_ram_vmap(phys_addr_t start, size_t size,
446446
vaddr = vmap(pages, page_count, VM_MAP | VM_IOREMAP, prot);
447447
kfree(pages);
448448

449+
/*
450+
* vmap() may fail and return NULL. Do not add the offset in this
451+
* case, otherwise a NULL mapping would appear successful.
452+
*/
453+
if (!vaddr)
454+
return NULL;
455+
449456
/*
450457
* Since vmap() uses page granularity, we must add the offset
451458
* into the page here, to get the byte granularity address

0 commit comments

Comments
 (0)